:root {
  --bg: #120d0a;
  --bg-2: #1b1410;
  --card: #231a14;
  --ink: #f4e8d8;
  --dim: #a89880;
  --gold: #e8a04a;
  --ember: #d45a2a;
  --line: rgba(244, 232, 216, 0.1);
  --danger: #e24b3a;
  --ok: #d7b56a;
  --radius: 14px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font-d: "Cairo", sans-serif;
  --font-b: "Tajawal", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-b);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

#gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

.speed-lines {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
}
.speed-lines::before,
.speed-lines::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.speed-lines::before {
  background: repeating-conic-gradient(
    from 0deg at 50% 58%,
    transparent 0deg 8deg,
    rgba(244, 232, 216, 0) 8deg,
    rgba(244, 232, 216, 0.2) 8.28deg,
    rgba(244, 232, 216, 0) 8.55deg,
    transparent 9deg 13deg
  );
  mask-image: radial-gradient(ellipse 44% 40% at 50% 56%, transparent 52%, #000 100%);
  -webkit-mask-image: radial-gradient(ellipse 44% 40% at 50% 56%, transparent 52%, #000 100%);
  opacity: 0.9;
}
.speed-lines::after {
  background:
    linear-gradient(90deg, rgba(244, 232, 216, 0.2) 0%, transparent 16%, transparent 84%, rgba(244, 232, 216, 0.2) 100%),
    linear-gradient(180deg, transparent 62%, rgba(212, 90, 42, 0.1) 100%);
}

@media (prefers-reduced-motion: no-preference) {
  .speed-lines::before { animation: sl-spin 22s linear infinite; }
}

@keyframes sl-spin { to { transform: rotate(-18deg); } }

.hidden { display: none !important; }

.screen {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.screen > * { pointer-events: auto; }

.screen-fill {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(18, 13, 10, 0.28) 0%, rgba(18, 13, 10, 0.62) 100%);
  color: var(--ink);
}

#screen-loading,
#screen-error {
  background: radial-gradient(ellipse at 50% 20%, #3a2214 0%, #120d0a 62%);
  color: var(--ink);
  pointer-events: auto;
}

#screen-menu {
  justify-content: space-between;
  background: transparent;
  color: var(--ink);
}
#screen-menu::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 58% 48% at 50% 40%, transparent 0%, rgba(22, 12, 10, 0.18) 52%, rgba(14, 8, 7, 0.72) 82%, rgba(10, 6, 5, 0.9) 100%),
    linear-gradient(180deg, rgba(18, 10, 10, 0.42) 0%, transparent 22%, transparent 58%, rgba(12, 7, 6, 0.55) 100%);
}
#screen-menu > * {
  position: relative;
  z-index: 1;
}

#screen-hud {
  pointer-events: none;
  background: transparent;
}

#screen-hud .hud-top,
#screen-hud .hud-bottom,
#screen-hud .touch-layer,
#screen-hud #btn-pause {
  pointer-events: auto;
}

.brand-title {
  font-family: var(--font-d);
  font-weight: 900;
  font-size: 42px;
  letter-spacing: -0.03em;
  line-height: 1.1;
  background: linear-gradient(180deg, #f8e2b8 0%, #e8a04a 55%, #d45a2a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
}

.brand-title-sm { font-size: 28px; text-align: start; }
.title-panel {
  flex: 1;
  min-width: 0;
  background: rgba(22, 16, 14, 0.78);
  color: var(--ink);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(244, 232, 216, 0.08);
  border-radius: 16px;
  padding: 10px 14px 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
}
.title-panel .eyebrow {
  text-align: start;
  color: var(--dim);
  margin-bottom: 2px;
}
.name-panel {
  background: rgba(22, 16, 14, 0.76);
  color: var(--ink);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(244, 232, 216, 0.08);
  border-radius: 16px;
  padding: 10px 12px 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.3);
}
.spec-card {
  background: rgba(16, 12, 11, 0.84);
  color: var(--ink);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(244, 232, 216, 0.08);
  border-radius: 16px;
  padding: 10px 12px 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.38);
}
.spec-card .car-desc {
  margin: 0 0 10px;
  max-width: none;
  font-size: 14px;
  line-height: 1.55;
  color: var(--dim);
}
.spec-card .stat-grid { gap: 8px; }
.spec-card .car-dots { margin-top: 10px; }

.brand-sub, .eyebrow {
  font-family: var(--font-d);
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: none;
  color: var(--dim);
  text-align: center;
  margin-top: 8px;
}

.eyebrow { letter-spacing: 0.08em; margin-top: 0; }

.muted { color: var(--dim); font-size: 15px; line-height: 1.6; text-align: center; }

