:root {
  --sand: #fbf3e4;
  --sand-2: #f3e3c3;
  --card: #fffdf8;
  --nile: #2f80a8;
  --nile-2: #6fb7d6;
  --nile-dark: #1f5f80;
  --clay: #e05a47;
  --gold: #f5b82e;
  --green: #3fa877;
  --ink: #1d3557;
  --muted: #6b7a8a;
  --line: #e6d6b5;
  --shadow: 0 3px 0 rgba(120, 90, 40, .18), 0 8px 20px rgba(120, 90, 40, .10);
  --radius: 20px;
  --ar: "Noto Naskh Arabic", "Geeza Pro", serif;
  --ui: "Fredoka", "Noto Naskh Arabic", "Trebuchet MS", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: var(--ui); color: var(--ink); background: var(--sand);
  background-image: radial-gradient(circle at 20% 0%, #fff7e8 0, transparent 40%), radial-gradient(circle at 90% 30%, #f8ead0 0, transparent 35%);
  min-height: 100dvh; font-size: 17px; line-height: 1.4;
  -webkit-user-select: none; user-select: none;
}
input { -webkit-user-select: text; user-select: text; }
button, a.btn, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
.ar, .ar-small, [lang=ar] { font-family: var(--ar); }

#view { max-width: 720px; margin: 0 auto; padding: 12px 16px calc(96px + env(safe-area-inset-bottom)); }
body:has(#nav[hidden]) #view { padding-bottom: 8px; }
.screen { animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* ---------- top bar & nav ---------- */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 52px; margin-bottom: 8px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.45rem; margin: 0; flex: 1; font-weight: 700; letter-spacing: .2px; }
.back { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); text-decoration: none; font-size: 1.6rem; color: var(--ink); }
.chips { display: flex; gap: 6px; }
.chip { background: var(--card); border-radius: 999px; padding: 4px 10px; font-weight: 600; font-size: .9rem; box-shadow: var(--shadow); white-space: nowrap; }
.sub { color: var(--muted); margin: 4px 0 14px; }
.center { text-align: center; }

#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, .95); backdrop-filter: blur(8px); border-top: 2px solid var(--line);
}
#nav[hidden] { display: none; }
#nav a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; font-size: .78rem; font-weight: 600; color: var(--muted); text-decoration: none; padding: 4px 0; border-radius: 14px; }
#nav a span { font-size: 1.5rem; line-height: 1.2; }
#nav a.active { color: var(--nile-dark); background: #e4f2f8; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; padding: 0 18px; border: 0; border-radius: 16px;
  background: var(--card); color: var(--ink); font-weight: 600; text-decoration: none;
  box-shadow: 0 4px 0 #d9c8a4; transition: transform .08s, box-shadow .08s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #d9c8a4; }
