/* ================= سائق المدينة — الطراز البصري ================= */
*,*::before,*::after{box-sizing:border-box}

:root{
  --ink:#0A0D12;
  --ink-2:#121820;
  --ink-3:#18202B;
  --ivory:#F4EFE6;
  --ivory-dim:rgba(244,239,230,.66);
  --ivory-faint:rgba(244,239,230,.38);
  --gold:#C8A96A;
  --gold-lite:#E7D3A6;
  --gold-line:rgba(200,169,106,.26);
  --gold-line-soft:rgba(200,169,106,.14);
  --green:#12A45A;
  --green-deep:#0A8A45;
  --ease:cubic-bezier(.22,.61,.36,1);
}

html,body{height:100%;margin:0}

body{
  background:var(--ink);
  color:var(--ivory);
  font-family:'IBM Plex Sans Arabic',system-ui,-apple-system,'Segoe UI',Tahoma,sans-serif;
  line-height:1.55;
  -webkit-font-smoothing:antialiased;
  overflow:hidden;
  user-select:none;
  -webkit-user-select:none;
  -webkit-tap-highlight-color:transparent;
  overscroll-behavior:none;
}

button{font-family:inherit}
.hidden{display:none !important}

/* ================= الهيكل ================= */
.game{
  position:relative;
  height:100vh;
  height:100dvh;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  background:var(--ink);
}

/* ================= الشريط العلوي ================= */
.hud{
  flex:0 0 auto;
  position:relative;
  z-index:5;
  padding:8px 12px 9px;
  display:flex;
  flex-direction:column;
  gap:8px;
  background:linear-gradient(180deg,rgba(10,13,18,.98),rgba(10,13,18,.82));
  border-bottom:1px solid var(--gold-line-soft);
}

.hud-row{display:flex;align-items:center;gap:8px;min-width:0}

.hud-stat{
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:0;
  min-width:0;
  flex:0 1 auto;
  padding:3px 12px;
  border-radius:11px;
  border:1px solid var(--gold-line-soft);
  background:rgba(244,239,230,.03);
}
.hud-k{font-size:9.5px;line-height:1.4;color:var(--ivory-faint);font-weight:400;white-space:nowrap}
.hud-v{
  font-family:'Amiri',serif;
  font-size:17px;
  line-height:1.15;
  font-weight:700;
  color:var(--gold-lite);
  white-space:nowrap;
}

.hud-spacer{flex:1 1 auto;min-width:4px}

.hud-btn{
  flex:0 0 auto;
  width:42px;height:42px;
  display:grid;place-items:center;
  border-radius:50%;
  border:1px solid var(--gold-line-soft);
  background:rgba(244,239,230,.04);
  color:var(--gold);
  cursor:pointer;
  transition:transform .12s var(--ease),background .18s var(--ease),color .18s var(--ease);
}
.hud-btn:active{transform:scale(.92)}
.hud-btn:focus-visible{outline:2px solid var(--gold-lite);outline-offset:2px}
.hud-btn[aria-pressed="true"]{color:var(--ivory-faint)}

