:root {
  --bg: #fff8e7;
  --surface: #ffffff;
  --ink: #1d3557;
  --muted: #5b6b80;
  --line: #f0e3c2;
  --brand: #ff6b35;
  --brand-ink: #ffffff;
  --accent: #2a9d8f;
  --sun: #ffbe0b;
  --shadow: 0 6px 0 rgba(29, 53, 87, 0.12), 0 12px 28px rgba(29, 53, 87, 0.12);
  --radius: 22px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131a26; --surface: #1d2737; --ink: #f1f5fb; --muted: #a6b3c6; --line: #2b3850;
    --shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 12px 28px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131a26; --surface: #1d2737; --ink: #f1f5fb; --muted: #a6b3c6; --line: #2b3850;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 12px 28px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons ---------- */
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 60px; padding: 0 34px; border: 0; border-radius: 999px;
  background: var(--brand); color: var(--brand-ink); font-size: 22px; font-weight: 800;
  box-shadow: 0 6px 0 #c94a1c; cursor: pointer; text-decoration: none;
  transition: transform 0.08s, box-shadow 0.08s;
}
.primary-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c94a1c; }
.primary-btn:disabled { opacity: 0.7; }
.round-btn {
  display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, 0.92); color: #1d3557; cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25); text-decoration: none;
}
.round-btn.small { width: 46px; height: 46px; flex: none; }
[dir="rtl"] .round-btn svg.flip, [dir="rtl"] #back svg { transform: scaleX(-1); }