.btn.primary { background: var(--nile); color: #fff; box-shadow: 0 4px 0 var(--nile-dark); }
.btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--nile-dark); }
.btn.danger { background: #fde4e0; color: #9b2c1f; box-shadow: 0 4px 0 #f0b6ab; }
.btn:disabled { opacity: .45; cursor: default; }
.big-btn .ar { font-size: 1.6rem; vertical-align: middle; }
.big-btn {
  display: block; width: 100%; margin: 6px 0 18px; min-height: 64px; border: 0; border-radius: 20px;
  background: var(--clay); color: #fff; font-size: 1.35rem; font-weight: 700; box-shadow: 0 5px 0 #a8382a;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #a8382a; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: center; margin: 10px 0; }
.listen { width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--gold); font-size: 2rem; box-shadow: 0 4px 0 #c48d14; display: block; margin: 8px auto; }
.listen:active { transform: translateY(3px); box-shadow: 0 1px 0 #c48d14; }

.hold.gear { width: 44px; height: 44px; border: 0; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-size: 1.2rem; position: relative; overflow: hidden; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.hold.gear::after { content: ""; position: absolute; inset: auto 0 0 0; height: 0; background: rgba(47, 128, 168, .35); }
.hold.holding::after { height: 100%; transition: height var(--hold) linear; }

/* ---------- Mishmish ---------- */
.mishmish { display: flex; align-items: center; gap: 10px; margin: 6px 0 12px; }
.cat-face { width: 76px; flex: none; }
.mishmish.small .cat-face { width: 58px; }
.cat { width: 100%; height: auto; display: block; }
.cat-face.bounce { animation: bounce .45s ease; }
@keyframes bounce { 30% { transform: translateY(-8px) rotate(-4deg); } 60% { transform: translateY(0) rotate(3deg); } }
.thinking .cat-face { animation: think 1s ease-in-out infinite; }
@keyframes think { 50% { transform: rotate(-8deg); } }
.bubble {
  position: relative; background: var(--card); border-radius: 18px; padding: 10px 14px; box-shadow: var(--shadow);
  font-weight: 500; flex: 1; min-height: 44px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px;
}
.bubble::before { content: ""; position: absolute; left: -8px; top: 50%; margin-top: -8px; border: 8px solid transparent; border-right-color: var(--card); border-left: 0; }
.bubble.empty { visibility: hidden; }
.bubble .tip { color: var(--nile-dark); }
.stars span { color: #d8cdb8; font-size: 1.15em; }
.stars span.on { color: var(--gold); text-shadow: 0 1px 0 #c48d14; }
.big-stars { font-size: 2.6rem; text-align: center; }
.big-stars .stars span.on { animation: pop .5s backwards; }
.big-stars .stars span:nth-child(2) { animation-delay: .15s; }
.big-stars .stars span:nth-child(3) { animation-delay: .3s; }
@keyframes pop { from { transform: scale(0); } 70% { transform: scale(1.3); } }

/* ---------- map ---------- */
.compass { text-align: center; color: var(--muted); font-size: .85rem; display: flex; justify-content: space-between; padding: 0 6px; }
.river { position: relative; padding: 10px 0 20px; }
.river::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 46px; margin-left: -23px;
  background: linear-gradient(90deg, var(--nile-2), var(--nile), var(--nile-2)); border-radius: 30px; opacity: .55;
  -webkit-mask: radial-gradient(circle at 50% 0, #000 70%, #000 100%);
}
.stop {
  position: relative; display: flex; align-items: center; gap: 12px; width: 78%; margin: 0 0 18px;
  padding: 12px 14px; border: 0; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); text-align: left;
}
.stop:nth-child(even) { margin-left: auto; flex-direction: row-reverse; text-align: right; }
.stop.locked { background: #f4ead6; box-shadow: none; cursor: default; }
.stop.locked > * { opacity: .55; filter: grayscale(.6); }
.stop.here { outline: 3px solid var(--gold); }
.stop.done .stop-pin { background: #d8f0e3; }
.stop-pin { width: 56px; height: 56px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--sand-2); font-size: 1.7rem; }
.stop-place { font-weight: 700; font-size: 1.1rem; }
.stop-title { color: var(--muted); font-size: .9rem; }
.stop-letters { font-family: var(--ar); font-size: 1.35rem; display: flex; gap: 8px; flex-wrap: wrap; }
.stop:nth-child(even) .stop-letters { justify-content: flex-end; }
.stop-letters span { color: #c4b38f; }
.stop-letters span.got { color: var(--green); font-weight: 700; }
.felucca { position: absolute; top: -14px; right: -12px; font-size: 2rem; animation: sail 3s ease-in-out infinite; }
.stop:nth-child(even) .felucca { right: auto; left: -12px; }
@keyframes sail { 50% { transform: translateY(-5px) rotate(-6deg); } }

/* ---------- unit ---------- */
.letter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.letter-tile { display: flex; flex-direction: column; align-items: center; padding: 10px 6px 12px; border: 0; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.letter-tile .ar { font-size: 4rem; line-height: 1.5; color: var(--nile-dark); }
.letter-tile .nm { font-weight: 600; }
.letter-tile.locked { opacity: .5; }
.letter-tile.done { background: #f2fbf6; }

/* ---------- lesson ---------- */
.progress { flex: 1; height: 14px; background: var(--sand-2); border-radius: 999px; overflow: hidden; min-width: 120px; }
.progress .bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--clay)); border-radius: 999px; transition: width .4s ease; }
.lesson-body { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lesson-foot { position: sticky; bottom: 0; z-index: 5; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 12px 0 calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--sand) 30%); }
.lesson-foot .btn { flex: 1; max-width: 220px; }
.letter-card { display: flex; flex-direction: column; align-items: center; width: min(100%, 300px); padding: 4px 10px 12px; border: 0; border-radius: 28px; background: var(--card); box-shadow: var(--shadow); }
.letter-card .ar { font-size: 9rem; line-height: 1.55; color: var(--nile-dark); }
.letter-card .nm { font-size: 1.4rem; font-weight: 700; }
.letter-card .tap { color: var(--muted); font-size: .85rem; }
.section { margin: 16px 0 6px; font-size: 1.05rem; color: var(--muted); font-weight: 600; text-align: center; }
.syllables { display: flex; gap: 12px; justify-content: center; }
.syl { display: flex; flex-direction: column; align-items: center; width: 92px; padding: 2px 0 8px; border: 0; border-radius: 18px; background: #e4f2f8; box-shadow: 0 4px 0 #b7d9e8; }
.syl:active { transform: translateY(3px); box-shadow: 0 1px 0 #b7d9e8; }
.syl .ar { font-size: 3rem; line-height: 1.7; color: var(--nile-dark); }
.syl .tr { font-weight: 700; }
.eg-chip { background: #fff3d6; border: 2px dashed #e8c66a; border-radius: 14px; padding: 8px 12px; font-size: .95rem; max-width: 460px; }
.vowel-card { background: var(--card); border-radius: 18px; padding: 12px 16px; box-shadow: var(--shadow); max-width: 460px; margin-top: 8px; }
.vowel-card p { margin: 4px 0; }
.vowel-card ul { margin: 0; padding-left: 4px; list-style: none; }
.vowel-card li { display: flex; align-items: center; gap: 8px; }
.vowel-card .ar { font-size: 2rem; width: 44px; text-align: center; color: var(--clay); }

.pad { position: relative; width: min(100%, 64vh, 520px); aspect-ratio: 1; border-radius: 26px; background: #fff; box-shadow: var(--shadow), inset 0 0 0 3px var(--line); --ink: #1d3557; --pad-line: #d4dde2; touch-action: none; }
.pad.wide { aspect-ratio: 2 / 1; width: 100%; }
.pad.free { background: #fffef9; }
.pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; }
.pad-ink { touch-action: none; }
.trace-count { display: flex; gap: 10px; }
.trace-count span { width: 46px; height: 30px; border-radius: 10px; background: var(--sand-2); display: grid; place-items: center; color: var(--gold); font-size: .8rem; letter-spacing: -1px; }
.trace-count span.on { background: #fff; box-shadow: var(--shadow); }
.celebrate { text-align: center; }
.huge { font-size: 8rem; line-height: 1.5; color: var(--nile-dark); animation: pop .6s; }

/* ---------- games ---------- */
.prompt { text-align: center; font-weight: 600; font-size: 1.1rem; margin: 6px 0; }
.bubbles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; max-width: 360px; margin: 14px auto; }
.bubble-opt {
  aspect-ratio: 1; border: 0; border-radius: 50%; font-family: var(--ar); font-size: 3.6rem; line-height: 1;
  background: radial-gradient(circle at 30% 25%, #fff 0, #dff1fb 35%, #a9d8ef 100%); color: var(--nile-dark);
  box-shadow: inset -6px -8px 14px rgba(47, 128, 168, .25), 0 6px 14px rgba(47, 128, 168, .25);
  animation: float 3s ease-in-out infinite; animation-delay: var(--d);
}
@keyframes float { 50% { transform: translateY(-8px); } }
.bubble-opt.right { animation: burst .5s forwards; background: radial-gradient(circle at 30% 25%, #fff, #c9f0d9 40%, #7fd3a6); }
@keyframes burst { 60% { transform: scale(1.25); } 100% { transform: scale(1.1); } }
.bubble-opt.wrong { opacity: .3; animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

.game-list { display: grid; gap: 14px; }
.game-card { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); text-decoration: none; color: var(--ink); }
.game-card .icon { font-size: 2.6rem; }
.game-card .txt { display: flex; flex-direction: column; }
.game-card b { font-size: 1.2rem; }
.game-card small { color: var(--muted); font-size: .9rem; }
.game-card.locked { opacity: .55; }
.finish { text-align: center; }
.score { font-size: 1.4rem; font-weight: 700; margin: 4px 0; }

.dd { display: flex; flex-direction: column; align-items: center; }
.dd-shape { font-family: var(--ar); font-size: 8rem; line-height: 1.6; color: var(--nile-dark); min-height: 1.6em; background: var(--card); border-radius: 28px; padding: 0 40px; box-shadow: var(--shadow); }
.dd-shape.right { color: var(--green); animation: pop .5s; }
.dd-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 16px; width: min(100%, 340px); }
.dd-opt { height: 84px; border: 0; border-radius: 18px; background: var(--card); box-shadow: 0 4px 0 #d9c8a4; color: var(--clay); }
.dd-opt.wrong { opacity: .35; animation: shake .4s; }
.dot-icon svg { width: 64px; height: 64px; }

.wb { display: flex; flex-direction: column; align-items: center; }
.wb-hint { display: flex; align-items: center; gap: 10px; font-size: 1.3rem; font-weight: 600; }
.wb-hint .emoji { font-size: 3rem; }
.wb-hint .tr { color: var(--nile-dark); font-style: italic; }
.wb-slot { font-family: var(--ar); font-size: 4rem; line-height: 1.7; min-height: 1.8em; min-width: 70%; text-align: center; border-bottom: 4px dashed var(--line); margin: 8px 0 14px; color: var(--nile-dark); }
.wb-slot.right { color: var(--green); border-bottom-color: var(--green); }
.wb-tiles { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.tile { min-width: 64px; height: 72px; border: 0; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 #d9c8a4; font-family: var(--ar); font-size: 2.4rem; line-height: 1; color: var(--ink); }
.tile.used { opacity: .25; }
.tile.wrong { background: #fde4e0; animation: shake .4s; }
.tile.known { background: #dcf3e6; box-shadow: 0 4px 0 #a5d9bb; }

.mm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 460px; margin: 12px auto; perspective: 800px; }
.mm-grid.four { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 420px) { .mm-grid.four { grid-template-columns: repeat(3, 1fr); } }
.mm-card { position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0; background: none; transform-style: preserve-3d; transition: transform .35s; }
.mm-card span { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 16px; backface-visibility: hidden; box-shadow: var(--shadow); }
.mm-card .back { background: repeating-linear-gradient(45deg, var(--nile), var(--nile) 10px, var(--nile-dark) 10px, var(--nile-dark) 20px); color: var(--gold); font-size: 2rem; }
.mm-card .front { background: var(--card); transform: rotateY(180deg); font-size: 2.6rem; }
.mm-card .front.ar { font-family: var(--ar); font-size: 1.7rem; color: var(--nile-dark); }
.mm-card.flip { transform: rotateY(180deg); }
.mm-card.done .front { background: #dcf3e6; }

/* ---------- words ---------- */
.cat h2 { font-size: 1.15rem; margin: 18px 0 8px; }
.cat h2 small { color: var(--muted); font-weight: 500; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 10px; }
.sticker-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.sticker { position: relative; display: flex; flex-direction: column; align-items: center; padding: 8px 4px 10px; border: 0; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); min-width: 98px; }
.sticker .emoji { font-size: 2.2rem; }
.sticker .ar { font-size: 1.6rem; line-height: 1.7; color: var(--nile-dark); }
.sticker .tr { font-style: italic; font-size: .9rem; }
.sticker .en { font-size: .8rem; color: var(--muted); }
.sticker.new::after { content: "NEW"; position: absolute; top: -6px; right: -4px; background: var(--clay); color: #fff; font-size: .65rem; font-weight: 700; padding: 2px 6px; border-radius: 999px; }
.sticker.locked { background: var(--sand-2); box-shadow: none; }
.sticker.locked .emoji { filter: grayscale(1) brightness(.4) blur(1px); opacity: .25; }
.sticker.locked .needs { font-family: var(--ar); color: var(--muted); font-size: 1.1rem; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(29, 53, 87, .45); display: flex; align-items: flex-end; justify-content: center; animation: fadein .2s; }
.sheet { position: relative; width: min(100%, 560px); max-height: 92dvh; overflow: auto; background: var(--sand); border-radius: 28px 28px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); text-align: center; animation: slideup .25s ease; }
@keyframes slideup { from { transform: translateY(40%); } }
.sheet-close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--card); font-size: 1.1rem; box-shadow: var(--shadow); }
.emoji.huge { font-size: 4.5rem; line-height: 1.2; }
.word-ar { border: 0; background: none; font-family: var(--ar); font-size: 4rem; line-height: 1.7; color: var(--nile-dark); padding: 0 10px; }
.word-tr { font-size: 1.5rem; font-style: italic; font-weight: 600; }
.word-en { color: var(--muted); font-size: 1.1rem; margin-bottom: 10px; }
.sheet .eg-chip { margin: 0 auto; }
.word-letters { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 6px 0 12px; }

/* ---------- name ---------- */
.name-setup { display: flex; flex-direction: column; gap: 12px; }
.text { width: 100%; min-height: 54px; padding: 0 14px; border-radius: 14px; border: 2px solid var(--line); background: #fff; font-size: 1.15rem; }
.text.ar { font-family: var(--ar); font-size: 1.5rem; }
.name-big { font-family: var(--ar); font-size: 4rem; text-align: center; color: var(--nile-dark); line-height: 1.8; }

/* ---------- parent ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 6px; font-size: 1.15rem; }
.card .row { justify-content: flex-start; flex-wrap: nowrap; }
.card .row .text { flex: 1; }
.status { font-size: .95rem; }
.table-wrap { overflow-x: auto; }
.progress-table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.progress-table th, .progress-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.progress-table .ar { font-size: 1.3rem; }
.progress-table tr.dim { opacity: .45; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; text-align: center; font-size: .8rem; }
.gallery img { width: 100%; border-radius: 12px; border: 2px solid var(--line); background: #fff; }
.switch { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.switch input { width: 22px; height: 22px; }

/* ---------- toast & confetti ---------- */
.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 60; transition: .3s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 50; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 640px) {
  body { font-size: 18px; }
  .stop { width: 62%; }
}
