:root {
  font:
    15px/1.6 -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "PingFang SC",
    "Microsoft YaHei",
    sans-serif;
  color: #202838;
  background: #f5f1e8;
  color-scheme: light;
  --blue: #283ecb;
  --blue-dark: #1c2c9f;
  --blue-soft: #eef0fb;
  --green: #3f7f69;
  --green-soft: #eaf3ee;
  --red: #b45a40;
  --red-soft: #f8ece6;
  --text-2: #5d6474;
  --muted: #7d828d;
  --line: #e6e2d9;
  --card: #fffefb;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
[hidden] {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.shell {
  max-width: 1120px;
  margin: auto;
  padding: 0 40px;
}

/* Header */
.masthead {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}
.brand > span {
  font-size: 22px;
  font-weight: 650;
}
/* Layout */
main {
  display: grid;
  grid-template-columns: 1fr minmax(0, 520px);
  gap: 72px;
  align-items: center;
  padding: 48px 0;
}
.footer {
  border-top: 1px solid var(--line);
  padding: 18px 0 22px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
  color: #969992;
}
.footer > #admin-entry {
  color: #626b71;
}

/* Intro */
.eyebrow {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
  margin: 0 0 16px;
}
h1 {
  font-family: Georgia, "Noto Serif CJK SC", "Songti SC", serif;
  font-weight: 500;
  font-size: 56px;
  letter-spacing: 1px;
  line-height: 1.35;
  margin: 0 0 16px;
}
h1 span {
  color: var(--blue);
}
.lead {
  font-size: 15px;
  line-height: 1.9;
  color: var(--text-2);
  margin: 0;
}
.art {
  position: relative;
  width: 260px;
  height: 220px;
  display: grid;
  place-items: center;
  margin: 12px 0;
}
.art img {
  position: relative;
  transform: rotate(-8deg);
  filter: drop-shadow(0 18px 24px #283ecb12);
}
.orbit {
  position: absolute;
  border: 1px solid #d9d6ce;
  width: 250px;
  height: 160px;
  border-radius: 50%;
  transform: rotate(-35deg);
}
.orbit:after {
  content: "";
  position: absolute;
  top: 18px;
  left: 22px;
  width: 8px;
  height: 8px;
  background: #e76b42;
  border: 4px solid #f5f1e8;
  box-sizing: content-box;
  border-radius: 50%;
}
.notes {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
}
.notes li {
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.notes li:before {
  content: "";
  flex: none;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--blue);
  opacity: 0.55;
  transform: translateY(-2px);
}

/* Session panel */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow:
    0 1px 2px #2028380a,
    0 18px 48px #2028380d;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid #efece5;
}
.steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #9a9ea8;
  white-space: nowrap;
}
.steps li {
  display: flex;
  align-items: center;
  gap: 7px;
}
.steps li + li:before {
  content: "";
  width: 18px;
  height: 1px;
  background: #dcd9d1;
  margin-right: 1px;
}
.step-mark {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #d6d4ce;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.steps .active {
  color: var(--blue);
  font-weight: 600;
}
.steps .active .step-mark {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.steps .done {
  color: var(--text-2);
}
.steps .done .step-mark {
  border-color: var(--green);
  color: transparent;
  position: relative;
}
.steps .done .step-mark:after {
  content: "";
  position: absolute;
  width: 5px;
  height: 9px;
  border: solid var(--green);
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-1px) rotate(45deg);
}
#expiry {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stage {
  display: flex;
  flex-direction: column;
  min-height: 340px;
  padding: 30px 28px 24px;
}
.stage-icon {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  margin-bottom: 18px;
  background: var(--blue-soft);
  color: var(--blue);
  display: grid;
  place-items: center;
}
.stage-icon:after {
  content: "→";
  font-size: 20px;
  line-height: 1;
}
.stage[data-tone="live"] .stage-icon:after {
  content: "";
  border-radius: 50%;
  border: 2px solid;
  width: 18px;
  height: 18px;
  border-color: #283ecb33;
  border-top-color: currentColor;
  animation: spin 0.9s linear infinite;
}
.stage[data-tone="success"] .stage-icon {
  background: var(--green-soft);
  color: var(--green);
}
.stage[data-tone="success"] .stage-icon:after {
  content: "";
  border: solid;
  width: 7px;
  height: 13px;
  border-radius: 0;
  border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg);
}
.stage[data-tone="error"] .stage-icon {
  background: var(--red-soft);
  color: var(--red);
}
.stage[data-tone="error"] .stage-icon:after {
  content: "!";
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
}
@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}
h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.3px;
  line-height: 1.4;
  margin: 0 0 6px;
}
#stage-text {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-2);
  margin: 0;
  min-height: 3.5em;
}
.result-box {
  margin-top: 14px;
}
.result-box textarea {
  display: block;
  width: 100%;
  height: 92px;
  resize: none;
  border: 1px solid #e6e8ef;
  border-radius: 10px;
  background: #f7f8fb;
  color: inherit;
  padding: 12px 14px;
  font: 12px/1.7 var(--mono);
  overflow-wrap: anywhere;
}
.result-box textarea:focus {
  outline: 2px solid #283ecb20;
  border-color: #7583d8;
}
#notice {
  min-height: 20px;
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--red);
}
.stage-actions {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
}
.stage-actions > * {
  flex: 1;
}
.stage-actions .secondary {
  order: 2;
  flex: 0 0 auto;
  min-width: 96px;
}
.stage-actions:not(:has(.primary:not([hidden]))) .secondary {
  flex: 1;
}
.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 10px 28px;
  border-top: 1px solid #efece5;
  background: #fbf9f4;
  font-size: 13px;
  color: var(--muted);
}
.helper-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
#helper-status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Controls */
.status-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #adafae;
}
.status-dot.live {
  background: var(--blue);
  box-shadow: 0 0 0 4px #283ecb14;
}
.status-dot.success {
  background: #4a8873;
}
.status-dot.error {
  background: #c46b52;
}
button,
a {
  touch-action: manipulation;
}
button {
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 10px;
  padding: 0 18px;
  min-height: 46px;
  border: 1px solid transparent;
  transition:
    background 0.2s,
    border-color 0.2s,
    color 0.2s;
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
.primary {
  background: var(--blue);
  color: #fff;
  font-weight: 500;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
.primary:hover:not(:disabled) {
  background: var(--blue-dark);
}
.secondary {
  background: transparent;
  color: var(--text-2);
  border-color: #dfe0e5;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
.secondary:hover:not(:disabled) {
  background: #f5f4f0;
}
.text-button {
  background: none;
  color: var(--muted);
  padding: 4px 2px;
  min-height: 32px;
  font-size: 13px;
  white-space: nowrap;
}
.text-button:hover:not(:disabled) {
  color: var(--blue);
}
.text-button.accent {
  color: var(--blue);
  font-weight: 500;
}
.chip {
  display: inline-flex;
  align-items: center;
  flex: none;
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid #d5daf3;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}
.chip:hover {
  border-color: #aab4e6;
}
label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin: 16px 0 8px;
}
input {
  font: inherit;
  font-size: 14px;
  width: 100%;
  height: 46px;
  border: 1px solid #e1e2e6;
  border-radius: 10px;
  padding: 0 14px;
  background: #fff;
  color: inherit;
  transition: border-color 0.2s;
}
input::placeholder {
  color: #a0a3ac;
}
input:focus {
  outline: 2px solid #283ecb20;
  border-color: #7583d8;
}
button:focus-visible,
a:focus-visible,
dialog:focus-visible {
  outline: 2px solid #7583d8;
  outline-offset: 3px;
}
.actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.actions > * {
  flex: 1;
}
.actions .secondary {
  flex: 0 0 auto;
  min-width: 80px;
}
.description {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-2);
  margin: 0 0 16px;
}

/* Dialogs */
dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 28px 28px;
  color: inherit;
  background: var(--card);
  box-shadow: 0 24px 100px #20283826;
}
dialog::backdrop {
  background: #18213855;
  backdrop-filter: blur(4px);
}
body:has(dialog[open]) {
  overflow: hidden;
}
.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 20px;
}
.dialog-heading h2 {
  font-size: 18px;
  margin: 0;
}
.close-dialog {
  font-size: 24px;
  line-height: 1;
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 0 10px;
  margin-right: -10px;
}
.close-dialog:hover {
  background: #f3f1ec;
}
.install-steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 0 0 18px;
  display: grid;
  gap: 10px;
}
.install-steps li {
  counter-increment: step;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #eeebe4;
  border-radius: 12px;
  background: #faf8f3;
  font-size: 14px;
  line-height: 1.6;
}
.install-steps li:before {
  content: counter(step);
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
}
.install-steps li > span {
  flex: 1;
  min-width: 0;
}
.install-steps code {
  font-family: var(--mono);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.description.note {
  font-size: 13px;
  color: var(--muted);
}
.dialog-foot {
  display: flex;
  align-items: center;
  gap: 14px;
}
.helper-dialog-status {
  flex: 1;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}
.helper-dialog-status[data-state="ok"] {
  color: var(--green);
}
.helper-dialog-status[data-state="error"] {
  color: var(--red);
}
.dialog-foot .primary {
  flex: none;
  min-width: 120px;
}

/* Device dialog */
.device-state {
  color: var(--blue);
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 14px;
}
.device-counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 0 14px;
}
.device-counts div {
  background: #f8f6f1;
  border: 1px solid #eeebe4;
  padding: 14px 8px;
  text-align: center;
  border-radius: 12px;
}
.device-counts dt {
  font-size: 13px;
  color: var(--muted);
}
.device-counts dd {
  margin: 2px 0 0;
  font-size: 28px;
  font-weight: 500;
  color: #283650;
  font-variant-numeric: tabular-nums;
}
#device-hint {
  min-height: 26px;
  margin-bottom: 4px;
}
.device-refresh {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
#device-updated {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#registration-notice {
  min-height: 22px;
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 22px;
  color: #936044;
}
.registration-success {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--green);
  font-size: 17px;
  font-weight: 500;
  margin: 14px 0 4px;
}
.registration-success:before {
  content: "✓";
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--green-soft);
  font-size: 13px;
}
.registered-id {
  font: 16px var(--mono);
  letter-spacing: 1px;
  margin: 0;
}
#registered-device-key {
  font-family: var(--mono);
}
#register-another-device {
  margin-top: 10px;
}

