:root {
  --bg: #050912;
  --surface: rgba(255, 255, 255, .055);
  --border: rgba(255, 255, 255, .10);
  --fg: #f2f6ff;
  --muted: #9fb0cc;
  --red: #dc2626;
  --blue: #2563eb;
  --green: #22c55e;
  --amber: #f59e0b;
  --cyan: #22d3ee;
  --accent: var(--cyan);
  --shadow: 0 18px 50px rgba(0, 0, 0, .55);
  --font-ar: 'Tajawal', 'Segoe UI', system-ui, -apple-system, 'Noto Kufi Arabic', sans-serif;
  --font-num: 'Orbitron', 'Tajawal', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: radial-gradient(120% 90% at 50% 0%, #101c33 0%, var(--bg) 60%, #01030a 100%);
  color: var(--fg);
  font-family: var(--font-ar);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }
body.playing #scene { cursor: default; }
#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(115% 85% at 50% 45%, transparent 46%, rgba(0, 0, 0, .58) 100%);
}
#flash, #fade { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
#flash { background: #ff2b2b; transition: opacity .12s ease; }
#fade { background: #02040a; transition: opacity .3s ease; }
#fade.on { opacity: 1; }
.hidden { display: none !important; }
button { font-family: inherit; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-radius: 9px; }
body.zone-0 { --accent: #22d3ee; }
body.zone-1 { --accent: #f59e0b; }
body.zone-2 { --accent: #14b8a6; }
body.zone-3 { --accent: #f97316; }
#hud {
  position: absolute; inset: 0 0 auto 0; display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; padding: 12px clamp(10px, 2vw, 22px); pointer-events: none; z-index: 5;
}
.hud-left, .hud-center, .hud-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hud-center { flex-direction: column; padding-top: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; font-size: 13px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, .04));
  border: 1px solid var(--border); border-radius: 999px; backdrop-filter: blur(12px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35); white-space: nowrap;
}
.chip-k { color: var(--muted); font-size: 12px; }
.chip-v { font-family: var(--font-num); font-weight: 900; color: var(--accent); }
.chip-n { font-weight: 700; }
.chip-zone { color: var(--muted); font-size: 12px; }
.chip-coins { color: #ffd166; font-family: var(--font-num); font-weight: 700; }
.chip-coins .ico { stroke: #ffd166; }
.dim { color: var(--muted); font-size: 11px; font-family: var(--font-num); }
.timer {
  font-family: var(--font-num); font-weight: 900; letter-spacing: .04em;
  font-size: clamp(18px, 3.4vw, 27px); text-shadow: 0 0 20px rgba(34, 211, 238, .55);
}
.timer-bar {
  width: clamp(120px, 22vw, 230px); height: 6px; border-radius: 99px; overflow: hidden;
  background: rgba(255, 255, 255, .13); border: 1px solid rgba(255, 255, 255, .07);
}
.timer-bar i { display: block; height: 100%; width: 100%; border-radius: 99px; background: linear-gradient(90deg, #22c55e, #86efac); transition: width .18s linear; }
.timer-bar i.warn { background: linear-gradient(90deg, #f59e0b, #fde68a); }
.timer-bar i.danger { background: linear-gradient(90deg, #dc2626, #f87171); animation: pulseBar .55s infinite alternate; }
.chip-lives { gap: 4px; padding: 6px 11px; }
.hp { width: 18px; height: 18px; fill: rgba(255, 255, 255, .14); stroke: rgba(255, 255, 255, .4); stroke-width: 1.5; transition: fill .2s ease; }
.hp.on { fill: #ef4444; stroke: #fecaca; filter: drop-shadow(0 0 6px rgba(239, 68, 68, .85)); }
.dash { width: 30px; height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .16); position: relative; margin-inline-start: 4px; }
.dash::after { content: ''; position: absolute; inset: 0; border-radius: 99px; background: var(--accent); opacity: .28; }
.dash.ready::after { opacity: 1; box-shadow: 0 0 12px var(--accent); }
.icon-btn {
  pointer-events: auto; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  color: var(--fg); border: 1px solid var(--border); backdrop-filter: blur(10px);
  background: linear-gradient(180deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, .04));
  transition: transform .18s ease, background .18s ease;
}
.icon-btn:hover { transform: translateY(-2px); background: rgba(255, 255, 255, .16); }
.icon-btn.muted { color: #64748b; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.chip-coins .ico { fill: none; width: 16px; height: 16px; }
#touch { position: absolute; inset: auto 0 0 0; height: 46vh; pointer-events: none; z-index: 6; }
#stick {
  position: absolute; left: 20px; bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  width: 126px; height: 126px; border-radius: 50%; pointer-events: auto; touch-action: none;
  background: radial-gradient(circle, rgba(255, 255, 255, .12), rgba(255, 255, 255, .03));
  border: 1px solid var(--border); backdrop-filter: blur(8px);
}
#knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, .82), rgba(255, 255, 255, .38));
  box-shadow: 0 8px 20px rgba(0, 0, 0, .5); transition: transform .06s linear;
}
.tbtns { position: absolute; right: 18px; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; align-items: flex-end; gap: 14px; }
.tbtn {
  pointer-events: auto; touch-action: none; display: grid; place-items: center; cursor: pointer; color: var(--fg);
  width: 72px; height: 72px; border-radius: 50%; border: 1px solid var(--border); backdrop-filter: blur(10px);
  background: linear-gradient(180deg, rgba(255, 255, 255, .15), rgba(255, 255, 255, .05));
  transition: transform .1s ease, background .18s ease;
}
.tbtn.big { width: 90px; height: 90px; border-color: rgba(34, 211, 238, .55); background: linear-gradient(180deg, rgba(34, 211, 238, .45), rgba(34, 211, 238, .15)); }
.tbtn:active { transform: scale(.93); }
.tbtn .ico { width: 26px; height: 26px; stroke-width: 2; }
.banner {
  position: absolute; top: 15vh; left: 50%; transform: translateX(-50%); text-align: center; z-index: 7; pointer-events: none;
  font-family: var(--font-num); font-weight: 900; letter-spacing: .04em; color: #fff;
  font-size: clamp(19px, 4vw, 34px); text-shadow: 0 8px 26px rgba(0, 0, 0, .75), 0 0 24px var(--accent);
}
.banner small { display: block; margin-top: 7px; font-family: var(--font-ar); font-size: 13px; font-weight: 600; color: #cbd5e1; text-shadow: none; }
.banner.anim { animation: bannerIn 2.3s ease forwards; }
.toast {
  position: absolute; left: 50%; bottom: 13vh; z-index: 8; transform: translateX(-50%) translateY(12px); opacity: 0;
  pointer-events: none; padding: 11px 19px; border-radius: 999px; font-size: 13.5px; font-weight: 600; text-align: center;
  max-width: min(88vw, 580px); background: rgba(8, 14, 26, .88); border: 1px solid var(--border); backdrop-filter: blur(12px);
  transition: opacity .26s ease, transform .26s ease;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.screen { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: clamp(12px, 3vw, 32px); overflow: auto; }
.glass {
  background: linear-gradient(180deg, rgba(12, 20, 36, .74), rgba(6, 10, 20, .86));
  border: 1px solid var(--border); border-radius: 22px; backdrop-filter: blur(16px); box-shadow: var(--shadow);
}
.menu-card { width: min(780px, 96vw); padding: clamp(18px, 3vw, 34px); animation: fadeUp .5s ease both; }
.logo-row { display: flex; align-items: center; gap: 16px; }
.logo {
  margin: 0; line-height: 1; letter-spacing: .06em; font-family: var(--font-num); font-weight: 900;
  font-size: clamp(30px, 6vw, 54px); color: transparent;
  background: linear-gradient(90deg, #ffffff, #7dd3fc); -webkit-background-clip: text; background-clip: text;
}
.logo span { color: transparent; background: linear-gradient(90deg, #f87171, #fbbf24); -webkit-background-clip: text; background-clip: text; }
.logo-ball {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 32% 28%, #fff, #9fd8ff 34%, #1e5eff 68%, #0a2a8a);
  box-shadow: 0 0 28px rgba(56, 160, 255, .85); animation: bob 2.6s ease-in-out infinite;
}
.logo-ar { margin: 5px 0 0; color: var(--muted); font-weight: 600; font-size: 14px; }
.tagline { color: #cdd8ea; font-size: 15px; line-height: 1.9; margin: 18px 0; }
.menu-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 15px; font-weight: 700;
  padding: 12px 20px; border-radius: 13px; color: var(--fg); border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, .04));
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(0, 0, 0, .45); }
.btn .ico { width: 17px; height: 17px; fill: currentColor; }
.btn.primary { color: #04121a; font-weight: 800; border-color: rgba(34, 211, 238, .6); background: linear-gradient(180deg, #22d3ee, #0e7fa8); }
.btn.ghost { background: transparent; color: var(--muted); }
.menu-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 20px; }
.menu-stats div { padding: 12px; text-align: center; border-radius: 14px; background: rgba(255, 255, 255, .05); border: 1px solid var(--border); }
.menu-stats b { display: block; font-family: var(--font-num); font-size: 22px; color: var(--accent); }
.menu-stats span { font-size: 12px; color: var(--muted); }
.keys { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 18px; font-size: 12.5px; color: var(--muted); }
.keys b { color: #dbe6f8; }
kbd {
  font-family: var(--font-num); font-size: 11px; padding: 3px 7px; margin-inline-end: 3px; border-radius: 6px;
  color: #fff; background: rgba(255, 255, 255, .10); border: 1px solid var(--border);
}
.levels-wrap { width: min(1060px, 97vw); padding: clamp(14px, 2.4vw, 28px); animation: fadeUp .45s ease both; }
.lv-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.lv-head h2 { margin: 0 0 4px; font-size: clamp(19px, 3vw, 27px); }
.lv-head p { margin: 0; color: var(--muted); font-size: 13px; }
.zone-block { margin-top: 16px; }
.zone-title { display: flex; align-items: center; gap: 8px; margin: 0 0 9px; font-size: 15px; color: #dbe6f8; }
.z-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.z-dot.z0 { background: #38bdf8; box-shadow: 0 0 10px #38bdf8; }
.z-dot.z1 { background: #f59e0b; box-shadow: 0 0 10px #f59e0b; }
.z-dot.z2 { background: #14b8a6; box-shadow: 0 0 10px #14b8a6; }
.z-dot.z3 { background: #ef4444; box-shadow: 0 0 10px #ef4444; }
.lv-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.lv {
  position: relative; display: flex; flex-direction: column; gap: 3px; text-align: right; cursor: pointer;
  padding: 10px 12px; border-radius: 14px; color: var(--fg); border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .025));
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.lv:hover:not(.locked) { transform: translateY(-3px); border-color: rgba(34, 211, 238, .55); box-shadow: 0 14px 28px rgba(0, 0, 0, .45); }
.lv.locked { opacity: .46; cursor: not-allowed; }
.lv-n { font-family: var(--font-num); font-weight: 900; font-size: 18px; color: var(--accent); }
.lv-name { font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lv-stars { display: flex; gap: 2px; }
.lv-best { font-family: var(--font-num); font-size: 11px; color: var(--muted); }
.st { width: 13px; height: 13px; fill: rgba(255, 255, 255, .16); }
.st.on { fill: #fbbf24; filter: drop-shadow(0 0 5px rgba(251, 191, 36, .8)); }
.st.sm { width: 12px; height: 12px; }
.lv-lock { position: absolute; left: 8px; top: 8px; width: 18px; height: 18px; color: var(--muted); }
.lock { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; }
.modal {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(2, 4, 10, .62); backdrop-filter: blur(7px); animation: fadeIn .2s ease both;
}
.modal-card { width: min(540px, 95vw); padding: clamp(18px, 3vw, 30px); text-align: center; animation: fadeUp .35s ease both; }
.m-title { margin: 0 0 6px; font-family: var(--font-num); font-weight: 900; font-size: clamp(20px, 4vw, 28px); }
.m-title.good { color: #4ade80; text-shadow: 0 0 22px rgba(74, 222, 128, .45); }
.m-title.bad { color: #f87171; text-shadow: 0 0 22px rgba(248, 113, 113, .45); }
.m-sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.m-stars { display: flex; justify-content: center; gap: 12px; margin: 8px 0 18px; }
.m-stars .st { width: 44px; height: 44px; animation: pop .45s ease both; }
.m-stars .st:nth-child(2) { animation-delay: .12s; }
.m-stars .st:nth-child(3) { animation-delay: .24s; }
.m-rows { display: grid; gap: 8px; margin-bottom: 18px; }
.m-rows div {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 15px; border-radius: 12px; font-size: 14px;
  background: rgba(255, 255, 255, .05); border: 1px solid var(--border);
}
.m-rows span { color: var(--muted); }
.m-rows b { font-family: var(--font-num); color: var(--accent); }
.m-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.fatal {
  position: absolute; inset: auto 16px 16px 16px; z-index: 60; padding: 14px 18px; border-radius: 14px;
  background: rgba(120, 12, 12, .94); border: 1px solid #f87171; color: #fff; box-shadow: var(--shadow);
}
.fatal b { display: block; margin-bottom: 4px; }
.fatal span { font-size: 13px; opacity: .88; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: scale(1); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes pulseBar { from { filter: brightness(1); } to { filter: brightness(1.6); } }
@keyframes bannerIn {
  0% { opacity: 0; transform: translateX(-50%) scale(.9); }
  16% { opacity: 1; transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(1.03); }
}
@media (max-width: 900px) {
  .lv-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .keys { display: none; }
  .menu-stats b { font-size: 19px; }
}
@media (max-width: 600px) {
  .lv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chip-n, .chip-zone { display: none; }
  .menu-card { padding: 16px; }
  .tagline { font-size: 14px; }
  .hud-center { order: 3; flex-basis: 100%; align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
