:root {
  --ink: #10242B;
  --surface: #183540;
  --line: #2A4A55;
  --lantern: #E0B45C;
  --lantern-hi: #EBC987;
  --sel: #2B3F3A;
  --sage: #8FC0A9;
  --sage-bg: #1E4A44;
  --clay: #D9806F;
  --clay-bg: #4A2F2E;
  --paper: #EAF0F1;
  --mute: #B8CACE;
  --kufi: 'Noto Kufi Arabic', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --sans: 'IBM Plex Sans Arabic', system-ui, 'Segoe UI', Tahoma, sans-serif;
  --naskh: 'Noto Naskh Arabic', 'Traditional Arabic', serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; }
html { background: var(--ink); }
body { margin: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); background: var(--ink); color: var(--paper); font-family: var(--sans); font-size: 18px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
h1, h2, p { margin: 0; }
button, input { font-family: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--lantern-hi); outline-offset: 3px; }

.screen { max-width: 1320px; min-height: 100dvh; margin: 0 auto; padding: clamp(16px, 3vw, 40px) clamp(16px, 4vw, 56px); display: flex; flex-direction: column; gap: clamp(16px, 2.4vh, 26px); }
.grow { flex: 1 1 auto; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.bar-id { display: flex; align-items: center; gap: 14px; }
.bar-title { font-family: var(--kufi); font-weight: 700; font-size: clamp(22px, 2.4vw, 30px); line-height: 1.3; }
.bar-sub { color: var(--mute); font-size: 18px; }
.bar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.home-btn { width: 60px; height: 60px; border-radius: 18px; border: 1.5px solid var(--line); background: var(--surface); display: grid; place-items: center; transition: border-color 0.2s; }
.home-btn:hover { border-color: var(--lantern); }
.wordmark { font-family: var(--kufi); font-weight: 700; font-size: 40px; line-height: 1.2; }

.btn { min-height: 58px; padding: 0 26px; border-radius: 18px; border: 1.5px solid var(--line); background: transparent; font-size: 19px; font-weight: 600; transition: background 0.2s, border-color 0.2s, transform 0.12s var(--ease); }
.btn:hover { border-color: var(--mute); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--lantern); border-color: var(--lantern); color: var(--ink); font-weight: 700; font-size: 21px; padding: 0 44px; }
.btn-primary:hover { background: var(--lantern-hi); border-color: var(--lantern-hi); }
.btn-small { min-height: 48px; padding: 0 18px; font-size: 17px; border-radius: 14px; }
.btn-good { background: var(--sage-bg); border-color: var(--sage); }
.btn-bad { background: var(--clay-bg); border-color: var(--clay); }

.tag { display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--line); font-size: 17px; font-weight: 500; white-space: nowrap; }
.stat { color: var(--mute); font-size: 18px; font-weight: 600; white-space: nowrap; }

/* الرئيسية */
.hero h1 { font-family: var(--kufi); font-weight: 700; font-size: clamp(34px, 4.4vw, 54px); line-height: 1.35; }
.hero p { color: var(--mute); font-size: 19px; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.mode-card { text-align: right; padding: 22px; min-height: 190px; border-radius: 24px; border: 2px solid var(--surface); background: var(--surface); display: flex; flex-direction: column; justify-content: space-between; gap: 16px; transition: border-color 0.2s, transform 0.15s var(--ease); }
.mode-card:hover { border-color: var(--line); }
.mode-card:active { transform: scale(0.98); }
.mode-card[aria-pressed="true"] { border-color: var(--lantern); }
.mode-icon { width: 58px; height: 58px; border-radius: 18px; background: var(--ink); color: var(--lantern); display: grid; place-items: center; font-family: var(--kufi); font-weight: 700; font-size: 32px; }
.mode-card[aria-pressed="true"] .mode-icon { background: var(--lantern); color: var(--ink); }
.mode-name { font-size: 25px; font-weight: 700; }
.mode-desc { color: var(--mute); font-size: 17px; line-height: 1.6; }

.cats { display: flex; flex-direction: column; gap: 18px; }
.cat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.cat-name { font-size: 20px; font-weight: 700; }
.cat-empty { color: var(--mute); font-size: 17px; }
.link-btn { background: none; border: 0; padding: 8px 4px; min-height: 44px; color: var(--lantern); font-size: 17px; font-weight: 600; }
.link-btn:hover { color: var(--lantern-hi); }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { min-height: 48px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--line); background: transparent; font-size: 17px; font-weight: 500; display: inline-flex; align-items: center; gap: 10px; transition: background 0.15s, border-color 0.15s; }
.chip:hover { border-color: var(--mute); }
.chip[aria-pressed="true"] { background: var(--lantern); border-color: var(--lantern); color: var(--ink); font-weight: 700; }
.chip small { font-size: 15px; font-weight: 600; opacity: 0.85; }
.start-row { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px 0; background: var(--ink); border-top: 1.5px solid var(--line); }

