/* Layout concept: an illuminated-mushaf study desk — cool paper, ink-green text, gold-leaf accents,
   a faint khatam (8-point star) lattice, and Arabic always given the most room on the page. */
:root {
  --paper: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #e8efeb;
  --ink: #102f2a;
  --ink-2: #4b635d;
  --ink-3: #7a8f89;
  --line: #d4e0da;
  --primary: #0f6b5e;
  --primary-ink: #ffffff;
  --gold: #b07a17;
  --gold-soft: #f4e6c4;
  --good: #1d7a45;
  --good-soft: #dff1e5;
  --bad: #b23a3a;
  --bad-soft: #f8e1e0;
  --shadow: 0 1px 2px rgba(16, 47, 42, .06), 0 8px 24px -12px rgba(16, 47, 42, .18);

  --c-teal: #0f6b5e;    --c-teal-soft: #d8eee9;
  --c-emerald: #1b7a4b; --c-emerald-soft: #dcf0e3;
  --c-amber: #a86a08;   --c-amber-soft: #f6e8cc;
  --c-indigo: #3f48a8;  --c-indigo-soft: #e1e3f6;
  --c-rose: #ad3f62;    --c-rose-soft: #f6dfe6;
  --c-violet: #74469f;  --c-violet-soft: #ece1f5;

  --tj-green: #16884a; --tj-gray: #7c8784; --tj-blue: #2464c7; --tj-red: #c8312f; --tj-orange: #d27409; --tj-purple: #8a3fb5;

  --f-ar: "Amiri", "Noto Naskh Arabic", "Traditional Arabic", "Arabic Typesetting", serif;
  --f-bn: "Hind Siliguri", "Noto Sans Bengali", "Nirmala UI", "Vrinda", sans-serif;
  --f-en: "Figtree", "Hind Siliguri", "Segoe UI", system-ui, sans-serif;
  --f-display: "Reem Kufi", "Hind Siliguri", "Figtree", "Segoe UI", sans-serif;

  --ar-scale: 1;
  --radius: 14px;
  --maxw: 1120px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0a1513; --surface: #10201d; --surface-2: #162a26; --ink: #e5efea; --ink-2: #a3b8b1; --ink-3: #6f8781;
    --line: #23403a; --primary: #3cbfa6; --primary-ink: #04201b; --gold: #e3b65b; --gold-soft: #3a2f16;
    --good: #57c784; --good-soft: #143322; --bad: #f07e7e; --bad-soft: #3a1818;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
    --c-teal: #3cbfa6; --c-teal-soft: #12302b; --c-emerald: #4fcf8a; --c-emerald-soft: #12301f;
    --c-amber: #e8ad44; --c-amber-soft: #33270f; --c-indigo: #8f97f0; --c-indigo-soft: #1d2043;
    --c-rose: #ef87a8; --c-rose-soft: #3a1825; --c-violet: #c19af0; --c-violet-soft: #2a1c3a;
    --tj-green: #4fd08a; --tj-gray: #9aa6a2; --tj-blue: #6fa4ff; --tj-red: #ff7570; --tj-orange: #ffa94d; --tj-purple: #c98cf0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0a1513; --surface: #10201d; --surface-2: #162a26; --ink: #e5efea; --ink-2: #a3b8b1; --ink-3: #6f8781;
  --line: #23403a; --primary: #3cbfa6; --primary-ink: #04201b; --gold: #e3b65b; --gold-soft: #3a2f16;
  --good: #57c784; --good-soft: #143322; --bad: #f07e7e; --bad-soft: #3a1818;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
  --c-teal: #3cbfa6; --c-teal-soft: #12302b; --c-emerald: #4fcf8a; --c-emerald-soft: #12301f;
  --c-amber: #e8ad44; --c-amber-soft: #33270f; --c-indigo: #8f97f0; --c-indigo-soft: #1d2043;
  --c-rose: #ef87a8; --c-rose-soft: #3a1825; --c-violet: #c19af0; --c-violet-soft: #2a1c3a;
  --tj-green: #4fd08a; --tj-gray: #9aa6a2; --tj-blue: #6fa4ff; --tj-red: #ff7570; --tj-orange: #ffa94d; --tj-purple: #c98cf0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.65 var(--f-bn); font-feature-settings: "kern";
}
:lang(en), .en { font-family: var(--f-en); }
a { color: var(--primary); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.25; margin: 0; }
p { margin: 0; }
mark { background: none; color: inherit; }
img { max-width: 100%; }