.bars{display:flex;flex-direction:column;gap:4px}
.bar{
  height:5px;
  border-radius:99px;
  background:rgba(244,239,230,.09);
  overflow:hidden;
}
.bar i{
  display:block;
  height:100%;
  border-radius:99px;
  width:100%;
  transition:width .08s linear;
}
.bar-hp{background:linear-gradient(90deg,var(--green-deep),var(--green))}
.bar-time{background:linear-gradient(90deg,#B08F4E,var(--gold-lite))}

/* ================= الساحة ================= */
.stage{
  position:relative;
  flex:1 1 auto;
  min-height:0;
  overflow:hidden;
  background:#0A0D12;
}
#scene{
  display:block;
  width:100%;
  height:100%;
  touch-action:none;
}

/* ================= أدوات التحكم ================= */
.controls{
  flex:0 0 auto;
  position:relative;
  z-index:5;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 14px 12px;
  background:linear-gradient(0deg,rgba(10,13,18,.99),rgba(10,13,18,.78));
  border-top:1px solid var(--gold-line-soft);
}

.pad{display:flex;align-items:center;gap:10px}

.pad-btn{
  -webkit-appearance:none;
  appearance:none;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:1px;
  border-radius:22px;
  border:1px solid var(--gold-line);
  background:linear-gradient(180deg,rgba(244,239,230,.10),rgba(244,239,230,.025));
  color:var(--gold-lite);
  cursor:pointer;
  touch-action:none;
  padding:0;
  transition:transform .1s var(--ease),background .14s var(--ease),color .14s var(--ease),box-shadow .14s var(--ease);
}
.pad-btn svg{width:28px;height:28px;display:block}
.pad-btn:focus-visible{outline:2px solid var(--gold-lite);outline-offset:2px}

.pad-btn--steer{width:70px;height:70px;border-radius:24px}
.pad-btn--brake{width:64px;height:64px;border-radius:50%;color:#F0B8A8;border-color:rgba(226,132,110,.35)}
.pad-btn--gas{
  width:78px;height:78px;border-radius:50%;
  color:#0B1A10;
  border-color:rgba(18,164,90,.55);
  background:linear-gradient(180deg,#4FD38C,#0F8C4B);
  box-shadow:0 10px 24px -14px rgba(18,164,90,.95);
}
.pad-btn--gas svg{width:30px;height:30px}
.pad-lbl{font-size:10px;font-weight:600;letter-spacing:.02em;line-height:1}

.pad-btn.is-on{transform:scale(.94)}
.pad-btn--steer.is-on{
  background:linear-gradient(180deg,rgba(200,169,106,.42),rgba(200,169,106,.16));
  color:#1A1409;
}
.pad-btn--gas.is-on{background:linear-gradient(180deg,#7BEAAF,#12A45A);transform:scale(.95)}
.pad-btn--brake.is-on{background:rgba(226,132,110,.3);color:#FFE6DE}

/* ================= الطبقات ================= */
.overlay{
  position:absolute;
  inset:0;
  z-index:20;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:14px;
  padding:26px 20px;
  text-align:center;
  overflow-y:auto;
  background:radial-gradient(ellipse 120% 80% at 50% 20%,rgba(20,27,37,.9),rgba(5,7,11,.97));
  backdrop-filter:blur(10px);
  -webkit-backdrop-filter:blur(10px);
}

.ov-head{display:flex;flex-direction:column;gap:6px;align-items:center}
.ov-kicker{
  margin:0;
  font-size:11px;
  letter-spacing:.16em;
  color:var(--gold);
  font-weight:500;
}
.ov-title{
  margin:0;
  font-family:'Amiri',serif;
  font-weight:700;
  font-size:clamp(2rem,9vw,2.7rem);
  line-height:1.25;
  color:var(--ivory);
}
.ov-title--sm{font-size:clamp(1.5rem,7vw,2rem)}
.ov-sub{
  margin:0;
  max-width:330px;
  font-size:13.5px;
  line-height:1.7;
  color:var(--ivory-dim);
  font-weight:300;
}
.ov-best{margin:0;font-size:12.5px;color:var(--ivory-faint);font-weight:300}
.ov-best b{font-family:'Amiri',serif;font-size:16px;color:var(--gold);font-weight:700}

.howto{
  list-style:none;
  margin:2px 0 0;
  padding:12px 14px;
  display:flex;
  flex-direction:column;
  gap:8px;
  width:100%;
  max-width:340px;
  border:1px solid var(--gold-line-soft);
  border-radius:14px;
  background:rgba(244,239,230,.025);
  font-size:12.5px;
  color:var(--ivory-dim);
  font-weight:300;
  text-align:start;
}
.howto li{display:flex;align-items:center;gap:9px}
.dot{
  flex:0 0 auto;
  width:9px;height:9px;border-radius:50%;
  box-shadow:0 0 10px currentColor;
}
.dot--gold{background:var(--gold);color:var(--gold)}
.dot--green{background:var(--green);color:var(--green)}
.dot--mint{background:#E7C97F;color:#E7C97F}

.btn{
  width:100%;
  max-width:340px;
  min-height:54px;
  border-radius:15px;
  border:1px solid transparent;
  font-size:16px;
  font-weight:600;
  cursor:pointer;
  display:grid;
  place-items:center;
  padding:0 20px;
  transition:transform .12s var(--ease),background .18s var(--ease),filter .18s var(--ease);
}
.btn:active{transform:translateY(1px) scale(.99)}
.btn:focus-visible{outline:2px solid var(--gold-lite);outline-offset:3px}
.btn--gold{
  background:linear-gradient(135deg,#F0E2C2 0%,#C8A96A 48%,#A98C51 100%);
  color:#181310;
  box-shadow:0 16px 32px -18px rgba(200,169,106,.9);
}
.btn--ghost{
  background:transparent;
  color:var(--ivory);
  border-color:var(--gold-line);
}

.final{display:flex;flex-direction:column;align-items:center;margin:2px 0 0}
.final-num{
  font-family:'Amiri',serif;
  font-weight:700;
  font-size:clamp(3.2rem,16vw,4.8rem);
  line-height:1;
  background:linear-gradient(180deg,#F3E6C7 0%,#C8A96A 58%,#9A7F49 100%);
  -webkit-background-clip:text;
  background-clip:text;
  color:transparent;
  -webkit-text-fill-color:transparent;
}
.final-unit{font-size:11px;letter-spacing:.2em;color:var(--ivory-faint);margin-top:4px}

.record{
  margin:2px 0 0;
  font-size:12.5px;
  font-weight:600;
  color:var(--gold-lite);
  animation:recordIn .45s var(--ease) both;
}
@keyframes recordIn{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}

.stats{display:flex;gap:8px;width:100%;max-width:340px}
.stat{
  flex:1;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:2px;
  padding:10px 6px;
  border:1px solid var(--gold-line-soft);
  border-radius:13px;
  background:rgba(244,239,230,.025);
}
.stat b{font-family:'Amiri',serif;font-size:19px;font-weight:700;color:var(--ivory);line-height:1.1}
.stat span{font-size:10.5px;color:var(--ivory-faint);font-weight:300}

/* ================= لوحة النتائج ================= */
.board{
  width:100%;
  max-width:340px;
  margin-top:6px;
  padding-top:12px;
  border-top:1px solid rgba(244,239,230,.08);
  text-align:start;
}
.board-title{margin:0 0 8px;font-family:'Amiri',serif;font-size:15px;font-weight:700;color:var(--gold-lite)}
.board-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:5px}
.board-row{
  display:flex;align-items:center;gap:9px;
  padding:7px 11px;
  border-radius:10px;
  background:rgba(244,239,230,.03);
  border:1px solid rgba(244,239,230,.06);
  font-size:12.5px;
}
.board-row.is-you{border-color:var(--gold-line);background:rgba(200,169,106,.1)}
.board-rank{font-family:'Amiri',serif;color:var(--gold);font-size:14px;min-width:16px}
.board-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ivory)}
.board-score{font-family:'Amiri',serif;font-weight:700;color:var(--gold-lite);font-size:14px}
.board-empty{padding:10px;font-size:12px;color:var(--ivory-faint);text-align:center;font-weight:300}
.board-note{margin:8px 0 0;font-size:10.5px;color:var(--ivory-faint);font-weight:300;line-height:1.6}

/* ================= شاشات قصيرة ================= */
@media (max-height:640px){
  .overlay{gap:10px;padding:18px 16px;justify-content:flex-start}
  .ov-title{font-size:clamp(1.6rem,7vw,2.1rem)}
  .howto{display:none}
  .btn{min-height:48px}
  .hud{padding:6px 10px 7px;gap:6px}
  .hud-v{font-size:15px}
  .hud-btn{width:38px;height:38px}
  .controls{padding:8px 12px 10px}
  .pad-btn--steer{width:62px;height:62px}
  .pad-btn--gas{width:70px;height:70px}
  .pad-btn--brake{width:58px;height:58px}
  .final-num{font-size:clamp(2.6rem,13vw,3.6rem)}
}

@media (max-width:359px){
  .controls{padding:8px 10px 10px}
  .pad{gap:8px}
  .pad-btn--steer{width:60px;height:60px;border-radius:20px}
  .pad-btn--gas{width:66px;height:66px}
  .pad-btn--brake{width:56px;height:56px}
  .pad-btn svg{width:24px;height:24px}
  .hud-stat{padding:3px 9px}
}

@media (min-width:720px){
  .controls{padding:14px 28px 16px}
  .pad-btn--steer{width:78px;height:78px}
  .pad-btn--gas{width:88px;height:88px}
  .pad-btn--brake{width:72px;height:72px}
  .hud{padding:10px 20px 11px}
}

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