/* ---------- home ---------- */
.home { min-height: 100%; padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom)); }
.home main { max-width: 560px; margin: 0 auto; display: grid; gap: 26px; }
.logo { text-align: center; margin-top: 8px; }
.logo h1 {
  margin: 0; font-size: clamp(40px, 12vw, 58px); line-height: 1; font-weight: 900; letter-spacing: -1px;
}
.logo h1 span:nth-child(1) { color: #e63946; }
.logo h1 span:nth-child(2) { color: #2a9d8f; }
.logo h1 span:nth-child(3) { color: #3a86ff; }
.logo h1 em { font-style: normal; color: var(--sun); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.logo p { margin: 8px 0 0; color: var(--muted); }
.section-title { margin: 0 0 12px; font-size: 20px; font-weight: 800; }
.lang-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.lang-btn {
  min-height: 74px; border-radius: var(--radius); border: 3px solid var(--line); background: var(--surface);
  font-size: 19px; font-weight: 800; cursor: pointer; box-shadow: var(--shadow);
}
.lang-btn[aria-pressed="true"] { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--surface)); }
.book-list { display: grid; gap: 14px; }
.book-card {
  display: grid; grid-template-columns: 92px 1fr; gap: 16px; align-items: center; padding: 12px;
  border-radius: var(--radius); background: var(--surface); border: 3px solid var(--line);
  box-shadow: var(--shadow); text-align: start; cursor: pointer; width: 100%;
}
.book-card img { width: 92px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 12px; display: block; }
.book-card strong { display: block; font-size: 20px; }
.book-card small { color: var(--muted); font-size: 14px; }
.test-box { border: 2px dashed var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; }
.test-box h2 { margin: 0; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented button {
  min-height: 46px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer;
}
.segmented button[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--muted); }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.links { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; font-size: 15px; }
.links a { color: var(--muted); }
.build { text-align: center; color: var(--muted); font-size: 12px; opacity: 0.7; }

/* ---------- AR screen ---------- */
body.ar { background: #000; overflow: hidden; position: fixed; inset: 0; touch-action: none; }
.ar-stage { position: fixed; inset: 0; overflow: hidden; }
.ar-video { position: absolute; z-index: 0; object-fit: cover; }
.ar-canvas { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; }
.ar-top {
  position: fixed; z-index: 5; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px; pointer-events: none;
}
.ar-top > * { pointer-events: auto; }
.lang-chips { display: flex; gap: 6px; background: rgba(255, 255, 255, 0.92); padding: 5px; border-radius: 999px; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25); }
.lang-chips button { border: 0; background: transparent; color: #1d3557; min-width: 46px; height: 42px; border-radius: 999px; font-weight: 800; cursor: pointer; }
.lang-chips button[aria-pressed="true"] { background: var(--brand); color: #fff; }

.scan-hint {
  position: fixed; z-index: 4; inset: 0; display: grid; place-items: center; align-content: center; gap: 22px;
  pointer-events: none; padding: 16px;
}
.scan-hint p {
  margin: 0; max-width: 300px; text-align: center; color: #fff; font-weight: 800; font-size: 19px;
  background: rgba(29, 53, 87, 0.78); padding: 12px 18px; border-radius: 18px;
}
.scan-frame { position: relative; width: min(62vw, 270px); aspect-ratio: 3 / 4; animation: breathe 1.8s ease-in-out infinite; }
.scan-frame i { position: absolute; width: 46px; height: 46px; border: 7px solid #fff; filter: drop-shadow(0 2px 4px rgba(0,0,0,.4)); }
.scan-frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 22px; }
.scan-frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 22px; }
.scan-frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 22px; }
.scan-frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 22px; }
@keyframes breathe { 50% { transform: scale(0.94); opacity: 0.75; } }

.word-card {
  position: fixed; z-index: 5; left: 16px; right: 16px; bottom: max(18px, env(safe-area-inset-bottom));
  margin: 0 auto; max-width: 460px; display: flex; align-items: center; gap: 14px;
  background: #fff; color: #1d3557; border-radius: 26px; padding: 10px 12px 10px 14px;
  box-shadow: 0 8px 0 rgba(0,0,0,.18), 0 12px 30px rgba(0,0,0,.3); animation: pop-in 0.35s cubic-bezier(.2,1.6,.4,1);
}
.word-letter {
  flex: none; display: grid; place-items: center; width: 68px; height: 68px; border-radius: 20px;
  background: var(--sun); font-size: 44px; font-weight: 900; line-height: 1;
}
.word-text { flex: 1; font-size: clamp(26px, 8vw, 36px); font-weight: 900; overflow-wrap: anywhere; }
@keyframes pop-in { from { transform: translateY(30px) scale(0.8); opacity: 0; } }

.overlay {
  position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 30%, #2a9d8f, #1d3557 70%);
}
.overlay-card { text-align: center; color: #fff; max-width: 360px; display: grid; gap: 22px; justify-items: center; }
.overlay-card p { margin: 0; font-size: 20px; font-weight: 700; white-space: pre-line; }
.big-emoji { font-size: 72px; line-height: 1; }

.debug-strip {
  position: fixed; z-index: 6; left: 0; right: 0; top: calc(max(12px, env(safe-area-inset-top)) + 64px);
  font: 12px/1.3 ui-monospace, monospace; color: #fff; background: rgba(0,0,0,.55); padding: 4px 8px; text-align: center;
}

/* ---------- plain pages (credits, demo pages) ---------- */
.doc { max-width: 720px; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 16px 40px; }
.doc h1 { font-size: 28px; margin: 8px 0 16px; }
.doc h2 { font-size: 20px; margin: 28px 0 8px; }
.doc p, .doc li { color: var(--muted); }
.doc a { color: var(--accent); }
.doc .back-link { display: inline-block; margin-bottom: 8px; }
.pages-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.pages-grid img { width: 100%; border-radius: 12px; box-shadow: var(--shadow); display: block; }

/* ---------- install ---------- */
.install { display: grid; justify-items: center; gap: 8px; }
.install:not(:has(> :not([hidden]))) { display: none; }
.install-hint { margin: 0; text-align: center; color: var(--muted); font-size: 15px; max-width: 420px; }

/* ---------- on the table ---------- */
body.table-page { background: radial-gradient(circle at 50% 35%, #fff8e7, #ffd166 75%); overflow: hidden; position: fixed; inset: 0; }
.table-page model-viewer { position: fixed; inset: 0; width: 100%; height: 100%; --poster-color: transparent; }
.table-ar-btn {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 104px); white-space: nowrap;
}
.table-ar-btn:active { transform: translate(-50%, 4px); }
.word-card .round-btn.small + .round-btn.small { margin-inline-start: -6px; }
