/* ============================================================
   زقاق الطيف — Najdi night palette
   ============================================================ */
:root{
  --night:#060A12;
  --mist:#0B1420;
  --mid:#14202B;
  --clay:#2A211C;
  --ground:#3A2E24;
  --moon:#7FE0D8;
  --brass:#FFB25C;
  --lemon:#C6F24A;
  --blood:#E0453C;
  --ivory:#EDE6DA;
  --hair:rgba(237,230,218,0.14);
  --hair-strong:rgba(237,230,218,0.26);

  --f-hud:"Noto Kufi Arabic",system-ui,sans-serif;
  --f-engrave:"Amiri","Noto Kufi Arabic",serif;
}

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

html,body{
  margin:0;padding:0;height:100%;
  background:var(--night);
  color:var(--ivory);
  font-family:var(--f-hud);
  -webkit-font-smoothing:antialiased;
  overscroll-behavior:none;
  overflow:hidden;
}

button{font-family:inherit;color:inherit;border:0;background:none;cursor:pointer;
  -webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;}
input{font-family:inherit;}

#app{
  position:relative;
  display:flex;
  flex-direction:column;
  height:100%;
  height:100dvh;
  width:100%;
  overflow:hidden;
  background:var(--night);
}

.hidden{display:none !important;}

/* ================= HUD ================= */
.hud{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:6px;
  padding:6px 8px;
  background:rgba(6,10,18,0.92);
  border-bottom:1px solid var(--hair);
  font-family:var(--f-hud);
  font-size:11px;
  line-height:1;
  z-index:30;
  direction:rtl;
}
.hud__cell{
  display:flex;align-items:center;gap:5px;
  min-width:0;
  color:var(--ivory);
  opacity:.92;
}
.ico{
  width:15px;height:15px;flex:0 0 auto;
  fill:none;stroke:currentColor;stroke-width:1.6;
  stroke-linecap:round;stroke-linejoin:round;
}
.hud__num{font-weight:500;font-size:11px;letter-spacing:.02em;font-variant-numeric:tabular-nums;}
.hud__cell--time .hud__num{color:var(--moon);}
.hud__cell--time.is-low .hud__num{color:var(--blood);}
.hud__cell--time.is-low .ico{color:var(--blood);}

.meter{
  position:relative;
  width:34px;height:6px;
  background:rgba(237,230,218,0.12);
  border-radius:2px;
  overflow:hidden;
  flex:0 0 auto;
}
.meter i{
  position:absolute;inset:0 auto 0 0;
  width:100%;
  background:var(--moon);
  transition:width .18s linear,background .3s;
  border-radius:2px;
}
.meter--battery.is-low i{background:var(--blood);}

.waves{display:flex;align-items:flex-end;gap:2px;height:13px;width:34px;flex:0 0 auto;}
.waves i{
  flex:1 1 0;min-width:2px;
  height:14%;
  background:var(--moon);
  border-radius:1px;
  transition:height .1s linear,background .2s;
}
.waves.is-hot i{background:var(--blood);}

.hud__gear{
  width:32px;height:32px;flex:0 0 auto;
  display:grid;place-items:center;
  border:1px solid var(--hair);
  border-radius:3px;
  color:var(--ivory);opacity:.8;
  transition:opacity .15s,background .15s;
}
.hud__gear:hover{opacity:1;background:rgba(237,230,218,0.06);}
.hud__gear:active{transform:scale(.95);}

/* ================= STAGE ================= */
.stage{
  position:relative;
  flex:1 1 auto;
  min-height:0;
  overflow:hidden;
  background:var(--night);
  touch-action:none;
}
#scene{
  display:block;
  width:100%;height:100%;
  touch-action:none;
  outline:none;
}
.vignette{
  position:absolute;inset:0;pointer-events:none;
  background:radial-gradient(120% 90% at 50% 45%,transparent 38%,rgba(3,5,10,0.72) 100%);
  mix-blend-mode:multiply;
}
.hud-tint{
  position:absolute;inset:0;pointer-events:none;
  opacity:0;transition:opacity .35s ease;
  box-shadow:inset 0 0 90px 20px rgba(224,69,60,0.55);
}
.hud-tint.is-on{opacity:1;}