/* Desktop: keep the whole page in one viewport. */
@media (min-width: 901px) and (min-height: 620px) {
  .shell {
    height: 100dvh;
    display: flex;
    flex-direction: column;
  }
  .masthead,
  .footer {
    flex: none;
  }
  main {
    flex: 1;
    min-height: 0;
    padding: 20px 0;
  }
}
@media (min-width: 901px) and (max-height: 800px) {
  .masthead {
    height: 64px;
  }
  h1 {
    font-size: 48px;
  }
  .art {
    height: 170px;
    margin: 4px 0;
  }
  .art img {
    width: 140px;
    height: 140px;
  }
  .orbit {
    width: 210px;
    height: 130px;
  }
  .stage {
    min-height: 300px;
    padding-top: 24px;
  }
  .footer {
    padding: 12px 0 14px;
  }
}
@media (min-width: 901px) and (max-height: 680px) {
  .art {
    display: none;
  }
  .notes {
    margin-top: 24px;
  }
}

/* Tablet & mobile */
@media (max-width: 900px) {
  .shell {
    padding: 0 24px;
  }
  main {
    grid-template-columns: 1fr;
    gap: 28px;
    padding: 32px 0 40px;
  }
  .intro {
    position: relative;
  }
  h1 {
    font-size: 44px;
  }
  .art {
    position: absolute;
    right: 0;
    top: 10px;
    width: 180px;
    height: 160px;
    margin: 0;
  }
  .art img {
    width: 130px;
    height: 130px;
  }
  .orbit {
    width: 180px;
    height: 110px;
  }
  .notes {
    margin-top: 22px;
  }
  .panel {
    width: 100%;
    max-width: 620px;
  }
}
@media (max-width: 660px) {
  .shell {
    padding: 0 16px;
  }
  .masthead {
    height: 64px;
  }
  .brand img {
    width: 34px;
    height: 34px;
  }
  .brand > span {
    font-size: 20px;
  }

  main {
    padding: 24px 0 28px;
    gap: 22px;
  }
  .eyebrow {
    font-size: 10px;
    letter-spacing: 1.4px;
    margin-bottom: 10px;
  }
  h1 {
    font-size: 36px;
    margin-bottom: 10px;
  }
  .lead {
    font-size: 13px;
    max-width: 240px;
  }
  .art {
    width: 120px;
    height: 120px;
    top: 24px;
    right: -4px;
  }
  .art img {
    width: 92px;
    height: 92px;
  }
  .orbit {
    width: 120px;
    height: 76px;
  }
  .orbit:after {
    top: 6px;
    left: 12px;
    width: 5px;
    height: 5px;
    border-width: 3px;
  }
  .notes {
    display: none;
  }
  .panel {
    border-radius: 16px;
  }
  .panel-head {
    flex-wrap: wrap;
    padding: 14px 18px;
    row-gap: 6px;
  }
  .steps {
    font-size: 12px;
    gap: 6px;
  }
  .steps li + li:before {
    width: 10px;
  }
  .stage {
    min-height: 320px;
    padding: 24px 18px 18px;
  }
  h2 {
    font-size: 20px;
  }
  .panel-foot {
    padding: 8px 18px;
  }
  input {
    font-size: 16px;
  }
  .footer > span:nth-child(2) {
    display: none;
  }
  .install-steps li {
    flex-wrap: wrap;
  }
  .install-steps li > span {
    flex-basis: calc(100% - 36px);
  }
  .install-steps .chip {
    margin-left: 36px;
  }
  dialog {
    padding: 20px 20px 24px;
  }
}
@media (max-width: 360px) {
  .brand {
    gap: 6px;
  }
  h1 {
    font-size: 32px;
  }
  .art {
    opacity: 0.8;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation-duration: 3s !important;
  }
}

