/* Signal Station — styles. Dark illustrated sci-fi, calm, high legibility. */
:root {
  color-scheme: dark;
  --bg: #0b1220; --bg2: #0f1829; --panel: #131e32; --panel2: #1a2a43; --line: #2b3f5e;
  --text: #e8eef8; --muted: #aebcd2; --accent: #4fd1c5; --accent-ink: #04211f; --accent-dim: #1b5a57;
  --gold: #f0b429; --good: #6ee7a8; --warn: #ffcf70; --bad: #ff8f8f; --focus: #ffe08a;
  --radius: 14px; --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}
:root[data-accent="amber"]  { --accent: #f0b429; --accent-ink: #261a00; --accent-dim: #6b4f0d; }
:root[data-accent="violet"] { --accent: #b9a2ff; --accent-ink: #1a1233; --accent-dim: #473b78; }
:root[data-accent="rose"]   { --accent: #ff9db0; --accent-ink: #330c16; --accent-dim: #7a3041; }
:root.high-contrast { --bg: #000; --bg2: #000; --panel: #0a0a0a; --panel2: #141414; --line: #fff; --text: #fff; --muted: #fff; --focus: #ffff00; }
:root.high-contrast .card, :root.high-contrast .btn, :root.high-contrast input[type=text], :root.high-contrast textarea { border-width: 2px; border-color: #fff; }
:root.large-text { font-size: 118%; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
:root.reduce-motion html, :root.reduce-motion * { scroll-behavior: auto !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
body { margin: 0; background: radial-gradient(1200px 600px at 80% -10%, #16284a 0%, transparent 60%), var(--bg); color: var(--text); font: 1rem/1.55 var(--font); min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 8px 16px 40px; }
main:focus { outline: none; }
h1 { font-size: clamp(1.5rem, 3.2vw, 2.1rem); line-height: 1.2; margin: 0.2em 0 0.5em; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; margin: 0 0 0.5em; font-weight: 650; }
h3 { font-size: 1rem; margin: 0.8em 0 0.3em; }
p { margin: 0 0 0.8em; }
h1:focus, h2:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 8px; z-index: 50; font-weight: 600; }
.skip:focus { top: 8px; }
.fine { color: var(--muted); font-size: 0.9rem; }
.eyebrow { color: var(--accent); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; margin: 0; font-weight: 600; }
.lede { font-size: 1.1rem; color: var(--text); max-width: 62ch; }

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(11, 18, 32, 0.85); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(6px); }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: 0.02em; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.mission-label { color: var(--muted); font-size: 0.9rem; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { margin-left: auto; display: flex; gap: 8px; }
.foot { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 18px 16px 28px; max-width: 70ch; margin: 0 auto; }

/* ---- generic ---- */
.card { background: linear-gradient(180deg, var(--panel), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin: 14px 0; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); }
.card.note { border-color: var(--accent-dim); background: linear-gradient(180deg, #14253b, var(--bg2)); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.col { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.btn { font: inherit; font-weight: 600; color: var(--text); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; text-align: center; text-decoration: none; transition: background 0.15s, transform 0.1s; }
.btn:hover:not(:disabled) { background: #223654; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: #3a1820; border-color: #7a2f3d; color: #ffd6dc; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.link { font: inherit; background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 2px 0; text-align: left; }
input[type=text], select, textarea { font: inherit; background: #0a1322; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; min-height: 44px; }
input[type=text]:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--focus); }
textarea { width: 100%; min-height: 90px; }
label { cursor: default; }
.field { margin: 14px 0; border: 0; padding: 0; }
.field label, .field legend { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
.msg { min-height: 1.4em; color: var(--warn); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; inset: 0; }
.swatch span { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 2px solid var(--line); font-weight: 600; }
.swatch.s-teal span { background: #1b5a57; } .swatch.s-amber span { background: #6b4f0d; } .swatch.s-violet span { background: #473b78; } .swatch.s-rose span { background: #7a3041; }
.swatch input:checked + span { border-color: var(--text); box-shadow: 0 0 0 2px var(--accent) inset; }
.swatch input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.toggle { display: flex; gap: 10px; align-items: center; padding: 8px 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.chip-sm { display: inline-block; margin-left: 10px; font-size: 0.78rem; padding: 1px 9px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); font-weight: 600; }
.chip-sm.sug { background: var(--accent-dim); color: var(--text); }

/* ---- welcome / hero ---- */
.welcome { max-width: 680px; margin: 32px auto; }
.hero .pip-line { display: flex; gap: 16px; align-items: center; }
.pip-icon { width: 56px; height: 56px; flex: none; }
.pip-body { fill: #24395a; stroke: var(--accent); stroke-width: 2; }
.pip-eye { fill: #0a1322; stroke: var(--gold); stroke-width: 2; }
.pip-glint { fill: var(--gold); }
.pip-ant, .pip-arm { stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.pip-tip { fill: var(--gold); }

/* ---- station ---- */
.dest { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.dest-card { text-align: left; font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-height: 96px; }
.dest-card.rec { border-color: var(--accent); }
.dest-card:hover { background: #223654; }
.dest-card small { color: var(--muted); }
.map-wrap { overflow-x: auto; }
.station-svg { width: 100%; height: auto; max-height: 440px; display: block; }
.station-svg .sky { fill: #070d19; }
.station-svg .star { fill: #7f93b5; opacity: 0.6; }
.station-svg .corridor { fill: #223654; }
.station-svg .module-body { fill: var(--panel2); stroke: var(--accent); stroke-width: 2; stroke-opacity: calc(0.25 + var(--lit, 0) * 0.75); }
.station-svg .restored .module-body { fill: #1d3452; }
.station-svg .module-title { fill: var(--text); font: 600 17px var(--font); }
.station-svg .module-count { fill: var(--muted); font: 14px var(--font); }
.station-svg .lamp { fill: #2a3a52; }
.station-svg .lamp.on { fill: var(--gold); filter: drop-shadow(0 0 4px var(--gold)); }
.station-svg .feature { fill: #172338; stroke: var(--line); }
.station-svg .feature.on { fill: var(--accent); stroke: transparent; opacity: 0.85; }
.station-svg .module-later { fill: transparent; stroke: var(--line); stroke-dasharray: 6 6; }
.station-svg .later-title { fill: var(--muted); font: 600 15px var(--font); }
.station-svg .later-sub { fill: var(--muted); font: 13px var(--font); }
.station-svg .decor { fill: var(--accent-dim); stroke: var(--accent); stroke-width: 1.5; }
.rooms { padding-left: 1.2em; }
.plain summary, .chapter summary, .rec summary { cursor: pointer; padding: 6px 0; }
.decor-choice { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 6px; }
.skills { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.skills li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 8px 12px; background: var(--panel2); border-radius: 10px; border: 1px solid var(--line); }
.sk-name { font-weight: 600; min-width: 16ch; }
.sk-status { font-size: 0.9rem; }
.st-ready .sk-status { color: var(--good); } .st-worth .sk-status { color: var(--warn); } .st-revisited .sk-status { color: var(--accent); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--muted); display: inline-block; }
.dots i.on { background: var(--good); border-color: var(--good); }
.chapter { border-top: 1px solid var(--line); padding: 8px 0; }
.chapter.later { color: var(--muted); }
.mlist { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 2px; }
.done-mark { color: var(--good); font-size: 0.85rem; }
.rec { border-left: 3px solid var(--accent-dim); padding-left: 12px; margin: 8px 0; }
.rec.locked { color: var(--muted); }
.rec.new { border-left-color: var(--gold); background: #1a2438; padding: 8px 12px; border-radius: 0 8px 8px 0; }
.sum-list { padding-left: 1.2em; }

/* ---- mission ---- */
.mhead { margin-top: 10px; }
.grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(260px, 1fr); gap: 18px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } .mission-label { display: none; } }
.stage { min-width: 0; }
.side .card { margin-top: 0; }
.pip-bubble { display: flex; gap: 12px; align-items: flex-start; background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin: 12px 0; }
.pip-bubble p { margin: 0; align-self: center; }
.pip-bubble .pip-icon { width: 44px; height: 44px; }
.pip-bubble.warn { border-color: #8a6a1f; background: #2a2314; }
.pip-bubble.good { border-color: #2f7d58; background: #12281f; }
.pip-bubble.info { border-color: var(--accent-dim); }
.workbench, .inputitem, .combine, .build, .diagnose, .choiceitem { background: linear-gradient(180deg, var(--panel), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.eq { text-align: center; padding: 10px 0; overflow-x: auto; overflow-y: hidden; }
.eq math { font-size: clamp(1.6rem, 4vw, 2.4rem); }
.eqmini { display: inline-block; }
.eq-text { font: 600 1.8rem var(--mono); }
.eqmini math { font-size: 1.5rem; }
.unknown { text-align: center; color: var(--muted); margin: 0 0 12px; }
.panels { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; margin: 10px 0 4px; }
.pcol { min-width: 0; display: flex; flex-direction: column; }
.plabel { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 4px; }
.wire { display: flex; align-items: center; justify-content: center; position: relative; min-width: 38px; }
.wire::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 3px solid var(--accent-dim); }
.wire span { position: relative; background: var(--panel); padding: 2px 6px; font-size: 1.6rem; color: var(--accent); font-weight: 700; }
@media (max-width: 520px) { .panels { grid-template-columns: 1fr; } .wire { min-height: 30px; } .wire::before { left: 50%; right: auto; top: 0; bottom: 0; border-top: 0; border-left: 3px solid var(--accent-dim); } }
.balance { text-align: center; color: var(--muted); font-size: 0.92rem; margin: 6px 0 10px; }
.tpanel { border: 2px solid var(--accent-dim); border-radius: 12px; padding: 10px; min-height: 84px; background: rgba(79, 209, 197, 0.04); flex: 1; }
.tpanel-body { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.zp-note { display: block; color: var(--muted); margin-top: 6px; font-size: 0.8rem; }
.tile { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; border-radius: 8px; user-select: none; transition: transform 0.35s, opacity 0.35s; }
.tile.x { width: 44px; height: 44px; background: var(--accent); color: var(--accent-ink); font-size: 1.15rem; }
.tile.unit { width: 30px; height: 30px; background: var(--gold); color: #2a1d00; font-size: 0.8rem; border-radius: 6px; }
.tile.chip { background: var(--panel2); border: 1px dashed var(--muted); padding: 6px 10px; }
.tile.bundle { background: var(--gold); color: #2a1d00; padding: 6px 12px; height: 34px; }
.tile.neg { background: transparent; border: 2px solid currentColor; }
.tile.x.neg { color: var(--accent); }
.tile.unit.neg { color: var(--gold); }
.tile.bundle.neg { color: var(--gold); }
.tile.zp { outline: 2px dashed var(--text); outline-offset: 2px; }
.tile.cancel { transform: scale(0.2); opacity: 0; }
.tile.sliced { width: auto; padding: 0; overflow: hidden; display: inline-flex; border-radius: 8px; }
.tile.sliced i { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 44px; font-style: normal; border-right: 2px solid rgba(0, 0, 0, 0.35); }
.tile.sliced i:last-child { border-right: 0; }
.slice-wrap { display: inline-flex; flex-direction: column; gap: 2px; }
.slice-wrap small, .group small { color: var(--muted); font-size: 0.75rem; }
.group { border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; background: rgba(255, 255, 255, 0.03); }
.group-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.group-box { border: 2px solid var(--accent-dim); border-radius: 8px; padding: 4px; display: flex; flex-wrap: wrap; gap: 4px; min-width: 40px; }
.ops { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 12px; margin: 14px 0 8px; }
.ops legend { padding: 0 8px; font-weight: 600; }
.opbtns { display: flex; flex-wrap: wrap; gap: 8px; }
.opbtn { position: relative; }
.opbtn input { position: absolute; opacity: 0; inset: 0; }
.opbtn span { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel2); font-weight: 600; cursor: pointer; }
.opbtn input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.opbtn input:checked + span::before { content: "\2713\00a0"; }
.opbtn input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.kline { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.kline label { font-weight: 600; }
.kline input { width: 7.5ch; text-align: center; font-size: 1.1rem; }
.preview { margin: 10px 0 0; padding: 8px 12px; background: #0a1322; border-radius: 8px; border-left: 4px solid var(--line); font-family: var(--mono); font-size: 0.95rem; overflow-wrap: anywhere; min-height: 2.6em; }
.preview.ok { border-left-color: var(--good); }
.preview.blocked, .preview.format { border-left-color: var(--warn); color: var(--warn); font-family: var(--font); }
.simp { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0 4px; padding: 6px; border-radius: 12px; }
.simp .lbl { font-weight: 600; color: var(--muted); margin-right: 4px; }
.tools { margin-top: 6px; }
.check { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin-top: 12px; padding: 10px 6px 4px; border-top: 1px dashed var(--line); border-radius: 12px; }
.check label { font-weight: 600; }
.check input { width: 9ch; }
.spotlight { outline: 2px solid var(--gold); outline-offset: 4px; animation: glow 2.2s ease-in-out infinite; }
@keyframes glow { 50% { outline-color: transparent; } }
:root.reduce-motion .spotlight { animation: none; }
.nl-box { margin: 10px 0; }
.numline { margin: 8px 0; }
.numline-svg { width: 100%; max-width: 560px; height: auto; display: block; }
.numline .axis { stroke: var(--muted); stroke-width: 2; }
.numline .tick { stroke: var(--muted); stroke-width: 1.5; }
.numline .tick.zero { stroke: var(--text); stroke-width: 3; }
.numline .tlabel { fill: var(--text); font: 12px var(--font); }
.numline .jump, .numline .jump-head { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.numline .dot.start { fill: var(--gold); } .numline .dot.end { fill: var(--accent); }
.numline figcaption { color: var(--muted); font-size: 0.9rem; }
.choices { border: 0; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.choices legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.choice { display: flex; align-items: center; gap: 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; cursor: pointer; min-height: 48px; }
.choice input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.choice:has(input:checked) { border-color: var(--accent); background: #20385a; }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice.tried { opacity: 0.5; text-decoration: line-through; cursor: not-allowed; }
.log { list-style: none; padding: 0; margin: 4px 0 8px; display: grid; gap: 6px; }
.log li { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; background: #0a1322; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.lineno { font-weight: 700; color: var(--accent); min-width: 5ch; }
.did { color: var(--muted); }
.answer { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.answer label { font-weight: 600; }
.answer input[type=text] { width: 12ch; font-size: 1.15rem; }
.combine .answer input[type=text] { width: 6ch; text-align: center; }
.answer .fine { flex-basis: 100%; margin: 0; }
.scratch { margin-top: 14px; }
.hint { background: #14233a; border-left: 4px solid var(--accent); border-radius: 0 8px 8px 0; padding: 8px 12px; }
.hist ol { margin: 6px 0 0; padding-left: 1.3em; }
.hist li { margin-bottom: 4px; font-family: var(--mono); font-size: 0.88rem; overflow-wrap: anywhere; }
.hist summary { cursor: pointer; font-weight: 650; }
.done h2 { color: var(--good); }
.reward { background: #12281f; border: 1px solid #2f7d58; border-radius: 12px; padding: 4px 16px 8px; margin: 12px 0; }
.reward h3 { margin-top: 8px; }

/* ---- dialogs ---- */
.dlg { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); padding: 18px 20px; width: min(560px, calc(100vw - 24px)); max-height: 90vh; overflow: auto; }
.dlg::backdrop { background: rgba(3, 7, 14, 0.7); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.dlg-head h2 { margin: 0; }
.calc { display: grid; gap: 8px; }
.calc input, .calc select { width: 100%; }
.calc-out { font-size: 1.2rem; font-weight: 650; margin: 8px 0 0; }

/* ---- high contrast + motion tweaks ---- */
:root.high-contrast .tile.x { background: #00ffe0; } :root.high-contrast .tile.unit { background: #ffd400; }
:root.high-contrast .btn.primary { background: #00ffe0; color: #000; }
:root.high-contrast .station-svg .module-body { stroke-opacity: 1; }
@media (prefers-contrast: more) { :root { --line: #6f86ad; --muted: #d0dbed; } }
@media print { .topbar, .foot { display: none; } }
