:root {
  --bg: #f7f6f2; --card: #ffffff; --ink: #1d1d1b; --muted: #6b6a64; --line: #e3e1da;
  --accent: #1f6f5c; --accent-ink: #ffffff; --carry: #b25f00; --warn: #b3261e; --ok: #2e7d32;
  --due: #c77700; --soft: #eef3f1;
  --arabic: "Amiri Quran", "Amiri", "Noto Naskh Arabic", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141513; --card: #1d1f1c; --ink: #ecebe6; --muted: #9e9d96; --line: #30322e;
    --accent: #4fb89a; --accent-ink: #0d1f19; --carry: #f0a04b; --warn: #ef6b61; --ok: #6fcf73;
    --due: #f0a04b; --soft: #1f2a26;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
.wrap { max-width: 720px; margin: 0 auto; padding: 12px 16px 32px; }
header.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--card); position: sticky; top: 0; z-index: 5; }
header.bar h1 { font-size: 1.05rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.bar a { text-decoration: none; font-weight: 600; }
.ar { font-family: var(--arabic); direction: rtl; unicode-bidi: isolate; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 12px 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 10px 14px; min-height: 44px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--warn); }
button:disabled { opacity: .5; cursor: default; }
button.link { border: none; background: none; color: var(--muted); min-height: 44px; padding: 8px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-height: 40px; max-width: 100%; }
textarea { width: 100%; min-height: 110px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; min-width: 40px; padding: 4px 10px; border-radius: 99px; font-size: .85rem; }
.chip.rot { border-color: var(--ok); color: var(--ok); }
.chip.due { background: var(--due); border-color: var(--due); color: #fff; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .8rem; background: var(--soft); color: var(--accent); }
.badge.warn { color: var(--warn); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90vw; font-size: .9rem; }
.err { color: var(--warn); white-space: pre-wrap; }

/* ---- drill ---- */
body.drill { display: flex; flex-direction: column; }
.stage { flex: 1; display: flex; flex-direction: column; max-width: 720px; width: 100%; margin: 0 auto; padding: 8px 16px 16px; }
.meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .85rem; padding: 4px 0; }
.kind { font-weight: 700; color: var(--ink); }
.textcard { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; min-height: 34dvh;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px 14px; margin: 8px 0;
  cursor: pointer; user-select: none; }
.textcard .ar { font-size: clamp(1.9rem, 8.5vw, 3.1rem); line-height: 2.1; word-spacing: .12em; }
.textcard .ar .w { transition: color .15s, opacity .2s; }
.textcard .ar .w.carry { color: var(--carry); }
.textcard .ar .w.cue { color: var(--carry); }
.textcard.hidden .ar .w:not(.cue) { filter: blur(9px); opacity: .5; }
.phase { text-align: center; font-size: 1.35rem; font-weight: 700; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.phase small { display: block; font-size: .85rem; font-weight: 400; color: var(--muted); }
.countdown { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px auto 0; width: 70%; }
.countdown > i { display: block; height: 100%; width: 0; background: var(--carry); }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding: 10px 0 max(10px, env(safe-area-inset-bottom)); }
.bigbtn { width: 96px; height: 96px; border-radius: 50%; font-size: 2.2rem; background: var(--accent); color: var(--accent-ink);
  border: none; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.bigbtn.speak { background: var(--carry); color: #fff; }
.controls .l { justify-self: start; } .controls .r { justify-self: end; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grades button { min-height: 56px; flex-direction: column; gap: 0; font-weight: 600; }
.grades button small { font-weight: 400; color: var(--muted); font-size: .75rem; }
.opts { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.opts label { flex-direction: row; align-items: center; }
.opts select { min-height: 36px; padding: 4px 8px; }

/* ---- admin ---- */
#wave { border: 1px solid var(--line); border-radius: 10px; background: var(--card); overflow: hidden; }
.words { width: 100%; border-collapse: collapse; font-size: .9rem; }
.words td { border-top: 1px solid var(--line); padding: 4px; vertical-align: middle; }
.words tr.sel td { background: var(--soft); }
.words tr.interpolated td:first-child { box-shadow: inset 3px 0 var(--warn); }
.words tr.aligned td:first-child { box-shadow: inset 3px 0 var(--due); }
.words input.t { width: 9em; font-family: var(--arabic); direction: rtl; font-size: 1.15rem; }
.words input.n { width: 5.2em; }
.words input.ay { width: 3.2em; }
.words button { min-height: 34px; padding: 4px 8px; border-radius: 8px; }
.nudge { display: inline-flex; align-items: center; gap: 2px; }
.tablewrap { overflow-x: auto; max-height: 60dvh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.legend span { margin-inline-end: 12px; }