#devices-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: 85vh;
}
#register-device-form {
  margin-top: 16px;
}
#device-registration .description {
  margin: 12px 0;
}
#device-registration-result {
  padding: 16px;
  background: #f1f7f4;
  border: 1px solid #dce8df;
  border-radius: 12px;
  margin-top: 18px;
}

.cdk-field {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #faf9f5;
}
.cdk-field label {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.cdk-input-wrap {
  position: relative;
}
.cdk-input-wrap svg {
  position: absolute;
  top: 15px;
  left: 14px;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #8a91a8;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
#cdk-code {
  height: 50px;
  padding-left: 44px;
}
#cdk-hint {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
#cdk-settings {
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
  margin-bottom: 20px;
}

@media (max-width: 640px) {
  .cdk-field {
    padding: 12px;
  }
  #cdk-code {
    font-size: 13px;
  }
}

.verify-source {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.source-number {
  flex: none;
  color: var(--muted);
  font: 12px var(--mono);
}
.source-input {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 13px;
}
.source-remove {
  flex: none;
}
.source-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.source-test {
  flex: none;
  color: var(--blue);
}
#cdk-test-address {
  overflow-wrap: anywhere;
}
#cdk-test-result {
  min-height: 44px;
  margin: 14px 0;
  font-size: 13px;
  line-height: 22px;
}
#cdk-test-result[data-state="available"] {
  color: var(--green);
}
#cdk-test-result[data-state="error"],
#cdk-test-result[data-state="unavailable"] {
  color: var(--red);
}
@media (max-width: 640px) {
  .verify-source {
    flex-wrap: wrap;
    gap: 8px;
  }
  .source-input {
    flex-basis: calc(100% - 32px);
  }
  .source-test {
    margin-left: 24px;
  }
}

.admin-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 12px 0 24px;
  background: #f3f2ee;
  border: 1px solid var(--line);
  border-radius: 11px;
}
.admin-tabs button {
  flex: 1;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  font-size: 13px;
}
.admin-tabs button[aria-selected="true"] {
  background: var(--card);
  color: var(--blue);
  box-shadow: 0 1px 4px #20283810;
}

#registration-notice[data-tone="success"] { color: var(--green); }
