:root {
  --bg: #f7f3ee;
  --surface: #fffdfb;
  --surface-2: #f2ece4;
  --ink: #2a2622;
  --muted: #6f6660;
  --gold: #b08968;
  /* Darker gold for anything carrying text — the decorative gold fails AA. */
  --gold-ink: #8b6644;
  --gold-soft: #e8dbcc;
  --line: #e8e0d6;
  --ok: #3f7a5c;
  --ok-soft: #e4f0e9;
  --err: #a84539;
  --err-soft: #f7e6e4;
  --warn: #8a6320;
  --warn-soft: #f8efdf;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(42, 38, 34, .04), 0 8px 24px rgba(42, 38, 34, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Heebo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body { direction: rtl; }

h1, h2, h3, .display { font-family: 'Frank Ruhl Libre', Georgia, serif; font-weight: 500; line-height: 1.3; }

a { color: inherit; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 18px 96px; }

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(247, 243, 238, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto; padding: 12px 18px;
  display: flex; align-items: center; gap: 12px;
}
.brand { font-family: 'Frank Ruhl Libre', serif; font-size: 19px; letter-spacing: .01em; }
.brand small { display: block; font-family: 'Heebo', sans-serif; font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.topbar .spacer { flex: 1; }

.iconbtn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-size: 16px; transition: background .15s;
}
.iconbtn:hover { background: var(--surface-2); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  border: none; border-radius: 12px; padding: 13px 22px;
  background: var(--ink); color: #fff; font-weight: 500;
  transition: transform .12s, opacity .15s;
}
.btn:hover { opacity: .9; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.gold { background: var(--gold-ink); }
.btn.sm { padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.danger { background: var(--err); }

/* ── Home ────────────────────────────────────────────────── */
.hero { padding: 26px 0 18px; }
.hero h1 { margin: 0 0 6px; font-size: 30px; }
.hero p { margin: 0; color: var(--muted); }

.resume {
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: #fff; border-radius: var(--radius);
  padding: 16px 18px; margin: 18px 0 26px; box-shadow: var(--shadow);
}
.resume .label { font-size: 12px; opacity: .65; letter-spacing: .06em; }
.resume .title { font-family: 'Frank Ruhl Libre', serif; font-size: 18px; }
.resume .spacer { flex: 1; }
.resume .go { font-size: 22px; }

.overall { margin: 0 0 26px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--gold); border-radius: 99px; transition: width .4s; }
.bar-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.modlist { display: grid; gap: 12px; }
.modcard {
  display: flex; align-items: center; gap: 14px; text-align: right; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); transition: transform .12s, border-color .15s;
}
.modcard:hover { border-color: var(--gold-soft); transform: translateY(-1px); }
.modcard .glyph {
  width: 44px; height: 44px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--gold-ink); font-size: 19px;
}
.modcard.done .glyph { background: var(--ok-soft); color: var(--ok); }
.modcard .body { flex: 1; min-width: 0; }
.modcard .body h3 { margin: 0; font-size: 18px; }
.modcard .body p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.modcard .count { font-size: 12px; color: var(--muted); white-space: nowrap; }

.ring { width: 34px; height: 34px; flex: none; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.5; }
.ring .track { stroke: var(--gold-soft); }
.ring .fill { stroke: var(--gold); stroke-linecap: round; transition: stroke-dashoffset .5s; }

/* ── Lesson list ─────────────────────────────────────────── */
.crumb { font-size: 13px; color: var(--muted); padding: 20px 0 4px; }
.lessonlist { display: grid; gap: 8px; margin-top: 16px; }
.lessonrow {
  display: flex; align-items: center; gap: 12px; text-align: right; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px;
}
.lessonrow:hover { border-color: var(--gold-soft); }
.lessonrow .tick {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  border: 1.5px solid var(--line); display: grid; place-items: center; font-size: 12px; color: transparent;
}
.lessonrow.done .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.lessonrow .t { flex: 1; }
.lessonrow .m { font-size: 12px; color: var(--muted); }

/* ── Lesson player ───────────────────────────────────────── */
.player-head { padding: 18px 0 10px; }
.player-head .of { font-size: 12px; letter-spacing: .08em; color: var(--gold-ink); text-transform: uppercase; }
.player-head h1 { margin: 4px 0 0; font-size: 27px; }

.blocks { display: grid; gap: 20px; margin-top: 22px; }

.b-lead { font-family: 'Frank Ruhl Libre', serif; font-size: 23px; line-height: 1.45; margin: 0; }
.b-text { margin: 0; }
.b-text.narrated, .b-lead.narrated { margin-bottom: 0; }

