/* ═══ مسیر آنباکس / Onbox Run ══════════════════════════════
   The 3D road is a full-bleed canvas; everything else is a DOM
   layer on top. Persian text stays in HTML where it renders
   properly, never inside the WebGL scene.
   ═════════════════════════════════════════════════════════ */

:root {
  --brand:       #1649ff;
  --brand-dark:  #0d35cc;
  --brand-glow:  #4d7cff;
  --accent:      #FF8C42;
  --navy:        #0a1733;
  --navy-light:  #0f2050;
  --ink:         #ffffff;
  --ink-dim:     rgba(255, 255, 255, 0.62);
  --ink-faint:   rgba(255, 255, 255, 0.28);
  --good:        #22d38a;
  --bad:         #ff4d5e;
  --line:        rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  color: var(--ink);
  font-family: 'YekanBakh', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  cursor: none;
}

/* ── the road ────────────────────────────────────────── */
#stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
}
/* Rendered at 720p and stretched, so keep the upscale smooth. */
.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 78% 62% at 50% 46%, transparent 55%, rgba(4, 9, 22, 0.72));
}

/* ── screens ─────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.screen.is-active { display: flex; }
/* Menus need a scrim; the HUD must not dim the road. */
.screen:not(.screen--hud) { background: rgba(8, 17, 39, 0.74); backdrop-filter: blur(2px); }
.screen--hud { justify-content: flex-start; padding: 2.4vmin 3vmin; pointer-events: none; }

/* ── shared ──────────────────────────────────────────── */
.key {
  display: inline-block;
  min-width: 2.2em;
  padding: 0.18em 0.55em;
  border: 2px solid var(--ink-faint);
  border-bottom-width: 4px;
  border-radius: 0.4em;
  background: rgba(255, 255, 255, 0.07);
  font-weight: 700;
  font-size: 0.9em;
  text-align: center;
  direction: ltr;
}
.key--wide { min-width: 6em; letter-spacing: 0.1em; }

