* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: #0b0f14; color: #e6edf3;
  font-family: system-ui, -apple-system, "SF Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
body { touch-action: manipulation; }
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.screen { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- menu ---------- */
#menu { padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px); gap: 10px; overflow-y: auto; }
.menuHead h1 { margin: 6px 0 2px; font-size: 40px; letter-spacing: 0; color: #f0f6fc; }
.menuHead .sub { margin: 0 0 6px; color: #9aa7b4; font-size: 15px; }
.levelList { display: flex; flex-direction: column; gap: 8px; }
.levelCard {
  display: flex; align-items: center; gap: 10px;
  background: #141a22; border: 1px solid #232c37; border-radius: 16px;
  padding: 12px 14px; text-align: start; color: inherit; font: inherit;
  width: 100%; cursor: pointer;
}
.levelCard:active { background: #1a222c; }
.levelCard.locked { opacity: .45; }
.levelNum {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px;
  background: #1f2937; display: grid; place-items: center; font-weight: 700; color: #7dd3fc;
}
.levelMeta { flex: 1 1 auto; min-width: 0; }
.levelName { font-size: 17px; font-weight: 600; }
.levelGoal { font-size: 13px; color: #8b98a5; margin-top: 2px; }
.levelStars { font-size: 15px; color: #f5c451; letter-spacing: 1px; }
.menuFoot { display: flex; gap: 8px; margin-top: auto; padding-top: 10px; }

/* ---------- play ---------- */
#play {
  padding: calc(env(safe-area-inset-top) + 6px) 8px calc(env(safe-area-inset-bottom) + 6px);
  gap: 6px;
}
#topbar { display: flex; align-items: center; gap: 8px; height: 34px; }
#levelTitle { flex: 1 1 auto; text-align: center; font-size: 15px; color: #c9d5e1; }
#starsTop { width: 56px; text-align: end; color: #f5c451; font-size: 13px; }
.iconBtn { background: none; border: 0; color: #7d8b99; font: inherit; font-size: 13px; padding: 6px; }

#stage { position: relative; flex: 1 1 auto; min-height: 110px; border-radius: 14px; overflow: hidden; background: #0f141b; }
#scene { width: 100%; height: 100%; display: block; }

#banner {
  position: absolute; top: 8px; inset-inline: 8px;
  background: rgba(8, 12, 17, .62); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.08); border-radius: 12px;
  padding: 8px 10px; font-size: 13.5px; line-height: 1.45; color: #dbe6f0;
  display: flex; align-items: center; gap: 8px;
}
#banner .step { flex: 1 1 auto; }
#banner .counter { flex: 0 0 auto; color: #7d8b99; font-size: 12px; }
#banner .step { display: block; color: #7d8b99; }
#banner .step.now { color: #7dd3fc; font-weight: 600; }
#banner .step.done { color: #4ade80; text-decoration: line-through; opacity: .7; }

#toast {
  position: absolute; inset-inline: 8px; bottom: 8px;
  background: #7f1d1d; border: 1px solid #b91c1c; color: #fee2e2;
  border-radius: 12px; padding: 9px 11px; font-size: 13.5px; line-height: 1.45;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
#toast.good { background: #14532d; border-color: #166534; color: #dcfce7; }
#toast.warn { background: #4a2d05; border-color: #92400e; color: #fde68a; }

#restartWrap { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5,8,12,.35); }
.restartPill {
  font: inherit; font-size: 15px; font-weight: 700; color: #e6edf3;
  background: rgba(15,23,32,.92); border: 1px solid #334155; border-radius: 999px; padding: 10px 20px;
}

#hud { display: flex; align-items: center; gap: 10px; height: 84px; padding-inline: 4px; }
#gaugeWrap { width: 84px; height: 84px; flex: 0 0 84px; }
#gauge { width: 100%; height: 100%; }
.gaugeTrack { fill: none; stroke: #1c2530; stroke-width: 9; stroke-linecap: round; }
.gaugeRed { fill: none; stroke: #7f1d1d; stroke-width: 9; stroke-linecap: round; stroke-dasharray: 15 100; stroke-dashoffset: -85; }
.gaugeFill { fill: none; stroke: #38bdf8; stroke-width: 9; stroke-linecap: round; stroke-dasharray: 0 100; transition: stroke .15s; }
.gaugeFill.redline { stroke: #ef4444; }
#rpmText { fill: #93a4b5; font-size: 15px; font-weight: 600; }
#readouts { flex: 1 1 auto; display: flex; gap: 8px; }
.readout {
  flex: 1 1 0; background: #121821; border: 1px solid #212a35; border-radius: 14px;
  padding: 6px 10px; display: flex; align-items: baseline; gap: 5px;
}
.readout span { font-size: 26px; font-weight: 700; color: #f0f6fc; font-variant-numeric: tabular-nums; }
.readout small { font-size: 12px; color: #7d8b99; }
.gearReadout span { color: #7dd3fc; }

#controls { display: flex; flex-direction: column; gap: 8px; }
#pedals { display: flex; gap: 8px; height: 122px; }
.pedal {
  position: relative; flex: 1 1 0; border-radius: 16px; overflow: hidden;
  background: linear-gradient(180deg, #131a23, #0e141b);
  border: 1px solid #26303c; touch-action: none; cursor: pointer;
}
.pedalFill {
  position: absolute; top: 0; inset-inline: 0; height: 0%;
  background: linear-gradient(180deg, rgba(56,189,248,.55), rgba(56,189,248,.18));
  border-bottom: 2px solid rgba(125,211,252,.9);
}
.pedal[data-pedal="brake"] .pedalFill { background: linear-gradient(180deg, rgba(249,115,22,.55), rgba(249,115,22,.18)); border-bottom-color: rgba(251,146,60,.95); }
.pedal[data-pedal="gas"] .pedalFill { background: linear-gradient(180deg, rgba(34,197,94,.55), rgba(34,197,94,.18)); border-bottom-color: rgba(74,222,128,.95); }
.pedalLabel { position: absolute; bottom: 8px; inset-inline: 0; text-align: center; font-size: 13px; color: #b6c4d2; font-weight: 600; }
.biteBand {
  position: absolute; inset-inline: 0; top: 30%; height: 32%;
  border-block: 1px dashed rgba(250,204,21,.5);
  background: rgba(250,204,21,.05); pointer-events: none;
}
.biteBand::after {
  content: "نقطة التعشيق"; position: absolute; top: 50%; inset-inline: 0;
  transform: translateY(-50%); text-align: center; font-size: 10px; color: rgba(250,204,21,.75);
}

#sideControls { display: flex; gap: 8px; height: 122px; align-items: stretch; }
#leverWrap { position: relative; flex: 1 1 auto; min-width: 150px; background: #121821; border: 1px solid #212a35; border-radius: 16px; touch-action: none; }
#leverSvg { width: 100%; height: 100%; display: block; }
.hPath { stroke: #2c3745; stroke-width: 8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.slotLabel { fill: #7d8b99; font-size: 13px; font-weight: 700; }
.neutralLabel { fill: #4b5b6b; }
#knob {
  position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; background: radial-gradient(circle at 35% 30%, #64748b, #334155 70%);
  border: 2px solid #94a3b8; box-shadow: 0 4px 12px rgba(0,0,0,.5);
  left: 50%; top: 50%; pointer-events: none;
}
#btns { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; width: 108px; }
#btns .smallBtn { flex: 0 0 auto; height: 46px; }
.smallBtn {
  flex: 1 1 0; font: inherit; font-size: 13px; font-weight: 600; color: #cbd5e1;
  background: #161d26; border: 1px solid #2a3542; border-radius: 14px; padding: 8px;
}
.smallBtn.on { background: #7f1d1d; border-color: #b91c1c; color: #fecaca; }

/* ---------- result ---------- */
#result { justify-content: center; padding: 20px; }
#resultCard { background: #121821; border: 1px solid #212a35; border-radius: 20px; padding: 22px 18px; text-align: center; }
#resultCard h2 { margin: 0 0 6px; font-size: 24px; }
.bigStars { font-size: 34px; color: #f5c451; letter-spacing: 4px; margin: 6px 0; }
#resultText { color: #9aa7b4; font-size: 14px; line-height: 1.6; margin: 8px 0 16px; white-space: pre-line; }
.resultBtns { display: flex; flex-direction: column; gap: 8px; }
.primaryBtn {
  font: inherit; font-size: 16px; font-weight: 700; color: #06121c;
  background: #7dd3fc; border: 0; border-radius: 14px; padding: 13px;
}
.ghostBtn {
  font: inherit; font-size: 15px; color: #cbd5e1; background: #161d26;
  border: 1px solid #2a3542; border-radius: 14px; padding: 12px;
}

/* ---------- help ---------- */
#help { justify-content: center; padding: 18px; }
.helpCard { background: #121821; border: 1px solid #212a35; border-radius: 20px; padding: 18px; }
.helpCard h2 { margin: 0 0 10px; font-size: 20px; }
.helpCard ul { margin: 0 0 14px; padding-inline-start: 18px; color: #b6c4d2; font-size: 14px; line-height: 1.7; }
.helpCard b { color: #7dd3fc; }
