:root{
  --ink:#07090A;
  --concrete:#2B2C2A;
  --beige:#4A433A;
  --amber:#FFD79A;
  --amber-dim:#c9a468;
  --red:#C0392B;
  --brass:#6B4A32;
  --moon:#7F97A8;
  --paper:#e8e0d2;
}
*{box-sizing:border-box}
html,body{
  margin:0;padding:0;height:100%;width:100%;
  background:var(--ink);color:var(--paper);
  font-family:'Tajawal',system-ui,-apple-system,'Segoe UI',sans-serif;
  overflow:hidden;overscroll-behavior:none;
  -webkit-tap-highlight-color:transparent;
}
body{position:fixed;inset:0}
button{font-family:inherit}
svg{fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}

.app{
  position:fixed;inset:0;display:flex;flex-direction:column;
  background:var(--ink);
  user-select:none;-webkit-user-select:none;
}

/* ================= HUD ================= */
.hud{
  flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;
  gap:8px;padding:7px 10px;
  background:linear-gradient(180deg,rgba(12,14,15,.98),rgba(7,9,10,.92));
  border-bottom:1px solid rgba(255,215,154,.10);
  color:var(--amber);z-index:40;
  min-height:46px;
}
.hud-group{display:flex;align-items:center;gap:8px;min-width:0}
.hud-chip{
  display:flex;align-items:center;gap:5px;
  background:rgba(255,215,154,.06);
  border:1px solid rgba(255,215,154,.16);
  border-radius:8px;padding:4px 8px;
  font-size:12.5px;font-weight:700;line-height:1;
  color:var(--amber);white-space:nowrap;
}
.hud-chip svg{width:15px;height:15px;stroke:var(--amber-dim);stroke-width:2}
.hud-chip b{font-size:14px;font-variant-numeric:tabular-nums}
.hud-chip i{font-style:normal;opacity:.55;font-size:11px}
.hud-chip.timer{
  font-variant-numeric:tabular-nums;letter-spacing:.5px;
  font-size:14px;padding:5px 9px;
}
.hud-chip.timer.warn{color:#ffb0a4;border-color:rgba(192,57,43,.55);background:rgba(192,57,43,.16)}
.hud-bars{display:flex;flex-direction:column;gap:4px}
.barrow{display:flex;align-items:center;gap:4px}
.barrow .mini{width:11px;height:11px;stroke:var(--amber-dim);stroke-width:2;opacity:.8}
.bar{
  width:52px;height:5px;border-radius:3px;overflow:hidden;
  background:rgba(255,255,255,.09);
}
.bar i{display:block;height:100%;width:100%;border-radius:3px;
  background:linear-gradient(90deg,#b8863f,#FFD79A);
  transition:width .18s linear;}
.bar.stam i{background:linear-gradient(90deg,#4b6b74,#8fb6c4)}
.icon-btn{
  width:36px;height:36px;border-radius:9px;
  display:grid;place-items:center;
  background:rgba(255,215,154,.06);
  border:1px solid rgba(255,215,154,.18);
  color:var(--amber);cursor:pointer;
  transition:background .15s,border-color .15s;
}
.icon-btn svg{width:16px;height:16px;fill:currentColor;stroke:none}
.icon-btn:active{background:rgba(255,215,154,.2)}

/* ================= STAGE ================= */
.stage{
  position:relative;flex:1 1 auto;min-height:0;
  overflow:hidden;background:#040505;
  touch-action:none;
}
#scene{
  position:absolute;inset:0;width:100%;height:100%;display:block;
  touch-action:none;
}
.fx{position:absolute;inset:0;pointer-events:none;z-index:5}
.fx-grain{
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  opacity:.16;mix-blend-mode:overlay;
  animation:grainShift .55s steps(2) infinite;
}
@keyframes grainShift{
  0%{transform:translate3d(0,0,0)}
  50%{transform:translate3d(-6px,4px,0)}
  100%{transform:translate3d(3px,-5px,0)}
}
.fx-scan{
  background:repeating-linear-gradient(180deg,rgba(0,0,0,.22) 0 1px,rgba(0,0,0,0) 1px 3px);
  opacity:.35;mix-blend-mode:multiply;
}
.fx-vignette{
  background:radial-gradient(ellipse at 50% 50%,rgba(0,0,0,0) 34%,rgba(0,0,0,.55) 74%,rgba(0,0,0,.92) 100%);
}
.fx-red{
  background:radial-gradient(ellipse at 50% 50%,rgba(192,57,43,0) 35%,rgba(192,57,43,.55) 100%);
  opacity:0;transition:opacity .18s ease-out;
}
.fx-dark{background:#000;opacity:0;transition:opacity .4s ease-out;z-index:6}

.crosshair{
  position:absolute;left:50%;top:50%;width:5px;height:5px;margin:-2.5px 0 0 -2.5px;
  border-radius:50%;background:rgba(255,215,154,.55);
  box-shadow:0 0 8px rgba(255,215,154,.5);
  pointer-events:none;z-index:7;transition:transform .1s,background .1s;
}
.crosshair.hot{background:rgba(255,215,154,1);transform:scale(1.9)}

.prompt{
  position:absolute;left:50%;bottom:16%;transform:translateX(-50%);
  background:rgba(8,9,10,.82);border:1px solid rgba(255,215,154,.25);
  color:var(--amber);font-size:13px;font-weight:700;
  padding:7px 14px;border-radius:999px;pointer-events:none;z-index:8;
  white-space:nowrap;backdrop-filter:blur(6px);
}
.toast{
  position:absolute;left:50%;top:12%;transform:translate(-50%,-14px);
  background:rgba(8,9,10,.9);border:1px solid rgba(255,215,154,.3);
  color:var(--amber);font-size:13.5px;font-weight:700;
  padding:8px 16px;border-radius:10px;pointer-events:none;z-index:9;
  opacity:0;transition:opacity .25s,transform .25s;white-space:nowrap;
  max-width:92vw;overflow:hidden;text-overflow:ellipsis;
}
.toast.show{opacity:1;transform:translate(-50%,0)}
.carry{
  position:absolute;right:10px;top:10px;display:flex;align-items:center;gap:6px;
  background:rgba(107,74,50,.35);border:1px solid rgba(255,215,154,.35);
  color:var(--amber);font-size:11.5px;font-weight:700;
  padding:5px 10px;border-radius:8px;z-index:8;pointer-events:none;
  backdrop-filter:blur(6px);max-width:70vw;
}
.carry svg{width:13px;height:13px;flex:0 0 auto}
.carry span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

/* ================= OVERLAYS ================= */
/* القوائم تبدأ من أعلى الشاشة وتُمرَّر عند الحاجة، فلا يخرج زر البدء عن الشاشة أبداً */
.overlay{
  position:absolute;inset:0;z-index:80;
  display:block;
  padding:10px;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;touch-action:pan-y;
  min-height:0;text-align:center;
  background:radial-gradient(ellipse at 50% 40%,rgba(8,10,11,.88),rgba(3,4,5,.97));
  backdrop-filter:blur(4px);
  animation:fadeIn .28s ease-out;
}
/* إطار Meeem يفرض display:flex وتوسيطاً على الحوارات؛ نُلغي ذلك صراحةً
   حتى لا يُقتطع أعلى اللوحة ويصبح زر البدء غير قابل للوصول */
#startOverlay,#pauseOverlay,#endOverlay,#boardOverlay{
  display:block !important;
  position:absolute !important;inset:0 !important;
  overflow-y:auto !important;overflow-x:hidden !important;
  padding:10px !important;
}
#startOverlay.hidden,#pauseOverlay.hidden,#endOverlay.hidden,#boardOverlay.hidden{
  display:none !important;
}
#startOverlay>.panel,#pauseOverlay>.panel,#endOverlay>.panel,#boardOverlay>.panel{
  margin-block:0 !important;
  margin-inline:auto !important;
  max-height:none !important;
  overflow:visible !important;
  flex:0 0 auto !important;
}
#startOverlay .btn-primary{margin-top:2px}
.overlay.hidden{display:none !important}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}