/* ---------- Arabic ---------- */
.ar, .ar-in { font-family: var(--f-ar); direction: rtl; unicode-bidi: isolate; }
.ar { font-size: calc(1.9rem * var(--ar-scale)); line-height: 1.9; }
.ar-in { font-size: 1.28em; line-height: 1.2; color: var(--ink); padding: 0 .08em; }
.ar-xl { font-size: calc(3.4rem * var(--ar-scale)); line-height: 1.6; }
.ar-lg { font-size: calc(2.4rem * var(--ar-scale)); line-height: 1.8; }
.ar-md { font-size: calc(1.6rem * var(--ar-scale)); line-height: 1.8; }
.hl { color: var(--gold); border-bottom: 2px solid currentColor; }
.tj-green { color: var(--tj-green); } .tj-gray { color: var(--tj-gray); } .tj-blue { color: var(--tj-blue); }
.tj-red { color: var(--tj-red); } .tj-orange { color: var(--tj-orange); } .tj-purple { color: var(--tj-purple); }
mark.tj-green, mark.tj-gray, mark.tj-blue, mark.tj-red, mark.tj-orange, mark.tj-purple { border-bottom: 2px solid currentColor; }

/* bilingual: secondary language line */
.sub { display: block; font-family: var(--f-en); color: var(--ink-2); font-size: .9em; margin-top: .2em; }
.sub .ar-in { color: var(--ink-2); }
.muted { color: var(--ink-2); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in {
  max-width: var(--maxw); margin: 0 auto; display: flex; align-items: center; gap: 18px;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center; font: 700 28px/1 var(--f-ar);
  color: var(--primary-ink); background: var(--primary); padding-top: 6px;
  clip-path: polygon(50% 0, 64.6% 14.6%, 85.4% 14.6%, 85.4% 35.4%, 100% 50%, 85.4% 64.6%, 85.4% 85.4%, 64.6% 85.4%, 50% 100%, 35.4% 85.4%, 14.6% 85.4%, 14.6% 64.6%, 0 50%, 14.6% 35.4%, 14.6% 14.6%, 35.4% 14.6%);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-weight: 700; font-size: 1rem; }
.brand-text small { font: 600 .72rem/1.2 var(--f-display); letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }
.mainnav { display: flex; gap: 2px; }
.mainnav a {
  text-decoration: none; color: var(--ink-2); padding: 7px 11px; border-radius: 9px; font-weight: 500; font-size: .95rem; white-space: nowrap;
}
.mainnav a:hover { background: var(--surface-2); color: var(--ink); }
.mainnav a[aria-current="page"] { color: var(--primary); background: var(--surface-2); }
.top-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search input {
  width: 170px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 14px var(--f-bn);
}
.page-search { display: block !important; margin-top: 8px; }
.page-search input { width: 100%; max-width: 420px; padding: 10px 16px; font-size: 15px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: none; padding: 4px 10px; border-radius: 999px; cursor: pointer; font-size: .82rem; color: var(--ink-2); font-weight: 600;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { color: var(--ink); }
.icon-btn svg, .btn svg, .tabbar svg, .xp-chip svg { width: 18px; height: 18px; }
.xp-chip {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink); font: 600 .85rem var(--f-en);
  background: var(--gold-soft); padding: 6px 11px; border-radius: 999px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.xp-chip svg { color: var(--gold); }
.read-progress { height: 3px; width: 0; background: linear-gradient(90deg, var(--primary), var(--gold)); transition: width .15s; }

.tabbar { display: none; }

/* ---------- Page ---------- */
.view {
  max-width: var(--maxw); margin: 0 auto; outline: none;
  padding-block: 28px 80px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.page-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 22px; }
.eyebrow { font: 600 .75rem/1.2 var(--f-display); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.page-title { font-size: clamp(1.6rem, 3.5vw, 2.3rem); font-weight: 700; }
.page-title .sub { font: 600 .5em/1.3 var(--f-display); letter-spacing: .02em; }
.section-title { font-size: 1.25rem; font-weight: 700; margin: 34px 0 14px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.section-title .sub { display: inline; font-size: .75em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 9px 16px; border-radius: 11px; cursor: pointer; font-weight: 600; text-decoration: none; font-size: .95rem; line-height: 1.3;
}
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); border-color: transparent; }
.btn-gold { background: var(--gold); color: #fff; border-color: transparent; }
.btn-ghost { background: none; border-color: transparent; color: var(--ink-2); }
.btn-sm { padding: 6px 11px; font-size: .85rem; border-radius: 9px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.play {
  width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--primary); display: inline-grid; place-items: center; cursor: pointer; flex-shrink: 0;
}
.play:hover { background: var(--primary); color: var(--primary-ink); }
.play svg { width: 15px; height: 15px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* unit colour helpers */
[data-c="teal"] { --uc: var(--c-teal); --ucs: var(--c-teal-soft); }
[data-c="emerald"] { --uc: var(--c-emerald); --ucs: var(--c-emerald-soft); }
[data-c="amber"] { --uc: var(--c-amber); --ucs: var(--c-amber-soft); }
[data-c="indigo"] { --uc: var(--c-indigo); --ucs: var(--c-indigo-soft); }
[data-c="rose"] { --uc: var(--c-rose); --ucs: var(--c-rose-soft); }
[data-c="violet"] { --uc: var(--c-violet); --ucs: var(--c-violet-soft); }

/* khatam pattern (8-point star lattice) used as a mask so it follows theme colours */
.pattern {
  position: absolute; inset: 0; pointer-events: none; background: var(--gold); opacity: .13;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.3'%3E%3Cpath d='M32 10l6.4 15.6L54 32l-15.6 6.4L32 54l-6.4-15.6L10 32l15.6-6.4z'/%3E%3Crect x='17' y='17' width='30' height='30' transform='rotate(0 32 32)'/%3E%3Cpath d='M0 0l10 10M64 0L54 10M0 64l10-10M64 64L54 54'/%3E%3C/g%3E%3C/svg%3E") repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.3'%3E%3Cpath d='M32 10l6.4 15.6L54 32l-15.6 6.4L32 54l-6.4-15.6L10 32l15.6-6.4z'/%3E%3Crect x='17' y='17' width='30' height='30' transform='rotate(0 32 32)'/%3E%3Cpath d='M0 0l10 10M64 0L54 10M0 64l10-10M64 64L54 54'/%3E%3C/g%3E%3C/svg%3E") repeat;
}
.star-clip { clip-path: polygon(50% 0, 64.6% 14.6%, 85.4% 14.6%, 85.4% 35.4%, 100% 50%, 85.4% 64.6%, 85.4% 85.4%, 64.6% 85.4%, 50% 100%, 35.4% 85.4%, 14.6% 85.4%, 14.6% 64.6%, 0 50%, 14.6% 35.4%, 14.6% 14.6%, 35.4% 14.6%); }

/* ---------- Home ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 22px; background: var(--surface); border: 1px solid var(--line);
  display: grid; grid-template-columns: 1.25fr 1fr; gap: 0; box-shadow: var(--shadow);
}
.hero-main { position: relative; padding: 34px 34px 30px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.hero-greet { font: 400 2.2rem/1.3 var(--f-ar); color: var(--gold); direction: rtl; text-align: left; }
.hero h1 { font-size: clamp(1.6rem, 3.6vw, 2.5rem); font-weight: 700; }
.hero h1 .sub { font: 500 .5em/1.35 var(--f-display); letter-spacing: .01em; margin-top: .35em; }
.hero-lead { color: var(--ink-2); max-width: 46ch; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 6px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font: 700 1.35rem/1.2 var(--f-display); font-variant-numeric: tabular-nums; }
.stat span { font-size: .78rem; color: var(--ink-2); }
.wotd {
  position: relative; background: var(--primary); color: var(--primary-ink); padding: 30px; display: flex; flex-direction: column; gap: 10px; justify-content: center; min-width: 0;
}
.wotd .pattern { background: var(--primary-ink); opacity: .12; }
.wotd .eyebrow { color: var(--primary-ink); opacity: .8; position: relative; }
.wotd-ar { position: relative; font: 700 calc(4rem * var(--ar-scale))/1.5 var(--f-ar); text-wrap: balance; text-align: center; direction: rtl; }
.wotd-tr { position: relative; text-align: center; font-weight: 600; }
.wotd-mean { position: relative; text-align: center; opacity: .9; }
.wotd-mean .sub { color: inherit; opacity: .8; }
.wotd .play { position: relative; align-self: center; background: color-mix(in srgb, var(--primary-ink) 18%, transparent); color: var(--primary-ink); }

.unit-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.unit-card {
  position: relative; display: flex; flex-direction: column; gap: 10px; padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); overflow: hidden; transition: transform .15s, box-shadow .15s;
}
.unit-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.unit-card .u-top { display: flex; align-items: center; gap: 12px; }
.u-badge {
  width: 52px; height: 52px; flex-shrink: 0; display: grid; place-items: center; background: var(--uc); color: var(--surface);
  font: 700 26px/1 var(--f-ar); padding-top: 6px;
}
.u-num { font: 600 .72rem var(--f-display); letter-spacing: .12em; text-transform: uppercase; color: var(--uc); }
.unit-card h3 { font-size: 1.08rem; }
.unit-card h3 .sub { font-size: .8em; font-weight: 500; }
.unit-card p { color: var(--ink-2); font-size: .9rem; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--uc, var(--primary)); border-radius: 99px; }
.u-meta { display: flex; justify-content: space-between; font-size: .8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.tools-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tool {
  display: flex; flex-direction: column; gap: 6px; padding: 18px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); text-decoration: none; color: var(--ink); min-width: 0;
}
.tool:hover { border-color: var(--primary); }
.tool .t-ar { font: 700 2rem/1.4 var(--f-ar); color: var(--primary); }
.tool b { font-size: 1rem; }
.tool span { font-size: .85rem; color: var(--ink-2); }

/* ---------- Unit path ---------- */
.unit-hero {
  position: relative; overflow: hidden; border-radius: 20px; padding: 28px; background: var(--ucs); border: 1px solid var(--line);
  display: flex; gap: 22px; align-items: center; margin-bottom: 26px;
}
.unit-hero .pattern { background: var(--uc); opacity: .12; }
.unit-hero .u-badge { width: 84px; height: 84px; font-size: 42px; position: relative; }
.unit-hero > div:not(.pattern) { position: relative; min-width: 0; }
.path { display: flex; flex-direction: column; gap: 0; position: relative; max-width: 760px; margin: 0 auto; }
.path-row { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 18px; align-items: center; position: relative; padding: 8px 0; }
.path-row::before { content: ""; position: absolute; left: 37px; top: 0; bottom: 0; width: 2px; background: var(--line); z-index: 0; }
.path-row:first-child::before { top: 50%; } .path-row:last-child::before { bottom: 50%; }
.node {
  position: relative; z-index: 1; width: 76px; height: 76px; display: grid; place-items: center; text-decoration: none;
  background: var(--surface-2); color: var(--ink-2); font: 700 24px/1 var(--f-ar);
}
.node.done { background: var(--gold); color: #fff; }
.node.next { background: var(--uc); color: var(--surface); animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.07); } }
.lesson-link {
  display: flex; flex-direction: column; gap: 3px; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink); min-width: 0;
}
.lesson-link:hover { border-color: var(--uc); }
.lesson-link .l-n { font: 600 .72rem var(--f-display); letter-spacing: .1em; color: var(--uc); text-transform: uppercase; }
.lesson-link b { font-size: 1.02rem; }
.lesson-link small { color: var(--ink-2); }
.lesson-link .l-meta { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

/* ---------- Lesson ---------- */
.lesson { max-width: 820px; margin: 0 auto; }
.crumbs { display: flex; gap: 8px; align-items: center; font-size: .85rem; color: var(--ink-2); flex-wrap: wrap; }
.crumbs a { color: var(--ink-2); text-decoration: none; } .crumbs a:hover { color: var(--primary); }
.lesson-head {
  position: relative; overflow: hidden; margin: 14px 0 22px; padding: 26px; border-radius: 20px; background: var(--ucs); border: 1px solid var(--line);
  display: flex; gap: 20px; align-items: flex-start;
}
.lesson-head .pattern { background: var(--uc); opacity: .1; }
.lesson-head .u-badge { position: relative; width: 70px; height: 70px; font-size: 32px; }
.lesson-head > div:not(.pattern) { position: relative; min-width: 0; flex: 1; }
.lesson-head h1 { font-size: clamp(1.5rem, 3.2vw, 2rem); }
.lesson-head h1 .sub { font: 600 .55em/1.3 var(--f-display); }
.lesson-head p { color: var(--ink-2); margin-top: 6px; }
.goals { margin-top: 14px; display: grid; gap: 6px; padding: 0; list-style: none; }
.goals li { display: flex; gap: 8px; align-items: flex-start; font-size: .95rem; }
.goals li::before { content: ""; width: 9px; height: 9px; margin-top: .55em; flex-shrink: 0; background: var(--uc); transform: rotate(45deg); }

.blocks { display: flex; flex-direction: column; gap: 18px; }
.block-title { font-size: 1.12rem; font-weight: 700; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.block-title .sub { display: inline; font-size: .8em; font-weight: 500; }
.b-text { font-size: 1.04rem; }
.b-text .sub { font-size: .92em; }

.tip { border-radius: 14px; padding: 14px 16px 14px 16px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.tip-label { font: 700 .72rem/1.2 var(--f-display); letter-spacing: .1em; text-transform: uppercase; display: flex; align-items: center; gap: 6px; }
.tip-label svg { width: 16px; height: 16px; }
.tip-tip { background: var(--c-teal-soft); border-color: transparent; } .tip-tip .tip-label { color: var(--c-teal); }
.tip-warn { background: var(--bad-soft); border-color: transparent; } .tip-warn .tip-label { color: var(--bad); }
.tip-memory { background: var(--gold-soft); border-color: transparent; } .tip-memory .tip-label { color: var(--gold); }
.tip-fun { background: var(--c-violet-soft); border-color: transparent; } .tip-fun .tip-label { color: var(--c-violet); }

/* letter tiles */
.letter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.ltile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 12px 6px 10px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; text-align: center; transition: transform .12s, border-color .12s;
}
.ltile:hover { transform: translateY(-2px); border-color: var(--primary); }
.ltile .l-ar { font: 400 calc(3rem * var(--ar-scale))/1.5 var(--f-ar); color: var(--ink); }
.ltile .l-name { font-weight: 600; font-size: .95rem; }
.ltile .l-tr { font: 500 .78rem var(--f-en); color: var(--ink-2); }
.ltile .l-dot { position: absolute; top: 8px; left: 8px; width: 8px; height: 8px; border-radius: 50%; }
.ltile.heavy .l-ar { color: var(--c-rose); }
.ltile .l-num { position: absolute; top: 6px; right: 9px; font: 600 .7rem var(--f-en); color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* example cards */
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.ex {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 12px 10px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; min-width: 0;
}
.ex:hover { border-color: var(--primary); }
.ex .ar { font-size: calc(2rem * var(--ar-scale)); line-height: 1.7; }
.ex .ex-tr { font-weight: 600; font-size: .92rem; color: var(--primary); }
.ex .ex-tr .sub { display: inline; margin: 0 0 0 4px; font-weight: 500; }
.ex .ex-mean { font-size: .88rem; color: var(--ink-2); }
.ex .ex-note { font-size: .8rem; color: var(--ink-3); margin-top: 4px; }

/* tables */
.tbl-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--surface-2); font-weight: 600; font-size: .85rem; color: var(--ink-2); }
tr:last-child td { border-bottom: 0; }
td.ar-cell { font-family: var(--f-ar); font-size: calc(1.55rem * var(--ar-scale)); line-height: 1.6; direction: rtl; text-align: right; cursor: pointer; white-space: nowrap; }
td.ar-cell:hover { color: var(--primary); }
td .sub, th .sub { font-size: .85em; }

/* build grid */
.build { display: grid; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.build-row { display: grid; gap: 6px; grid-template-columns: 60px repeat(var(--cols), minmax(64px, 1fr)); direction: rtl; }
.build-cell {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 4px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; min-width: 0;
}
.build-cell:hover { border-color: var(--primary); background: var(--c-teal-soft); }
.build-cell .ar { font-size: calc(1.9rem * var(--ar-scale)); line-height: 1.5; }
.build-cell small { font-size: .72rem; color: var(--ink-2); direction: ltr; }
.build-head { font-size: .78rem; font-weight: 600; color: var(--ink-2); text-align: center; align-self: end; padding-bottom: 2px; }
.build-head .ar-in { font-size: 1.6em; }
.build-base { font: 700 calc(1.9rem * var(--ar-scale))/1.5 var(--f-ar); text-align: center; color: var(--gold); align-self: center; }

/* compare */
.compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.cmp { padding: 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.cmp .ar { font-size: calc(3rem * var(--ar-scale)); line-height: 1.4; }
.cmp b { font-size: 1rem; }
.cmp p { font-size: .88rem; color: var(--ink-2); }
.vs { display: grid; place-items: center; font: 700 .8rem var(--f-display); color: var(--ink-3); }

/* tajweed rule */
.rule { border-radius: 16px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.rule-head { display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.rule-swatch { width: 14px; align-self: stretch; border-radius: 6px; flex-shrink: 0; }
.rule-head h4 { font-size: 1.1rem; }
.rule-head h4 .sub { display: inline; margin-left: 6px; font-weight: 500; font-size: .8em; }
.rule-head .ar { font-size: calc(1.6rem * var(--ar-scale)); margin-left: auto; line-height: 1.4; }
.rule-body { padding: 14px 16px; display: grid; gap: 10px; }
.rule-letters { font-family: var(--f-ar); font-size: calc(1.7rem * var(--ar-scale)); letter-spacing: .25em; direction: rtl; text-align: right; }
.rule-how { font-size: .93rem; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.rule-how b { font-family: var(--f-display); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); display: block; }
.rule-ex { display: flex; flex-wrap: wrap; gap: 8px; }
.rule-ex button { border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 6px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.rule-ex .ar { font-size: calc(1.7rem * var(--ar-scale)); line-height: 1.6; }
.rule-ex small { font-size: .75rem; color: var(--ink-2); }

/* practice */
.practice { padding: 16px; border-radius: 16px; background: var(--surface); border: 1px dashed var(--ink-3); display: grid; gap: 10px; }
.practice-top { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.p-line { display: flex; flex-wrap: wrap; gap: 4px 14px; direction: rtl; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.p-line:last-child { border-bottom: 0; }
.p-word { font: 400 calc(2rem * var(--ar-scale))/1.8 var(--f-ar); cursor: pointer; border-radius: 8px; padding: 0 6px; border: 0; background: none; color: var(--ink); }
.p-word:hover, .p-word.speaking { background: var(--gold-soft); }
.p-line .play { margin-right: auto; }

/* vocab list */
.vocab { display: grid; gap: 0; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.vrow { display: grid; grid-template-columns: minmax(110px, 1.1fr) minmax(0, 1fr) minmax(0, 1.3fr) auto; gap: 12px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.vrow:last-child { border-bottom: 0; }
.vrow .ar { font-size: calc(1.75rem * var(--ar-scale)); line-height: 1.6; text-align: right; cursor: pointer; }
.vrow .v-tr { font-weight: 600; color: var(--primary); font-size: .92rem; }
.vrow .v-tr .sub { display: block; font-weight: 500; margin: 0; }
.vrow .v-mean { font-size: .95rem; }
.vrow .v-ex { grid-column: 1 / -1; font-size: .88rem; color: var(--ink-2); background: var(--surface-2); border-radius: 10px; padding: 6px 10px; }
.vrow .v-ex .ar-in { font-size: 1.4em; }
.root { font-family: var(--f-ar); font-size: 1.05rem; direction: rtl; background: var(--gold-soft); color: var(--gold); padding: 0 8px; border-radius: 999px; white-space: nowrap; }

/* ayah */
.ayah { border-radius: 18px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.ayah-top { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--c-violet-soft); gap: 10px; flex-wrap: wrap; }
.ayah-ref { font: 600 .82rem var(--f-display); letter-spacing: .06em; color: var(--c-violet); }
.ayah-ar { padding: 18px 18px 8px; font: 400 calc(2.3rem * var(--ar-scale))/2.1 var(--f-ar); direction: rtl; text-align: right; }
.ayah-ar .w { cursor: pointer; border-radius: 8px; padding: 0 3px; transition: background .12s; }
.ayah-ar .w:hover, .ayah-ar .w.on { background: var(--gold-soft); }
.ayah-num { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; font-size: .6em; border: 1.5px solid var(--gold); color: var(--gold); border-radius: 50%; margin-right: .2em; vertical-align: middle; font-family: var(--f-ar); }
.wbw { display: flex; flex-wrap: wrap; direction: rtl; gap: 8px; padding: 6px 18px 14px; }
.wbw-w { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 6px 10px; border-radius: 12px; background: var(--surface-2); min-width: 70px; cursor: pointer; }
.wbw-w .ar { font-size: calc(1.6rem * var(--ar-scale)); line-height: 1.6; }
.wbw-w small { direction: ltr; font-size: .8rem; line-height: 1.3; }
.wbw-w small.en { color: var(--ink-2); }
.ayah-tr { padding: 0 18px 6px; color: var(--primary); font-weight: 500; font-size: .95rem; }
.ayah-mean { padding: 4px 18px 18px; font-size: 1.02rem; }

/* steps */
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; counter-reset: st; }
.steps li { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 12px; padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); counter-increment: st; }
.steps li::before {
  content: counter(st); width: 40px; height: 40px; display: grid; place-items: center; background: var(--uc, var(--primary)); color: var(--surface);
  font: 700 1rem var(--f-display);
  clip-path: polygon(50% 0, 64.6% 14.6%, 85.4% 14.6%, 85.4% 35.4%, 100% 50%, 85.4% 64.6%, 85.4% 85.4%, 64.6% 85.4%, 50% 100%, 35.4% 85.4%, 14.6% 85.4%, 14.6% 64.6%, 0 50%, 14.6% 35.4%, 14.6% 14.6%, 35.4% 14.6%);
}
.steps .st-body { display: grid; gap: 4px; min-width: 0; }
.steps .st-body b { font-size: 1.02rem; }
.steps .ar { font-size: calc(1.8rem * var(--ar-scale)); text-align: right; cursor: pointer; }
.steps .st-tr { color: var(--primary); font-weight: 500; font-size: .93rem; }
.steps .st-desc { color: var(--ink-2); font-size: .93rem; }

/* trace */
.trace { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 14px; padding: 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.trace-pad { position: relative; width: 100%; max-width: 100%; aspect-ratio: 4 / 3; border-radius: 12px; background: var(--paper); border: 1px solid var(--line); touch-action: none; overflow: hidden; }
.trace-pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.trace-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.trace-letters { display: flex; flex-wrap: wrap; gap: 6px; direction: rtl; }
.trace-letters button { font: 400 1.6rem/1.4 var(--f-ar); border: 1px solid var(--line); background: var(--paper); border-radius: 10px; min-width: 46px; cursor: pointer; padding: 0 8px; }
.trace-letters button[aria-pressed="true"] { border-color: var(--primary); background: var(--c-teal-soft); }
.trace-score { font: 700 1.6rem var(--f-display); color: var(--gold); min-height: 1.4em; }
.trace-score small { display: block; font: 500 .8rem var(--f-bn); color: var(--ink-2); }

/* quiz */
.quiz { border-radius: 18px; background: var(--surface); border: 2px solid var(--uc, var(--primary)); padding: 18px; display: grid; gap: 14px; }
.quiz-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.quiz-dots { display: flex; gap: 5px; flex-wrap: wrap; }
.quiz-dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-2); }
.quiz-dots i.ok { background: var(--good); } .quiz-dots i.no { background: var(--bad); } .quiz-dots i.cur { outline: 2px solid var(--uc, var(--primary)); outline-offset: 1px; }
.quiz-q { font-size: 1.12rem; font-weight: 600; }
.quiz-ar { font: 400 calc(3rem * var(--ar-scale))/1.6 var(--f-ar); text-align: center; direction: rtl; }
.quiz-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.opt {
  text-align: left; border: 1.5px solid var(--line); background: var(--paper); border-radius: 12px; padding: 11px 14px; cursor: pointer; font-size: 1rem;
  display: flex; gap: 10px; align-items: center; min-width: 0;
}
.opt:hover:not([disabled]) { border-color: var(--uc, var(--primary)); }
.opt .k { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font: 600 .8rem var(--f-en); flex-shrink: 0; }
.opt .ar-in { font-size: 1.6em; }
.opt.ok { border-color: var(--good); background: var(--good-soft); } .opt.ok .k { background: var(--good); color: #fff; }
.opt.no { border-color: var(--bad); background: var(--bad-soft); } .opt.no .k { background: var(--bad); color: #fff; }
.opt[disabled] { cursor: default; }
.quiz-explain { font-size: .93rem; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.quiz-foot { display: flex; justify-content: flex-end; gap: 8px; }
.quiz-result { text-align: center; display: grid; gap: 8px; justify-items: center; padding: 10px 0; }
.quiz-result .big { font: 700 3rem/1 var(--f-display); color: var(--uc, var(--primary)); font-variant-numeric: tabular-nums; }

.lesson-foot { margin-top: 30px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; padding-top: 20px; border-top: 1px solid var(--line); }
.done-banner { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; background: var(--good-soft); color: var(--good); font-weight: 600; }

/* ---------- Alphabet explorer ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.filters button { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: .88rem; color: var(--ink-2); }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.ltile.dim { opacity: .25; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--ink-2); margin-top: 14px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* letter modal */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.modal-scrim { position: absolute; inset: 0; background: rgba(5, 20, 17, .55); }
.modal-card { position: relative; width: min(760px, 100%); max-height: 100%; overflow: auto; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); }
.lm-head { position: relative; overflow: hidden; display: flex; gap: 20px; align-items: center; padding: 24px; background: var(--surface-2); }
.lm-big { position: relative; font: 400 calc(6rem * var(--ar-scale))/1.3 var(--f-ar); width: 140px; text-align: center; color: var(--primary); flex-shrink: 0; }
.lm-head > div:not(.pattern) { position: relative; min-width: 0; }
.lm-head h2 { font-size: 1.8rem; }
.lm-close { position: absolute; top: 12px; right: 12px; z-index: 2; }
.lm-body { padding: 20px 24px 24px; display: grid; gap: 16px; }
.forms { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; direction: rtl; }
.form-box { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; text-align: center; padding: 6px; }
.form-box .ar { font-size: calc(2.6rem * var(--ar-scale)); line-height: 1.6; }
.form-box small { display: block; direction: ltr; font-size: .78rem; color: var(--ink-2); }
.kv { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 14px; font-size: .95rem; }
.kv dt { color: var(--ink-2); font-weight: 600; font-size: .85rem; padding-top: 2px; }
.kv dd { margin: 0; }
.lm-nav { display: flex; justify-content: space-between; gap: 8px; }

/* ---------- Flashcards ---------- */
.fc-wrap { max-width: 640px; margin: 0 auto; display: grid; gap: 16px; }
.fc-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.fc-bar select { padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 14px var(--f-bn); max-width: 100%; }
.card3d { perspective: 1200px; cursor: pointer; }
.card3d-in { position: relative; min-height: 300px; transition: transform .5s cubic-bezier(.2, .8, .2, 1); transform-style: preserve-3d; }
.card3d.flip .card3d-in { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 22px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; overflow: hidden; text-align: center;
}
.face .pattern { opacity: .08; }
.face > * { position: relative; }
.face.back { transform: rotateY(180deg); }
.face .ar { font-size: calc(4rem * var(--ar-scale)); line-height: 1.6; }
.face .hint { font-size: .8rem; color: var(--ink-3); position: absolute; bottom: 14px; }
.fc-mean { font-size: 1.4rem; font-weight: 600; }
.fc-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.fc-actions .btn { padding: 12px; flex-direction: column; gap: 0; }
.fc-actions .btn small { font-weight: 500; font-size: .75rem; opacity: .8; }
.boxes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.boxes div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; }
.boxes b { display: block; font: 700 1.2rem var(--f-display); font-variant-numeric: tabular-nums; }
.boxes small { font-size: .72rem; color: var(--ink-2); }

/* ---------- Games ---------- */
.game-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.game-card { position: relative; overflow: hidden; padding: 22px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.game-card .g-ar { font: 700 3rem/1.3 var(--f-ar); color: var(--uc); position: relative; }
.game-card > * { position: relative; }
.game-card p { color: var(--ink-2); font-size: .92rem; flex: 1; }
.arena { max-width: 680px; margin: 0 auto; display: grid; gap: 18px; }
.arena-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; font: 600 1rem var(--f-display); font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.timer { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.timer i { display: block; height: 100%; background: var(--gold); transition: width 1s linear; }
.prompt { text-align: center; padding: 26px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); }
.prompt .big { font: 700 2.2rem/1.3 var(--f-display); }
.prompt .ar { font-size: calc(3.5rem * var(--ar-scale)); }
.answers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.answers button { font: 400 calc(2.6rem * var(--ar-scale))/1.6 var(--f-ar); border: 1.5px solid var(--line); background: var(--surface); border-radius: 16px; cursor: pointer; padding: 6px; color: var(--ink); }
.answers button:hover { border-color: var(--primary); }
.answers button.ok { background: var(--good-soft); border-color: var(--good); } .answers button.no { background: var(--bad-soft); border-color: var(--bad); }
.memory { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.mem {
  min-height: 92px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; padding: 8px; display: grid; place-items: center;
  font-size: .92rem; text-align: center; color: var(--ink); transition: transform .15s;
}
.mem .ar-in { font-size: 2em; }
.mem.sel { border-color: var(--gold); background: var(--gold-soft); transform: scale(1.03); }
.mem.matched { border-color: var(--good); background: var(--good-soft); opacity: .55; cursor: default; }
.mem.wrong { animation: shake .35s; border-color: var(--bad); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.result-card { text-align: center; padding: 30px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); display: grid; gap: 10px; justify-items: center; }
.result-card .big { font: 700 3.4rem/1 var(--f-display); color: var(--gold); }

/* search & settings */
.results { display: grid; gap: 8px; }
.result { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.result .ar { font-size: 1.7rem; line-height: 1.5; min-width: 90px; text-align: center; }
.settings { display: grid; gap: 12px; max-width: 680px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); flex-wrap: wrap; }
.set-row > div:first-child { min-width: 0; flex: 1 1 240px; }
.set-row small { display: block; color: var(--ink-2); }
input[type="range"] { accent-color: var(--primary); width: 180px; max-width: 100%; }

.empty { text-align: center; padding: 50px 20px; color: var(--ink-2); border: 1px dashed var(--line); border-radius: 18px; }
.empty .ar { font-size: 3rem; color: var(--gold); }

.site-foot {
  max-width: var(--maxw); margin: 0 auto; display: flex; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap;
  padding-block: 18px 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-top: 1px solid var(--line); color: var(--ink-3); font-size: .82rem;
}
.view { padding-bottom: 48px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 70; background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 12px; font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 80; }

/* ---------- Responsive ---------- */
@media (max-width: 1220px) {
  .search { display: none; }
  .xp-chip .xp-label { display: none; }
}
@media (max-width: 1020px) {
  .mainnav a { padding: 7px 8px; }
  .brand-text small { display: none; }
}
@media (max-width: 880px) {
  .mainnav, .search { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; text-decoration: none; color: var(--ink-2); font-size: .7rem; font-weight: 600; }
  .tabbar a[aria-current="page"] { color: var(--primary); }
  .tabbar svg { width: 21px; height: 21px; }
  .view { padding-bottom: 32px; }
  .site-foot { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .hero { grid-template-columns: 1fr; }
  .unit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tools-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .game-grid { grid-template-columns: 1fr; }
  .trace { grid-template-columns: 1fr; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 560px) {
  .brand-text { display: none; }
  #themeBtn { display: none; }
  .top-tools { gap: 6px; }
  .topbar-in { gap: 10px; }
  .xp-chip span.xp-label { display: none; }
  .hero-main { padding: 24px 20px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .unit-grid { grid-template-columns: 1fr; }
  .quiz-opts, .answers { grid-template-columns: 1fr; }
  .vrow { grid-template-columns: minmax(0, 1fr) auto; }
  .vrow .ar { grid-column: 1 / -1; text-align: right; }
  .vrow .v-tr { grid-column: 1; }
  .vrow .v-mean { grid-column: 1; }
  .vrow .play { grid-column: 2; grid-row: 2 / span 2; }
  .lesson-head, .unit-hero { flex-direction: column; padding: 20px; }
  .lm-head { flex-direction: column; text-align: center; }
  .forms { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .memory { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .boxes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .path-row { grid-template-columns: 58px minmax(0, 1fr); gap: 12px; }
  .node { width: 58px; height: 58px; font-size: 20px; }
  .path-row::before { left: 28px; }
  .seg button { padding: 4px 7px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.wotd-ar.long { font-size: calc(2.6rem * var(--ar-scale)); }

.u-badge.bx3, .node .bx3 { font-size: .72em; }
.u-badge.bx4, .node .bx4 { font-size: .56em; }
.node > span { font-size: inherit; }
