:root {
  color-scheme: dark;
  --bg: #0b1120;
  --top: #0b1525;
  --tab: #101d2e;
  --surface: #102036;
  --edge: #2c435b;
  --edge-strong: #385873;
  --text: #f1f6fb;
  --muted: #a5b7ca;
  --quiet: #859db5;
  --cyan: #5de5ec;
  --cyan-text: #071e27;
  --cyan-fade: #12323e;
  --gold: #facc15;
  --north: #ff6266;
  --south: #65a8ff;
  --good: #72ecd4;
  --warning: #ff9b8e;
  font: 400 14px/1.5 "PingFang SC", "Microsoft YaHei UI", "Noto Sans CJK SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 315px; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .44; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid #e1feff; outline-offset: 3px;
}
[hidden] { display: none !important; }
a { color: #86ddf2; text-underline-offset: 3px; }

.masthead {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 9px clamp(14px, 2vw, 29px);
  border-bottom: 1px solid var(--edge);
  background: var(--top);
}
.identity { display: flex; align-items: center; min-width: 0; gap: 19px; }
.brand-symbol {
  flex: 0 0 49px;
  height: 42px;
  border: 1px solid #54d9e7;
  border-radius: 7px;
  display: grid;
  place-content: center;
  position: relative;
  color: #62e4ec;
}
.brand-symbol i {
  z-index: 1;
  position: absolute;
  inset: 8px 7px;
  border: 1px solid currentColor;
  border-radius: 50%;
  transform: rotate(-27deg) scale(.84,.64);
  box-shadow: inset 0 0 6px #53e4f130;
}
.brand-symbol i:nth-child(2) { transform: rotate(27deg) scale(.84,.64); }
.brand-symbol i:nth-child(3) { transform: rotate(90deg) scale(.69,.74); }
.brand-symbol b { width: 5px; height: 5px; border-radius: 50%; background: currentColor; box-shadow: 0 0 9px currentColor; }
h1 { margin: 0; font-size: clamp(20px, 2.2vw, 32px); font-weight: 750; letter-spacing: -.035em; white-space: nowrap; }
.grade { color: #c3d0df; border-left: 1px solid #607183; padding-left: 16px; white-space: nowrap; letter-spacing: .06em; }
.mode-button {
  flex-shrink: 0;
  min-height: 40px;
  border: 1px solid #53dfe9;
  padding: 6px 14px;
  border-radius: 7px;
  color: var(--cyan);
  background: #091e29;
  font-weight: 650;
}
.mode-button span { padding-left: 4px; font-size: 1.08em; }
.mode-button:hover, .mode-button[aria-pressed="true"] { background: #173744; color: #c9feff; }
.tabbar {
  display: flex;
  overflow-x: auto;
  scrollbar-width: thin;
  min-height: 51px;
  background: var(--tab);
  border-bottom: 1px solid var(--edge-strong);
  padding-inline: 13px;
}
.tabbar button {
  flex: 0 0 clamp(142px, 18vw, 225px);
  min-height: 48px;
  position: relative;
  color: #c6d3e1;
  background: transparent;
  border: 0;
  font-weight: 570;
  font-size: clamp(14px, 1.45vw, 20px);
  letter-spacing: .015em;
}
.tabbar button:hover { background: #192a3f; color: var(--text); }
.tabbar button[aria-pressed="true"] { color: #f5fdff; font-weight: 700; }
.tabbar button[aria-pressed="true"]::after {
  content: "";
  height: 3px;
  inset: auto 0 0;
  position: absolute;
  background: var(--cyan);
  box-shadow: 0 -2px 13px #43d8ed24;
}
.tabbar button:focus-visible { outline-offset: -5px; }

.workspace {
  height: calc(100svh - 162px);
  min-height: 545px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 27.4vw, 405px);
  gap: 13px;
  padding: 13px;
}
.stage {
  overflow: hidden;
  isolation: isolate;
  position: relative;
  min-width: 0;
  background: radial-gradient(ellipse at 51% 53%, #152e49 0%, #0b182b 53%, #070e1c 100%);
  border: 1px solid var(--edge-strong);
  border-radius: 12px;
}
.stage[data-result="correct"] { border-color: #5bae9f; }
.stage[data-result="incorrect"] { border-color: #a66160; }
.viewport, .label-layer {
  overflow: hidden;
  position: absolute;
  inset: 0;
}
.viewport canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.viewport canvas:active { cursor: grabbing; }
.label-layer { pointer-events: none; }
.stage-heading {
  position: absolute;
  z-index: 2;
  max-width: calc(100% - 126px);
  top: clamp(16px, 2.1vw, 26px);
  left: clamp(16px, 2.2vw, 30px);
  padding-left: 18px;
  pointer-events: none;
}
.stage-heading::before {
  content: "";
  position: absolute;
  background: var(--cyan);
  width: 4px;
  height: 25px;
  border-radius: 2px;
  top: 4px;
  left: 0;
  box-shadow: 0 0 12px #54dfea45;
}
.stage-heading h2 { margin: 0; font-size: clamp(23px, 2.25vw, 34px); letter-spacing: -.02em; line-height: 1.13; }
.stage-heading p { margin: 8px 0 0; color: #bdcddd; font-size: clamp(12px, 1.2vw, 16px); }
.stage-status {
  position: absolute;
  top: 20px;
  right: 18px;
  z-index: 2;
  max-width: 29%;
  padding: 5px 9px;
  border: 1px solid #47748a;
  background: #102437e8;
  border-radius: 5px;
  color: #c2e6f1;
  font-size: 12px;
  pointer-events: none;
  text-align: center;
}
.stage-bottom {
  position: absolute;
  inset: auto 17px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 2;
  pointer-events: none;
}
.legend, .view-controls { display: flex; align-items: center; gap: 13px; }
.legend {
  background: #0a1727d6;
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 13px;
  color: #c6d4e2;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend b { display: inline-block; font-size: 22px; line-height: 1; }
.legend-current { color: var(--gold); }
.legend-field { color: var(--cyan); }
.legend .legend-needle {
  width: 20px; height: 9px;
  background: linear-gradient(90deg, #4188e4 0 50%, #f1646b 50%);
  clip-path: polygon(0 50%, 50% 0, 100% 50%, 50% 100%);
}
.view-controls { gap: 8px; }
.view-controls button {
  pointer-events: auto;
  display: grid;
  place-items: center;
  border: 1px solid #53798e;
  border-radius: 7px;
  width: 44px;
  height: 40px;
  color: #e3f5ff;
  background: #0b1c2bdc;
  font: 24px/1 system-ui, sans-serif;
}
.view-controls button:hover { background: #214357; }
.stage:fullscreen { border-radius: 0; border: 0; width: 100%; height: 100%; }
.workspace.wide { grid-template-columns: minmax(0, 1fr); }
.workspace.wide .inspector { display: none; }
.loading { position: absolute; top: 49%; inset-inline: 12%; text-align: center; color: var(--muted); }
.scene-label {
  border: 1px solid #577b94;
  background: #102134f2;
  color: #ebf6ff;
  border-radius: 5px;
  box-shadow: 0 2px 12px #060c18a8;
  white-space: nowrap;
  user-select: none;
  padding: 1px 6px;
  font-size: 12px;
  font-weight: 640;
  line-height: 1.45;
}
button.scene-label {
  appearance: none;
  pointer-events: auto;
  min-width: 30px;
  min-height: 28px;
  padding-inline: 7px;
}
button.scene-label:hover { filter: brightness(1.28); }
.scene-label.pole, .scene-label.north, .scene-label.south {
  min-width: 27px;
  padding: 1px 6px;
  text-align: center;
  font: 750 17px/1.4 ui-monospace, monospace;
}
.scene-label.north, .scene-label.positive { border-color: #ff8784; background: #8e2b38; color: #fff2f4; }
.scene-label.south, .scene-label.negative { border-color: #81b6ff; background: #1d4a93; color: #f1f7ff; }
.scene-label.positive, .scene-label.negative, .scene-label.undecided { font-size: 17px; }
.scene-label.current { color: #ffe88d; border-color: #806d36; background: #231f16eb; }
.scene-label.probe, .scene-label.target, .scene-label.reading {
  color: #bff3fa;
  border-color: #3e9cae;
  background: #0d2936ed;
}
.scene-label.target { border-style: dashed; }
.scene-label.reading { font: 650 15px/1.5 ui-monospace, monospace; }
.scene-label.detail, .scene-label.cardinal { padding: 1px 5px; color: #d8eaf6; font-weight: 560; }
.scene-label.control-side, .scene-label.work-side { padding: 4px 8px; font-weight: 660; letter-spacing: .045em; }
.scene-label.control-side { color: #f6d7a4; border-color: #a38153; }
.scene-label.work-side { color: #bcddff; border-color: #5a89aa; }
.scene-label.scale-mark, .scene-label.cardinal {
  padding: 0 3px;
  font-size: 10px;
  border: 0;
  background: #122438e0;
}

.inspector {
  overflow: auto;
  min-width: 0;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #36556d #091322;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel {
  flex: 0 0 auto;
  min-width: 0;
  padding: 13px 16px 15px;
  border-radius: 12px;
  border: 1px solid var(--edge-strong);
  background: linear-gradient(155deg, #13263be8, #101f33eb 63%, #101d30ec);
  backdrop-filter: blur(13px);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  padding-bottom: 9px;
  border-bottom: 1px solid #3a536b;
}
.panel-header h2 { margin: 0; font-size: clamp(19px, 1.7vw, 24px); letter-spacing: -.02em; }
.fold {
  color: #abc7d9;
  background: none;
  border: 0;
  padding: 4px 2px 4px 6px;
  font-size: 12px;
}
.fold:hover { color: #f0fdff; }
.control-row { padding: 9px 0; border-bottom: 1px solid #314960; }
.control-row.inline, .control-title { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.control-row p, .small-note { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.control-title { font-weight: 590; }
.secondary, .segment, .hint, .choice, .step, .rig-button {
  border: 1px solid #49647d;
  border-radius: 6px;
  color: #e0edf8;
  background: #122338;
  font-weight: 580;
  min-height: 35px;
  padding: 5px 9px;
  transition: color .15s, border-color .15s, background .15s;
}
.secondary:hover, .segment:hover, .hint:hover, .choice:hover, .step:hover, .rig-button:hover {
  border-color: #7fb2c6; background: #1b374b;
}
.segment[aria-pressed="true"], .hint[aria-pressed="true"], .choice[aria-pressed="true"],
.step[aria-current="step"], .rig-button[aria-pressed="true"] {
  border-color: #69e7ee;
  background: var(--cyan-fade);
  color: #a8ffff;
}
.segment { min-width: 0; line-height: 1.24; }
.segments, .choices, .answer-actions, .probe-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.segments > button, .choices > button { flex: 1 1 auto; }
.segments { margin-top: 6px; }
.primary {
  border: 1px solid #70eff3;
  border-radius: 7px;
  min-height: 40px;
  padding: 7px 13px;
  color: var(--cyan-text);
  background: #62e1e9;
  font-weight: 760;
  letter-spacing: .01em;
}
.primary:not(:disabled):hover { background: #90f6fa; box-shadow: 0 0 15px #52ecf630; }
.main-action { width: 100%; margin-top: 11px; }
.primary[aria-pressed="true"] {
  color: #bbffff;
  background: #143541;
}
.primary[aria-pressed="true"]:hover { background: #214958; }
.switch {
  display: inline-flex;
  align-items: center;
  flex: 0 0 47px;
  width: 47px;
  height: 25px;
  padding: 2px;
  border: 1px solid #586c80;
  border-radius: 20px;
  background: #3b4e62;
  transition: background .18s;
}
.switch::before { content: ""; width: 18px; height: 18px; border-radius: 50%; background: #f7fcff; transition: transform .18s; }
.switch[aria-checked="true"] { background: #42cbd6; border-color: #6becf3; }
.switch[aria-checked="true"]::before { transform: translateX(21px); }
.number { font: 620 13px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; font-variant-numeric: tabular-nums; }
.output {
  border: 1px solid #4a657d;
  border-radius: 5px;
  color: #effaff;
  padding: 2px 6px;
  min-width: 48px;
  text-align: center;
  background: #0e1e30;
}
.range {
  width: 100%;
  height: 21px;
  padding: 0;
  margin: 5px 0 0;
  accent-color: #61dee8;
  cursor: pointer;
}
.range-endpoints { display: flex; justify-content: space-between; color: var(--quiet); font-size: 11px; }
.readings { display: grid; grid-template-columns: 1fr auto; column-gap: 9px; row-gap: 6px; margin: 10px 0; align-items: baseline; }
.readings dt { color: #aec0d1; }
.readings dd { margin: 0; font-weight: 650; text-align: right; }
.north-ink { color: var(--north); }
.south-ink { color: var(--south); }
.good-ink { color: #68eeb0; }
.warning-ink { color: #ff8985; }
.lab-note { padding-top: 8px; border-top: 1px solid #38516a; margin: 10px 0 0; color: #c5d6e6; font-size: 13px; }
.probe-actions { margin-top: 9px; }
.probe-actions .secondary { min-height: 30px; font-size: 12px; padding: 3px 7px; }

.question-panel { padding-bottom: 14px; }
.question-count { color: #a2ccdf; white-space: nowrap; }
.steps { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 11px 0; }
.step { padding-inline: 0; min-height: 31px; font-size: 13px; }
.step[data-solved="true"]:not([aria-current="step"]) { color: var(--good); border-color: #3a8e82; }
.prompt { margin: 10px 0 12px; color: #e3edf7; font-size: 14px; line-height: 1.75; }
.choice-group { margin-top: 8px; border: 0; padding: 0; min-width: 0; }
.choice-group legend { padding: 0; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.choice { min-height: 34px; }
.hints { margin-top: 11px; }
.hints h3 { margin: 0 0 5px; font-weight: 650; font-size: 13px; color: #b8d5e7; }
.hint-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.hint { min-width: 0; padding-inline: 4px; font-size: 12px; }
.hint-note { margin: 7px 0 0; padding: 7px 8px; border-left: 2px solid #59d8e4; background: #103240a8; color: #cfe9f0; font-size: 12px; }
.answer-status { margin-top: 11px; border: 1px solid #628ca4; background: #182f43; border-radius: 7px; padding: 8px 10px; }
.answer-status strong { color: #dceef9; }
.answer-status p { margin: 2px 0 0; font-size: 13px; color: #d7e6f1; }
.answer-status.correct { border-color: #468c83; background: #112f32; }
.answer-status.correct strong { color: var(--good); }
.answer-status.incorrect { border-color: #aa6d68; background: #3a222b; }
.answer-status.incorrect strong { color: var(--warning); }
.answer-actions { margin-top: 8px; }
.answer-actions button { flex: 1; min-height: 34px; }
.source { margin: 10px 0 0; color: var(--muted); font-size: 11px; }
.rigs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; pointer-events: auto; }
.rig-button { font-size: 12px; min-height: 29px; padding: 3px 8px; }

.footer {
  min-height: 42px;
  padding: 8px clamp(14px, 2vw, 29px);
  border-top: 1px solid var(--edge);
  color: #aebfd1;
  background: #0c1726;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.pole-key { white-space: nowrap; }
.pole-key b { margin: 0 3px 0 11px; font: 700 14px ui-monospace, monospace; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(265px, 32%); gap: 9px; padding: 9px; }
  .panel { padding-inline: 12px; }
  .grade { display: none; }
  .tabbar button { flex: 1 0 126px; }
  .stage-status { right: 12px; top: 15px; }
}
@media (max-width: 680px) {
  :root { --mobile-stage-height: clamp(285px, 46svh, 480px); scroll-padding-top: calc(var(--mobile-stage-height) + 12px); }
  .masthead { min-height: 58px; gap: 6px; padding: 8px 10px; }
  .identity { gap: 8px; }
  .brand-symbol { flex-basis: 33px; height: 32px; }
  .brand-symbol i { inset: 6px 3px; }
  h1 { font-size: clamp(13px, 3.95vw, 22px); }
  .mode-button { min-height: 34px; padding: 4px 7px; font-size: 11px; }
  .mode-button span { display: none; }
  .tabbar { min-height: 40px; padding-inline: 4px; }
  .tabbar button { min-height: 40px; flex: 1 0 auto; font-size: clamp(11px, 3.3vw, 14px); padding-inline: 7px; }
  .workspace { min-height: 0; height: auto; display: flex; flex-direction: column; gap: 9px; padding: 8px; }
  .stage { position: sticky; top: 0; z-index: 3; height: var(--mobile-stage-height); flex-shrink: 0; }
  .stage:fullscreen { position: relative; }
  .stage-heading { max-width: calc(100% - 82px); left: 12px; top: 15px; padding-left: 12px; }
  .stage-heading::before { height: 18px; width: 3px; }
  .stage-heading p { margin-top: 4px; }
  .stage-status { top: 12px; right: 8px; padding: 3px 5px; font-size: 10px; max-width: 25%; }
  .stage-bottom { inset: auto 8px 8px; }
  .legend { gap: 6px; padding: 5px 6px; font-size: 10px; }
  .legend b { font-size: 18px; }
  .legend span { gap: 3px; }
  .legend .legend-needle { width: 15px; }
  .view-controls { gap: 5px; }
  .view-controls button { width: 36px; height: 34px; font-size: 20px; }
  .inspector { overflow: visible; gap: 8px; }
  .scene-label { font-size: 10px; padding: 1px 4px; }
  .scene-label.north, .scene-label.south { font-size: 13px; min-width: 19px; }
  .scene-label.scale-mark { font-size: 8px; }
  .scene-label.control-side, .scene-label.work-side { padding: 2px 4px; }
  .scene-label.reading { font-size: 11px; }
  .hand-direction-label { translate: 13px 14px; }
  .footer { min-height: 36px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}