.logo {
  font-weight: 900;
  font-size: clamp(20px, 2.6vmin, 34px);
  letter-spacing: 0.34em;
  direction: ltr;
}
.logo::after {
  content: '';
  display: block;
  height: 3px;
  margin-top: 0.5em;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

.storage-warning {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  padding: 0.6vmin 2vmin;
  background: var(--bad);
  font-size: clamp(11px, 1.5vmin, 18px);
  font-weight: 700;
  text-align: center;
}
.perf-badge {
  position: fixed; bottom: 1vmin; left: 1vmin; z-index: 90;
  padding: 0.4vmin 1vmin;
  border-radius: 0.6vmin;
  background: rgba(0, 0, 0, 0.5);
  color: var(--ink-dim);
  font-size: clamp(9px, 1.2vmin, 14px);
  direction: ltr;
}

/* ── attract ─────────────────────────────────────────── */
.attract { display: flex; flex-direction: column; align-items: center; gap: 3.4vmin; }
.attract__brand { display: flex; flex-direction: column; align-items: center; gap: 1.4vmin; text-align: center; }
.attract__title {
  font-weight: 900;
  font-size: clamp(38px, 9vmin, 130px);
  line-height: 1;
  background: linear-gradient(180deg, #fff 40%, var(--brand-glow));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.attract__sub { font-size: clamp(14px, 2.3vmin, 30px); color: var(--ink-dim); }
.attract__keys {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7vmin;
  margin-top: 0.6vmin;
  font-size: clamp(13px, 2vmin, 24px);
}
.attract__or { margin: 0 0.9vmin; font-style: normal; color: var(--ink-dim); }
.attract__cta {
  display: flex; align-items: center; gap: 1.4vmin;
  font-size: clamp(14px, 2.2vmin, 28px);
  font-weight: 700;
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ── leaderboard ─────────────────────────────────────── */
.board {
  width: min(62vw, 720px);
  padding: 2.4vmin 2.8vmin;
  border: 1px solid var(--line);
  border-radius: 2vmin;
  background: rgba(10, 23, 51, 0.72);
  box-shadow: 0 2.4vmin 6vmin rgba(0, 0, 0, 0.45);
}
.board__head {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 1.4vmin; margin-bottom: 1vmin;
  border-bottom: 1px solid var(--line);
}
.board__title { font-weight: 700; font-size: clamp(14px, 2.1vmin, 26px); }
.board__dots { display: flex; gap: 0.7vmin; }
.board__dots i {
  width: 0.9vmin; height: 0.9vmin; min-width: 6px; min-height: 6px;
  border-radius: 50%; background: var(--ink-faint);
}
.board__dots i.on { background: var(--accent); }
.board__list { list-style: none; }
.board__row {
  display: grid; grid-template-columns: 3.4em 1fr auto;
  align-items: center; gap: 1vmin;
  padding: 0.85vmin 0;
  font-size: clamp(13px, 1.95vmin, 24px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.board__row:last-child { border-bottom: 0; }
.board__rank { font-weight: 900; color: var(--ink-faint); text-align: center; }
.board__row--1 .board__rank { color: #ffd85e; }
.board__row--2 .board__rank { color: #d8e2f5; }
.board__row--3 .board__rank { color: var(--accent); }
.board__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board__score { font-weight: 900; font-variant-numeric: tabular-nums; }
.board__empty { padding: 2vmin 0; text-align: center; color: var(--ink-dim); }

/* ── register ────────────────────────────────────────── */
.panel {
  width: min(58vw, 640px);
  padding: 4vmin;
  border: 1px solid var(--line);
  border-radius: 2.4vmin;
  background: rgba(10, 23, 51, 0.78);
  box-shadow: 0 2.4vmin 6vmin rgba(0, 0, 0, 0.5);
}
.panel__title { font-size: clamp(20px, 3.4vmin, 44px); font-weight: 900; text-align: center; margin-bottom: 2.4vmin; }
.panel__hint {
  display: flex; justify-content: center; gap: 3vmin;
  margin-top: 2.4vmin;
  font-size: clamp(12px, 1.7vmin, 20px);
  color: var(--ink-dim);
}
.target {
  padding: 1.6vmin; margin-bottom: 2.4vmin;
  border-radius: 1.2vmin;
  background: rgba(255, 140, 66, 0.12);
  border: 1px solid rgba(255, 140, 66, 0.35);
  text-align: center;
  font-size: clamp(13px, 2vmin, 24px);
  line-height: 1.7;
}
.target b { color: var(--accent); font-weight: 900; }
.field { display: block; margin-bottom: 1.8vmin; }
.field__label { display: block; margin-bottom: 0.7vmin; font-size: clamp(12px, 1.7vmin, 20px); color: var(--ink-dim); }
.field__input {
  width: 100%;
  padding: 1.3vmin 1.6vmin;
  border: 2px solid var(--line);
  border-radius: 1.1vmin;
  background: rgba(0, 0, 0, 0.34);
  color: var(--ink);
  font-family: inherit;
  font-size: clamp(16px, 2.6vmin, 32px);
  font-weight: 700;
  outline: none;
  cursor: text;
}
.field__input:focus { border-color: var(--brand-glow); box-shadow: 0 0 0 0.5vmin rgba(22, 73, 255, 0.22); }
.field__input--ltr { direction: ltr; text-align: left; letter-spacing: 0.08em; }
.field__input::placeholder { color: var(--ink-faint); font-weight: 400; }
.field__error { min-height: 1.4em; text-align: center; color: var(--bad); font-size: clamp(12px, 1.7vmin, 20px); font-weight: 700; }

/* ── countdown ───────────────────────────────────────── */
.countdown {
  font-size: clamp(90px, 34vmin, 460px);
  font-weight: 900; line-height: 1;
  text-shadow: 0 0 8vmin rgba(77, 124, 255, 0.75);
  animation: countPop 0.85s ease-out;
}
@keyframes countPop {
  0%   { transform: scale(2.1); opacity: 0; }
  35%  { transform: scale(1);   opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.75; }
}
.countdown__hint { font-size: clamp(14px, 2.4vmin, 30px); color: var(--ink-dim); }

/* ── HUD ─────────────────────────────────────────────── */
.hud {
  display: grid;
  grid-template-columns: 1fr 2.1fr 1fr;
  align-items: center;
  gap: 2vmin;
  width: 100%;
  text-shadow: 0 0.2vmin 1.2vmin rgba(0, 0, 0, 0.8);
}
.hud__stat { display: flex; flex-direction: column; align-items: center; }
.hud__label { font-size: clamp(11px, 1.5vmin, 18px); color: var(--ink-dim); }
.hud__value { font-size: clamp(28px, 6vmin, 82px); font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hud__timer.is-low .hud__value { color: var(--bad); animation: tick 0.5s ease-in-out infinite; }
@keyframes tick { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.16); } }

.tug { direction: ltr; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1.6vmin; }
.tug__side { display: flex; flex-direction: column; align-items: center; min-width: 9vmin; }
.tug__name { font-size: clamp(11px, 1.5vmin, 18px); color: var(--ink-dim); max-width: 18vmin; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tug__score { font-size: clamp(14px, 2.3vmin, 30px); font-weight: 900; font-variant-numeric: tabular-nums; }
.tug__side--you .tug__score { color: var(--brand-glow); }
.tug__track { position: relative; height: 2.2vmin; min-height: 15px; border-radius: 999px; background: rgba(0, 0, 0, 0.5); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.tug__fill { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-glow)); transition: left 0.2s ease, width 0.2s ease; }
.tug__fill.is-behind { background: linear-gradient(90deg, #e07330, var(--accent)); }
.tug__mid { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: rgba(255, 255, 255, 0.35); }
.tug__knob {
  position: absolute; top: 50%; left: 50%;
  width: 2.7vmin; height: 2.7vmin; min-width: 18px; min-height: 18px;
  border-radius: 50%; background: #fff;
  box-shadow: 0 0 2.2vmin rgba(255, 255, 255, 0.7);
  transform: translate(-50%, -50%);
  transition: left 0.2s ease;
}

/* the package to match at the next gate */
.cargo {
  margin-top: 2vmin;
  display: flex; flex-direction: column; align-items: center; gap: 0.3vmin;
  padding: 1.2vmin 3.4vmin;
  border: 2px solid var(--brand-glow);
  border-radius: 1.6vmin;
  background: rgba(10, 23, 51, 0.8);
  box-shadow: 0 0 4vmin rgba(77, 124, 255, 0.4);
}
.cargo__label { font-size: clamp(10px, 1.4vmin, 17px); color: var(--ink-dim); }
.cargo__city { font-size: clamp(24px, 5.4vmin, 70px); font-weight: 900; line-height: 1.05; }
.cargo__express { font-size: clamp(10px, 1.4vmin, 17px); font-weight: 900; color: var(--accent); letter-spacing: 0.14em; direction: ltr; }
.cargo.is-express { border-color: var(--accent); box-shadow: 0 0 4vmin rgba(255, 140, 66, 0.5); }

.combo {
  margin-top: 1.2vmin;
  font-size: clamp(20px, 4.4vmin, 60px);
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 3vmin rgba(255, 140, 66, 0.65);
}
.combo.bump { animation: comboBump 0.35s ease-out; }
@keyframes comboBump { 0% { transform: scale(1.9) rotate(-6deg); } 100% { transform: scale(1) rotate(0); } }

.speed {
  position: fixed; bottom: 12vmin; right: 3vmin;
  font-size: clamp(12px, 1.8vmin, 22px);
  color: var(--ink-dim);
  direction: ltr;
  text-shadow: 0 0.2vmin 1vmin rgba(0, 0, 0, 0.8);
}
.speed b { font-size: clamp(20px, 3.6vmin, 46px); font-weight: 900; color: var(--ink); }

/* lane keys */
.lanes {
  position: fixed; left: 3vmin; right: 3vmin; bottom: 2.4vmin;
  direction: ltr;                /* must match the physical keycaps */
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.6vmin;
}
.lane {
  display: flex; align-items: center; justify-content: center;
  height: 6vmin; min-height: 40px;
  border: 2px solid var(--line);
  border-radius: 1.2vmin;
  background: rgba(10, 23, 51, 0.55);
  font-size: clamp(16px, 2.8vmin, 36px);
  font-weight: 900;
  color: var(--ink-dim);
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.12s;
}
.lane.is-on {
  border-color: var(--brand-glow);
  background: rgba(22, 73, 255, 0.45);
  color: #fff;
  transform: translateY(-0.6vmin);
}
.lane.is-good { border-color: var(--good); background: rgba(34, 211, 138, 0.35); }
.lane.is-bad  { border-color: var(--bad);  background: rgba(255, 77, 94, 0.35); }

.pop {
  position: fixed; z-index: 70;
  font-size: clamp(18px, 3.4vmin, 44px);
  font-weight: 900;
  color: var(--good);
  text-shadow: 0 0.3vmin 1vmin rgba(0, 0, 0, 0.7);
  pointer-events: none;
  animation: popUp 0.8s ease-out forwards;
}
.pop--bad { color: var(--bad); }
@keyframes popUp {
  0%   { transform: translate(-50%, 0) scale(0.7); opacity: 0; }
  25%  { transform: translate(-50%, -2vmin) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -10vmin) scale(1); opacity: 0; }
}

.flash { position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: 0; }
.flash.is-bad { background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 77, 94, 0.55)); animation: flashOut 0.32s; }
@keyframes flashOut { from { opacity: 1; } to { opacity: 0; } }

/* ── result ──────────────────────────────────────────── */
.result { display: flex; flex-direction: column; align-items: center; gap: 2.2vmin; width: min(72vw, 900px); }
.result__score { display: flex; flex-direction: column; align-items: center; }
.result__label { font-size: clamp(14px, 2.2vmin, 28px); color: var(--ink-dim); }
.result__value {
  font-size: clamp(56px, 14vmin, 190px);
  font-weight: 900; line-height: 1;
  background: linear-gradient(180deg, #fff 45%, var(--brand-glow));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.result__meta { font-size: clamp(12px, 1.9vmin, 23px); color: var(--ink-dim); margin-top: 0.8vmin; }
.result__ranks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.6vmin; width: 100%; }
.rank-card { padding: 1.8vmin 1vmin; border: 1px solid var(--line); border-radius: 1.4vmin; background: rgba(255, 255, 255, 0.05); text-align: center; }
.rank-card__title { font-size: clamp(11px, 1.6vmin, 19px); color: var(--ink-dim); }
.rank-card__rank { font-size: clamp(24px, 5vmin, 64px); font-weight: 900; line-height: 1.15; }
.rank-card--top { border-color: rgba(255, 140, 66, 0.5); background: rgba(255, 140, 66, 0.1); }
.rank-card--top .rank-card__rank { color: var(--accent); }
.result__banner {
  width: 100%; padding: 1.8vmin;
  border-radius: 1.4vmin;
  background: linear-gradient(90deg, rgba(255, 140, 66, 0.28), rgba(255, 140, 66, 0.08));
  border: 1px solid rgba(255, 140, 66, 0.5);
  text-align: center; font-size: clamp(14px, 2.2vmin, 28px); font-weight: 700;
  animation: bannerIn 0.5s ease-out;
}
@keyframes bannerIn { from { transform: translateY(2vmin) scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
.result__prize { font-size: clamp(15px, 2.5vmin, 32px); font-weight: 900; color: var(--good); text-align: center; }

/* ── admin ───────────────────────────────────────────── */
.admin {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 9, 22, 0.9);
  cursor: default;
}
.admin__box {
  width: min(80vw, 860px); padding: 3vmin;
  border: 1px solid var(--line); border-radius: 1.8vmin;
  background: var(--navy-light);
  display: flex; flex-direction: column; gap: 1.6vmin;
}
.admin__box h3 { font-size: clamp(16px, 2.6vmin, 30px); }
.admin__stats { display: flex; flex-wrap: wrap; gap: 2vmin; font-size: clamp(12px, 1.8vmin, 20px); color: var(--ink-dim); }
.admin__stats b { color: var(--ink); }
.admin__actions { display: flex; flex-wrap: wrap; gap: 1vmin; }
.admin__actions button {
  padding: 1vmin 1.8vmin;
  border: 1px solid var(--line); border-radius: 0.9vmin;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink); font-family: inherit;
  font-size: clamp(12px, 1.7vmin, 19px); font-weight: 700; cursor: pointer;
}
.admin__actions button:hover { background: var(--brand); border-color: var(--brand-glow); }
.admin__actions button.danger:hover { background: var(--bad); border-color: var(--bad); }
.admin__out {
  height: 22vmin; min-height: 140px; padding: 1.2vmin;
  border: 1px solid var(--line); border-radius: 0.9vmin;
  background: rgba(0, 0, 0, 0.4); color: var(--ink);
  font-family: ui-monospace, monospace; font-size: 12px;
  direction: ltr; resize: none;
  user-select: text; -webkit-user-select: text;
}
