/* Train Trax — flat vector cartoon, phone first.
   Nothing here may scroll, zoom or select under a thumb. */

:root {
  --ink: #1b1b24;
  --paper: #f6efe2;
  --brand: #e8853a;
  --gold: #ffd23f;
  --green: #4fc07a;
  --pink: #e8608f;
  --muted: #9aa7b2;
  --panel: rgba(20, 20, 28, 0.88);
  --radius: 14px;
  --font: ui-rounded, "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

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

/* ── Panels ─────────────────────────────────────────────────────────────────────────── */

.panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(16, 16, 24, 0.94), rgba(24, 18, 30, 0.97));
  overflow-y: auto;
  text-align: center;
}

.panel[hidden] { display: none; }

h1 {
  margin: 0;
  font-size: clamp(38px, 11vw, 68px);
  letter-spacing: -0.02em;
  line-height: 0.95;
}
h1 span { color: var(--brand); }

h2 { margin: 0; font-size: clamp(20px, 5vw, 28px); }
h3 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }

.tag { margin: 0; color: var(--gold); font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; line-height: 1.5; max-width: 44ch; }

.pack, .controls {
  width: min(520px, 100%);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
}

.ladder { margin: 10px 0; padding-left: 0; list-style: none; display: grid; gap: 5px; }
.ladder li {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 10px;
  align-items: baseline;
  font-size: 14px;
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}
.ladder b { color: var(--gold); font-variant-numeric: tabular-nums; }
.ladder em { color: var(--muted); font-style: normal; font-size: 12px; display: block; }

.controls ul { margin: 0 0 8px; padding-left: 0; list-style: none; display: grid; gap: 6px; font-size: 13.5px; }
.controls b { color: var(--paper); }
.controls span { color: var(--muted); font-size: 12px; }

.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }

.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

button {
  font: 600 15px var(--font);
  color: var(--paper);
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 13px 24px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
button:active { transform: scale(0.97); }
button.primary { background: var(--brand); border-color: transparent; color: #1b1b24; }

/* ── Calibration ────────────────────────────────────────────────────────────────────── */

.cal-target { display: grid; place-items: center; height: 130px; }
#cal-dot {
  width: 70px; height: 70px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 40px rgba(255, 210, 63, 0.45);
  will-change: transform;
}

/* ── Stats ──────────────────────────────────────────────────────────────────────────── */

.stats { display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: center; margin: 6px 0; }
.stats div { text-align: center; }
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats.big dd { font-size: 34px; color: var(--gold); }

.reason { margin: 0; color: var(--muted); }
.pb { margin: 0; color: var(--green); font-weight: 700; }

/* ── HUD ────────────────────────────────────────────────────────────────────────────── */

.hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hud[hidden] { display: none; }

.hud-top { display: flex; gap: 16px; align-items: flex-end; }
.hud-top .stat { display: flex; flex-direction: column; line-height: 1.05; }
.hud-top span { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-top em {
  font-style: normal; font-size: 9.5px; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--muted);
}
.combo span { color: var(--gold); }
#mult[data-level="2"] { color: var(--green); }
#mult[data-level="4"] { color: var(--brand); }
#mult[data-level="8"] { color: var(--pink); }

.steam {
  height: 7px;
  width: min(320px, 60%);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.steam i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--pink), var(--gold), var(--green));
  transition: width 0.12s linear;
}

.tier { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; }

/* The layer meters are the adaptive score made visible: combo brings each one in. */
.layers { margin-top: auto; display: grid; gap: 3px; width: 148px; }
.layer { display: grid; grid-template-columns: 62px 1fr; gap: 6px; align-items: center; }
.layer span { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.layer i {
  height: 5px; border-radius: 999px; background: var(--gold);
  transform-origin: left center; transform: scaleX(0);
  transition: transform 0.2s ease;
}

/* ── Debug overlay ──────────────────────────────────────────────────────────────────── */

.debug {
  position: absolute;
  right: 14px;
  top: max(12px, env(safe-area-inset-top));
  width: 300px;
  background: rgba(10, 10, 16, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px;
  font: 11px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--muted);
}
.debug[hidden] { display: none; }
.debug canvas { width: 100%; height: 70px; display: block; border-radius: 6px; }
.debug p { margin: 6px 0 0; }
#debug-stats { margin-top: 6px; color: var(--paper); word-spacing: 0.2em; }

@media (max-width: 520px) {
  .debug { width: calc(100% - 28px); }
  .hud-top { gap: 12px; }
  .hud-top span { font-size: 18px; }
}

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