:root {
  --bg: #0b0f17;
  --bg2: #121826;
  --bg3: #1a2234;
  --fg: #e8edf6;
  --muted: #9aa6bb;
  --line: #273149;
  --accent: #56b4e9;      /* Okabe-Ito sky blue */
  --accent2: #e69f00;     /* Okabe-Ito orange */
  --known: #56b4e9;
  --unknown: #ff5ccd;     /* distinct from everything else */
  --gaia: #f0e442;        /* Okabe-Ito yellow */
  --ok: #009e73;
  --warn: #e69f00;
  --err: #ff6b6b;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f6f7fb;
  --bg2: #ffffff;
  --bg3: #eef1f7;
  --fg: #141a26;
  --muted: #566176;
  --line: #d6dbe6;
  --accent: #0072b2;
  --accent2: #b36b00;
  --known: #0072b2;
  --shadow: 0 6px 20px rgba(20, 30, 60, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--font); }
body { min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; outline: none; }
a { color: var(--accent); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
button, input, select { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: #000; padding: 6px 10px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

/* ---------- top bar */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--fg); text-decoration: none; font-weight: 700; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.topbar nav a[aria-current="page"], .topbar nav a:hover { color: var(--fg); background: var(--bg3); }
.topbar-tools { display: flex; gap: 6px; }
.icon-btn { background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; min-width: 36px; min-height: 32px; }
.icon-btn[aria-pressed="true"] { border-color: var(--accent2); color: var(--accent2); }

.footer { padding: 18px 16px 28px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); text-align: center; }
.footer p { margin: 0 auto; max-width: 900px; }

/* ---------- generic */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--bg3); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--fg); min-height: 38px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04121c; border-color: var(--accent); font-weight: 650; }
[data-theme="light"] .btn.primary { color: #fff; }
.btn[aria-pressed="true"], .seg button[aria-pressed="true"] { background: var(--accent); color: #04121c; border-color: var(--accent); }
[data-theme="light"] .seg button[aria-pressed="true"] { color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); color: var(--muted); }
.pill.unknown { border-color: var(--unknown); color: var(--unknown); }
.pill.known { border-color: var(--known); color: var(--known); }
.err { color: var(--err); }
kbd { font-family: var(--mono); font-size: 12px; background: var(--bg3); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { background: var(--bg2); border: 0; border-right: 1px solid var(--line); padding: 7px 12px; cursor: pointer; min-height: 36px; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--bg3); }

/* ---------- home */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line);
  background: radial-gradient(1200px 400px at 70% -10%, rgba(86, 180, 233, .18), transparent), radial-gradient(800px 300px at 10% 110%, rgba(230, 159, 0, .12), transparent); }
