:root {
  --bg0: #04060b;
  --bg1: #0a1020;
  --cyan: #3fd6ff;
  --violet: #a06bff;
  --amber: #ffb347;
  --ice: #9fd8ff;
  --green: #57e6a8;
  --red: #ff5d5d;
  --gold: #d8b25c;
  --text: #e8edf5;
  --dim: #8a95a8;
  --glass: rgba(9, 15, 27, 0.78);
  --line: rgba(130, 170, 220, 0.16);
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
  background:
    radial-gradient(120% 90% at 50% 30%, #0b1424 0%, var(--bg0) 60%, #020308 100%);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body.fallback-mode { overflow: auto; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#scene:active { cursor: grabbing; }

/* ---------- top bar ---------- */

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 22px;
  gap: 16px;
  z-index: 30;
  pointer-events: none;
}

#topbar > * { pointer-events: auto; }

.brand-kicker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.32em;
  color: var(--cyan);
  opacity: 0.85;
}

.brand h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1.15;
  background: linear-gradient(120deg, #ffffff 20%, var(--cyan) 80%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sub {
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.seg-btn {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  padding: 9px 13px;
  background: transparent;
  color: var(--dim);
  border: none;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.seg-btn.active {
  background: rgba(63, 214, 255, 0.14);
  color: var(--cyan);
}

.ctl {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  padding: 9px 13px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, transform 0.15s;
}

.ctl:hover { border-color: rgba(63, 214, 255, 0.55); color: var(--cyan); }
.ctl:active { transform: scale(0.97); }

button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---------- component panel ---------- */

#panel {
  position: fixed;
  top: 92px;
  right: 22px;
  width: 384px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  z-index: 40;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateX(16px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#panel.in { opacity: 1; transform: translateX(0); }

#panel[hidden] { display: none; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.p-kicker {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.26em;
  color: var(--cyan);
  margin-bottom: 5px;
}

.p-title { font-size: 19px; font-weight: 750; letter-spacing: 0.01em; }

.p-close {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--dim);
  width: 30px; height: 30px;
  cursor: pointer;
  flex: none;
  font-size: 12px;
}
.p-close:hover { color: var(--text); border-color: rgba(255,255,255,0.35); }

.p-lede {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--cyan);
  margin-bottom: 10px;
  line-height: 1.35;
}

.p-body p {
  font-size: 13px;
  line-height: 1.55;
  color: #c3cbd8;
  margin-bottom: 9px;
}

.p-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: 12px 0;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.02);
}

.stat-k {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--dim);
  text-transform: uppercase;
}

.stat-v {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  margin-top: 2px;
}

.p-flow[hidden] { display: none; }

.p-flow {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 1px dashed rgba(130, 170, 220, 0.3);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 9px;
  padding: 9px 11px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.2s, background 0.2s;
}

.p-flow:hover { background: rgba(63, 214, 255, 0.06); border-color: rgba(63, 214, 255, 0.5); }

.pf-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--fc, var(--cyan));
  box-shadow: 0 0 10px var(--fc, var(--cyan));
  flex: none;
}

.pf-name { font-weight: 600; }
.pf-rate { font-family: var(--mono); color: var(--dim); font-size: 11px; }
.pf-hint { margin-left: auto; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.1em; color: var(--cyan); opacity: 0.8; }

.p-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
}

.p-nav button {
  background: none;
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 8px;
  padding: 7px 12px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  cursor: pointer;
}
.p-nav button:hover { color: var(--cyan); border-color: rgba(63, 214, 255, 0.5); }

/* ---------- dock ---------- */

#dock {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 30;
  padding: 7px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  max-width: calc(100vw - 24px);
  overflow-x: auto;
}

.dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
  color: var(--dim);
  min-width: 58px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.dock-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.dock-btn.active { color: var(--cyan); border-color: rgba(63, 214, 255, 0.4); background: rgba(63, 214, 255, 0.08); }

.dock-key { font-family: var(--mono); font-size: 9px; opacity: 0.6; }
.dock-name { font-size: 10.5px; font-weight: 600; letter-spacing: 0.03em; white-space: nowrap; }

body.touring #dock { display: none; }
body.touring #hints { display: none; }

/* ---------- tour ---------- */

.letterbox {
  position: fixed;
  left: 0; right: 0;
  height: 0;
  background: #000;
  z-index: 25;
  transition: height 0.7s cubic-bezier(0.6, 0, 0.2, 1);
}

