/* ══════════════════════════════════════════════════════════════
   TURBO LANES 3D — طُرُق تيربو ٣
   Sana AI Agent Platform · Mabahith for Research and Development
   ══════════════════════════════════════════════════════════════ */

:root {
  /* surfaces */
  --bg: #05080f;
  --bg-2: #0b1220;
  --panel: rgba(9, 14, 26, 0.74);
  --panel-solid: #0b1220;
  --card: rgba(255, 255, 255, 0.045);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);

  /* ink */
  --text: #f2f6ff;
  --muted: #8b93a7;
  --dim: #5b6478;

  /* brand accents */
  --primary: #dc2626;
  --primary-2: #f87171;
  --secondary: #2563eb;
  --accent: #22c55e;
  --gold: #fbbf24;

  /* type */
  --font-display: 'Orbitron', 'Noto Kufi Arabic', system-ui, sans-serif;
  --font-ar: 'Noto Kufi Arabic', 'Segoe UI', system-ui, sans-serif;
  --font-hud: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', monospace;

  /* geometry */
  --r-sm: 8px;
  --r: 14px;
  --r-lg: 22px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  --ring: 0 0 0 3px rgba(220, 38, 38, 0.35);
  --t-fast: 140ms cubic-bezier(0.16, 1, 0.3, 1);
  --t: 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ar);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { overscroll-behavior: none; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; }

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

.vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background:
    radial-gradient(ellipse at 50% 45%, transparent 42%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.35), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.45));
}

.flash {
  position: absolute; inset: 0; pointer-events: none; z-index: 6;
  background: radial-gradient(circle at 50% 55%, rgba(255, 60, 40, 0.75), rgba(120, 0, 0, 0.25) 60%, transparent 75%);
  opacity: 0; transition: opacity 380ms ease-out;
}
.flash.on { opacity: 1; transition: opacity 40ms linear; }

/* ── HUD ─────────────────────────────────────────────────────── */
.hud {
  position: absolute; inset: 0; z-index: 4;
  pointer-events: none;
  padding: clamp(10px, 2vw, 22px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr auto;
  gap: 10px;
  animation: fadeIn 400ms ease both;
}
.hud > * { pointer-events: auto; }

.hud-row {
  grid-column: 1; grid-row: 1;
  display: flex; align-items: stretch; gap: clamp(6px, 1vw, 12px);
}

.stat {
  display: flex; flex-direction: column; justify-content: center;
  min-width: clamp(76px, 11vw, 128px);
  padding: 8px clamp(10px, 1.4vw, 16px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: clamp(9px, 1vw, 11px); font-weight: 700; letter-spacing: 0.14em;
  color: var(--muted); text-transform: uppercase;
}
.stat-value {
  font-family: var(--font-display); font-weight: 900; line-height: 1.05;
  font-size: clamp(20px, 3.2vw, 34px);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stat-value.small { font-size: clamp(15px, 2.2vw, 22px); color: var(--gold); }
.stat-unit { display: none; }
.stat-score .stat-value { color: var(--accent); text-shadow: 0 0 22px rgba(34, 197, 94, 0.35); }
.stat-score.pulse .stat-value { animation: scorePop 260ms cubic-bezier(0.16, 1, 0.3, 1); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; align-self: center;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  cursor: pointer; transition: transform var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.10); border-color: var(--border-strong); }
.icon-btn:active { transform: translateY(0) scale(0.96); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn svg { width: 20px; height: 20px; stroke-width: 1.75; }
.icon-btn i:empty::before { content: "II"; font-family: var(--font-display); font-size: 13px; }

/* ── Speedometer ─────────────────────────────────────────────── */
.hud-right {
  grid-column: 2; grid-row: 1;
  display: flex; align-items: flex-start; gap: 10px;
}
.speedo { position: relative; width: clamp(120px, 17vw, 200px); filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5)); }
.speedo svg { width: 100%; height: auto; display: block; }
#speedArc { transition: stroke-dashoffset 120ms linear; }
.speedo-readout {
  position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%);
  display: flex; align-items: baseline; gap: 4px;
}
.speedo-readout span {
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(22px, 3.6vw, 40px); font-variant-numeric: tabular-nums;
  text-shadow: 0 0 24px rgba(120, 190, 255, 0.35);
}
.speedo-readout small { font-size: clamp(9px, 1.1vw, 12px); color: var(--muted); font-weight: 700; }

.gear {
  display: grid; place-items: center;
  width: clamp(30px, 4vw, 44px); height: clamp(30px, 4vw, 44px);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-sm);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-family: var(--font-display); font-weight: 900; font-size: clamp(13px, 1.6vw, 18px);
  color: var(--accent);
}

/* ── Nitro + combo ───────────────────────────────────────────── */
.hud-bottom {
  grid-column: 1 / -1; grid-row: 3;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}