.hero .wrap { padding-block: 56px 40px; display: grid; gap: 28px; grid-template-columns: 1.1fr .9fr; align-items: center; }
.hero h1 { font-size: clamp(30px, 5vw, 50px); letter-spacing: -.02em; }
.hero p.lead { font-size: 18px; color: var(--muted); max-width: 560px; }
.hero-blink { aspect-ratio: 1; width: 100%; max-width: 420px; justify-self: center; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line); background: #000; position: relative; box-shadow: var(--shadow); }
.hero-blink img { width: 100%; height: 100%; object-fit: cover; image-rendering: auto; display: block; }
.hero-blink .tag { position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 2px 8px; border-radius: 6px; font-size: 13px; }
.search { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.search input { flex: 1; min-width: 200px; padding: 11px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg2); }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.steps .n { font-size: 26px; font-weight: 800; color: var(--accent2); }
.field-card { display: flex; flex-direction: column; text-decoration: none; color: var(--fg); padding: 0; overflow: hidden; transition: transform .15s; }
.field-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.field-card img { aspect-ratio: 1; object-fit: cover; width: 100%; background: #000; display: block; }
.field-card .body { padding: 12px 14px; }
.field-card .ph { aspect-ratio: 1; display: grid; place-items: center; background: var(--bg3); color: var(--muted); }

/* ---------- field view */
.fieldview { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0; min-height: calc(100vh - 110px); }
.viewer { position: relative; background: #000; min-height: 360px; overflow: hidden; touch-action: none; }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.viewer .hud { position: absolute; left: 10px; top: 10px; right: 10px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; }
.viewer .hud > * { background: rgba(5, 8, 14, .72); color: #e8edf6; padding: 4px 10px; border-radius: 7px; font-size: 13px; pointer-events: auto; }
.viewer .frame-label { font-weight: 650; }
.viewer .readout { font-family: var(--mono); font-size: 12px; }
.viewer .zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.viewer .zoom button { background: rgba(5, 8, 14, .72); color: #fff; border: 1px solid #334; border-radius: 6px; width: 34px; height: 34px; cursor: pointer; }
.viewer .legend { position: absolute; left: 10px; bottom: 10px; background: rgba(5, 8, 14, .72); color: #e8edf6; padding: 6px 10px; border-radius: 7px; font-size: 12px; max-width: 60%; }
.viewer .legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
[hidden] { display: none !important; } /* el.hidden must win over display rules like .loading's */
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.6); color: #fff; z-index: 5; text-align: center; padding: 20px; }
.progress { width: min(360px, 80vw); height: 8px; background: #223; border-radius: 9px; overflow: hidden; margin: 10px auto; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .4s; }

.panel { border-left: 1px solid var(--line); background: var(--bg2); padding: 14px; overflow-y: auto; max-height: calc(100vh - 110px); display: flex; flex-direction: column; gap: 14px; }
.panel h2 { font-size: 18px; margin: 0; }
.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.controls { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.timeline { display: flex; flex-direction: column; gap: 6px; }
.timeline input[type=range] { width: 100%; accent-color: var(--accent); }
.ticks { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.bands button { min-width: 44px; }
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; font-size: 13px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-family: var(--mono); font-size: 12px; word-break: break-word; }
.explain { font-size: 13px; color: var(--muted); background: var(--bg3); border-radius: 8px; padding: 8px 10px; }
.cand-list { display: flex; flex-direction: column; gap: 6px; }
.cand { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: var(--bg); font-size: 13px; text-align: left; width: 100%; }
.cand:hover, .cand[aria-current="true"] { border-color: var(--accent); }
.cand .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.spec { position: relative; }
.spec canvas { width: 100%; height: 220px; display: block; background: var(--bg); border-radius: 8px; border: 1px solid var(--line); }
.spec .tip { position: absolute; pointer-events: none; background: var(--bg3); border: 1px solid var(--line); padding: 4px 8px; border-radius: 6px; font-size: 12px; display: none; max-width: 220px; z-index: 3; }

/* ---------- game */
.game { max-width: 760px; margin: 0 auto; padding: 24px 16px; text-align: center; }
.game .stage { position: relative; width: min(420px, 100%); aspect-ratio: 1; margin: 16px auto; background: #000; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.game .stage canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.game .stage .badge { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.65); color: #fff; padding: 2px 8px; border-radius: 6px; font-size: 13px; }
.answers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.answers .btn { justify-content: center; flex-direction: column; padding: 10px 6px; }
.feedback { min-height: 28px; margin-top: 10px; font-weight: 600; }

/* ---------- tour */
.tour { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.tour .card { max-width: 440px; box-shadow: var(--shadow); }
.tour .dots { display: flex; gap: 6px; justify-content: center; margin: 10px 0; }
.tour .dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.tour .dots span.on { background: var(--accent); }

#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; }

#aladin { width: 100%; height: calc(100vh - 230px); min-height: 380px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }

.prose { max-width: 760px; }
.prose h2 { margin-top: 1.6em; }
.prose figure { margin: 1em 0; }
.prose figcaption { font-size: 13px; color: var(--muted); }
.ack { font-size: 13px; background: var(--bg2); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 6px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl-wrap { overflow-x: auto; }
.thumb { width: 72px; height: 72px; image-rendering: pixelated; background: #000; border-radius: 6px; display: block; }

@media (max-width: 900px) {
  .fieldview { grid-template-columns: 1fr; }
  .viewer { min-height: 62vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .hero .wrap { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr; }
  .answers { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