/* بطاقة السؤال */
.card { flex: 1 1 auto; padding: clamp(24px, 4vw, 48px); border-radius: 32px; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(20px, 4vh, 40px); text-align: center; }
.q-text { font-size: clamp(30px, 4.6vw, 58px); font-weight: 700; line-height: 1.5; text-wrap: balance; }
.boxes { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.box { width: clamp(46px, 5.6vw, 74px); height: clamp(56px, 6.6vw, 86px); border-radius: 16px; border: 2px dashed var(--line); display: grid; place-items: center; font-family: var(--kufi); font-weight: 700; font-size: clamp(24px, 3.2vw, 42px); }
.box.on { border-style: solid; border-color: var(--lantern); color: var(--lantern); background: var(--ink); }
.box.gap { border: 0; width: 18px; }
.box i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.answer { padding: 14px 34px; border-radius: 20px; background: var(--sage-bg); border: 2px solid var(--sage); font-size: clamp(30px, 4.4vw, 54px); font-weight: 700; animation: pop 0.35s var(--ease); }
.src { color: var(--mute); font-size: 17px; }
.note { color: var(--mute); font-size: 18px; }
.actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.actions > div { display: flex; gap: 12px; flex-wrap: wrap; }
@keyframes pop { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* اختيار الحرف */
.letters { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 12px; }
.letter { min-height: 112px; border-radius: 22px; border: 2px solid var(--surface); background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transition: border-color 0.15s, transform 0.12s var(--ease); }
.letter b { font-family: var(--kufi); font-size: 40px; line-height: 1.3; color: var(--lantern); }
.letter span { font-size: 15px; color: var(--mute); }
.letter:hover:not(:disabled) { border-color: var(--lantern); }
.letter:active:not(:disabled) { transform: scale(0.96); }
.letter:disabled { background: transparent; border: 2px dashed var(--line); }
.letter:disabled b { color: var(--line); }

/* توب 10 */
.t10-head h1 { font-family: var(--kufi); font-weight: 700; font-size: clamp(26px, 3.4vw, 42px); line-height: 1.4; }
.t10-kicker { color: var(--lantern); font-size: 18px; font-weight: 600; }
.counter { text-align: center; }
.counter b { display: block; font-size: 32px; line-height: 1.2; color: var(--sage); }
.counter span { color: var(--mute); font-size: 17px; }
.dots { display: flex; gap: 8px; justify-content: center; height: 38px; align-items: center; }
.dots i { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); }
.dots i.x { background: var(--clay); border-color: var(--clay); }
.t10-grid { flex: 1 1 auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(var(--rows, 5), minmax(60px, 1fr)); grid-auto-flow: column; gap: 12px 20px; }
.t10-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row { display: flex; align-items: center; gap: 14px; padding: 8px 20px; border-radius: 18px; background: var(--surface); border: 2px dashed var(--line); font-size: clamp(22px, 2.6vw, 30px); font-weight: 700; min-width: 0; }
.row .n { width: 46px; flex: none; font-family: var(--kufi); color: var(--mute); }
.row .v { min-width: 0; overflow-wrap: anywhere; }
.row .v em { font-style: normal; font-size: 17px; font-weight: 500; color: var(--mute); margin-inline-start: 10px; }
.row.open { background: var(--sage-bg); border: 2px solid var(--sage); animation: pop 0.35s var(--ease); }
.row.open .n { color: var(--sage); }
.row.missed { background: var(--clay-bg); border: 2px solid var(--clay); }
.row.missed .n { color: var(--clay); }
.row .hid { display: flex; gap: 8px; }
.row .hid i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.guess { display: flex; flex-direction: column; gap: 10px; }
.suggest { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 50px; }
.suggest .lbl { color: var(--mute); font-size: 18px; }
.sug { min-height: 48px; padding: 0 22px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-size: 20px; font-weight: 600; }
.sug:hover, .sug.first { border-color: var(--lantern); background: var(--sel); }
.guess-row { display: flex; gap: 12px; flex-wrap: wrap; }
.guess-input { flex: 1 1 260px; min-width: 0; max-width: 100%; min-height: 64px; padding: 0 24px; border-radius: 18px; border: 2px solid var(--line); background: var(--surface); font-size: 24px; font-weight: 600; }
.guess-input:focus { border-color: var(--lantern); outline: none; }
.wrongs { color: var(--mute); font-size: 17px; min-height: 28px; }
.wrongs s { color: var(--clay); margin-inline-end: 12px; }
.banner { padding: 14px 22px; border-radius: 18px; font-size: 22px; font-weight: 700; text-align: center; animation: pop 0.35s var(--ease); }
.banner.win { background: var(--sage-bg); border: 2px solid var(--sage); }
.banner.lose { background: var(--clay-bg); border: 2px solid var(--clay); }

/* السلّم */
.ladder { flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 28px; }
.ladder-main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.ladder .card { padding: clamp(20px, 3vw, 36px); border-radius: 28px; }
.ladder .q-text { font-size: clamp(26px, 3.4vw, 44px); }
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.opt { min-height: 80px; padding: 10px 18px; border-radius: 20px; border: 2px solid var(--line); background: var(--surface); display: flex; align-items: center; gap: 14px; text-align: right; font-size: clamp(20px, 2.3vw, 27px); font-weight: 600; transition: border-color 0.15s, background 0.2s; }
.opt .k { width: 46px; height: 46px; flex: none; border-radius: 14px; background: var(--ink); color: var(--lantern); display: grid; place-items: center; font-family: var(--kufi); font-weight: 700; font-size: 23px; }
.opt:hover:not(:disabled) { border-color: var(--mute); }
.opt.sel { border-color: var(--lantern); background: var(--sel); }
.opt.sel .k { background: var(--lantern); color: var(--ink); }
.opt.correct { border-color: var(--sage); background: var(--sage-bg); }
.opt.wrong { border-color: var(--clay); background: var(--clay-bg); }
.opt.gone { visibility: hidden; }
.lives { display: flex; gap: 10px; flex-wrap: wrap; }
.life { min-height: 58px; padding: 0 16px; border-radius: 18px; border: 1.5px solid var(--line); background: var(--surface); font-size: 18px; font-weight: 600; }
.life:hover:not(:disabled) { border-color: var(--lantern); }
.life:disabled { background: transparent; border-style: dashed; color: var(--mute); text-decoration: line-through; }
.rungs { padding: 16px; border-radius: 28px; background: var(--surface); display: flex; flex-direction: column-reverse; gap: 6px; }
.rung { flex: 1 1 0; min-height: 30px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-radius: 12px; font-size: 18px; font-weight: 500; color: var(--mute); }
.rung.done { background: var(--sage-bg); color: var(--paper); }
.rung.now { background: var(--lantern); color: var(--ink); font-weight: 700; }
.rung.top { border: 1.5px solid var(--lantern); color: var(--lantern); font-weight: 700; }
.rung.top.now { color: var(--ink); }
.rule { padding: 10px 20px; border-radius: 999px; border: 1.5px solid var(--clay); font-size: 17px; font-weight: 600; }
.overlay { position: fixed; inset: 0; background: rgba(8, 20, 24, 0.86); display: grid; place-items: center; padding: 20px; z-index: 5; }
.modal { width: min(560px, 100%); padding: 36px; border-radius: 28px; background: var(--surface); border: 1.5px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; animation: pop 0.3s var(--ease); }
.modal h2 { font-family: var(--kufi); font-size: 30px; line-height: 1.4; }
.modal p { color: var(--mute); font-size: 19px; }
.timer { font-family: var(--kufi); font-size: 72px; font-weight: 700; line-height: 1.2; color: var(--lantern); }
.final { font-family: var(--kufi); font-weight: 700; font-size: clamp(34px, 5vw, 60px); line-height: 1.4; }

/* كمّل المثل */
.proverb { display: flex; align-items: center; justify-content: center; gap: 22px; flex-wrap: wrap; font-family: var(--naskh); font-weight: 700; font-size: clamp(38px, 6.4vw, 84px); line-height: 1.5; }
.blank { min-width: clamp(140px, 18vw, 240px); height: clamp(70px, 9vw, 110px); padding: 0 20px; border-radius: 22px; border: 3px dashed var(--lantern); display: inline-flex; align-items: center; justify-content: center; gap: 12px; }
.blank i { width: 14px; height: 14px; border-radius: 50%; background: var(--lantern); }
.blank.filled { border-style: solid; border-color: var(--sage); background: var(--sage-bg); animation: pop 0.35s var(--ease); }
.blank .hint { color: var(--lantern); }

/* طريقة اللعب والنقاط */
.kinds { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.kind { text-align: right; padding: 26px; min-height: 150px; border-radius: 24px; border: 2px solid var(--surface); background: var(--surface); display: flex; flex-direction: column; gap: 10px; transition: border-color 0.2s; }
.kind:hover { border-color: var(--line); }
.kind[aria-pressed="true"] { border-color: var(--lantern); }
.kind b { font-family: var(--kufi); font-size: 28px; line-height: 1.3; }
.kind[aria-pressed="true"] b { color: var(--lantern); }
.kind span { color: var(--mute); font-size: 18px; }
.players { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.players .cat-head { flex-wrap: wrap; width: 100%; justify-content: flex-start; }
.pl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; width: 100%; }
.pl-row { display: flex; gap: 10px; }
.pl-input { flex: 1 1 auto; min-width: 0; min-height: 56px; padding: 0 18px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface); font-size: 20px; font-weight: 600; }
.pl-input:focus { border-color: var(--lantern); outline: none; }
.play-kind { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.board { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.board-lbl { color: var(--mute); font-size: 18px; font-weight: 600; }
.pl { min-height: 52px; padding: 0 8px 0 18px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); display: inline-flex; align-items: center; gap: 12px; font-size: 19px; font-weight: 600; }
.pl b { min-width: 38px; height: 38px; padding: 0 8px; border-radius: 999px; background: var(--ink); color: var(--lantern); display: grid; place-items: center; font-family: var(--kufi); font-size: 18px; }
.pl:hover { border-color: var(--mute); }
.pl[aria-pressed="true"] { background: var(--lantern); border-color: var(--lantern); color: var(--ink); }
.award { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; width: 100%; }
.award .pl { min-height: 60px; font-size: 21px; }
.standings { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.standings li { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-radius: 16px; background: var(--ink); font-size: 21px; font-weight: 600; }
.standings li b { font-family: var(--kufi); color: var(--lantern); }
.standings li.lead { border: 2px solid var(--lantern); }
.modal.wide { width: min(760px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto; }
.modal-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.xp { width: 100%; display: flex; flex-direction: column; gap: 18px; text-align: right; }
.xp-kick { color: var(--lantern); font-size: 16px; font-weight: 700; }
.xp h2 { margin: -10px 0 0; }
.modal .xp-lead { margin: 0; color: var(--paper); font-size: 22px; line-height: 1.85; }
.xp-warn { padding: 14px 18px; border-radius: 16px; background: var(--clay-bg); }
.xp-warn b { display: block; color: var(--clay); font-size: 16px; }
.modal .xp-warn p { margin: 4px 0 0; color: var(--paper); font-size: 19px; line-height: 1.75; }
.xp-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.xp-facts div { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 16px; background: var(--ink); }
.xp-facts b { font-family: var(--kufi); color: var(--lantern); font-size: 20px; line-height: 1.5; }
.xp-facts span { color: var(--mute); font-size: 15px; line-height: 1.55; }
.modal .xp-note, .modal .xp-rules { margin: 0; color: var(--mute); font-size: 16px; line-height: 1.7; }
.modal .xp-note { color: var(--paper); }
.xp .btn { align-self: center; }
@media (max-width: 640px) { .xp-facts { grid-template-columns: 1fr; } }
.explain { list-style: none; margin: 0; padding: 0; text-align: right; display: flex; flex-direction: column; gap: 12px; font-size: 19px; }
.explain b { color: var(--lantern); }
.log { width: 100%; min-height: 220px; padding: 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--ink); color: var(--paper); font: inherit; font-size: 16px; }

/* شاشة الأجوبة */
.remote-btn.on { border-color: var(--sage); color: var(--sage); }
.qr { width: 236px; height: 236px; padding: 8px; border-radius: 16px; background: var(--paper); display: grid; place-items: center; color: var(--ink); }
.qr img, .qr canvas { display: block; }
.room-code { font-family: var(--kufi); font-size: 40px; font-weight: 700; letter-spacing: 6px; color: var(--lantern); direction: ltr; }
.room-link { font-size: 15px; color: var(--mute); word-break: break-all; }
.phone { max-width: 640px; padding-bottom: 96px; }
.phone-card { flex: 1 1 auto; padding: 28px 22px; border-radius: 28px; background: var(--surface); display: flex; flex-direction: column; justify-content: center; gap: 22px; text-align: center; }
.phone-kicker { color: var(--lantern); font-size: 18px; font-weight: 600; }
.phone-q { font-size: 24px; font-weight: 600; line-height: 1.6; }
.phone-a { padding: 18px; border-radius: 20px; background: var(--sage-bg); border: 2px solid var(--sage); font-family: var(--kufi); font-size: clamp(30px, 9vw, 44px); font-weight: 700; line-height: 1.4; animation: pop 0.35s var(--ease); }
.phone-foot { text-align: center; }

/* توب 10: أدوات */
.t10-head .link-btn { padding: 0; min-height: 36px; }
.t10-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tools { display: flex; gap: 10px; flex-wrap: wrap; }
.row.hinted { border-style: solid; border-color: var(--lantern); }
.row.hinted .v { color: var(--lantern); }
.row .who { margin-inline-start: auto; flex: none; padding: 2px 12px; border-radius: 999px; background: var(--ink); color: var(--sage); font-size: 16px; font-weight: 600; }

/* السلّم: الأمان والمساعدات */
.life.active { border-color: var(--lantern); background: var(--sel); }
.rung.safe { outline: 2px solid var(--sage); outline-offset: -2px; color: var(--sage); }
.rung.safe.done { color: var(--paper); }
.safe-on { border-color: var(--sage); color: var(--sage); }
.ladder-rule { font-size: 17px; }

#toast { position: fixed; inset-inline: 0; bottom: 28px; margin: 0 auto; width: fit-content; max-width: calc(100% - 32px); padding: 14px 24px; border-radius: 16px; background: var(--paper); color: var(--ink); font-size: 18px; font-weight: 600; opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity 0.25s, transform 0.25s var(--ease); z-index: 9; }
#toast.show { opacity: 1; transform: none; }

@media (max-width: 860px) {
  .ladder { grid-template-columns: minmax(0, 1fr); }
  .rungs { flex-direction: row; overflow-x: auto; padding: 10px; }
  .rung { min-width: 44px; min-height: 44px; justify-content: center; padding: 0 8px; }
  .rung span:last-child { display: none; }
  .opts { grid-template-columns: minmax(0, 1fr); }
  .t10-grid, .t10-grid.cols-3 { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-flow: row; }
  .btn-primary { padding: 0 28px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