.crosshair{
  position:absolute;left:50%;top:50%;
  width:7px;height:7px;margin:-3.5px 0 0 -3.5px;
  pointer-events:none;opacity:.5;
}
.crosshair span{
  display:block;width:100%;height:100%;
  border:1px solid var(--ivory);border-radius:50%;
  opacity:.85;
}
.crosshair.is-hot span{border-color:var(--lemont,#C6F24A);}

.prompt{
  position:absolute;left:50%;bottom:14px;transform:translateX(-50%);
  display:flex;align-items:center;gap:8px;
  padding:7px 12px;
  background:rgba(6,10,18,0.82);
  border:1px solid rgba(198,242,74,0.45);
  border-radius:3px;
  color:var(--ivory);
  font-size:12px;
  white-space:nowrap;
  pointer-events:none;
  animation:promptPulse 2.2s ease-in-out infinite;
  z-index:6;
}
@keyframes promptPulse{0%,100%{box-shadow:0 0 0 0 rgba(198,242,74,.0);}50%{box-shadow:0 0 0 4px rgba(198,242,74,.10);}}
.keycap{
  display:inline-grid;place-items:center;
  min-width:19px;height:19px;padding:0 4px;
  border:1px solid var(--lemon);border-radius:2px;
  color:var(--lemon);font-size:10px;font-weight:700;
}

.toast{
  position:absolute;left:50%;top:12px;transform:translateX(-50%);
  padding:6px 12px;border-radius:3px;
  background:rgba(6,10,18,0.88);
  border:1px solid var(--hair-strong);
  font-size:11.5px;color:var(--ivory);
  pointer-events:none;z-index:7;
  max-width:88vw;text-align:center;
  animation:toastIn .22s ease-out;
}
.toast.is-good{border-color:rgba(198,242,74,0.55);color:#DCF7A0;}
.toast.is-bad{border-color:rgba(224,69,60,0.6);color:#FFB0A8;}
@keyframes toastIn{from{opacity:0;transform:translate(-50%,-6px);}to{opacity:1;transform:translate(-50%,0);}}

.catchfade{
  position:absolute;inset:0;background:#000;
  opacity:0;pointer-events:none;transition:opacity .12s linear;z-index:8;
}

.zonebanner{
  position:absolute;left:50%;top:26%;transform:translateX(-50%);
  text-align:center;pointer-events:none;z-index:7;
  animation:zoneIn .6s ease-out;
}
.zonebanner b{
  display:block;font-family:var(--f-engrave);font-size:clamp(20px,6vw,30px);
  color:var(--ivory);letter-spacing:.02em;
  text-shadow:0 2px 18px rgba(0,0,0,.9);
}
.zonebanner i{
  display:block;width:64px;height:1px;margin:8px auto 0;
  background:linear-gradient(90deg,transparent,var(--lemon),transparent);
  opacity:.7;
}
@keyframes zoneIn{from{opacity:0;transform:translate(-50%,10px);}to{opacity:1;transform:translate(-50%,0);}}

/* ================= DOCK ================= */
.dock{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:2%;
  padding:6px 2.5%;
  width:100%;
  max-width:100%;
  background:rgba(6,10,18,0.95);
  border-top:1px solid var(--hair);
  z-index:30;
  direction:ltr;
  overflow:hidden;
}
.dpad{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  grid-template-rows:repeat(2,auto);
  gap:4%;
  flex:0 1 45%;
  min-width:0;
  max-width:min(45%,168px);
}
.pad{
  display:grid;place-items:center;
  width:100%;
  min-width:0;
  min-height:40px;
  aspect-ratio:1/0.9;
  padding:0;
  border:1px solid var(--hair-strong);
  border-radius:4px;
  background:rgba(237,230,218,0.05);
  color:var(--ivory);
  transition:background .1s,transform .1s,border-color .1s;
}
.pad svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;}
.pad--up{grid-column:2;grid-row:1;}
.pad--left{grid-column:1;grid-row:2;}
.pad--right{grid-column:3;grid-row:2;}
.pad--down{grid-column:2;grid-row:2;}
.pad.is-down,.pad:active{background:rgba(198,242,74,0.16);border-color:rgba(198,242,74,0.55);transform:scale(.96);}

.acts{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:3%;
  flex:0 1 50%;
  min-width:0;
  max-width:min(52%,186px);
}
.act{
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
  flex:1 1 0;
  min-width:0;
  min-height:44px;
  max-width:62px;
  aspect-ratio:1/0.94;
  padding:2px;
  border:1px solid var(--hair-strong);
  border-radius:4px;
  background:rgba(237,230,218,0.05);
  color:var(--ivory);
  font-size:clamp(7.5px,2.1vw,10px);font-family:var(--f-hud);
  line-height:1;
  overflow:hidden;
  transition:background .1s,transform .1s,border-color .12s,color .12s;
}
.act span{max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.act svg{width:17px;height:17px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;}
.act.is-on{background:rgba(127,224,216,0.15);border-color:rgba(127,224,216,0.55);color:var(--moon);}
.act---{background:transparent;}
.act--accent{border-color:rgba(198,242,74,0.4);color:#DCF7A0;}
.act--accent.is-ready{
  background:rgba(198,242,74,0.18);
  border-color:var(--lemon);
  color:var(--lemon);
  box-shadow:0 0 0 3px rgba(198,242,74,0.10);
  animation:promptPulse 1.8s ease-in-out infinite;
}
.act:active{transform:scale(.95);}

/* ================= OVERLAYS ================= */
.overlay{
  position:absolute;inset:0;
  display:flex;align-items:center;justify-content:center;
  padding:16px;
  background:rgba(4,7,13,0.84);
  -webkit-backdrop-filter:blur(9px);backdrop-filter:blur(9px);
  z-index:40;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}
.overlay--riddle{background:rgba(4,7,13,0.9);}
.overlay--over{padding-top:120px;align-items:flex-end;}

.panel{
  width:100%;
  max-width:440px;
  margin:auto;
  background:linear-gradient(180deg,rgba(14,19,28,0.96),rgba(8,12,19,0.97));
  border:1px solid var(--hair-strong);
  border-radius:4px;
  padding:20px 18px;
  box-shadow:0 24px 60px -20px rgba(0,0,0,0.9),inset 0 1px 0 rgba(237,230,218,0.06);
  animation:panelIn .26s cubic-bezier(.2,.8,.3,1);
}
@keyframes panelIn{from{opacity:0;transform:translateY(10px) scale(.99);}to{opacity:1;transform:none;}}

.panel--over{padding-top:16px;}

.crest{
  text-align:center;
  color:var(--lemon);
  font-size:13px;
  letter-spacing:.5em;
  margin-bottom:6px;
  opacity:.9;
}
.crest--sm{font-size:11px;margin-bottom:2px;}

.title{
  font-family:var(--f-engrave);
  font-weight:700;
  font-size:clamp(26px,7.5vw,38px);
  line-height:1.2;
  margin:0 0 6px;
  text-align:center;
  color:var(--ivory);
}
.title--sm{font-size:clamp(20px,5.5vw,26px);margin-bottom:4px;}

.sub{
  margin:0 0 16px;
  text-align:center;
  font-size:12.5px;
  line-height:1.7;
  color:rgba(237,230,218,0.72);
}
.sub--sm{margin-bottom:14px;font-size:12px;}

/* rules list */
.rules{
  display:grid;gap:8px;
  margin:0 0 18px;
  padding:12px 12px;
  border:1px solid var(--hair);
  border-radius:3px;
  background:rgba(237,230,218,0.025);
}
.rule{display:flex;align-items:flex-start;gap:8px;font-size:11.5px;line-height:1.6;color:rgba(237,230,218,0.82);}
.rule b{color:var(--lemon);font-weight:700;}
.dot{width:6px;height:6px;border-radius:50%;margin-top:6px;flex:0 0 auto;}
.dot--lemon{background:var(--lemon);}
.dot--brass{background:var(--brass);}
.dot--blood{background:var(--blood);}
.dot--moon{background:var(--moon);}

/* buttons */
.btn{
  display:block;width:100%;
  min-height:48px;
  padding:12px 16px;
  border-radius:3px;
  font-family:var(--f-hud);
  font-size:14px;
  font-weight:500;
  letter-spacing:.01em;
  transition:transform .1s,background .15s,border-color .15s,color .15s,box-shadow .15s;
}
.btn:active{transform:scale(.985);}
.btn--primary{
  background:rgba(198,242,74,0.12);
  border:1px solid var(--lemon);
  color:#E4FFA6;
  box-shadow:0 0 0 0 rgba(198,242,74,0);
}
.btn--primary:hover{background:rgba(198,242,74,0.2);box-shadow:0 0 22px -6px rgba(198,242,74,.55);}
.btn--ghost{
  background:rgba(237,230,218,0.04);
  border:1px solid var(--hair-strong);
  color:rgba(237,230,218,0.85);
  font-size:12.5px;
  min-height:42px;
  padding:9px 14px;
}
.btn--ghost:hover{background:rgba(237,230,218,0.09);color:var(--ivory);}
.btn--sm{font-size:11.5px;min-height:38px;padding:7px 12px;}

.menu__row{display:flex;gap:8px;margin-top:10px;align-items:stretch;}
.menu__row .btn{flex:1 1 0;}

.best{
  display:grid;place-items:center;
  padding:0 12px;
  border:1px solid var(--hair);
  border-radius:3px;
  font-size:11px;
  color:rgba(237,230,218,0.6);
  white-space:nowrap;
  min-height:42px;
}
.best b{display:block;color:var(--moon);font-size:13px;font-weight:500;font-variant-numeric:tabular-nums;}
.best--over{margin:12px 0;border:0;font-size:11.5px;color:rgba(237,230,218,0.55);}
.best--over b{display:inline;font-size:14px;margin-inline-start:6px;}

.keys{
  display:flex;flex-wrap:wrap;gap:10px 14px;
  margin-top:16px;padding-top:14px;
  border-top:1px solid var(--hair);
  font-size:10.5px;color:rgba(237,230,218,0.5);
  justify-content:center;
}
.keys span{display:flex;align-items:center;gap:4px;}
kbd{
  display:inline-grid;place-items:center;
  min-width:17px;height:17px;padding:0 3px;
  border:1px solid var(--hair-strong);border-radius:2px;
  font-family:var(--f-hud);font-size:9.5px;
  color:rgba(237,230,218,0.7);
}

/* ================= RIDDLE ================= */
.panel--riddle{padding:18px 16px 14px;}
.riddle__head{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  margin-bottom:14px;
}
.tag{
  font-size:10px;letter-spacing:.06em;
  padding:4px 9px;border-radius:2px;
  border:1px solid rgba(198,242,74,0.5);
  color:var(--lemon);
  background:rgba(198,242,74,0.07);
}
.doorlbl{font-family:var(--f-engrave);font-size:13px;color:rgba(237,230,218,0.62);}

.riddle__q{
  font-family:var(--f-engrave);
  font-size:clamp(17px,4.6vw,21px);
  line-height:1.8;
  margin:0 0 14px;
  color:var(--ivory);
  text-align:center;
}

.letters{
  display:flex;gap:7px;justify-content:center;flex-wrap:wrap;
  margin:0 0 16px;
  direction:rtl;
}
.letters span{
  display:grid;place-items:center;
  width:38px;height:44px;
  border:1px solid rgba(198,242,74,0.55);
  border-radius:2px;
  background:rgba(198,242,74,0.06);
  color:var(--lemon);
  font-family:var(--f-engrave);
  font-size:20px;
}

.options{display:grid;gap:8px;margin-bottom:12px;}
.opt{
  display:flex;align-items:center;gap:11px;
  width:100%;min-height:54px;
  padding:10px 14px;
  border:1px solid rgba(237,230,218,0.16);
  border-radius:3px;
  background:rgba(237,230,218,0.035);
  color:var(--ivory);
  font-family:var(--f-engrave);
  font-size:17px;
  text-align:start;
  transition:background .13s,border-color .13s,transform .1s;
}
.opt:hover{background:rgba(198,242,74,0.08);border-color:rgba(198,242,74,0.45);}
.opt:active{transform:scale(.99);}
.opt .bullet{
  display:grid;place-items:center;
  width:26px;height:26px;flex:0 0 auto;
  border:1px solid rgba(198,242,74,0.5);border-radius:50%;
  color:var(--lemon);font-family:var(--f-hud);font-size:11.5px;
}
.opt.is-wrong{
  border-color:rgba(224,69,60,0.8);
  background:rgba(224,69,60,0.13);
  color:#FFC4BE;
  animation:shake .34s;
}
.opt.is-wrong .bullet{border-color:var(--blood);color:var(--blood);}
.opt.is-right{
  border-color:var(--lemon);
  background:rgba(198,242,74,0.16);
  color:#EAFFB4;
}
.opt.is-right .bullet{border-color:var(--lemon);background:var(--lemon);color:#10160a;}
.opt:disabled{cursor:default;}
@keyframes shake{
  0%,100%{transform:translateX(0);}
  20%{transform:translateX(-5px);}
  45%{transform:translateX(5px);}
  70%{transform:translateX(-3px);}
}

.feedback{
  padding:9px 12px;margin-bottom:10px;
  border-radius:3px;font-size:12px;line-height:1.6;
  border:1px solid var(--hair-strong);
  background:rgba(237,230,218,0.04);
  text-align:center;
}
.feedback.is-good{border-color:rgba(198,242,74,0.55);color:#DCF7A0;background:rgba(198,242,74,0.08);}
.feedback.is-bad{border-color:rgba(224,69,60,0.55);color:#FFB0A8;background:rgba(224,69,60,0.08);}

.tideline{
  text-align:center;font-size:10px;color:rgba(237,230,218,0.34);
  margin:10px 0 0;letter-spacing:.04em;
}

/* ================= GAME OVER ================= */
.over__top{text-align:center;}
.stats{
  display:grid;grid-template-columns:1fr 1fr;gap:8px;
  margin:14px 0 4px;
}
.stat{
  display:flex;align-items:center;justify-content:space-between;gap:8px;
  padding:9px 12px;
  border:1px solid var(--hair);
  border-radius:3px;
  background:rgba(237,230,218,0.03);
  font-size:11px;color:rgba(237,230,218,0.62);
}
.stat b{font-size:13px;color:var(--ivory);font-weight:500;font-variant-numeric:tabular-nums;}
.stat--big{grid-column:1/-1;border-color:rgba(198,242,74,0.45);background:rgba(198,242,74,0.07);}
.stat--big b{font-size:22px;color:var(--lemon);}

/* ================= SETTINGS ================= */
.panel--settings{padding:20px 18px;}
.field{display:block;margin-bottom:18px;}
.field span{
  display:flex;justify-content:space-between;align-items:baseline;
  font-size:11.5px;color:rgba(237,230,218,0.7);margin-bottom:9px;
}
.field b{color:var(--moon);font-size:12.5px;font-weight:500;font-variant-numeric:tabular-nums;}

input[type=range]{
  -webkit-appearance:none;appearance:none;
  width:100%;height:26px;background:transparent;direction:ltr;
}
input[type=range]::-webkit-slider-runnable-track{
  height:2px;background:rgba(237,230,218,0.2);border-radius:2px;
}
input[type=range]::-moz-range-track{height:2px;background:rgba(237,230,218,0.2);border-radius:2px;}
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none;appearance:none;
  width:18px;height:18px;border-radius:50%;
  background:var(--lemon);border:0;
  margin-top:-8px;
  box-shadow:0 0 12px -2px rgba(198,242,74,.7);
}
input[type=range]::-moz-range-thumb{
  width:18px;height:18px;border-radius:50%;background:var(--lemon);border:0;
}

.toggle{
  display:flex;align-items:center;justify-content:space-between;
  width:100%;padding:12px 14px;margin-bottom:16px;
  border:1px solid var(--hair-strong);border-radius:3px;
  background:rgba(237,230,218,0.03);
  font-size:12.5px;color:rgba(237,230,218,0.82);
}
.switch{
  position:relative;width:38px;height:20px;border-radius:10px;
  background:rgba(237,230,218,0.16);
  transition:background .18s;
  flex:0 0 auto;
}
.switch b{
  position:absolute;top:2px;left:2px;
  width:16px;height:16px;border-radius:50%;
  background:var(--ivory);
  transition:transform .18s cubic-bezier(.2,.8,.3,1);
}
.toggle[aria-pressed="true"] .switch{background:rgba(224,69,60,0.7);}
.toggle[aria-pressed="true"] .switch b{transform:translateX(18px);}

.hint{
  font-size:10.5px;line-height:1.7;color:rgba(237,230,218,0.4);
  margin:0 0 16px;text-align:center;
}

/* ================= LEADERBOARD ================= */
.lb{
  margin-top:16px;padding-top:14px;
  border-top:1px solid var(--hair);
}
.lb__h{
  font-size:11px;font-weight:500;
  color:rgba(237,230,218,0.75);
  margin:0 0 10px;display:flex;justify-content:space-between;align-items:baseline;
}
.lb__h span{font-size:9.5px;color:rgba(237,230,218,0.36);font-weight:400;}
.lb__list{list-style:none;margin:0 0 10px;padding:0;display:grid;gap:4px;}
.lb__list li{
  display:flex;align-items:center;gap:9px;
  padding:7px 10px;border-radius:2px;
  background:rgba(237,230,218,0.03);
  font-size:11.5px;color:rgba(237,230,218,0.78);
}
.lb__list li.is-you{background:rgba(198,242,74,0.1);color:#DCF7A0;}
.lb__list .rank{color:var(--moon);font-variant-numeric:tabular-nums;min-width:16px;}
.lb__list .handle{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.lb__list .sc{font-variant-numeric:tabular-nums;color:var(--ivory);}

/* ================= RESPONSIVE ================= */
@media (max-height:520px){
  .hud{padding:4px 8px;}
  .panel{padding:14px 14px;}
  .rules{gap:5px;padding:9px 10px;margin-bottom:12px;}
  .rule{font-size:10.5px;}
  .title{font-size:clamp(20px,5vw,26px);}
  .sub{font-size:11px;margin-bottom:10px;}
  .keys{display:none;}
  .btn{min-height:44px;font-size:13px;}
  .overlay--over{padding-top:120px;}
  .panel--riddle{padding:14px 14px 10px;}
  .riddle__q{font-size:16px;line-height:1.65;margin-bottom:10px;}
  .opt{min-height:46px;font-size:15px;}
  .letters span{width:32px;height:38px;font-size:17px;}
  .dpad{max-width:min(44%,150px);gap:3%;}
  .act{max-width:min(50%,56px);font-size:clamp(7.5px,2vw,9.5px);min-height:42px;}
  .act svg{width:15px;height:15px;}
  .stats{margin:10px 0 2px;}
  .stat{padding:7px 10px;}
}

@media (max-width:380px){
  .hud{font-size:10px;gap:4px;}
  .meter{width:26px;}
  .waves{width:26px;}
  .hud__gear{width:29px;height:29px;}
  .acts{gap:2%;max-width:min(50%,150px);}
  .act{font-size:7.5px;min-height:42px;}
  .dpad{max-width:min(44%,140px);}
}

@media (min-width:900px){
  .panel{max-width:480px;}
  .dock{padding:8px 24px;}
  .hud{padding:7px 16px;font-size:12px;}
  .dpad{max-width:min(45%,190px);}
  .acts{max-width:min(52%,216px);}
  .act{max-width:72px;font-size:10.5px;}
  .act svg{width:19px;height:19px;}
}

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