/* Pixel AE (https://essssam.itch.io/pixel-ae, CC0) — Arabic + English pixel font drawn on a 10px grid, so it is only
   crisp at 10 / 20 / 30px. It is used for the game chrome (HUD, titles, big buttons); anything you read on a phone
   (dialog text, emails, choices, tables) uses the system sans, which every phone ships with good Arabic for. */
@font-face { font-family: 'Pixel AE'; font-weight: 400; font-display: swap;
  src: url('assets/fonts/PixelAE-Regular.ttf') format('truetype'), url('assets/fonts/PixelAE.ttf') format('truetype'); }
@font-face { font-family: 'Pixel AE'; font-weight: 700; font-display: swap;
  src: url('assets/fonts/PixelAE-Bold.ttf') format('truetype'), url('assets/fonts/PixelAE-Regular.ttf') format('truetype'); }
:root { --ink:#0d0b14; --panel:#2b2540; --panel2:#3a3156; --hi:#f6c83c; --txt:#f4eedd; --good:#2f6b3a; --bad:#7a2f35; --line:#4a4260; --muted:#b9b1c9;
  --font-px:"Pixel AE", "Press Start 2P", monospace;
  --font-body:system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, sans-serif;
  --fs:14px;
  --sat:env(safe-area-inset-top, 0px); --sal:env(safe-area-inset-left, 0px); }   /* read by game.js for the canvas HUD */
html[lang="ar"] { --fs:15px; }
[hidden] { display:none !important; }
html, body { margin:0; height:100%; background:#17141f; overflow:hidden; touch-action:none; overscroll-behavior:none;
  -webkit-user-select:none; user-select:none; -webkit-tap-highlight-color:transparent;
  font-family:var(--font-body); font-size:var(--fs); line-height:1.55; color:var(--txt); }
canvas#game { position:fixed; inset:0; display:block; image-rendering:pixelated; }   /* sized in px by game.js: 100vh overshoots the visible area on phones */
button, select, input { font-family:inherit; font-size:var(--fs); color:var(--txt); }
button { cursor:pointer; touch-action:manipulation; }
.px { background:var(--panel); border:3px solid var(--ink); box-shadow:inset -3px -3px 0 rgba(0,0,0,.35), inset 3px 3px 0 rgba(255,255,255,.12);
  border-radius:0; padding:8px 10px; }
.px:active, .px.on { background:var(--panel2); box-shadow:inset 3px 3px 0 rgba(0,0,0,.35); }
.px.on { outline:3px solid var(--hi); }
button:disabled { opacity:.5; cursor:default; }
.muted { color:var(--muted); } .small { font-size:12px; line-height:1.5; } p { margin:8px 0; }
.pre { white-space:pre-wrap; }

#topRight { position:fixed; top:calc(10px + env(safe-area-inset-top)); right:calc(10px + env(safe-area-inset-right));
  display:flex; gap:6px; align-items:center; flex-wrap:wrap; justify-content:flex-end; max-width:60vw; z-index:3; }
#topRight .px { font-size:18px; padding:8px 9px; line-height:1; min-width:44px; min-height:44px; }
#adminBar { display:flex; gap:6px; }
#roomSel { background:var(--panel); border:3px solid var(--ink); padding:7px 4px; max-width:130px; font-size:12px; }

#controls { position:fixed; right:calc(16px + env(safe-area-inset-right)); bottom:calc(18px + env(safe-area-inset-bottom));
  display:grid; grid-template-columns:auto auto; grid-template-rows:auto auto; gap:10px; align-items:end; z-index:3; }
#controls .small { width:52px; height:52px; font-size:22px; padding:0; }
#btnE { grid-row:1 / span 2; grid-column:2; width:80px; height:80px; border-radius:50%; font-family:var(--font-px); font-size:30px;
  background:#c94040; border:4px solid var(--ink); box-shadow:inset -4px -4px 0 rgba(0,0,0,.35), inset 4px 4px 0 rgba(255,255,255,.25); }