.lb-top { top: 0; }
.lb-bottom { bottom: 0; }

body.touring .letterbox { height: 9vh; }

#tour-caption {
  position: fixed;
  bottom: calc(9vh + 64px);
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 48px));
  text-align: center;
  z-index: 35;
  pointer-events: none;
}

#tour-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.4em;
  color: var(--cyan);
  margin-bottom: 8px;
  text-transform: uppercase;
}

#tour-text {
  font-size: 17px;
  line-height: 1.5;
  color: var(--text);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.9);
  font-weight: 450;
}

#tour-text.reveal { animation: capIn 0.8s cubic-bezier(0.2, 0.7, 0.2, 1); }

@keyframes capIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

#tour-transport {
  position: fixed;
  bottom: calc(9vh + 12px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 36;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 8px 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#tour-transport button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 7px;
  border-radius: 6px;
}
#tour-transport button:hover { background: rgba(255, 255, 255, 0.12); }

#tour-dots { display: flex; gap: 4px; margin: 0 6px; }
#tour-dots i {
  width: 5px; height: 5px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  transition: background 0.3s, transform 0.3s;
}
#tour-dots i.on { background: var(--cyan); transform: scale(1.15); }

#tour-count { font-family: var(--mono); font-size: 10.5px; color: var(--dim); letter-spacing: 0.1em; }
#tour-exit { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; color: var(--dim); }

/* ---------- modals ---------- */

#compare, #about {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 4, 9, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#compare[hidden], #about[hidden] { display: none; }

.modal-card {
  width: min(940px, calc(100vw - 32px));
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  background: #0a101d;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.6);
}

.modal-card.narrow { width: min(680px, calc(100vw - 32px)); }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}

.m-kicker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--cyan);
  margin-bottom: 6px;
}

.modal-head h2 { font-size: 22px; font-weight: 800; }

.modal-head > button {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--dim);
  width: 34px; height: 34px;
  cursor: pointer;
}
.modal-head > button:hover { color: var(--text); }

/* comparison table */

.cmp-head, .cmp-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr 1fr;
  gap: 12px;
  align-items: center;
}

.cmp-head { padding-bottom: 10px; border-bottom: 1px solid var(--line); }

.cmp-console { border-left: 3px solid var(--cc); padding-left: 10px; }
.cmp-cname { font-weight: 750; font-size: 14px; }
.cmp-csub { font-size: 10.5px; color: var(--dim); }

.cmp-row { padding: 11px 0; border-bottom: 1px solid rgba(130, 170, 220, 0.08); }

.cmp-label { font-size: 12.5px; font-weight: 650; }
.cmp-unit { font-family: var(--mono); font-size: 9.5px; color: var(--dim); letter-spacing: 0.06em; margin-top: 2px; }

.cmp-barline {
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  overflow: hidden;
}

.cmp-bar {
  height: 100%;
  background: var(--cc);
  opacity: 0.45;
  border-radius: 4px;
}

.cmp-bar.win { opacity: 1; box-shadow: 0 0 12px var(--cc); }

.cmp-val { font-family: var(--mono); font-size: 12px; margin-top: 5px; }
.cmp-note { font-size: 10px; color: var(--dim); line-height: 1.35; margin-top: 1px; }

.cmp-verdict {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 18px;
}

.cmp-verdict h4 {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.2em;
  margin-bottom: 8px;
}

.cmp-col:first-child h4 { color: var(--cyan); }
.cmp-col:last-child h4 { color: var(--amber); }

.cmp-verdict li {
  font-size: 12.5px;
  line-height: 1.45;
  color: #c3cbd8;
  margin-left: 16px;
  margin-bottom: 5px;
}

