:root {
  --panel: rgba(12, 27, 56, 0.82);
  --panel-solid: #0c1b38;
  --edge: rgba(160, 210, 255, 0.22);
  --ink: #eef6ff;
  --ink-dim: #9fb6d6;
  --accent: #ffd60a;
  --accent-2: #4cc9f0;
  --danger: #ff5d5d;
  --radar: #3dff8b;
  --shadow: 0 10px 30px rgba(0, 8, 30, 0.35), 0 2px 0 rgba(255, 255, 255, 0.05) inset;
  --font-head: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  --font-body: 'Nunito', ui-rounded, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #071226; color: var(--ink); font-family: var(--font-body); }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; }
body.hide-ui #topbar, body.hide-ui #story, body.hide-ui #right, body.hide-ui #timeline,
body.hide-ui #controls-hint, body.hide-ui #settings { opacity: 0; pointer-events: none; }

.panel {
  background: var(--panel);
  border: 1.5px solid var(--edge);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; font-family: var(--font-head); font-weight: 600; font-size: 15px; letter-spacing: 0.02em; margin-bottom: 8px; }
.pill { background: rgba(255, 214, 10, 0.16); color: var(--accent); border-radius: 999px; padding: 2px 10px; font-weight: 700; font-family: var(--font-head); font-variant-numeric: tabular-nums; }
.btn { background: linear-gradient(180deg, #ffe156, #ffc300); color: #2b2100; border: none; border-radius: 12px; padding: 8px 16px; font-family: var(--font-head); font-weight: 700; box-shadow: 0 4px 0 #b88a00, 0 6px 14px rgba(0,0,0,.25); transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b88a00; }
.btn.ghost { background: rgba(255, 255, 255, 0.08); color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.btn.big { font-size: 20px; padding: 12px 26px; }
.btn:disabled { opacity: .35; pointer-events: none; }
.icon-btn { background: rgba(255,255,255,.08); border: 1.5px solid var(--edge); border-radius: 12px; width: 40px; height: 40px; font-size: 20px; display: grid; place-items: center; }
.icon-btn.small { width: 28px; height: 28px; font-size: 13px; border-radius: 9px; }
.icon-btn:hover { background: rgba(255,255,255,.16); }

/* ---------- top bar */
#topbar { position: fixed; top: 14px; left: 16px; right: 16px; display: flex; align-items: center; justify-content: space-between; gap: 16px; pointer-events: none; transition: opacity .3s; z-index: 5; }
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1.5px solid var(--edge); border-radius: 16px; padding: 8px 14px 8px 10px; box-shadow: var(--shadow); }
.brand-title { font-family: var(--font-head); font-weight: 700; font-size: 18px; letter-spacing: 0.08em; }
.brand-sub { font-size: 12px; color: var(--ink-dim); margin-top: -2px; }
.logo { position: relative; width: 32px; height: 32px; border-radius: 50%; background: radial-gradient(circle, #0b3d2a 0 60%, #062016 61%); border: 2px solid var(--radar); overflow: hidden; flex: none; }
.logo.big { width: 72px; height: 72px; margin: 0 auto 10px; border-width: 3px; }
.logo-ring { position: absolute; inset: 0; background: conic-gradient(from 0deg, rgba(61,255,139,.75), rgba(61,255,139,0) 30%); animation: sweep 2.4s linear infinite; border-radius: 50%; }
.logo-dot { position: absolute; width: 18%; height: 18%; left: 62%; top: 28%; background: var(--danger); border-radius: 50%; box-shadow: 0 0 8px var(--danger); }
@keyframes sweep { to { transform: rotate(360deg); } }

#steps { display: flex; gap: 6px; background: var(--panel); border: 1.5px solid var(--edge); border-radius: 999px; padding: 5px; box-shadow: var(--shadow); }
.step { display: flex; align-items: center; gap: 7px; border: none; background: transparent; border-radius: 999px; padding: 6px 12px 6px 6px; font-family: var(--font-head); font-weight: 600; font-size: 13px; color: var(--ink-dim); white-space: nowrap; }
.step .n { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.1); font-size: 12px; }
.step.active { background: var(--accent); color: #2b2100; }
.step.active .n { background: rgba(0,0,0,.15); }
.step.locked { opacity: .45; cursor: not-allowed; }
.step.locked .n::after { content: ''; }
.step:not(.locked):not(.active):hover { background: rgba(255,255,255,.08); color: var(--ink); }

/* ---------- story card */
#story { position: fixed; left: 16px; top: 86px; width: 340px; padding: 18px 18px 14px; transition: opacity .3s, transform .4s; z-index: 4; }
.story-kicker { font-family: var(--font-head); font-weight: 700; color: var(--accent); font-size: 13px; letter-spacing: .12em; }
#story-of { color: var(--ink-dim); margin-left: 4px; }
#story h1 { font-family: var(--font-head); font-weight: 700; font-size: 26px; line-height: 1.1; margin: 4px 0 10px; }
#story-body { font-size: 14.5px; line-height: 1.5; color: #d5e5f8; }
#story-body p { margin: 0 0 9px; }
#story-body b { color: #fff; }
#story-body .src { font-size: 11.5px; color: var(--ink-dim); }
#story-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 12px; }
#story-stats:empty { display: none; }
.stat { background: rgba(255,255,255,.06); border-radius: 12px; padding: 8px 8px 6px; text-align: center; }
.stat .v { font-family: var(--font-head); font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 11px; color: var(--ink-dim); line-height: 1.2; }
.story-nav { display: flex; justify-content: space-between; gap: 8px; }
.story-nav .btn { flex: 1; }
.story-nav .btn.ghost { flex: 0 0 52px; }

/* ---------- right column */
#right { position: fixed; right: 16px; top: 86px; bottom: 108px; width: 300px; display: flex; flex-direction: column; gap: 12px; pointer-events: none; transition: opacity .3s; z-index: 4; }
#right > * { pointer-events: auto; }
#legend { padding: 14px 12px 10px; overflow: auto; min-height: 0; }
#legend-list { display: flex; flex-direction: column; gap: 2px; }
.lg-row { display: grid; grid-template-columns: 16px 1fr auto; align-items: center; gap: 9px; padding: 5px 8px; border-radius: 10px; font-size: 13.5px; cursor: pointer; user-select: none; }
.lg-row:hover { background: rgba(255,255,255,.07); }
.lg-row.off { opacity: .38; }
.lg-row.empty { display: none; }
.lg-dot { width: 14px; height: 14px; border-radius: 5px; border: 2px solid rgba(0,0,0,.35); }
.lg-n { font-family: var(--font-head); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-dim); }
.legend-hint { font-size: 11px; color: var(--ink-dim); margin-top: 8px; text-align: center; }

#info { padding: 14px 14px 12px; flex: none; }
.info-top { display: flex; gap: 10px; align-items: flex-start; }
.info-flag { font-size: 30px; line-height: 1; }
.info-name { font-family: var(--font-head); font-weight: 700; font-size: 20px; line-height: 1.1; word-break: break-word; }
.chip { display: inline-block; margin-top: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; color: #10213f; }
.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; margin: 10px 0 10px; }
.info-grid dt { color: var(--ink-dim); }
.info-grid dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.info-actions { display: flex; gap: 8px; }
.info-actions .btn { flex: 1; padding: 6px 10px; font-size: 13px; }
.info-close { margin-left: auto; }

/* ---------- settings */
#settings { position: fixed; right: 16px; top: 86px; width: 300px; padding: 14px; z-index: 6; }
.slider { display: block; font-size: 13px; margin: 10px 0 2px; }
.slider b { float: right; color: var(--accent); font-family: var(--font-head); }
.slider input { width: 100%; accent-color: var(--accent); }
.note { font-size: 11px; color: var(--ink-dim); line-height: 1.35; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0; font-size: 13px; }
.toggles input { accent-color: var(--accent); }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; font-size: 11.5px; color: var(--ink-dim); border-top: 1px solid var(--edge); padding-top: 10px; }
kbd { font-family: var(--font-head); background: rgba(255,255,255,.12); border-radius: 5px; padding: 0 5px; margin-right: 3px; color: var(--ink); font-size: 11px; }

/* ---------- timeline */
#timeline { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); width: min(880px, calc(100vw - 32px)); display: flex; align-items: center; gap: 14px; padding: 10px 14px; transition: opacity .3s; z-index: 4; }
.play { width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--accent); color: #2b2100; font-size: 16px; font-weight: 900; box-shadow: 0 3px 0 #b88a00; flex: none; }
.clock { flex: none; width: 128px; }
#clock-time { font-family: var(--font-head); font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1; }
#clock-date { font-size: 11.5px; color: var(--ink-dim); margin-top: 3px; white-space: nowrap; }
#scrub { position: relative; flex: 1; height: 26px; cursor: pointer; }
#scrub-track { position: absolute; left: 0; right: 0; top: 10px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.14); overflow: hidden; }
#scrub-track .gap { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, rgba(255,93,93,.55) 0 3px, transparent 3px 6px); }
#scrub-track .day { position: absolute; top: -2px; bottom: -2px; width: 1px; background: rgba(255,255,255,.35); }
#scrub-fill { position: absolute; left: 0; top: 10px; height: 6px; border-radius: 3px; background: var(--accent-2); pointer-events: none; }
#scrub-knob { position: absolute; top: 4px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; background: #fff; border: 3px solid var(--accent-2); pointer-events: none; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
#speeds { display: flex; gap: 3px; flex: none; }
#speeds button { border: none; background: rgba(255,255,255,.08); border-radius: 8px; padding: 5px 7px; font-size: 12px; font-family: var(--font-head); font-weight: 600; color: var(--ink-dim); }
#speeds button.on { background: var(--accent-2); color: #062033; }
#controls-hint { position: fixed; bottom: 8px; left: 50%; transform: translateX(-50%); font-size: 11.5px; color: rgba(230, 242, 255, .75); text-shadow: 0 1px 3px rgba(0,0,0,.6); white-space: nowrap; transition: opacity .3s; z-index: 3; }

/* ---------- labels & tooltip */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.lbl { position: absolute; left: 0; top: 0; white-space: nowrap; font-family: var(--font-head); font-weight: 600; color: #fff; transform-origin: 0 0; will-change: transform, opacity;
  text-shadow: 0 0 3px #10213f, 0 0 3px #10213f, 0 2px 2px rgba(0,0,0,.5); transition: opacity .25s; }
.lbl.country { font-size: 22px; letter-spacing: .25em; font-weight: 700; color: #fff8e1; }
.lbl.sea { font-size: 16px; font-style: italic; letter-spacing: .12em; color: #d6f4ff; font-weight: 500; text-shadow: 0 0 4px #0c4a7a, 0 1px 2px #0c4a7a; }
.lbl.city, .lbl.port, .lbl.island { font-size: 13px; }
.lbl.city::before, .lbl.port::before, .lbl.island::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #fff; border: 2px solid #10213f; margin-right: 5px; vertical-align: 1px; }
.lbl.port::before { background: var(--accent-2); }
.lbl.island::before { background: #ffd166; }
.lbl.peak { font-size: 12px; color: #fff3d6; }
.lbl.median { font-size: 12.5px; color: #ffe0e0; letter-spacing: .06em; text-shadow: 0 0 4px #7a0c0c, 0 1px 2px #7a0c0c; }
.tooltip { position: fixed; z-index: 7; pointer-events: none; background: var(--panel-solid); border: 1.5px solid var(--edge); border-radius: 10px; padding: 5px 10px; font-size: 13px; white-space: nowrap; box-shadow: var(--shadow); transform: translate(14px, -50%); }
.tooltip b { font-family: var(--font-head); }
.tooltip .dim { color: var(--ink-dim); }

/* ---------- loader */
#loader { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: radial-gradient(ellipse at center, #10264d 0%, #050b18 75%); transition: opacity .8s; }
#loader.done { opacity: 0; pointer-events: none; }
.loader-card { text-align: center; width: min(460px, 90vw); }
.loader-title { font-family: var(--font-head); font-weight: 700; font-size: 40px; letter-spacing: .12em; }
.loader-sub { color: var(--ink-dim); margin: 6px 0 22px; font-size: 15px; }
.bar { height: 10px; border-radius: 6px; background: rgba(255,255,255,.1); overflow: hidden; }
#loader-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--radar), var(--accent-2)); transition: width .3s; }
#loader-msg { font-size: 13px; color: var(--ink-dim); margin: 10px 0 18px; min-height: 18px; }

@media (max-width: 980px) {
  #steps .label { display: none; }
  #story { width: 290px; }
  #right { width: 250px; }
}
@media (max-width: 700px) {
  #story { top: auto; bottom: 110px; left: 16px; right: 16px; width: auto; max-height: 38vh; overflow: auto; }
  #right { display: none; }
  .brand-sub { display: none; }
  .clock { width: 96px; }
  #speeds { display: none; }
  #controls-hint { display: none; }
}
.lbl.focus { color: var(--accent); font-size: 17px; z-index: 1; }
.lbl.focus::before { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.lbl.median.focus { font-size: 15px; color: #fff; text-shadow: 0 0 6px #ff1f1f, 0 0 2px #7a0c0c; }

/* ---------- sensor story */
.truth-btn { width: 100%; margin: -2px 0 12px; border: 1.5px solid rgba(255, 93, 93, .55); background: rgba(255, 93, 93, .12); color: #ffd6d6; border-radius: 12px; padding: 7px 10px; font-family: var(--font-head); font-weight: 600; font-size: 13px; }
.truth-btn.off { border-color: var(--edge); background: rgba(255,255,255,.05); color: var(--ink-dim); }
.pill.radar { background: rgba(61, 255, 139, .15); color: var(--radar); }
#radar-panel { padding: 14px 14px 12px; overflow: auto; flex: none; max-height: 100%; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; margin: 8px 0; }
.field select { flex: 1; max-width: 190px; background: rgba(255,255,255,.08); color: var(--ink); border: 1.5px solid var(--edge); border-radius: 9px; padding: 4px 6px; font: inherit; font-size: 12.5px; }
.field select option { background: var(--panel-solid); }
#radar-panel .slider input { accent-color: var(--radar); }
#radar-panel .slider b { color: var(--radar); }
.participants { display: flex; flex-direction: column; gap: 3px; margin: 10px 0 6px; border-top: 1px solid var(--edge); padding-top: 8px; }
.participants label { display: grid; grid-template-columns: 16px 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; cursor: pointer; }
.participants input { accent-color: var(--radar); margin: 0; }
.participants .n { color: var(--ink-dim); font-family: var(--font-head); font-variant-numeric: tabular-nums; }
.cov-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 8px; }
.cov-stats .stat .v { color: var(--radar); }
#toasts { position: fixed; bottom: 106px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column-reverse; gap: 8px; align-items: center; z-index: 8; pointer-events: none; }
.toast { background: rgba(60, 8, 12, .9); border: 1.5px solid rgba(255, 93, 93, .7); color: #ffe3e3; border-radius: 14px; padding: 8px 14px 8px 12px; font-size: 13.5px; box-shadow: 0 0 24px rgba(255, 60, 60, .35), var(--shadow); animation: toastIn .35s ease-out, toastOut .6s ease-in 7.4s forwards; max-width: min(620px, 90vw); }
.toast .t { color: #ffb3b3; font-family: var(--font-head); margin-right: 6px; }
.toast.cross { background: rgba(80, 10, 10, .95); border-color: #ff3b3b; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }
#sat-hud { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); padding: 8px 16px; font-size: 13.5px; z-index: 5; white-space: nowrap; }
#sat-hud b { font-family: var(--font-head); }
#sat-hud .bar { display: inline-block; width: 120px; height: 8px; vertical-align: middle; margin: 0 8px; background: rgba(255,255,255,.12); border-radius: 4px; overflow: hidden; }
#sat-hud .bar i { display: block; height: 100%; background: var(--accent-2); }
#inset { position: fixed; left: 16px; bottom: 104px; width: 390px; padding: 10px 12px 8px; z-index: 4; transition: opacity .3s; }
#inset canvas { width: 100%; height: 168px; display: block; }
.inset-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-family: var(--font-head); font-weight: 600; font-size: 13px; margin-bottom: 4px; }
#inset-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#inset-status.ok { background: rgba(61,255,139,.15); color: var(--radar); }
#inset-status.no { background: rgba(255,93,93,.18); color: #ff8b8b; }
body.hide-ui #inset, body.hide-ui #sat-hud { opacity: 0; }
.lbl.contact { font-size: 12.5px; color: #fff; background: rgba(90, 8, 12, .82); border: 1.5px solid #ff4d4d; border-radius: 9px; padding: 3px 8px; text-align: center; text-shadow: none; line-height: 1.25; box-shadow: 0 0 14px rgba(255, 50, 50, .45); }
.lbl.contact span { color: #ffb3b3; font-size: 11px; font-weight: 500; }