#btnE.ready { background:#e8a33a; animation:pulse 0.8s infinite alternate; }
#btnE:active { transform:translateY(2px); }
@keyframes pulse { to { transform:scale(1.08); } }
#emotePanel { position:fixed; right:calc(16px + env(safe-area-inset-right)); bottom:calc(140px + env(safe-area-inset-bottom));
  display:grid; grid-template-columns:repeat(5, 48px); gap:6px; background:var(--panel); border:3px solid var(--ink); padding:8px; z-index:4; }
#emotePanel button { width:48px; height:48px; padding:4px; background:#fff; border:3px solid var(--ink); }
#emotePanel canvas { width:36px; height:39px; image-rendering:pixelated; pointer-events:none; }
#chatBar { position:fixed; left:50%; transform:translateX(-50%); top:calc(10px + env(safe-area-inset-top)); width:min(92vw, 480px); display:flex; gap:6px; z-index:5; }
#chatBar input { flex:1; background:#fff; color:#111; border:3px solid var(--ink); padding:10px; font-size:16px; user-select:text; -webkit-user-select:text; }

#toasts { position:fixed; left:50%; transform:translateX(-50%); top:calc(64px + env(safe-area-inset-top));
  display:flex; flex-direction:column; gap:6px; align-items:center; pointer-events:none; z-index:30; width:94vw; }
.toast { background:var(--panel); border:3px solid var(--ink); padding:9px 12px; line-height:1.45; text-align:center; max-width:440px;
  animation:pop .2s ease-out; transition:opacity .4s, transform .4s; }