/* خلفية القائمة: ممر المدرسة ليلاً */
#startOverlay{
  background-image:
    linear-gradient(180deg,rgba(4,5,6,.70) 0%,rgba(4,5,6,.86) 40%,rgba(3,4,5,.96) 78%,rgba(3,4,5,.99) 100%),
    url('assets/menu-bg.png');
  background-size:cover,cover;
  background-position:center,center 32%;
  background-repeat:no-repeat,no-repeat;
  background-color:#040506;
}

/* لقطة الفزع عند الإمساك بك */
.scare{
  position:absolute;inset:0;z-index:15;
  display:none;align-items:center;justify-content:center;
  background:#000;pointer-events:none;overflow:hidden;
}
.scare.show{display:flex;animation:scareIn .22s steps(3) 1}
.scare img{width:100%;height:100%;object-fit:cover;
  filter:contrast(1.15) saturate(.85) brightness(.92)}
@keyframes scareIn{
  0%{opacity:.25;transform:scale(1.14)}
  100%{opacity:1;transform:scale(1)}
}
.hint{
  font-size:10.5px;font-weight:700;line-height:1.5;
  color:rgba(255,215,154,.42);margin:0 0 10px;
}
.panel{
  flex:0 0 auto;width:100%;max-width:430px;margin:auto;
  max-height:100%;overflow-y:auto;overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;scrollbar-width:thin;
  background:linear-gradient(180deg,rgba(16,18,19,.94),rgba(9,10,11,.96));
  border:1px solid rgba(255,215,154,.15);
  border-radius:16px;padding:20px 18px;
  box-shadow:0 24px 60px rgba(0,0,0,.7),inset 0 1px 0 rgba(255,215,154,.06);
  text-align:center;
}
.panel.narrow{max-width:340px}
.kicker{
  font-size:10.5px;font-weight:700;letter-spacing:0;
  color:rgba(255,215,154,.55);margin-bottom:8px;
}
.title{
  margin:0 0 10px;font-size:clamp(30px,10vw,46px);font-weight:900;line-height:1.05;
  color:#f6ecdb;text-shadow:0 0 26px rgba(255,215,154,.28);
}
.title span{
  color:var(--amber);
  text-shadow:0 0 30px rgba(255,215,154,.5),0 0 60px rgba(192,57,43,.28);
}
.h2{margin:0 0 10px;font-size:21px;font-weight:900;color:#f4ead9}
.credit{
  display:inline-flex;flex-direction:column;align-items:center;gap:1px;
  font-size:13.5px;font-weight:900;color:var(--amber);
  border:1px solid rgba(255,215,154,.32);
  background:linear-gradient(180deg,rgba(107,74,50,.34),rgba(107,74,50,.12));
  padding:5px 16px;border-radius:9px;margin:2px 0 12px;
  line-height:1.4;
  box-shadow:inset 0 1px 0 rgba(255,215,154,.16);
}
.credit span{font-size:9.5px;font-weight:700;color:rgba(255,215,154,.62);letter-spacing:.3px}
.credit b{font-size:13.5px;font-weight:900;color:#ffe6bd}
.credit.small{display:inline-block;font-size:11.5px;padding:5px 11px;margin:10px 0 4px;opacity:.92}
.lead{
  font-size:12.8px;line-height:1.75;color:rgba(232,224,210,.72);
  margin:0 0 16px;
}
.btn-primary{
  display:block;width:100%;border:none;cursor:pointer;
  padding:13px 18px;border-radius:11px;
  font-size:16px;font-weight:900;color:#140f08;
  background:linear-gradient(180deg,#ffe1ae,#e8b571);
  box-shadow:0 8px 22px rgba(255,215,154,.18),inset 0 1px 0 rgba(255,255,255,.6);
  transition:transform .12s ease,box-shadow .12s ease,filter .12s;
  margin-bottom:9px;
}
.btn-primary:hover{filter:brightness(1.06)}
.btn-primary:active{transform:scale(.975);box-shadow:0 3px 10px rgba(255,215,154,.22)}
.btn-primary:focus-visible{outline:2px solid #fff;outline-offset:3px}
.btn-primary[disabled]{opacity:.5;cursor:default}
.row{display:flex;gap:8px}
.btn-ghost{
  flex:1;cursor:pointer;padding:10px 8px;border-radius:10px;
  background:rgba(255,215,154,.05);
  border:1px solid rgba(255,215,154,.2);
  color:rgba(255,215,154,.9);font-size:12.5px;font-weight:700;
  transition:background .15s,border-color .15s;
}
.btn-ghost:hover{background:rgba(255,215,154,.11)}
.btn-ghost:active{background:rgba(255,215,154,.2)}
.btn-ghost:focus-visible{outline:2px solid var(--amber);outline-offset:2px}
.best{margin-top:12px;font-size:11.5px;color:rgba(232,224,210,.45);font-weight:700}
.howto{
  margin-top:14px;padding-top:13px;border-top:1px dashed rgba(255,215,154,.16);
  font-size:11.8px;line-height:1.9;color:rgba(232,224,210,.6);text-align:right;
}
.howto.hidden{display:none}
.howto b{color:var(--amber);font-weight:900}

.stats{
  display:flex;flex-direction:column;gap:6px;margin:4px 0 8px;
  background:rgba(0,0,0,.35);border:1px solid rgba(255,215,154,.1);
  border-radius:11px;padding:11px 13px;
}
.stats div{display:flex;justify-content:space-between;align-items:center;
  font-size:12.5px;color:rgba(232,224,210,.62)}
.stats b{color:#f4ead9;font-size:14px;font-variant-numeric:tabular-nums}
.stats .big{border-top:1px solid rgba(255,215,154,.14);padding-top:7px;margin-top:3px}
.stats .big b{color:var(--amber);font-size:22px;font-weight:900}
.status{
  min-height:17px;font-size:11.5px;font-weight:700;margin-bottom:9px;
  color:rgba(232,224,210,.55);
}
.status.ok{color:#8fce9b}
.status.err{color:#ff9b8c}
.board-body{
  text-align:right;max-height:46vh;overflow-y:auto;
  margin-bottom:10px;font-size:13px;
}
.board-body .bl{display:flex;justify-content:space-between;align-items:center;
  padding:8px 10px;border-radius:8px;background:rgba(255,255,255,.04);margin-bottom:5px}
.board-body .bl.you{background:rgba(255,215,154,.13);border:1px solid rgba(255,215,154,.28)}
.board-body .bl .rk{color:rgba(255,215,154,.7);font-weight:900;margin-inline-end:8px;min-width:22px;display:inline-block}
.board-body .bl .hd{color:rgba(232,224,210,.85);font-weight:700}
.board-body .bl .sc{color:var(--amber);font-weight:900;font-variant-numeric:tabular-nums}
.board-body .empty{color:rgba(232,224,210,.45);text-align:center;padding:16px 0;font-size:12.5px}
.note{font-size:10.5px;line-height:1.6;color:rgba(232,224,210,.38);margin:2px 0 12px}
.board-body::-webkit-scrollbar{width:5px}
.board-body::-webkit-scrollbar-thumb{background:rgba(255,215,154,.2);border-radius:3px}

/* ================= DOCK ================= */
.dock{
  flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;
  gap:12px;padding:8px 14px 10px;
  background:linear-gradient(0deg,rgba(9,11,12,.99),rgba(7,9,10,.9));
  border-top:1px solid rgba(255,215,154,.09);
  z-index:40;
}
.stick-wrap{display:flex;flex-direction:column;align-items:center;gap:3px;flex:0 0 auto}
.stick-base{
  position:relative;width:104px;height:104px;border-radius:50%;
  background:radial-gradient(circle at 50% 45%,rgba(255,215,154,.09),rgba(20,22,23,.85));
  border:1px solid rgba(255,215,154,.2);
  touch-action:none;cursor:grab;
  box-shadow:inset 0 3px 14px rgba(0,0,0,.6);
}
.stick-ring{
  position:absolute;inset:22px;border-radius:50%;
  border:1px dashed rgba(255,215,154,.12);
}
.stick-knob{
  position:absolute;left:50%;top:50%;width:42px;height:42px;border-radius:50%;
  transform:translate(-50%,-50%);
  background:radial-gradient(circle at 40% 35%,#ffe6bd,#c99a5d 70%,#8a6534);
  box-shadow:0 4px 12px rgba(0,0,0,.6),inset 0 -2px 5px rgba(0,0,0,.35);
  pointer-events:none;
}
.stick-label{font-size:9.5px;font-weight:700;color:rgba(255,215,154,.42)}
.actions{display:grid;grid-template-columns:repeat(2,1fr);gap:8px;flex:0 0 auto}
.act{
  width:60px;height:52px;border-radius:12px;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
  background:linear-gradient(180deg,rgba(46,48,47,.9),rgba(24,26,26,.95));
  border:1px solid rgba(255,215,154,.16);
  color:rgba(255,215,154,.85);cursor:pointer;
  transition:transform .08s,background .12s,border-color .12s;
  touch-action:none;
}
.act svg{width:19px;height:19px;stroke-width:1.8}
.act span{font-size:9.5px;font-weight:700;line-height:1;opacity:.72}
.act:active,.act.on{
  background:linear-gradient(180deg,rgba(255,215,154,.9),rgba(201,158,94,.9));
  border-color:rgba(255,215,154,.9);
  color:#150f08;transform:scale(.95);
}
.act.on span{opacity:.95}

/* ================= RESPONSIVE ================= */
@media (max-height:640px){
  .stick-base{width:84px;height:84px}
  .stick-knob{width:34px;height:34px}
  .act{width:54px;height:46px;border-radius:11px}
  .act svg{width:17px;height:17px}
  .dock{padding:6px 12px 7px}
  .panel{padding:16px 14px}
  .lead{font-size:12px;line-height:1.65;margin-bottom:12px}
}
@media (max-width:380px){
  .bar{width:42px}
  .hud-chip{font-size:11.5px;padding:4px 6px}
  .stick-base{width:92px;height:92px}
}
@media (max-height:430px){
  .stick-label{display:none}
  .stick-base{width:74px;height:74px}
  .stick-knob{width:30px;height:30px}
  .act{width:50px;height:42px}
  .act span{font-size:8.5px}
}
/* شاشات قصيرة: قائمة البداية والنهاية تبقى كاملة داخل الشاشة */
@media (max-height:620px){
  .overlay{padding:8px 10px}
  .panel{padding:13px 12px;max-width:520px}
  .panel.narrow{max-width:340px}
  .kicker{font-size:9.5px;margin-bottom:4px}
  .title{font-size:clamp(22px,6.5vw,30px);margin-bottom:6px}
  .credit{font-size:11px;padding:4px 10px;margin-bottom:8px}
  .credit.small{font-size:10px;padding:3px 9px;margin:6px 0 3px}
  .lead{display:none}
  .h2{font-size:18px;margin-bottom:8px}
  .btn-primary{padding:10px 14px;font-size:14.5px;margin-bottom:7px}
  .btn-ghost{padding:8px 6px;font-size:11.5px}
  .best{margin-top:8px;font-size:10.5px}
  .stats{padding:8px 10px;gap:4px;margin:0 0 6px}
  .stats div{font-size:11.5px}
  .stats b{font-size:13px}
  .stats .big b{font-size:19px}
  .status{min-height:14px;margin-bottom:6px}
  .howto{font-size:11px;line-height:1.7;margin-top:10px;padding-top:9px}
  .board-body{max-height:38vh}
  .note{margin:2px 0 8px}
}

/* الهاتف الأفقي: قائمة مضغوطة يظهر زر البدء قبل أي شيء آخر */
@media (max-height:520px){
  .overlay{padding:6px 8px}
  .panel{padding:10px 12px;border-radius:12px;max-width:560px}
  .kicker{display:none}
  .title{font-size:clamp(20px,5.4vw,26px);margin-bottom:4px}
  .credit{font-size:10.5px;padding:3px 9px;margin-bottom:7px}
  .credit.small{display:none}
  .lead{display:none}
  .h2{font-size:16px;margin-bottom:6px}
  .btn-primary{padding:9px 12px;font-size:14px;margin-bottom:6px}
  .row{gap:6px}
  .btn-ghost{padding:7px 5px;font-size:11px}
  .best{margin-top:6px;font-size:10px}
  .stats{padding:6px 9px;gap:3px;margin:0 0 5px}
  .stats div{font-size:10.5px}
  .stats b{font-size:12px}
  .stats .big b{font-size:17px}
  .status{min-height:12px;font-size:10px;margin-bottom:5px}
  .howto{font-size:10px;line-height:1.6;margin-top:7px;padding-top:6px}
  .board-body{max-height:40vh}
  .note{display:none}
}
@media (max-height:400px){
  .overlay{padding:5px 7px}
  .hint{display:none}
  .panel{padding:8px 10px}
  .title{font-size:18px;margin-bottom:3px}
  .credit{font-size:9.5px;padding:2px 8px;margin-bottom:5px}
  .h2{font-size:15px;margin-bottom:4px}
  .btn-primary{padding:8px 10px;font-size:13px;margin-bottom:5px}
  .btn-ghost{padding:6px 4px;font-size:10px}
  .best{display:none}
  .stats{padding:5px 8px;gap:2px;margin:0 0 4px}
  .stats div{font-size:10px}
  .stats b{font-size:11px}
  .stats .big b{font-size:15px}
  .status{font-size:9.5px;min-height:10px;margin-bottom:4px}
  .howto{display:none}
  .board-body{max-height:36vh}
}
/* معاينة المحرر والشاشات شديدة القِصر */
@media (max-height:300px){
  .overlay{padding:4px 6px}
  .panel{padding:6px 9px;border-radius:10px}
  .title{font-size:16px;margin-bottom:2px}
  .credit{font-size:9px;padding:2px 7px;margin-bottom:4px}
  .h2{font-size:14px;margin-bottom:3px}
  .btn-primary{padding:7px 9px;font-size:12.5px;margin-bottom:4px}
  .btn-ghost{padding:5px 4px;font-size:9.5px}
  .stick-base{width:64px;height:64px}
  .stick-knob{width:26px;height:26px}
  .stick-ring{inset:14px}
  .act{width:48px;height:40px}
  .dock{padding:4px 10px 5px}
}
/* شاشات شديدة القِصر (معاينة المحرر): يبقى زر البدء ظاهراً بلا حاجة للتمرير */
@media (max-height:250px){
  .overlay{padding:3px 5px}
  .panel{padding:5px 8px;border-radius:9px}
  .title{font-size:15px;margin-bottom:2px}
  .credit{font-size:8.5px;padding:1px 6px;margin-bottom:3px}
  .h2{font-size:13px;margin-bottom:2px}
  .btn-primary{padding:6px 8px;font-size:12px;margin-bottom:3px}
  .btn-ghost{padding:4px 3px;font-size:9px}
  .row{gap:4px}
  .stick-base{width:56px;height:56px}
  .stick-knob{width:24px;height:24px}
  .act{width:46px;height:38px}
  .act span{display:none}
}
@media (prefers-reduced-motion:reduce){
  .fx-grain{animation:none}
  .overlay{animation:none}
}