/* ==========================================================================
   RekaCode EDU — design system
   Tokens, scale and components per docs/DESIGN.md. Nothing here is decorative
   for its own sake: colour carries meaning, there are two shadow levels, and
   every radius comes off the scale.
   ========================================================================== */

:root {
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --paper: #ffffff;
  --surface: #f7f9fc;
  --surface-2: #eef2f7;
  --line: #e3e8ef;

  --brand: #2563eb;
  --brand-ink: #1d4ed8;
  --brand-tint: #eff4ff;

  --read: #0d9488;
  --read-tint: #effcfa;

  --faith: #7c3aed;
  --faith-tint: #f5f1ff;

  --ok: #16a34a;
  --ok-tint: #effdf4;
  --warn: #f59e0b;
  --bad: #e11d48;
  --bad-tint: #fff1f3;
  --star: #f59e0b;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;

  --sh-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --sh-2: 0 8px 24px rgba(15, 23, 42, .08);

  --ease: cubic-bezier(.2, .7, .3, 1);
  --wrap: 1080px;

  --font: "Nunito", ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-ar: "Scheherazade New", "Noto Naskh Arabic", "Amiri", "Traditional Arabic", serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

img, svg { max-width: 100%; }
svg.ico { display: block; flex: none; }

/* The hidden attribute only sets display:none at user-agent weight, so any
   component rule with its own display silently beats it. Several here do. */
[hidden] { display: none !important; }

h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }

a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- type scale ---------- */
.t-display { font-size: 2.5rem; line-height: 1.1;  font-weight: 800; letter-spacing: -.02em; }
.t-h1      { font-size: 1.875rem; line-height: 1.2; font-weight: 800; letter-spacing: -.015em; }
.t-h2      { font-size: 1.375rem; line-height: 1.27; font-weight: 800; letter-spacing: -.01em; }
.t-h3      { font-size: 1.125rem; line-height: 1.33; font-weight: 700; }
.t-body    { font-size: 1.0625rem; line-height: 1.53; }
.t-sm      { font-size: .9375rem; line-height: 1.47; }
.t-label {
  font-size: .8125rem; line-height: 1.23;
  font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.t-mute { color: var(--ink-2); }
.t-num  { font-variant-numeric: tabular-nums; }

@media (min-width: 640px) {
  .t-display { font-size: 3rem; }
}

/* ---------- layout ---------- */
.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 20px;
}
.wrap-narrow { max-width: 640px; }