.nitro-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 999px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.nitro-label, .nitro-key {
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase;
}
.nitro-key { font-family: var(--font-hud); letter-spacing: 0; color: var(--dim); }
.nitro {
  position: relative; width: clamp(100px, 20vw, 220px); height: 9px;
  background: rgba(255, 255, 255, 0.10); border-radius: 999px; overflow: hidden;
}
.nitro-fill {
  position: absolute; inset: 0 0 0 auto; width: 100%;
  background: linear-gradient(270deg, #38bdf8, #2563eb 70%, #1e40af);
  border-radius: 999px; transition: width 120ms linear, filter 200ms;
}
.nitro-wrap.ready .nitro-fill { box-shadow: 0 0 18px rgba(56, 189, 248, 0.75); }
.nitro-wrap.boosting .nitro-fill { background: linear-gradient(270deg, #fbbf24, #f97316 70%, #dc2626); }

.combo {
  font-family: var(--font-display); font-weight: 900; font-size: clamp(14px, 2vw, 22px);
  color: var(--gold); opacity: 0; transform: translateY(8px);
  transition: opacity 200ms, transform 200ms; text-align: left;
}
.combo.on { opacity: 1; transform: none; }

.toasts { position: absolute; top: 40%; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 5; }
.toast {
  padding: 8px 18px; border-radius: 999px; font-weight: 700; font-size: clamp(12px, 1.5vw, 15px);
  background: rgba(9, 14, 26, 0.8); border: 1px solid var(--border-strong);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: toastIn 260ms cubic-bezier(0.16, 1, 0.3, 1) both;
  white-space: nowrap;
}
.toast.good { color: var(--accent); border-color: rgba(34, 197, 94, 0.4); }
.toast.gold { color: var(--gold); border-color: rgba(251, 191, 36, 0.45); }
.toast.bad { color: var(--primary-2); border-color: rgba(248, 113, 113, 0.45); }
.toast.out { animation: toastOut 220ms ease forwards; }

.fps {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-hud); font-size: 10px; color: var(--dim); opacity: 0.7;
}

/* ── Overlay & panels ────────────────────────────────────────── */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: clamp(12px, 3vw, 32px);
  background: radial-gradient(ellipse at 50% 40%, rgba(6, 10, 20, 0.55), rgba(3, 5, 10, 0.9));
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  overflow-y: auto;
}
.overlay[data-screen="none"] { display: none; }
.screen { display: none; animation: panelIn 380ms cubic-bezier(0.16, 1, 0.3, 1) both; }
.overlay[data-screen="start"] .screen-start,
.overlay[data-screen="pause"] .screen-pause,
.overlay[data-screen="over"] .screen-over { display: block; }

.panel {
  width: min(100%, 660px);
  padding: clamp(20px, 3.2vw, 40px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  text-align: center;
}
.panel.danger { border-color: rgba(220, 38, 38, 0.35); }

.badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; margin-bottom: 18px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
}
.badge svg { width: 14px; height: 14px; stroke-width: 1.75; }

.game-title {
  margin: 0; font-family: var(--font-display); font-weight: 900;
  font-size: clamp(30px, 6.4vw, 62px); line-height: 1.05; letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff 20%, #ff9d9d 60%, var(--primary));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 60px rgba(220, 38, 38, 0.28);
}
.game-title-en {
  margin: 6px 0 16px; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(11px, 1.6vw, 15px); letter-spacing: 0.46em; color: var(--muted);
}
.lead { margin: 0 auto 22px; max-width: 46ch; color: #c3cbdb; font-size: clamp(13px, 1.6vw, 15px); line-height: 1.85; }

.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 14px; margin-bottom: 22px; }
.ctrl { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
kbd {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 7px;
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 6px;
  font-family: var(--font-hud); font-size: 11px; color: var(--text);
}

/* ── Segmented settings ──────────────────────────────────────── */
.settings { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin-bottom: 24px; }
.seg {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 4px; background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border); border-radius: 999px;
}
.seg-label { padding: 0 8px 0 4px; font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.seg button {
  padding: 7px 14px; min-height: 34px;
  background: transparent; border: none; border-radius: 999px;
  color: var(--muted); font-family: var(--font-ar); font-size: 12px; font-weight: 700; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.seg button:hover { color: var(--text); background: rgba(255, 255, 255, 0.07); }
.seg button.on { background: linear-gradient(135deg, var(--secondary), #3b82f6); color: #fff; box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4); }
.seg button:focus-visible { outline: none; box-shadow: var(--ring); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 46px; padding: 12px 22px;
  border: none; border-radius: 999px; cursor: pointer;
  font-family: var(--font-ar); font-size: 14px; font-weight: 800; color: var(--text);
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), opacity var(--t-fast);
}
.btn svg { width: 18px; height: 18px; stroke-width: 1.75; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #f43f3f);
  box-shadow: 0 10px 34px rgba(220, 38, 38, 0.36); color: #fff;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 16px 46px rgba(220, 38, 38, 0.5); }
.btn-primary:active:not(:disabled) { transform: translateY(0) scale(0.985); }
.btn-ghost { background: transparent; border: 1.5px solid var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); transform: translateY(-2px); }
.btn-xl { min-height: 58px; padding: 16px 40px; font-size: clamp(15px, 2.1vw, 19px); letter-spacing: 0.01em; }
.btn-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 24px; }

.best-line { margin: 16px 0 6px; font-size: 12.5px; color: var(--muted); }
.best-line strong { color: var(--gold); font-family: var(--font-hud); font-size: 14px; }
.credit { margin: 18px 0 0; font-size: 11px; color: var(--dim); line-height: 1.9; }
.credit strong { color: var(--muted); }
.hint { margin: 16px 0 0; font-size: 12px; color: var(--dim); }

/* ── Panels: stats, states ───────────────────────────────────── */
.panel-title {
  margin: 0 0 6px; font-family: var(--font-display); font-weight: 900;
  font-size: clamp(22px, 3.6vw, 34px);
}
.panel-title.danger { color: var(--primary-2); text-shadow: 0 0 40px rgba(220, 38, 38, 0.35); }
.reason { margin: 0 0 4px; color: #c3cbdb; font-size: 13.5px; }
.crash-mark {
  display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto 14px;
  border-radius: 50%; background: rgba(220, 38, 38, 0.14); border: 1px solid rgba(220, 38, 38, 0.4);
  color: var(--primary-2); animation: shake 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.crash-mark svg { width: 30px; height: 30px; stroke-width: 1.75; }
.record {
  display: inline-flex; align-items: center; gap: 8px; margin: 14px 0 0; padding: 7px 16px;
  border-radius: 999px; background: rgba(251, 191, 36, 0.14); border: 1px solid rgba(251, 191, 36, 0.45);
  color: var(--gold); font-weight: 800; font-size: 12px;
  animation: scorePop 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.record svg { width: 15px; height: 15px; stroke-width: 1.75; }
.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 22px 0 0; padding: 16px 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r);
}
.stats-grid > div { display: flex; flex-direction: column; gap: 6px; }
.stats-grid span { font-size: 10px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.stats-grid strong { font-family: var(--font-display); font-weight: 900; font-size: clamp(18px, 3vw, 26px); font-variant-numeric: tabular-nums; }

/* ── Touch controls ──────────────────────────────────────────── */
.touch { position: absolute; inset: auto 0 0 0; z-index: 15; padding: 18px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; pointer-events: none; }
.touch > * { pointer-events: auto; }
.touch-left, .touch-right { display: flex; gap: 12px; }
.tbtn {
  display: grid; place-items: center; width: 68px; height: 68px;
  background: rgba(9, 14, 26, 0.62); border: 1px solid var(--border-strong);
  border-radius: 20px; color: var(--text); cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: transform 90ms, background 90ms;
  touch-action: none;
}
.tbtn:active, .tbtn.active { transform: scale(0.94); background: rgba(255, 255, 255, 0.14); }
.tbtn svg { width: 26px; height: 26px; stroke-width: 1.75; }
.tbtn-wide { width: 74px; }
.tbtn.gas { background: rgba(34, 197, 94, 0.24); border-color: rgba(34, 197, 94, 0.5); }
.tbtn-nitro { width: 60px; height: 60px; background: rgba(37, 99, 235, 0.28); border-color: rgba(59, 130, 246, 0.55); }
.tbtn i:empty::before { font-family: var(--font-display); font-size: 16px; }
#tLeft i:empty::before, #tRight i:empty::before { content: "\2039"; }
#tRight i:empty::before { content: "\203A"; }
#tGas i:empty::before { content: "\25B2"; }
#tNitro i:empty::before { content: "N"; }

.error { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; background: rgba(3, 5, 10, 0.94); }
.error .panel { text-align: center; }
#errorMsg { color: var(--muted); font-family: var(--font-hud); font-size: 12.5px; line-height: 1.8; word-break: break-word; }

/* ── Motion ──────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes panelIn { from { opacity: 0; transform: translateY(18px) scale(0.985) } to { opacity: 1; transform: none } }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px) } }
@keyframes scorePop { 0% { transform: scale(1) } 40% { transform: scale(1.16) } 100% { transform: scale(1) } }
@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0) }
  18% { transform: translateX(-7px) rotate(-6deg) }
  38% { transform: translateX(6px) rotate(5deg) }
  58% { transform: translateX(-4px) rotate(-3deg) }
  80% { transform: translateX(2px) rotate(1deg) }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 60ms !important; }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 860px) {
  .stat { min-width: 70px; padding: 6px 10px; }
  .stat-label { letter-spacing: 0.08em; }
  .nitro-key { display: none; }
  .hud-bottom { align-items: center; }
}
@media (max-width: 640px) {
  .hud { padding: 8px; }
  .controls { display: none; }
  .stat:nth-child(3) { display: none; }
  .panel { padding: 20px 16px; }
  .game-title-en { letter-spacing: 0.3em; }
  .btn { min-height: 48px; }
}
@media (max-width: 420px) {
  .tbtn { width: 60px; height: 60px; }
  .tbtn-wide { width: 66px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (hover: none) and (pointer: coarse) {
  .icon-btn:hover, .btn:hover { transform: none; }
}