.load-mark {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin-bottom: 20px;
  background: conic-gradient(from 180deg, #e8a04a, #d45a2a, transparent 70%);
  mask: radial-gradient(circle 22px, transparent 98%, #000 100%);
  -webkit-mask: radial-gradient(circle 22px, transparent 98%, #000 100%);
}

@media (prefers-reduced-motion: no-preference) {
  .load-mark { animation: spin 1.1s var(--ease-out) infinite; }
}

@keyframes spin { to { transform: rotate(-360deg); } }

.load-track {
  width: min(280px, 72vw);
  height: 6px;
  background: rgba(244, 232, 216, 0.08);
  border-radius: 99px;
  overflow: hidden;
  margin: 28px 0 12px;
}

#load-bar {
  height: 100%;
  width: 8%;
  background: linear-gradient(90deg, #e8a04a, #d45a2a);
  border-radius: 99px;
}

.menu-top, .menu-bot, .menu-mid {
  width: min(520px, 100%);
}
.menu-mid {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding-top: 6px;
}

.menu-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.menu-tools { display: flex; gap: 8px; }

.choose-label {
  font-family: var(--font-d);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--dim);
  text-align: center;
  margin-bottom: 8px;
}

.car-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.car-identity { text-align: center; flex: 1; min-width: 0; }
.car-identity h2 {
  font-family: var(--font-d);
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.15;
}
.car-identity p { color: var(--gold); font-size: 15px; margin-top: 2px; }

.car-desc {
  text-align: center;
  color: var(--dim);
  font-size: 15px;
  line-height: 1.65;
  margin: 0;
}

.stat-grid { display: grid; gap: 10px; }
.stat {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 13px;
}
.bar {
  height: 8px;
  background: rgba(244, 232, 216, 0.08);
  border-radius: 99px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #e8a04a, #d45a2a);
  border-radius: 99px;
  transition: width 420ms var(--ease-out);
}

.car-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}
.car-dots button {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  border: 0;
  background: rgba(244, 232, 216, 0.22);
  color: transparent;
  padding: 0;
}
.car-dots button.on {
  width: 22px;
  background: linear-gradient(90deg, #e8a04a, #d45a2a);
}

.menu-bot {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 8px;
}

.record-chip {
  align-self: center;
  display: flex;
  gap: 10px;
  align-items: baseline;
  color: var(--dim);
  font-size: 13px;
  background: rgba(18, 13, 10, 0.55);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 99px;
}
.record-chip strong { color: var(--gold); font-family: var(--font-d); font-size: 18px; }

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: var(--font-d);
  font-weight: 800;
  font-size: 16px;
  border-radius: var(--radius);
  min-height: 48px;
  padding: 12px 20px;
  color: var(--ink);
  background: var(--card);
  transition: transform 120ms ease-out, filter 200ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.btn-gold {
  background: linear-gradient(180deg, #e8a04a 0%, #d47828 46%, #b83c16 100%);
  color: #2a140a;
  border: 1px solid rgba(255, 226, 176, 0.28);
  box-shadow:
    inset 0 1px 0 rgba(255, 236, 200, 0.7),
    0 10px 28px rgba(168, 58, 18, 0.38);
}
.btn-xl { min-height: 56px; font-size: 18px; width: 100%; }
.btn-ghost {
  background: rgba(244, 232, 216, 0.06);
  color: var(--ink);
  border: 1px solid var(--line);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(18, 13, 10, 0.55);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn-lg { width: 52px; height: 52px; }
.icon-btn:active { transform: scale(0.96); }
.icon-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.glass {
  background: rgba(24, 17, 13, 0.78);
  color: var(--ink);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(244, 232, 216, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.panel {
  width: min(420px, 100%);
  border-radius: 20px;
  padding: 28px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel h2 {
  font-family: var(--font-d);
  font-size: 28px;
  letter-spacing: -0.02em;
  text-align: center;
  color: var(--ink);
}
.panel-sheet { gap: 18px; }
.panel-results { text-align: center; }

.stack { display: flex; flex-direction: column; gap: 8px; }
.stack .btn { width: 100%; }

.howto-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.howto-list li {
  background: rgba(244, 232, 216, 0.04);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--dim);
  line-height: 1.55;
  font-size: 15px;
}
.howto-list em {
  display: block;
  font-style: normal;
  color: var(--gold);
  font-family: var(--font-d);
  font-weight: 800;
  margin-bottom: 2px;
}

.hud-top {
  position: absolute;
  top: 10px;
  right: 10px;
  left: 10px;
  display: flex;
  align-items: stretch;
  gap: 6px;
  max-width: 100%;
}

.hud-card {
  background: rgba(18, 13, 10, 0.62);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 10px 7px;
  min-width: 0;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.score-card { flex: 1.4; position: relative; overflow: hidden; }
.timer-card, .multi-card { flex: 0 0 auto; min-width: 64px; text-align: center; }
.hud-k {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--dim);
  font-family: var(--font-d);
}
.hud-card strong {
  font-family: var(--font-d);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.multi-card strong { color: var(--gold); }
.hud-pause { flex: 0 0 44px; }

.bank-pop {
  position: absolute;
  left: 10px;
  top: 8px;
  color: var(--gold);
  font-style: normal;
  font-family: var(--font-d);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
}

.hud-mid {
  position: absolute;
  top: 68px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.drift-ribbon {
  min-width: 108px;
  padding: 6px 16px 8px;
  border-radius: 99px;
  background: rgba(18, 13, 10, 0.55);
  border: 1px solid rgba(232, 160, 74, 0.35);
  color: var(--gold);
  text-align: center;
  opacity: 0;
  transform: translateY(-8px);
}
.drift-ribbon.on { opacity: 1; transform: none; }
.drift-ribbon span {
  display: block;
  font-family: var(--font-d);
  font-weight: 800;
  font-size: 22px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.drift-ribbon small { color: var(--dim); font-size: 11px; letter-spacing: 0.08em; }

.toast {
  min-height: 0;
  padding: 0;
  color: var(--ink);
  font-family: var(--font-d);
  font-weight: 800;
  font-size: 15px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
  opacity: 0;
}
.toast.on { opacity: 1; }

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-d);
  font-weight: 900;
  font-size: 88px;
  color: #f8e2b8;
  text-shadow: 0 8px 40px rgba(212, 90, 42, 0.55);
  pointer-events: none;
  letter-spacing: -0.04em;
}

.hud-bottom {
  position: absolute;
  bottom: 168px;
  left: 12px;
  width: 118px;
  pointer-events: none;
}

.speedo { position: relative; color: var(--ink); }
.speedo-svg { width: 118px; height: 78px; display: block; }
.speedo-read {
  position: absolute;
  inset: 18px 0 0;
  text-align: center;
}
.speedo-read strong {
  display: block;
  font-family: var(--font-d);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.speedo-read span { font-size: 11px; color: var(--dim); }

.slip-meter {
  margin-top: 4px;
  height: 5px;
  border-radius: 99px;
  background: rgba(244, 232, 216, 0.1);
  overflow: hidden;
}
#slip-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #e8a04a, #d45a2a);
}

.touch-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 12px;
  pointer-events: none;
}

.cluster { display: flex; gap: 8px; pointer-events: auto; }
.cluster-steer { align-items: flex-end; }
.cluster-pedals { flex-direction: column; align-items: flex-end; }
.pedal-row { display: flex; gap: 8px; }

.pad {
  border: 1px solid rgba(244, 232, 216, 0.12);
  background: rgba(18, 13, 10, 0.58);
  color: var(--ink);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.pad span {
  font-family: var(--font-d);
  font-size: 11px;
  font-weight: 700;
  color: var(--dim);
}
.pad:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.pad.is-pressed {
  transform: scale(0.96);
  background: rgba(232, 160, 74, 0.22);
  border-color: rgba(232, 160, 74, 0.5);
  color: var(--gold);
}
.pad.is-pressed span { color: var(--gold); }

.pad-steer { width: 72px; height: 72px; border-radius: 50%; }
.pad-gas {
  width: 78px;
  height: 86px;
  border-radius: 24px 24px 18px 18px;
  background: rgba(232, 160, 74, 0.16);
  color: #f0b45c;
}
.pad-brake { width: 64px; height: 78px; }
.pad-hand { width: 86px; height: 52px; flex-direction: row; gap: 6px; border-radius: 14px; }
.pad-hand.is-pressed {
  background: rgba(226, 75, 58, 0.28);
  border-color: rgba(226, 75, 58, 0.55);
  color: #f2c2b8;
}

.mega-score {
  font-family: var(--font-d);
  font-weight: 900;
  font-size: 48px;
  letter-spacing: -0.03em;
  color: var(--gold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.record-flag {
  color: #2a160c;
  background: linear-gradient(90deg, #e8a04a, #d45a2a);
  display: inline-block;
  align-self: center;
  padding: 4px 12px;
  border-radius: 99px;
  font-family: var(--font-d);
  font-weight: 800;
  font-size: 13px;
}
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.result-grid div {
  background: rgba(244, 232, 216, 0.04);
  border-radius: 12px;
  padding: 10px 8px;
  color: var(--ink);
}
.result-grid span { display: block; color: var(--dim); font-size: 12px; margin-bottom: 2px; }
.result-grid strong { font-family: var(--font-d); font-size: 18px; }

@media (max-width: 430px) {
  .brand-title { font-size: 36px; }
  .hud-card strong { font-size: 17px; }
  .pad-steer { width: 68px; height: 68px; }
  .pad-gas { width: 72px; height: 80px; }
  .hud-bottom { bottom: 156px; }
}

@media (min-width: 900px) {
  .brand-title { font-size: 56px; }
  .touch-layer { padding: 0 28px 18px; }
  .hud-top { right: 20px; left: 20px; top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .bar i, .drift-ribbon, .toast, .load-mark { transition: none; animation: none; }
}