/* ============================================================
   tunnel.gamestheory.org — Wind Tunnel
   Dark trading-terminal aesthetic, shared with the other games.
   ============================================================ */

:root {
  --bg: #0b0f17;
  --bg-grad-1: #0e1422;
  --bg-grad-2: #070a11;
  --panel: #111827;
  --panel-2: #0d1320;
  --panel-3: #0a0f1a;
  --line: #1f2937;
  --line-2: #2a3548;
  --text: #e6edf3;
  --text-dim: #9aa7b8;
  --text-faint: #8492a6;
  --green: #16c784;
  --red: #ea3943;
  --rose: #ef5350;
  --blue: #4f8cff;
  --amber: #f0a843;
  --cyan: #35d0e0;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --ff: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ff-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* keep the hidden attribute authoritative even on flex/grid elements */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--ff);
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1100px 560px at 50% -10%, var(--bg-grad-1), transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-grad-2) 100%);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -999px; top: 8px;
  background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: 10px; z-index: 50;
  text-decoration: none; border: 1px solid var(--line);
}
.skip-link:focus { left: 12px; }

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px clamp(14px, 4vw, 32px) 8px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand__mark { width: 34px; height: 34px; flex: none; }
.bm-wing { fill: var(--blue); }
.bm-flow { stroke: var(--cyan); stroke-width: 2; stroke-linecap: round; fill: none; opacity: 0.85; }
.brand__text { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand__name { font-weight: 800; letter-spacing: 0.12em; font-size: 1.02rem; }
.brand__name em { font-style: normal; color: var(--text-faint); font-weight: 600; }
.brand__tag { font-size: 0.68rem; color: var(--text-faint); letter-spacing: 0.04em; margin-top: 2px; }

.toolbar { display: flex; align-items: center; gap: 8px; flex: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 1rem; font-weight: 700;
  cursor: pointer; text-decoration: none;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-faint); }
.icon-btn--lang { font-family: var(--ff-mono); font-size: 0.74rem; font-weight: 800; letter-spacing: 0.04em; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn--home svg { stroke: currentColor; }

/* ---------- Stage layout ---------- */
.stage {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 6px clamp(14px, 4vw, 32px) 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas:
    "tunnel controls"
    "disc   controls";
  gap: 18px;
  align-content: start;
}
.tunnel-panel { grid-area: tunnel; min-width: 0; }
.controls { grid-area: controls; }
.disclaimer { grid-area: disc; }

@media (max-width: 860px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-areas: "tunnel" "controls" "disc";
  }
}

/* ---------- Canvas ---------- */
.canvas-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #05070c;
  box-shadow: var(--shadow);
  aspect-ratio: 2 / 1;
  touch-action: none;
}
.view {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  image-rendering: auto;
}
.regime-badge {
  position: absolute;
  top: 10px; left: 10px;
  font-family: var(--ff-mono);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(10, 15, 26, 0.72);
  border: 1px solid var(--line-2);
  color: var(--text-dim);
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.hint-draw {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(10, 15, 26, 0.7);
  border: 1px dashed var(--line-2);
  color: var(--text-dim);
  font-size: 0.92rem;
  pointer-events: none;
  transition: opacity .4s ease;
  backdrop-filter: blur(3px);
}
.hint-draw.is-hidden { opacity: 0; }

/* ---------- Readouts ---------- */
.readouts {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.ro {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 8px 8px;
  text-align: center;
  min-width: 0;
}
.ro__val {
  display: block;
  font-family: var(--ff-mono);
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ro__lbl {
  display: block;
  font-size: 0.64rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-top: 3px;
}
.ro--wide { grid-column: span 2; }
.ro--fps { grid-column: span 1; }
.ro--fps .ro__val { color: var(--text-dim); font-size: 0.9rem; }
#ro-re .ro__val { color: var(--amber); }

/* meters (relative drag / lift) */
.ro__word {
  display: block;
  font-family: var(--ff-mono);
  font-size: 0.82rem; font-weight: 700; line-height: 1.15;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meter {
  display: block;
  position: relative;
  height: 6px;
  margin: 6px 0 5px;
  border-radius: 999px;
  background: var(--line-2);
  overflow: hidden;
}
.meter__fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  border-radius: 999px;
  background: var(--amber);
  transition: width .2s ease, left .2s ease, background .2s ease;
}
.meter--center { overflow: visible; }
.meter--center::before {
  content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px;
  width: 1px; background: var(--text-faint); transform: translateX(-0.5px);
}
.meter__fill--lift { left: 50%; width: 0%; background: var(--cyan); }

@media (max-width: 620px) {
  .readouts { grid-template-columns: repeat(3, 1fr); }
  .ro--wide { grid-column: span 3; }
}

/* ---------- Controls ---------- */
.controls { display: flex; flex-direction: column; gap: 14px; }
.ctl-group {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px 16px;
}
.ctl-title {
  margin: 0 0 12px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 700;
}

/* Segmented buttons */
.seg { display: flex; gap: 6px; }
.seg--wrap { flex-wrap: wrap; }
.seg__btn {
  flex: 1 1 auto;
  min-width: 66px;
  padding: 9px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  color: var(--text-dim);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.seg__btn:hover { color: var(--text); border-color: var(--text-faint); }
.seg__btn.is-active {
  color: var(--text);
  border-color: var(--blue);
  background: rgba(79, 140, 255, 0.14);
}

/* Sliders */
.slider { display: block; margin-top: 14px; }
.slider:first-of-type { margin-top: 0; }
.slider__lbl {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.82rem; color: var(--text-dim); margin-bottom: 7px; gap: 8px;
}
.slider__lbl output { font-family: var(--ff-mono); color: var(--text); font-weight: 700; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 5px; border-radius: 999px;
  background: var(--line-2); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--blue); border: 2px solid #0b0f17;
  box-shadow: 0 0 0 1px var(--blue);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--blue); border: 2px solid #0b0f17; cursor: pointer;
}

/* Presets */
.preset-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  margin-top: 14px;
}
.preset {
  padding: 9px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  color: var(--text-dim);
  font-size: 0.82rem; font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.preset:hover { color: var(--text); border-color: var(--blue); }

/* Buttons */
.btn {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--text);
  font-size: 0.86rem; font-weight: 700;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.btn:hover { border-color: var(--text-faint); }
.btn--ghost { background: transparent; color: var(--text-dim); }
.btn--ghost:hover { color: var(--text); }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row .btn { width: auto; flex: 1; }
#btn-clear { margin-top: 14px; }

/* Checkbox */
.check {
  display: flex; align-items: center; gap: 9px;
  margin-top: 14px;
  font-size: 0.86rem; color: var(--text-dim); cursor: pointer;
}
.check input { width: 17px; height: 17px; accent-color: var(--blue); cursor: pointer; }

/* Disclaimer */
.disclaimer {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-faint);
  max-width: 640px;
}

/* ---------- Mode bar ---------- */
.modebar { display: flex; gap: 6px; margin-bottom: 12px; }
.mode-btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  color: var(--text-dim);
  font-size: 0.9rem; font-weight: 700;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.mode-btn:hover { color: var(--text); border-color: var(--text-faint); }
.mode-btn.is-active { color: var(--text); border-color: var(--blue); background: rgba(79, 140, 255, 0.14); }

/* ---------- Quiz ---------- */
.quiz {
  grid-area: controls;
  display: flex; flex-direction: column; gap: 12px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
}
.quiz__top {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--ff-mono); font-size: 0.74rem; color: var(--text-faint);
  letter-spacing: 0.03em;
}
.quiz__score { color: var(--amber); }
.quiz__q { margin: 2px 0 0; font-size: 1.05rem; line-height: 1.35; color: var(--text); }
.quiz__info {
  margin: 0; font-family: var(--ff-mono); font-size: 0.82rem; color: var(--cyan);
}
.quiz__opts { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.q-opt {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--panel-3);
  color: var(--text);
  font-size: 0.92rem; font-weight: 600; text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}