.golden {
  background: linear-gradient(180deg, #fdf8f1, #f9f0e4);
  border: 1px solid var(--gold-soft); border-radius: var(--radius);
  padding: 18px 20px; position: relative;
}
.golden .k { font-size: 11px; letter-spacing: .12em; color: var(--gold-ink); font-weight: 600; }
.golden p { margin: 6px 0 0; font-family: 'Frank Ruhl Libre', serif; font-size: 19px; line-height: 1.5; }

.media { border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 16/9; }
.media iframe { width: 100%; height: 100%; border: 0; display: block; }
.media.portrait { aspect-ratio: 9/16; max-height: 70vh; margin: 0 auto; }

figure { margin: 0; }
figure img { border-radius: var(--radius); border: 1px solid var(--line); }
figcaption { font-size: 13px; color: var(--muted); margin-top: 8px; }

.audio {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.audio .info { flex: 1; min-width: 0; }
.audio .info b { display: block; font-weight: 500; font-size: 15px; }
.audio audio { width: 100%; margin-top: 6px; }
.narration { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.narration audio { height: 32px; flex: 1; }

.placeholder {
  border: 1.5px dashed var(--gold-soft); background: #fdfaf6; border-radius: var(--radius);
  padding: 20px; text-align: center; color: var(--muted);
}
.placeholder .icon { font-size: 26px; color: var(--gold-ink); }
.placeholder b { display: block; color: var(--ink); font-weight: 500; margin: 6px 0 4px; }
.placeholder .note { font-size: 13px; text-align: right; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.placeholder .note em { color: var(--gold-ink); font-style: normal; font-weight: 500; }

.todo {
  border-right: 3px solid var(--warn); background: var(--warn-soft);
  border-radius: 12px; padding: 14px 16px; font-size: 15px;
}
.todo .k { font-size: 11px; letter-spacing: .1em; color: var(--warn); font-weight: 600; display: block; margin-bottom: 4px; }

.note-block {
  background: var(--surface-2); border: 1px dashed var(--gold-soft); border-radius: 12px;
  padding: 11px 14px; font-size: 14px; color: var(--muted); line-height: 1.6;
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.panel h4 { margin: 0 0 12px; font-size: 13px; letter-spacing: .08em; color: var(--muted); font-weight: 500; }

ul.check, ol.steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
ul.check li { display: flex; gap: 10px; align-items: flex-start; }
ul.check li::before { content: '·'; color: var(--gold-ink); font-size: 26px; line-height: .8; }
ol.steps { counter-reset: s; }
ol.steps li { display: flex; gap: 12px; align-items: flex-start; counter-increment: s; }
ol.steps li::before {
  content: counter(s); flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface-2); color: var(--gold-ink); font-size: 12px; display: grid; place-items: center; margin-top: 3px;
}
ol.steps.flow li::before { content: '←'; background: transparent; }

.quote { display: grid; gap: 10px; }
.quote .line {
  background: var(--surface); border: 1px solid var(--line); border-right: 3px solid var(--gold);
  border-radius: 12px; padding: 12px 15px; font-family: 'Frank Ruhl Libre', serif; font-size: 17px;
}

.cards { display: grid; gap: 10px; }
.cards.c2 { grid-template-columns: repeat(2, 1fr); }
.cards.c3 { grid-template-columns: repeat(3, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
}
.card .thumb { aspect-ratio: 3/4; background: var(--surface-2); display: grid; place-items: center; color: var(--gold); font-size: 22px; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .cap { padding: 11px 13px; }
.card .cap b { display: block; font-weight: 500; font-size: 15px; }
/* isolate: a number range like 2,500–4,500 reorders inside an RTL run. */
.card .cap span { font-size: 13px; color: var(--muted); unicode-bidi: isolate; }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare .col { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 15px; }
.compare .col h5 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.compare .col.pos { border-color: #d7e7de; background: #f7fbf8; }
.compare .col.pos h5 { color: var(--ok); }
.compare .col.neg { border-color: #eddcda; background: #fdf8f7; }
.compare .col.neg h5 { color: var(--err); }
.compare ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; font-size: 15px; }

.flips { display: grid; gap: 10px; }
.flip {
  width: 100%; text-align: right; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 15px; transition: border-color .15s;
}
.flip .front { font-weight: 500; display: flex; justify-content: space-between; gap: 10px; }
.flip .front i { color: var(--gold-ink); font-style: normal; font-size: 13px; }
.flip .back { display: none; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 15px; }
.flip.open { border-color: var(--gold-soft); }
.flip.open .back { display: block; }
.flip.open .front i { opacity: 0; }

.hotwrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
/* Anchored from the left so authored x/y read the same way you look at the image. */
.hot { position: absolute; width: 28px; height: 28px; border-radius: 50%; transform: translate(-50%, -50%);
  background: rgba(255,255,255,.95); border: 1.5px solid var(--gold-ink); color: var(--gold-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.hot.active { background: var(--gold-ink); color: #fff; }
.hotinfo { margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 13px 15px; scroll-margin-bottom: 110px; }
.hotinfo b { display: block; font-weight: 500; }
.hotinfo span { font-size: 15px; color: var(--muted); }

/* ── Interactive ─────────────────────────────────────────── */
.ask { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.ask .q { font-family: 'Frank Ruhl Libre', serif; font-size: 19px; line-height: 1.5; margin: 0 0 14px; }
.ask .qn { font-size: 12px; letter-spacing: .08em; color: var(--gold-ink); }
.opts { display: grid; gap: 9px; }
.opt {
  width: 100%; text-align: right; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 13px 15px; transition: border-color .15s, background .15s;
}
.opt:hover:not(:disabled) { border-color: var(--gold); }
/* Without this, answered options fall back to the UA's disabled grey and the
   correct answer becomes the least readable thing on screen. */
.opt:disabled { cursor: default; color: var(--ink); -webkit-text-fill-color: var(--ink); opacity: 1; }
.opt.correct { background: var(--ok-soft); border-color: var(--ok); }
.opt.wrong { background: var(--err-soft); border-color: var(--err); }
.feedback { margin-top: 12px; border-radius: 12px; padding: 13px 15px; font-size: 15px; }
.feedback.good { background: var(--ok-soft); color: #2f5d47; }
.feedback.bad { background: var(--err-soft); color: #7d3831; }
.score { text-align: center; padding: 22px; }
.score .n { font-family: 'Frank Ruhl Libre', serif; font-size: 44px; color: var(--gold); }

/* ── Footer nav ──────────────────────────────────────────── */
.footnav {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 30;
  background: rgba(247, 243, 238, .94); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
}
.footnav-inner { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.footnav .btn { flex: 1; }
.footnav .prev { flex: none; width: 52px; padding: 13px 0; text-align: center; }

/* ── Login ───────────────────────────────────────────────── */
.loginpage { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.loginbox { width: 100%; max-width: 380px; text-align: center; }
.loginbox .mark { font-family: 'Frank Ruhl Libre', serif; font-size: 34px; }
.loginbox .sub { color: var(--muted); margin: 2px 0 28px; font-size: 14px; letter-spacing: .04em; }
.field { text-align: right; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px 15px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); font-family: inherit; font-size: 16px;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--gold); }
/* Trailing letter-spacing after the last character shifts centred text right;
   the padding offset pulls it back to true centre. */
.codeinput { text-align: center; letter-spacing: .35em; padding-left: calc(15px + .35em); font-size: 22px !important; text-transform: uppercase; }
.msg { font-size: 14px; margin-top: 14px; min-height: 20px; }
.msg.err { color: var(--err); }
.msg.ok { color: var(--ok); }

/* ── Admin ───────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0 22px; overflow-x: auto; }
.tab { border: none; background: none; padding: 11px 15px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--ink); border-bottom-color: var(--gold); }

.adminwrap { max-width: 1120px; margin: 0 auto; padding: 0 18px 80px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: right; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: .04em; }
tr:hover td { background: var(--surface); }
.code-pill { font-family: ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 3px 9px; border-radius: 7px; letter-spacing: .12em; }
.pct { display: inline-block; min-width: 42px; }

.grid2 { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.sidelist { display: grid; gap: 4px; max-height: 72vh; overflow: auto; }
.sideitem { text-align: right; width: 100%; background: none; border: none; border-radius: 10px; padding: 9px 12px; color: var(--muted); font-size: 15px; }
.sideitem:hover { background: var(--surface); }
.sideitem.active { background: var(--ink); color: #fff; }
.sideitem.mod { font-weight: 600; color: var(--ink); margin-top: 10px; font-size: 13px; letter-spacing: .04em; }
.sideitem.mod:hover { background: none; }
.sideitem .dot { color: var(--warn); }

.blockedit { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.blockedit header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.blockedit header .type { font-size: 12px; letter-spacing: .06em; color: var(--gold-ink); background: var(--surface-2); padding: 3px 9px; border-radius: 7px; }
.blockedit header .spacer { flex: 1; }
.blockedit .mini { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; width: 28px; height: 28px; }
.blockedit textarea { min-height: 70px; resize: vertical; }
.blockedit .row { display: flex; gap: 8px; align-items: center; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 7px; background: var(--surface-2); color: var(--muted); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 12px; z-index: 90;
  transition: transform .25s; font-size: 15px;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .compare { grid-template-columns: 1fr; }
  .cards.c3 { grid-template-columns: repeat(2, 1fr); }
  .hero h1 { font-size: 26px; }
  .player-head h1 { font-size: 23px; }
}
