:root {
  color-scheme: light;
  --ink:#222529; --muted:#596067; --paper:#fff; --green:#303840;
  --border:#dadddf; --soft:#f4f5f5; --raised:#fff; --pressed:#24292d;
  --button-ink:#fff; --map-panel:rgba(255,255,255,.96); --foot:rgba(255,255,255,.85);
}
:root[data-theme="dark"] {
  color-scheme:dark;
  --ink:#eef0f1; --muted:#b5bdc3; --paper:#191c20; --green:#e4e9ed;
  --border:#3c4249; --soft:#24282e; --raised:#2c3137; --pressed:#ecedef;
  --button-ink:#191c20; --map-panel:rgba(32,36,41,.96); --foot:rgba(26,30,35,.88);
}
header,aside,.mapcard,.tools button,.field select,.field input,.diagram,.coord,.primary,.secondary,.fact,.seg,.answers button {
  border-color:var(--border);
}
header {background:var(--paper);border-bottom:1px solid var(--border);color:var(--ink)}
.brand,.tagline,.about-btn,.how .ic,.brand-text,.textbtn,.fieldgroup label {color:var(--ink)}
.brand svg {filter:grayscale(1)}
.nav-actions{display:flex;align-items:center;gap:12px}
#theme {display:grid;place-items:center;width:34px;height:34px;border:1px solid var(--border);border-radius:7px;color:var(--ink);background:var(--paper)}
.mapcard,.tools button {background:var(--map-panel);color:var(--ink)}
.tools{top:14px;left:14px;right:auto;display:flex;flex-direction:column;gap:7px}
.tools button{width:34px;height:34px;box-shadow:0 1px 5px #0002}
.control-group button{font-size:20px;line-height:1}
.tip{left:58px;top:14px}
.mapfoot{background:var(--foot);color:var(--muted)}#scale{border-color:var(--muted)}
.primary{background:var(--pressed);color:var(--button-ink)}
.secondary,.diagram,.fact,.seg,.answers button,.progress{background:var(--soft)}
.seg button[aria-pressed=true],.field select,.field input{background:var(--raised);color:var(--ink)}
.diagram svg{filter:grayscale(1)}[data-theme=dark] .diagram svg{filter:grayscale(1) invert(.9)}
.section-label:before,.progress i{background:var(--green)}
.resultkey .guess-symbol{width:15px;height:24px}
.station-total{font-size:14px;color:var(--muted)}
.coord,.how,.under,.source,.meta,.how .ic{color:var(--muted)}
@media(max-width:760px){.tools{top:10px;left:10px}.nav-actions{gap:5px}header{padding:0 10px}.tip{left:51px;top:10px}}
.detail-trigger {display:none}

@media (max-width:760px), (max-height:520px) and (max-width:960px) and (orientation:landscape) {
  body {--gutter:max(14px,env(safe-area-inset-left));--right:max(14px,env(safe-area-inset-right))}
  header {height:calc(52px + env(safe-area-inset-top));padding:env(safe-area-inset-top) var(--right) 0 var(--gutter);gap:4px}
  .brand {gap:7px;min-width:0}
  .brand svg {width:30px;height:30px;flex:none}
  .brand-text {display:block;text-align:left;min-width:0}
  .brand strong,.tagline {display:block;line-height:1.3}
  .brand strong {font-size:16px}
  .tagline {font-size:12px;letter-spacing:0}
  .nav-actions {gap:2px;flex:none}
  #theme,.about-btn,.close {min-width:44px;min-height:44px}
  #theme {border:0}
  .about-btn {gap:4px;white-space:nowrap}
  .tools {left:max(8px,env(safe-area-inset-left));top:8px;gap:6px}
  .tools button {width:44px;height:44px}
  .tip {left:60px;top:8px}
  .legend {left:max(8px,env(safe-area-inset-left));bottom:24px;display:flex;align-items:center;gap:6px;padding:4px 6px;pointer-events:none}
  .legend-head {gap:3px;font-size:12px}
  .legend-head small {font-size:10px}
  .levels {margin:0;gap:2px}
  .levels img {width:clamp(14px,3.9vw,19px);height:auto}
  .mapfoot {padding-inline:var(--gutter) var(--right)}
  aside {padding:12px var(--right) max(12px,env(safe-area-inset-bottom)) var(--gutter)}
  .round-heading,.result-actions,.action-row {display:flex;align-items:center;justify-content:space-between;gap:8px}
  .round-heading {min-height:44px}
  .section-label {letter-spacing:.04em}
  .round-heading .section-label:before {display:none}
  .detail-trigger {display:inline-flex;align-items:center;min-height:44px;padding:0 3px;color:var(--muted);font-size:14px;gap:6px}
  .detail-trigger::after {content:"";width:6px;height:6px;border-top:1.5px solid;border-right:1.5px solid;transform:rotate(45deg)}
  #panel h2 {font-size:clamp(19px,5vw,24px);margin:0 0 8px;line-height:1.35}
  .play-title,.play-help,.progress,.clue-notes > :first-child,#quit,.catalog,.event-time {display:none}
  .facts {margin:0 0 8px}
  .clues {grid-template-columns:repeat(4,minmax(0,1fr))}
  .fact {padding:6px clamp(5px,2vw,12px)}
  .fact b {font-size:clamp(17px,4.7vw,22px);line-height:1.35}
  .fact small {font-size:12px;margin-left:2px}
  .fact span {font-size:13px}
  .coord {padding:0;border:0;font:13px/1.4 system-ui,sans-serif;font-variant-numeric:tabular-nums}
  .primary {min-height:46px}
  .action-row .primary,.result-actions .primary {width:auto;min-width:108px;flex:none;margin:0;padding:8px 12px}
  .result-keys {display:flex;flex-wrap:wrap;gap:3px 10px}
  .resultkey {margin:0;white-space:nowrap}
  .resultkey img {width:17px;height:18px}
  .resultkey .guess-symbol {width:12px;height:20px}
  dialog {padding:16px;width:min(460px,calc(100vw - 24px));max-height:85dvh;overscroll-behavior:contain}
  dialog select,.field select {min-height:44px;font-size:16px}
  .textbtn,.seg button,.answers button {min-height:44px}
}
@media (max-width:760px) {
  main {min-height:0}
  .map {height:32svh;min-height:160px}
  body:is([data-stage="play"],[data-stage="answer"],[data-stage="review"]) main {
    height:calc(100dvh - 52px - env(safe-area-inset-top));
    display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) auto;
  }
  body:is([data-stage="play"],[data-stage="answer"],[data-stage="review"]) .map {height:auto;min-height:0;max-height:none}
  body:is([data-stage="play"],[data-stage="answer"],[data-stage="review"]) aside {max-height:50dvh;min-height:0;overflow:auto;padding-top:0}
  body[data-stage="summary"] .map {display:none}
}
@media (orientation:landscape) and (max-height:520px) and (max-width:960px) {
  main,body:is([data-stage="play"],[data-stage="answer"],[data-stage="review"]) main {
    display:grid;height:calc(100dvh - 52px - env(safe-area-inset-top));min-height:0;
    grid-template-columns:minmax(0,1fr) minmax(264px,38%);grid-template-rows:minmax(0,1fr);
  }
  .map {height:auto;min-height:0;max-height:none}
  body[data-stage] aside {overflow:auto;max-height:none;padding-top:0;border-top:0;border-left:1px solid var(--border)}
  body[data-stage="summary"] .map {display:block}
  .legend {gap:4px}
  .levels img {width:14px}
  .clues {grid-template-columns:repeat(2,minmax(0,1fr))}
}