.q-opt:hover:not(:disabled) { border-color: var(--blue); transform: translateY(-1px); }
.q-opt:disabled { cursor: default; opacity: 0.9; }
.q-opt.is-correct { border-color: var(--green); background: rgba(22, 199, 132, 0.16); color: #d6ffe9; }
.q-opt.is-wrong { border-color: var(--red); background: rgba(234, 57, 67, 0.16); color: #ffe1e3; }
.q-opt.is-picked { outline: 2px solid var(--text-faint); outline-offset: 1px; }

.quiz__fb { display: flex; flex-direction: column; gap: 10px; }
.quiz__verdict { margin: 0; font-size: 1rem; font-weight: 800; }
.quiz__verdict.ok { color: var(--green); }
.quiz__verdict.no { color: var(--red); }
.quiz__explain { margin: 0; font-size: 0.86rem; line-height: 1.55; color: var(--text-dim); }

.quiz__result { display: flex; flex-direction: column; gap: 8px; text-align: center; }
.quiz__result-score { margin: 4px 0 0; font-family: var(--ff-mono); font-size: 2rem; font-weight: 800; color: var(--text); }
.quiz__result-sub { margin: 0; font-size: 0.88rem; color: var(--text-dim); line-height: 1.5; }
.quiz__result .btn-row { margin-top: 6px; }

/* ---------- Footer ---------- */
.footer {
  width: 100%; max-width: 1120px;
  margin: 0 auto; padding: 8px clamp(14px, 4vw, 32px) 26px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  color: var(--text-faint); font-size: 0.78rem;
  border-top: 1px solid var(--line);
}
.footer p { margin: 0; max-width: 60ch; }
.footer__links { display: inline-flex; align-items: center; gap: 16px; }
.mono { font-family: var(--ff-mono); color: var(--text-faint); }
.link-btn {
  background: none; border: none; padding: 0;
  color: var(--text-dim); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
  display: inline-flex; align-items: center; gap: 6px;
}
.link-btn:hover { color: var(--text); }
.link-btn--gh svg { width: 15px; height: 15px; fill: currentColor; }

/* ---------- Modal ---------- */
.modal {
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  color: var(--text);
  max-width: 560px;
  width: calc(100vw - 32px);
  padding: 0;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.modal::backdrop { background: rgba(3, 5, 10, 0.66); backdrop-filter: blur(2px); }
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel);
}
.modal__head h2 { margin: 0; font-size: 1.1rem; }
.modal__body { padding: 16px 20px 22px; max-height: min(72vh, 640px); overflow-y: auto; }
.modal__body h3 { margin: 18px 0 6px; font-size: 0.95rem; color: var(--blue); }
.modal__body h3:first-child { margin-top: 0; }
.modal__body p { margin: 0 0 10px; color: var(--text-dim); font-size: 0.9rem; line-height: 1.6; }
.modal__body ul { margin: 0 0 10px; padding-left: 18px; color: var(--text-dim); font-size: 0.9rem; line-height: 1.6; }
.modal__body li { margin-bottom: 5px; }
.modal__body strong { color: var(--text); }
.modal__body code {
  font-family: var(--ff-mono); font-size: 0.84em;
  background: var(--panel-3); padding: 1px 5px; border-radius: 5px; color: var(--cyan);
}
.modal__body .muted { color: var(--text-faint); font-size: 0.82rem; }

/* ---------- Motion / focus ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.001ms !important; }
}
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 8px; }