.stack > * + * { margin-top: 16px; }
.stack-lg > * + * { margin-top: 32px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.spacer { flex: 1 1 auto; }

main { padding: 24px 0 72px; }

/* ---------- app bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.appbar-in {
  display: flex; align-items: center; gap: 12px;
  height: 64px;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--ink); font-weight: 800; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-name { font-size: 1.0625rem; letter-spacing: -.01em; white-space: nowrap; }
.brand-name span { color: var(--brand); }

.chipbar { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  font-size: .9375rem; font-weight: 700;
  color: var(--ink-2);
}
.chip:hover { text-decoration: none; border-color: var(--ink-3); color: var(--ink); }
.chip-star { color: var(--star); }
.chip-star .ico { color: var(--star); }
.chip-name {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* On a phone the bar runs out of room before the content does, so the wordmark
   steps aside (the mark still identifies the app) and a long name truncates. */
@media (max-width: 520px) {
  .brand-name { display: none; }
  .chip-name { max-width: 84px; }
  .appbar-in { gap: 8px; }
  .chipbar { gap: 6px; }
  .chip { padding: 0 10px; }
}

.seg {
  display: inline-flex; padding: 3px;
  background: var(--surface-2);
  border-radius: var(--r-pill);
}
.seg a {
  display: grid; place-items: center;
  min-width: 38px; height: 34px; padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: .8125rem; font-weight: 800; letter-spacing: .04em;
  color: var(--ink-2);
}
.seg a:hover { text-decoration: none; color: var(--ink); }
.seg a[aria-current="true"] { background: var(--paper); color: var(--brand-ink); box-shadow: var(--sh-1); }

.avatar {
  width: 36px; height: 36px; flex: none;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 52px; padding: 0 22px;
  background: var(--brand); color: #fff;
  border: 0; border-radius: var(--r-md);
  font-size: 1.0625rem; font-weight: 800; letter-spacing: -.005em;
  box-shadow: var(--sh-1);
  transition: transform .12s var(--ease), background .12s var(--ease), box-shadow .12s var(--ease);
  text-align: center;
}
.btn:hover { background: var(--brand-ink); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled { background: var(--surface-2); color: var(--ink-3); box-shadow: none; cursor: not-allowed; }
.btn-lg { min-height: 60px; padding: 0 28px; font-size: 1.1875rem; }
.btn-block { width: 100%; }
.btn-2 {
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--line);
}
.btn-2:hover { background: var(--paper); color: var(--ink); border-color: var(--ink-3); }
.btn-ghost { background: none; color: var(--ink-2); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-read { background: var(--read); }
.btn-read:hover { background: #0f766e; }
.btn-faith { background: var(--faith); }
.btn-faith:hover { background: #6d28d9; }

.iconbtn {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  background: var(--paper); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  transition: background .12s var(--ease), color .12s var(--ease);
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.iconbtn:disabled { color: var(--ink-3); cursor: not-allowed; }
.iconbtn-lg { width: 56px; height: 56px; }

/* ---------- cards ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  padding: 20px;
}
.card-pad-lg { padding: 28px; }

a.card, .card-link { transition: box-shadow .14s var(--ease), transform .14s var(--ease), border-color .14s var(--ease); }
a.card:hover, .card-link:hover { box-shadow: var(--sh-2); transform: translateY(-2px); text-decoration: none; border-color: #d4dbe6; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 860px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }

/* module tile */
.tile {
  display: flex; flex-direction: column; gap: 14px;
  padding: 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-1);
  color: var(--ink);
}
.tile-ico {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  border-radius: var(--r-md);
  background: var(--brand-tint); color: var(--brand);
}
.tile-read .tile-ico { background: var(--read-tint); color: var(--read); }
.tile-faith .tile-ico { background: var(--faith-tint); color: var(--faith); }
.tile-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; color: var(--ink-3); font-weight: 700; font-size: .9375rem; }
.tile-read .tile-foot { color: var(--read); }
.tile-faith .tile-foot { color: var(--faith); }
.tile .tile-foot { color: var(--brand); }

/* ---------- stars ---------- */
.stars { display: inline-flex; gap: 2px; }
.star { color: var(--ink-3); line-height: 0; }
.star.on { color: var(--star); }

/* ---------- gate (name entry) ---------- */
.gate { min-height: calc(100dvh - 64px); display: grid; place-items: center; padding: 32px 0 64px; }
.gate-card { width: 100%; max-width: 520px; }
.gate-mark { width: 72px; height: 72px; margin: 0 auto 20px; }

.field {
  display: flex; align-items: center; gap: 12px;
  height: 64px; padding: 0 18px;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  transition: border-color .12s var(--ease);
}
.field:focus-within { border-color: var(--brand); }
.field input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: none;
  font-size: 1.25rem; font-weight: 700;
}
.field input::placeholder { color: var(--ink-3); font-weight: 600; }

.avatars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (min-width: 420px) { .avatars { grid-template-columns: repeat(8, 1fr); } }
.avatars input { position: absolute; opacity: 0; pointer-events: none; }
.avatars label {
  display: grid; place-items: center;
  aspect-ratio: 1;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color .12s var(--ease), background .12s var(--ease);
}
.avatars label:hover { border-color: var(--ink-3); }
.avatars input:checked + label { border-color: var(--brand); background: var(--brand-tint); }
.avatars input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }
.avatars img { width: 78%; height: 78%; }

/* ---------- option / difficulty pickers ---------- */
.pick { display: grid; gap: 12px; }
.pick-row {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 20px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  color: var(--ink);
  box-shadow: var(--sh-1);
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease), transform .14s var(--ease);
}
.pick-row:hover { text-decoration: none; border-color: var(--brand); box-shadow: var(--sh-2); transform: translateY(-1px); }
.pick-ico {
  display: grid; place-items: center;
  width: 48px; height: 48px; flex: none;
  border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink-2);
}
.pick-row:hover .pick-ico { background: var(--brand-tint); color: var(--brand); }
.pick-e .pick-ico { background: var(--ok-tint); color: var(--ok); }
.pick-m .pick-ico { background: #fff7ea; color: var(--warn); }
.pick-h .pick-ico { background: var(--bad-tint); color: var(--bad); }
.pick-txt { min-width: 0; }
.pick-end { margin-left: auto; color: var(--ink-3); display: flex; align-items: center; gap: 10px; }

/* difficulty strength meter */
.meter { display: inline-flex; gap: 3px; align-items: flex-end; height: 18px; }
.meter i { display: block; width: 5px; border-radius: 2px; background: var(--surface-2); }
.meter i:nth-child(1) { height: 7px; }
.meter i:nth-child(2) { height: 12px; }
.meter i:nth-child(3) { height: 18px; }
.meter-1 i:nth-child(1) { background: var(--ok); }
.meter-2 i:nth-child(1), .meter-2 i:nth-child(2) { background: var(--warn); }
.meter-3 i { background: var(--bad); }

/* ---------- stage map ---------- */
.stagemap { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (min-width: 560px) { .stagemap { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 860px) { .stagemap { grid-template-columns: repeat(5, 1fr); } }

.stage {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 18px 12px 14px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  color: var(--ink);
  text-align: center;
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease), transform .14s var(--ease);
}
.stage:hover { text-decoration: none; border-color: var(--brand); box-shadow: var(--sh-2); transform: translateY(-2px); }
.stage-n {
  display: grid; place-items: center;
  width: 52px; height: 52px;
  border-radius: var(--r-pill);
  background: var(--brand-tint); color: var(--brand-ink);
  font-size: 1.375rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.stage-name { font-size: .9375rem; font-weight: 700; line-height: 1.3; }
.stage.is-locked { background: var(--surface); color: var(--ink-3); box-shadow: none; cursor: not-allowed; }
.stage.is-locked:hover { border-color: var(--line); transform: none; box-shadow: none; }
.stage.is-locked .stage-n { background: var(--surface-2); color: var(--ink-3); }
.stage.is-done .stage-n { background: var(--ok-tint); color: var(--ok); }

/* ---------- play surface (bare layout) ---------- */
.play {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  background: var(--surface);
}
.play-bar {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: max(10px, env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.play-body {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  justify-content: center; gap: 14px;
  overflow-y: auto;
  padding: 20px 16px;
}
.play-foot {
  flex: none;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.hearts { display: inline-flex; gap: 4px; }
.hearts .ico { color: var(--bad); }
.hearts .spent .ico { color: var(--line); }

.pbar { height: 8px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; flex: 1; }
.pbar i { display: block; height: 100%; border-radius: var(--r-pill); background: var(--brand); transition: width .25s var(--ease); }
.pbar-read i { background: var(--read); }
.pbar-faith i { background: var(--faith); }

.timer { position: relative; width: 40px; height: 40px; flex: none; }
.timer svg { transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 3.5; }
.timer .track { stroke: var(--surface-2); }
.timer .run { stroke: var(--brand); stroke-linecap: round; transition: stroke-dashoffset 1s linear, stroke .3s; }
.timer.low .run { stroke: var(--bad); }
.timer b {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: .875rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* the sum */
.sum {
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 10px;
  margin: auto 0;
  padding: 24px 8px;
}
.sum-n, .sum-op, .sum-blank {
  display: grid; place-items: center;
  min-width: 68px; height: 86px;
  padding: 0 14px;
  border-radius: var(--r-md);
  font-size: 3rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.sum-n { background: var(--paper); border: 1.5px solid var(--line); box-shadow: var(--sh-1); }
.sum-op { min-width: 52px; color: var(--brand); font-size: 2.25rem; }
.sum-op .ico { width: 36px; height: 36px; }
.sum-blank {
  background: var(--brand-tint);
  border: 2px dashed var(--brand);
  color: var(--brand-ink);
}
.sum-blank.filled { border-style: solid; background: var(--paper); color: var(--ink); }
@media (min-width: 560px) {
  .sum-n, .sum-op, .sum-blank { min-width: 84px; height: 104px; font-size: 3.75rem; }
}
/* Keep a one-line equation on a narrow phone rather than wrapping the answer
   box onto its own row, which breaks the read of "a + b = ?". */
@media (max-width: 400px) {
  .sum { gap: 6px; }
  .sum-n, .sum-blank { min-width: 54px; height: 74px; font-size: 2.375rem; padding: 0 8px; }
  .sum-op { min-width: 32px; height: 74px; }
  .sum-op .ico { width: 26px; height: 26px; }
}

/* counting dots for the easy stages.
   The groups shrink to their contents — a fixed 5-column grid reserved space
   for dots that were not there and pushed the operator off to one side. */
.dots { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 16px; margin-bottom: 4px; }
.dotgroup {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 7px; max-width: 182px;
}
.dot {
  width: 26px; height: 26px;
  border-radius: var(--r-pill);
  background: var(--brand);
  box-shadow: inset 0 -2px 0 rgba(15, 23, 42, .12);
  animation: pop .22s var(--ease) both;
}
.dot.b { background: var(--warn); }
.dot.off { background: var(--surface-2); box-shadow: none; }
.dots-op { color: var(--ink-3); }

/* answer tiles */
.answers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.answers-3 { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 560px) { .answers { grid-template-columns: repeat(4, 1fr); } .answers-3 { grid-template-columns: repeat(3, 1fr); } }

.ans {
  display: grid; place-items: center;
  min-height: 80px;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  font-size: 1.875rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  box-shadow: var(--sh-1);
  transition: transform .14s var(--ease), border-color .14s var(--ease), background .14s var(--ease);
}
.ans .ico { width: 34px; height: 34px; }
.ans:active { transform: translateY(2px); box-shadow: none; }
.ans:disabled { cursor: default; }
.ans.is-ok { border-color: var(--ok); background: var(--ok-tint); color: #15803d; animation: pop .18s var(--ease); }
.ans.is-bad { border-color: var(--bad); background: var(--bad-tint); color: #be123c; animation: shake .16s var(--ease); }
.ans.is-reveal { border-color: var(--ok); border-style: dashed; color: #15803d; }
.ans.is-dim { opacity: .4; }

/* number pad */
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 360px; margin: 0 auto; }
.pad button {
  min-height: 62px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  font-size: 1.625rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--sh-1);
}
.pad button:active { transform: translateY(2px); box-shadow: none; }
.pad .pad-wide { grid-column: span 1; }
.pad .pad-go { background: var(--brand); color: #fff; border-color: var(--brand); }
.pad .pad-del { color: var(--ink-2); }

/* feedback strip */
.fb {
  display: flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 10px 16px;
  border-radius: var(--r-md);
  font-weight: 800;
  animation: rise .18s var(--ease) both;
}
.fb-ok  { background: var(--ok-tint);  color: #15803d; }
.fb-bad { background: var(--bad-tint); color: #be123c; }
.fb-idle { background: var(--surface-2); color: var(--ink-2); font-weight: 700; }

/* streak pill */
.streak {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 11px;
  border-radius: var(--r-pill);
  background: #fff7ea; color: #b45309;
  font-weight: 800; font-size: .9375rem;
  font-variant-numeric: tabular-nums;
}
.streak .ico { color: var(--warn); }

/* ---------- duel (2 player) ----------
   Both halves hold the SAME question. Whoever answers first waits for the
   other; a shared countdown is what creates the pressure, not a race to tap. */
.duel { position: fixed; inset: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--ink); }
.duel-side {
  position: relative;
  flex: 1 1 50%; min-height: 0;
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  transition: background .2s var(--ease);
}
.duel-side.p2 { transform: rotate(180deg); }

.duel-mid {
  position: relative; flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 6px 12px;
  background: var(--ink);
}
.duel-mid-btn {
  display: grid; place-items: center;
  width: 28px; height: 28px; flex: none;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--r-pill);
  background: none; color: #fff;
}
.duel-mid-btn:hover { background: rgba(255, 255, 255, .12); text-decoration: none; }

/* A bar carries the countdown because it reads the same from both sides —
   a number in the middle would be upside down for one of the two players. */
.duel-bar {
  flex: 1; height: 10px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .16);
  overflow: hidden;
}
.duel-bar i {
  display: block; height: 100%; width: 100%;
  border-radius: var(--r-pill);
  background: #60a5fa;
  transform-origin: center;
  transition: width 1s linear, background .3s var(--ease);
}
.duel-mid.warn .duel-bar i { background: var(--warn); }
.duel-mid.urgent .duel-bar i { background: #fb7185; animation: urgentBar .5s ease-in-out infinite; }
.duel-mid.urgent { animation: urgentStrip .5s ease-in-out infinite; }

.duel-head { display: flex; align-items: center; gap: 10px; flex: none; }
.duel-name { font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.duel-score {
  display: grid; place-items: center;
  min-width: 46px; height: 34px; padding: 0 10px;
  border-radius: var(--r-pill);
  background: var(--ink); color: #fff;
  font-weight: 800; font-variant-numeric: tabular-nums;
  transition: transform .18s var(--ease);
}
.duel-score.bump { transform: scale(1.22); }
.duel-side.a .duel-score { background: var(--brand); }
.duel-side.b .duel-score { background: var(--faith); }

.duel-clock {
  display: grid; place-items: center;
  min-width: 42px; height: 34px; padding: 0 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink-2);
  font-weight: 800; font-variant-numeric: tabular-nums;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.duel-side.warn .duel-clock { background: #fff3e0; color: #b45309; }
.duel-side.urgent .duel-clock {
  background: var(--bad); color: #fff;
  animation: urgentPulse .5s ease-in-out infinite;
}
/* A red wash creeping in from the edges — felt, not read. */
.duel-side.urgent { background: #fff5f6; }
.duel-side.urgent::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 4px var(--bad);
  border-radius: 2px;
  animation: urgentEdge .5s ease-in-out infinite;
}

.duel-state {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 10px;
  border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink-2);
  font-size: .8125rem; font-weight: 800;
  white-space: nowrap;
}
.duel-state:empty { display: none; }
.duel-state.ready { background: var(--brand-tint); color: var(--brand-ink); }

.duel-sum { margin: auto 0; }
.duel-sum .sum { padding: 4px; }
.duel-sum .sum-n, .duel-sum .sum-op, .duel-sum .sum-blank { min-width: 48px; height: 54px; font-size: 1.875rem; }
.duel-sum .sum-op { min-width: 32px; }
.duel-sum .sum-op .ico { width: 24px; height: 24px; }

.duel-fb {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 6px 12px;
  border-radius: var(--r-md);
  font-weight: 800; font-size: .9375rem;
  flex: none;
  animation: pop .2s var(--ease);
}
.duel-fb.ok   { background: var(--ok-tint);  color: #15803d; }
.duel-fb.bad  { background: var(--bad-tint); color: #be123c; }
.duel-fb.idle { background: var(--surface-2); color: var(--ink-2); }
.duel-fb .bolt { color: var(--warn); }

.duel-ans { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; flex: none; }
.duel-ans .ans { min-height: 56px; font-size: 1.25rem; }
/* The tile a player has committed to, before anyone knows if it is right. */
.duel-ans .ans.is-pick {
  border-color: var(--brand); background: var(--brand-tint);
  border-style: dashed; color: var(--brand-ink);
}
.duel-side.b .duel-ans .ans.is-pick { border-color: var(--faith); background: var(--faith-tint); color: #6d28d9; }
.duel-ans .ans:disabled { opacity: 1; }
.duel-ans .ans.is-dim:disabled { opacity: .45; }

/* A duel is played on a tablet lying flat between two children, so when there
   is height to spare the sum and the tiles grow — it has to be readable from
   the far side of the table, not just by whoever is holding it. */
@media (min-height: 700px) {
  .duel-sum .sum-n, .duel-sum .sum-blank { min-width: 64px; height: 74px; font-size: 2.5rem; }
  .duel-sum .sum-op { min-width: 40px; height: 74px; }
  .duel-sum .sum-op .ico { width: 30px; height: 30px; }
  .duel-ans .ans { min-height: 72px; font-size: 1.625rem; }
}
@media (min-height: 960px) {
  .duel-sum .sum-n, .duel-sum .sum-blank { min-width: 78px; height: 88px; font-size: 3rem; }
  .duel-sum .sum-op { min-width: 48px; height: 88px; }
  .duel-sum .sum-op .ico { width: 36px; height: 36px; }
  .duel-ans .ans { min-height: 86px; font-size: 1.875rem; }
  .duel-side { padding: 18px 20px; gap: 14px; }
}

@keyframes urgentPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes urgentBar   { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
@keyframes urgentStrip { 0%, 100% { background: var(--ink); } 50% { background: #7f1d1d; } }
@keyframes urgentEdge  { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* ---------- results ---------- */
.result { display: grid; place-items: center; text-align: center; gap: 18px; margin: auto 0; padding: 24px 0; }
.result-mascot { width: 128px; height: 128px; }
.result-stars { display: flex; gap: 8px; }
.result-stars .star .ico { width: 44px; height: 44px; }
.result-stars .star { animation: pop .3s var(--ease) both; }
.result-stars .star:nth-child(2) { animation-delay: .1s; }
.result-stars .star:nth-child(3) { animation-delay: .2s; }
.result-score {
  display: inline-flex; align-items: baseline; gap: 4px;
  font-variant-numeric: tabular-nums;
}
.result-score b { font-size: 3rem; font-weight: 800; line-height: 1; }
.result-actions { display: grid; gap: 10px; width: 100%; max-width: 340px; }

/* confetti canvas */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; }

/* ---------- story shelf ---------- */
.shelf-group + .shelf-group { margin-top: 36px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }

.sbook {
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  overflow: hidden;
  color: var(--ink);
  transition: box-shadow .14s var(--ease), transform .14s var(--ease);
}
.sbook:hover { text-decoration: none; box-shadow: var(--sh-2); transform: translateY(-2px); }
.sbook-cover {
  position: relative;
  display: grid; place-items: center;
  aspect-ratio: 16 / 10;
  font-size: 3.25rem; line-height: 1;
  background: var(--surface-2);
}
.sbook-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.sbook-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 10px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 10px;
  border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink-2);
  font-size: .8125rem; font-weight: 800;
}
.badge-1 { background: var(--ok-tint);  color: #15803d; }
.badge-2 { background: #fff7ea;         color: #b45309; }
.badge-3 { background: var(--bad-tint); color: #be123c; }
.badge-read { background: var(--read-tint); color: #0f766e; }
.badge-done { background: var(--ok-tint); color: #15803d; }

/* ---------- reader ---------- */
.plate {
  position: relative;
  display: grid; place-items: center;
  aspect-ratio: 3 / 2;
  max-height: 34vh;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background-color: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, rgba(15, 23, 42, .06) 1px, transparent 0);
  background-size: 24px 24px;
  overflow: hidden;
  flex: none;
}
.plate-art { font-size: clamp(64px, 17vw, 120px); line-height: 1; filter: saturate(1.05); }

.prose {
  font-size: 1.5rem; line-height: 1.62;
  font-weight: 600;
  letter-spacing: -.005em;
  margin: 22px 0;
  text-wrap: pretty;
}
.prose.lvl-1 { font-size: 1.625rem; line-height: 1.66; }
@media (min-width: 640px) { .prose { font-size: 1.625rem; } .prose.lvl-1 { font-size: 1.75rem; } }

.w {
  display: inline-block;
  padding: 1px 2px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s var(--ease);
}
.w:hover { background: var(--read-tint); }
.w.lit { background: #fde68a; }

.dotnav { display: flex; align-items: center; justify-content: center; gap: 7px; }
.dotnav i { width: 8px; height: 8px; border-radius: var(--r-pill); background: var(--surface-2); transition: background .15s, width .15s; }
.dotnav i.on { width: 22px; background: var(--read); }
.dotnav i.seen { background: var(--ink-3); }

.vocabs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.vcard {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  padding: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.vcard-e { font-size: 1.75rem; line-height: 1; }

/* ---------- quiz ---------- */
.qcard { display: flex; flex-direction: column; gap: 18px; margin: auto 0; width: 100%; }
.qtext { font-size: 1.375rem; font-weight: 800; line-height: 1.35; text-wrap: pretty; }
.qopts { display: grid; gap: 10px; }
.qopt {
  display: flex; align-items: center; gap: 13px;
  min-height: 62px; padding: 12px 16px;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sh-1);
  font-size: 1.0625rem; font-weight: 700;
  text-align: left; color: var(--ink);
  transition: transform .12s var(--ease), border-color .12s var(--ease), background .12s var(--ease);
}
.qopt:active { transform: translateY(1px); box-shadow: none; }
.qopt-k {
  display: grid; place-items: center;
  width: 32px; height: 32px; flex: none;
  border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink-2);
  font-weight: 800; font-size: .9375rem;
}
.qopt.is-ok { border-color: var(--ok); background: var(--ok-tint); }
.qopt.is-ok .qopt-k { background: var(--ok); color: #fff; }
.qopt.is-bad { border-color: var(--bad); background: var(--bad-tint); animation: shake .16s var(--ease); }
.qopt.is-bad .qopt-k { background: var(--bad); color: #fff; }
.qopt.is-reveal { border-color: var(--ok); border-style: dashed; }
.qopt:disabled { cursor: default; }
.qwhy {
  display: flex; gap: 10px;
  padding: 13px 16px;
  background: var(--brand-tint);
  border-radius: var(--r-md);
  font-size: .9375rem; font-weight: 600; color: #1e3a8a;
  animation: rise .18s var(--ease) both;
}

/* ---------- islamic module ---------- */
.ayah {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.ayah:last-child { border-bottom: 0; }
.ayah-top { display: flex; align-items: flex-start; gap: 12px; }
.ayah-n {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: none;
  border-radius: var(--r-pill);
  background: var(--faith-tint); color: var(--faith);
  font-size: .875rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.ar {
  font-family: var(--font-ar);
  direction: rtl; text-align: right;
  font-size: 2rem; line-height: 2.1;
  font-weight: 400;
}
.ar-sm { font-size: 1.625rem; line-height: 1.95; }
@media (min-width: 640px) { .ar { font-size: 2.375rem; } }
.translit { font-size: 1.0625rem; font-weight: 700; color: var(--faith); font-style: italic; }
.meaning { font-size: 1rem; color: var(--ink-2); }

.lafaz-line {
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.lafaz-times {
  display: inline-flex; align-items: center;
  height: 24px; padding: 0 9px;
  border-radius: var(--r-pill);
  background: var(--faith-tint); color: var(--faith);
  font-size: .8125rem; font-weight: 800;
}
.lafaz-variant { border-left: 3px solid var(--warn); background: #fffbf3; }

/* order-the-lines exercise */
.orderable { display: grid; gap: 10px; }
.orderable li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  cursor: grab;
}
.orderable li.is-ok { border-color: var(--ok); background: var(--ok-tint); }
.orderable li.is-bad { border-color: var(--bad); background: var(--bad-tint); }
.orderable li.dragging { opacity: .5; }

/* ---------- empty / notice ---------- */
.note {
  display: flex; gap: 12px;
  padding: 16px 18px;
  background: var(--brand-tint);
  border-radius: var(--r-lg);
  color: #1e3a8a;
  font-size: .9375rem; font-weight: 600;
}
.note .ico { flex: none; color: var(--brand); }
.note-warn { background: #fffbf3; color: #92400e; }
.note-warn .ico { color: var(--warn); }

.empty { display: grid; place-items: center; gap: 12px; padding: 48px 20px; text-align: center; color: var(--ink-2); }

/* ---------- install banner ----------
   Wraps on a narrow phone: without flex:none the icon tile collapsed to a
   sliver and the heading broke mid-phrase (the usual flex min-width trap). */
.install {
  display: flex; align-items: center; flex-wrap: wrap; gap: 14px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.install .tile-ico { flex: none; }
.install > div { flex: 1 1 180px; min-width: 0; }

/* ---------- animation ---------- */
@keyframes pop { from { transform: scale(.88); } 60% { transform: scale(1.04); } to { transform: scale(1); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.rise { animation: rise .2s var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  a.card:hover, .card-link:hover, .stage:hover, .sbook:hover, .pick-row:hover { transform: none; }
}