.cmp-rivals { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.cmp-rivals p { font-size: 12px; color: var(--dim); line-height: 1.5; margin-bottom: 6px; }

/* about */

.about-lede { font-size: 13px; color: #c3cbd8; line-height: 1.5; margin-bottom: 14px; }
.about-sources { margin: 0 0 16px 18px; }
.about-sources li { font-size: 11.5px; color: var(--dim); line-height: 1.55; margin-bottom: 7px; }
.about-keys { font-size: 11.5px; color: var(--dim); border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- intro ---------- */

#intro {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(90% 80% at 50% 40%, rgba(6, 10, 20, 0.55) 0%, rgba(3, 5, 10, 0.92) 100%);
  transition: opacity 0.5s ease;
}

#intro.gone { opacity: 0; pointer-events: none; }

.intro-card {
  text-align: center;
  max-width: 640px;
  padding: 30px;
  animation: capIn 1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.intro-kicker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.34em;
  color: var(--cyan);
  margin-bottom: 18px;
}

.intro-title {
  font-size: clamp(44px, 9vw, 84px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 0.98;
  background: linear-gradient(120deg, #ffffff 30%, var(--cyan) 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 20px;
}

.intro-sub {
  font-size: 15px;
  line-height: 1.6;
  color: #b9c2d0;
  margin-bottom: 26px;
}

.intro-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.btn-primary, .btn-ghost {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  padding: 14px 22px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s;
}

.btn-primary {
  background: linear-gradient(120deg, rgba(63, 214, 255, 0.22), rgba(63, 214, 255, 0.1));
  border: 1px solid rgba(63, 214, 255, 0.65);
  color: #dff6ff;
}

.btn-primary:hover { box-shadow: 0 0 30px rgba(63, 214, 255, 0.3); transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
}

.btn-ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.4); }

.intro-hints {
  margin-top: 24px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  color: rgba(138, 149, 168, 0.75);
}

/* ---------- labels ---------- */

#labels { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }

.label {
  position: absolute;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: opacity 0.25s ease;
  will-change: transform;
  text-align: center;
}

.l-name {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.9);
}

.l-sub {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--cyan);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

body[data-mode='story'] .l-sub { color: var(--amber); }

.label-int .l-name { font-size: 10px; }

/* ---------- misc ---------- */

#tooltip {
  position: fixed;
  top: 0; left: 0;
  z-index: 80;
  pointer-events: none;
  background: rgba(6, 12, 22, 0.92);
  border: 1px solid rgba(63, 214, 255, 0.35);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border-radius: 7px;
  white-space: nowrap;
}

#hints {
  position: fixed;
  left: 22px;
  bottom: 16px;
  display: flex;
  gap: 14px;
  z-index: 28;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: rgba(138, 149, 168, 0.7);
}

#toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 90;
  background: rgba(6, 12, 22, 0.94);
  border: 1px solid rgba(63, 214, 255, 0.4);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- fallback ---------- */

#fallback {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.fb-head h1 { font-size: 30px; margin-bottom: 10px; }
.fb-head p { color: var(--dim); font-size: 14px; line-height: 1.5; }

#fallback h2 {
  font-size: 19px;
  margin: 34px 0 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

#fallback p { font-size: 14px; line-height: 1.6; color: #c3cbd8; margin-bottom: 8px; }
.fb-tag { font-family: var(--mono); font-size: 10px; letter-spacing: 0.2em; color: var(--cyan); margin-bottom: 6px; }
.fb-lede { color: var(--cyan) !important; font-weight: 600; }
.fb-stats { font-family: var(--mono); font-size: 12px; color: var(--dim); margin-top: 6px; }
.fb-tour li { font-size: 13.5px; line-height: 1.55; color: #c3cbd8; margin: 0 0 8px 18px; }
.fb-cmp table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.fb-cmp th, .fb-cmp td { border: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }
.fb-cmp small { color: var(--dim); }
.fb-src li { font-size: 12px; color: var(--dim); line-height: 1.5; margin: 0 0 6px 18px; }

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  #topbar { padding: 12px 14px; flex-direction: column; gap: 10px; }
  .brand h1 { font-size: 17px; }
  .brand-sub { display: none; }
  .controls { width: 100%; justify-content: flex-start; }
  .seg-btn, .ctl { padding: 8px 10px; font-size: 9.5px; }

  #panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 46vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(16px);
  }
  #panel.in { transform: translateY(0); }

  #dock { bottom: 8px; gap: 3px; padding: 5px; }
  .dock-btn { min-width: 46px; padding: 5px 6px; }
  .dock-name { font-size: 9px; }

  #tour-text { font-size: 14px; }
  #tour-caption { bottom: calc(9vh + 76px); }
  #tour-transport { flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 20px); }

  #hints { display: none; }

  .cmp-head, .cmp-row { grid-template-columns: 1fr; gap: 6px; }
  .cmp-console { border-left: none; padding-left: 0; }
  .cmp-verdict { grid-template-columns: 1fr; }
}

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