.toast.out { opacity:0; transform:translateY(-8px); }
.toast.good { background:var(--good); } .toast.bad { background:var(--bad); }
.toast.badge { background:linear-gradient(#3b2f12, #2a2110); border-color:var(--hi); font-size:15px; padding:12px 16px; }
@keyframes pop { from { transform:scale(.7); opacity:0; } }
#status { position:fixed; left:50%; bottom:40%; transform:translateX(-50%); z-index:40; }

/* ---------- cards / overlays ---------- */
/* --vvh / --vvt track the visual viewport (game.js), so a dialog shrinks above the phone keyboard instead of hiding behind it */
.overlay { position:fixed; left:0; right:0; top:var(--vvt, 0px); height:var(--vvh, 100%); background:rgba(10,8,16,.74);
  display:flex; align-items:center; justify-content:center; z-index:10; padding:10px; box-sizing:border-box; }
.card { background:var(--panel); border:4px solid var(--ink); box-shadow:inset -4px -4px 0 rgba(0,0,0,.35), inset 4px 4px 0 rgba(255,255,255,.1);
  padding:16px; width:min(94vw, 480px); max-height:100%; box-sizing:border-box; -webkit-user-select:text; user-select:text;
  display:flex; flex-direction:column; overflow:hidden; }
.card > header { flex:none; display:flex; justify-content:space-between; align-items:center; gap:10px; margin-bottom:12px; }
#mBody, #dashBody { flex:1 1 auto; min-height:0; overflow-y:auto; overscroll-behavior:contain; -webkit-overflow-scrolling:touch; }
#dashTabs { flex:none; }
.card h2 { font-family:var(--font-px); font-size:20px; color:var(--hi); margin:0; line-height:1.3; }
.card h3 { font-size:16px; font-weight:700; color:var(--hi); margin:4px 0 10px; line-height:1.4; }
#mClose, #dashClose { padding:6px 10px; font-size:18px; line-height:1; min-width:44px; min-height:44px; }
.card .primary { display:block; width:100%; margin:12px 0 0; padding:14px 10px; background:var(--good); border:3px solid var(--ink);
  font-family:var(--font-px); font-size:20px; line-height:1.2; box-shadow:inset -3px -3px 0 rgba(0,0,0,.35), inset 3px 3px 0 rgba(255,255,255,.12); }
.card .secondary { display:block; width:100%; margin:8px 0 0; padding:12px 10px; background:var(--panel2); border:3px solid var(--ink);
  font-family:var(--font-px); font-size:20px; line-height:1.2; }
.card .secondary.danger { background:var(--bad); }
.card .mini { background:var(--panel2); border:2px solid var(--ink); font-size:13px; padding:8px 10px; margin:6px 0; }
.choices { display:flex; flex-direction:column; gap:8px; margin:10px 0; }
.choice { text-align:start; line-height:1.45; padding:12px 14px; background:var(--panel2); border:3px solid var(--ink); color:var(--txt); }
.choice.ok { background:var(--good); } .choice.bad { background:var(--bad); } .choice.locked { opacity:.6; } .choice.here { opacity:.5; }
.choice.mono { font-family:ui-monospace, Menlo, Consolas, monospace; font-size:15px; direction:ltr; text-align:left; word-break:break-all; }
.inp { display:block; width:100%; box-sizing:border-box; background:#fff; color:#111; border:3px solid var(--ink); padding:12px; font-size:16px; margin:8px 0; }   /* 16px: iOS doesn't zoom in on focus */
.lbl { display:block; font-size:12px; color:var(--muted); margin:12px 0 4px; }
.fb { margin:10px 0; padding:10px 12px; line-height:1.5; border:3px solid var(--ink); }
.fb.good { background:var(--good); } .fb.bad { background:var(--bad); }
.prog { font-size:12px; color:var(--muted); margin-bottom:8px; }
.big { font-family:var(--font-px); font-size:20px; color:var(--hi); line-height:1.4; margin:6px 0 12px; }
.lesson { background:rgba(0,0,0,.25); padding:10px 12px; border-inline-start:4px solid var(--hi); }
.hint { background:rgba(246,200,60,.15); padding:8px 10px; margin:8px 0; }
.kbd { color:var(--muted); font-size:12px; }
.claim { background:var(--ink); padding:12px; margin:12px 0; text-align:center; }
.claim b { display:block; font-family:var(--font-px); font-size:20px; color:var(--hi); letter-spacing:3px; margin:6px 0; }
.signbox p { margin:6px 0; }
.lvl { padding:2px 6px; font-size:12px; } .lvl.high { background:#8a5a1e; } .lvl.critical { background:#8a2e2e; }
.post { background:rgba(0,0,0,.25); padding:8px 10px; margin:6px 0; }
.post .by { color:var(--hi); font-size:12px; margin-bottom:4px; }

/* challenge content */
.email { background:#f4f2ee; color:#1d1d24; border:3px solid var(--ink); padding:10px 12px; margin:8px 0; line-height:1.5; }
.email .meta { border-bottom:1px solid #cfcac2; padding:4px 0; font-size:13px; word-break:break-all; }
.email .body p { margin:8px 0; }
.email .link { background:none; border:0; padding:0; color:#1a52c4; text-decoration:underline; font-size:inherit; cursor:pointer; }
.email .real { background:#ffe9b0; color:#5a3a00; padding:6px 8px; margin:6px 0; font-size:13px; word-break:break-all; direction:ltr; }
.email .hdr { background:#1d1f2a; color:#9ef0a0; padding:8px 10px; font-family:ui-monospace, Menlo, Consolas, monospace; font-size:12px; line-height:1.5;
  white-space:pre-wrap; word-break:break-all; direction:ltr; text-align:left; margin:6px 0 0; }
.email .mini { background:#e4e0d8; color:#1d1d24; border-color:#9a948a; }
.email .att { font-size:13px; margin:6px 0; }
.hiddentext { background:#fff3c4; color:#5a3a00; padding:8px 10px; margin:8px 0; font-size:13px; }
.notif { background:#1d1f2a; border:3px solid var(--ink); padding:10px 12px; margin:8px 0; }
.notif .app { color:var(--hi); font-size:12px; margin-bottom:4px; }
.phone { background:#1d1f2a; border:3px solid var(--ink); padding:10px 12px; margin:8px 0; }
.phone .cid { font-size:12px; color:var(--muted); margin:4px 0; } .phone .name { font-size:15px; color:var(--hi); margin:4px 0 8px; }
.bubble { background:#3a3156; padding:8px 12px; margin:6px 0; border-radius:0 10px 10px 10px; }
.sign { background:#f6e04a; color:#2b2b33; padding:10px 12px; margin:8px 0; border:3px solid var(--ink); }
.ai { background:#152238; border:3px solid #3a74d9; padding:10px 12px; margin:8px 0; }
.ai .t { color:#9fd8ff; font-size:12px; margin-bottom:4px; }
.pgrid { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin:8px 0; }
.pcard { background:rgba(0,0,0,.25); padding:8px; display:flex; gap:8px; align-items:flex-start; font-size:12px; line-height:1.45; }
.pcard canvas { width:40px; height:48px; image-rendering:pixelated; flex:none; }
.pcard b { display:block; color:var(--hi); margin-bottom:4px; }
.scene { margin:8px 0; background:#fff; border:3px solid var(--ink); } .scene svg { display:block; width:100%; height:auto; }
.scene .hs { fill:rgba(255,255,255,0); stroke:rgba(255,209,102,.6); stroke-width:1.5; stroke-dasharray:3 3; cursor:pointer; }
.scene .hs.sel { fill:rgba(255,209,102,.35); stroke:#ffd166; stroke-dasharray:none; }
.scene .hs.ok { fill:rgba(6,214,160,.35); stroke:#06d6a0; stroke-dasharray:none; }
.scene .hs.miss { fill:rgba(239,71,111,.2); stroke:#ef476f; stroke-dasharray:none; }
.scene .hs.bad { fill:rgba(239,71,111,.45); stroke:#ef476f; stroke-dasharray:none; }
.grid { display:grid; grid-template-columns:1fr 1fr; gap:6px; margin:8px 0; }
.tile { font-size:13px; line-height:1.4; padding:10px; background:var(--panel2); border:3px solid var(--ink); color:var(--txt); text-align:start; }
.tile.sel { outline:3px solid var(--hi); } .tile.ok { background:var(--good); } .tile.miss { background:#4a3b1e; } .tile.bad { background:var(--bad); }
.notes { font-size:13px; line-height:1.5; padding-inline-start:18px; } .notes .pass { color:#9ef0a0; }
.ransom { background:#5a1416; border:3px solid #e04848; padding:12px; margin:8px 0; }
.ransom b { display:block; color:#ff6b6b; font-size:16px; margin-bottom:6px; }
.timer { font-family:var(--font-px); font-size:20px; color:var(--hi); margin:8px 0; }
.seq { font-size:13px; line-height:1.6; padding-inline-start:20px; color:#9ef0a0; margin:6px 0; }
.rules { list-style:none; padding:0; margin:8px 0; font-size:13px; line-height:1.7; }
.rules li::before { content:'✖ '; color:#ff8a8a; } .rules li.pass::before { content:'✔ '; color:#9ef0a0; }

/* join card (no title bar, so the whole card scrolls) */
.jcard { display:block; overflow-y:auto; overscroll-behavior:contain; text-align:center; }
.jcard .logo { font-family:var(--font-px); font-size:30px; line-height:1.2; color:var(--hi); text-shadow:3px 3px 0 var(--ink); margin:6px 0; }
.jcard .logo .ar { display:block; font-size:20px; margin-top:8px; }
.jcard .tag { font-size:12px; color:var(--muted); margin-bottom:14px; }
.jcard p, .jcard .choices, .jcard .lbl { text-align:start; }
.langq { font-size:16px; } .langq.last { margin-bottom:14px; } .langbtn { font-size:20px; }
#preview { display:block; margin:10px auto; width:120px; height:132px; image-rendering:pixelated;
  background:repeating-conic-gradient(#e9e6e0 0% 25%, #f4f2ee 0% 50%) 0 0/24px 24px; border:3px solid var(--ink); }
.rows { text-align:start; }
.row { display:flex; align-items:center; gap:6px; margin:8px 0; }
.row .lbl { width:100px; font-size:12px; margin:0; }
.row .val { flex:1; text-align:center; font-size:13px; display:flex; align-items:center; justify-content:center; gap:6px; }
.row .px { padding:8px 12px; min-width:44px; }
.adm { color:var(--hi); font-style:normal; }
.sw { display:inline-block; width:18px; height:18px; border:3px solid var(--ink); }
.btnrow { display:flex; gap:8px; margin-top:10px; }
.btnrow .secondary, .btnrow .primary { flex:1; margin:0; }

/* dashboard */
.dashcard { width:min(96vw, 600px); }
#dashTabs { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:12px; }
.tab { font-size:13px; font-weight:700; padding:9px 10px; }
.stats { display:grid; grid-template-columns:repeat(4, 1fr); gap:6px; margin-bottom:14px; }
.stats div { background:var(--ink); padding:10px 4px; text-align:center; }
.stats b { display:block; font-family:var(--font-px); font-size:20px; color:var(--hi); font-weight:normal; margin-bottom:6px; }
.stats span { font-size:11px; color:var(--muted); }
.missions { list-style:none; padding:0; margin:0 0 10px; }
.missions li { display:flex; gap:10px; align-items:flex-start; padding:9px 6px; border-bottom:2px solid rgba(0,0,0,.3); font-size:13px; line-height:1.45; }
.missions li.done { opacity:.6; } .missions li.locked { opacity:.45; }
.missions .st { width:16px; color:#9ef0a0; } .missions li.open .st { color:var(--hi); }
.missions .mt { flex:1; } .missions b { font-weight:normal; } .missions small { font-size:11px; color:var(--muted); }
.missions .mp { color:var(--hi); font-size:12px; }
.achs { display:grid; grid-template-columns:repeat(auto-fill, minmax(118px, 1fr)); gap:6px; }
.achs .a { background:var(--ink); padding:10px 6px; text-align:center; opacity:.45; }
.achs .a.on { opacity:1; outline:2px solid #6b5520; }
.achs .ico { display:block; font-size:24px; margin-bottom:6px; }
.achs b { display:block; font-size:12px; font-weight:normal; color:var(--hi); margin-bottom:4px; line-height:1.4; }
.achs small { font-size:11px; color:var(--muted); line-height:1.45; }
table.board, table.ptable { width:100%; border-collapse:collapse; font-size:13px; }
.board th, .ptable th { text-align:start; color:var(--hi); font-weight:normal; padding:6px 4px; border-bottom:2px solid var(--ink); }
.board td, .ptable td { padding:8px 4px; border-bottom:1px solid rgba(0,0,0,.3); }
.board tr.me td { background:rgba(246,200,60,.15); }
.dot { display:inline-block; width:6px; height:6px; background:#4fd070; margin-inline-end:6px; vertical-align:middle; }
.bars { margin-bottom:16px; }
.bar { display:grid; grid-template-columns:130px 1fr 32px; gap:6px; align-items:center; font-size:11px; margin:5px 0; }
.bar i { display:block; height:10px; background:#3aa8a0; min-width:2px; } .bar b { font-weight:normal; text-align:end; }
@media (max-width:420px) { .bar { grid-template-columns:90px 1fr 28px; } .pgrid { grid-template-columns:1fr; } .stats { grid-template-columns:repeat(2, 1fr); } }

/* phones: dialogs and the scoreboard become a bottom sheet with a fixed title bar; only the body scrolls */
@media (max-width:600px) {
  #modal, #dash { align-items:flex-end; padding:0; }
  #modal .card, #dash .card { width:100%; max-height:92%; border-left:0; border-right:0; border-bottom:0; padding-bottom:calc(16px + env(safe-area-inset-bottom)); }
}
