:root {
  --bg: #f4f1e8;
  --card: #fffdf7;
  --ink: #1f2d2a;
  --muted: #6b7671;
  --brand: #2f6f5e;
  --brand-ink: #ffffff;
  --brand-soft: #dcebe4;
  --good: #2e7d4f;
  --good-soft: #e1f3e8;
  --retry: #a15c00;
  --retry-soft: #fff1dc;
  --danger: #a33b2f;
  --line: #e3ddcc;
  --star: #e0a100;
  --radius: 16px;
  --arabic: 'Amiri Quran', 'Noto Naskh Arabic', 'Scheherazade New', 'KFGQPC Uthmanic Script HAFS', 'Geeza Pro', 'Traditional Arabic', 'Arabic Typesetting', serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.screen { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.content { padding: 16px 16px 40px; display: flex; flex-direction: column; gap: 14px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.15rem; text-align: center; }
.topbar-actions { display: flex; gap: 6px; align-items: center; min-width: 44px; justify-content: flex-end; }
.icon-btn, .icon-spacer { width: 44px; height: 44px; }
.icon-btn {
  border: 0; border-radius: 50%; background: rgba(255,255,255,.15); color: inherit;
  font-size: 1.4rem; cursor: pointer;
}
.step-count { font-weight: 600; }

h2 { margin: 12px 0 0; font-size: 1.1rem; }
p { margin: 0; }
.small { font-size: .9rem; color: var(--muted); }
.muted { color: var(--muted); }
.center { text-align: center; }
.subtitle { text-align: center; font-weight: 600; color: var(--brand); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; }

.btn {
  min-height: 52px; padding: 10px 18px; border-radius: var(--radius);
  border: 2px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.btn.big { min-height: 64px; font-size: 1.15rem; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: .9rem; border-color: rgba(255,255,255,.6); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .choice:focus-visible, .piece:focus-visible, .chip:focus-visible { outline: 3px solid #f2b705; outline-offset: 2px; }
.next-btn .small { color: var(--brand-soft); }
.list-btn { align-items: flex-start; }
.links .btn { min-height: 44px; }

.note { padding: 12px 14px; border-radius: 12px; background: var(--brand-soft); font-size: .95rem; }
.note.warn { background: var(--retry-soft); color: #6b3d00; }
.note.good { background: var(--good-soft); color: #1d5435; }

.hero { text-align: center; padding: 12px 0; }
.hero-title { font-size: 1.6rem; font-weight: 700; color: var(--brand); }

/* Profiles */
.profile-list { display: grid; gap: 10px; }
.profile-card {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px; min-height: 72px;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--card);
  font: inherit; color: inherit; cursor: pointer; text-align: start;
}
.profile-name { flex: 1; font-size: 1.2rem; font-weight: 600; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; background: #4f8f7f;
}
.avatar.girl { background: #8b6fb3; }
.avatar.big { width: 60px; height: 60px; font-size: 1.4rem; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; }
input[type='text'], select {
  font: inherit; min-height: 52px; padding: 8px 12px; border-radius: 12px;
  border: 2px solid var(--line); background: #fff; color: var(--ink);
}
.segmented { display: flex; gap: 8px; }
.seg {
  flex: 1; min-height: 52px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer;
}
.seg.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.switch { width: 28px; height: 28px; accent-color: var(--brand); }

.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; align-items: center; gap: 12px; }

/* Home */
.level-card { display: flex; gap: 14px; align-items: center; background: var(--card); border-radius: var(--radius); padding: 14px; border: 2px solid var(--line); }
.level-info { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.level-title { font-weight: 700; }
.bar { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }

.surah-card {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 10px;
}
.surah-card.faded { opacity: calc(.45 + var(--fresh, 1) * .55); filter: saturate(.5); }
.fade-note { color: var(--retry); }
.surah-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.surah-name { font-weight: 700; }
.surah-ar { font-size: 1.5rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 48px; padding: 6px 12px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; font: inherit; font-size: .9rem; color: var(--ink); cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
}
.chip.next { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.badge { font-size: .75rem; color: var(--good); font-weight: 700; }
.stars { color: var(--star); letter-spacing: 1px; }
.stars-empty { color: var(--line); }

/* Arabic text */
.ar { font-family: var(--arabic); font-feature-settings: 'calt', 'liga'; }
.ayah-block { background: var(--card); border-radius: var(--radius); padding: 14px 16px; border: 2px solid var(--line); }
.ayah { font-size: clamp(26px, 7.2vw, 38px); line-height: 2.25; text-align: right; margin: 4px 0; word-spacing: .08em; }
.bismillah { font-size: clamp(22px, 6vw, 30px); text-align: center; line-height: 2; color: var(--brand); }
.ayah-no { color: var(--brand); white-space: nowrap; }
.w { border-radius: 8px; transition: background-color .2s; }
.w.lit { background: #ffe9a8; }
.blank { text-decoration: underline dashed var(--brand) 3px; text-underline-offset: .35em; white-space: pre; }
.blank.filled { text-decoration-color: var(--good); color: var(--good); white-space: normal; }
.hidden-text { display: none; }

/* Questions */
.q { display: flex; flex-direction: column; gap: 14px; }
.hint { font-weight: 600; text-align: center; }
.label { font-size: .85rem; color: var(--muted); margin-bottom: -8px; }
.stages { display: flex; justify-content: center; gap: 6px; padding: 10px 12px 0; }
.stage { padding: 4px 12px; border-radius: 999px; background: var(--line); font-size: .85rem; font-weight: 600; color: var(--muted); }
.stage.on { background: var(--brand); color: #fff; }

.choices { display: grid; gap: 10px; }
.choice {
  min-height: 64px; font-size: clamp(24px, 6.5vw, 32px); border-radius: var(--radius);
  border: 2px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; line-height: 1.8;
}
.choice.correct { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--retry); background: var(--retry-soft); opacity: .7; }

.slots, .pool {
  display: flex; flex-wrap: wrap; gap: 8px; min-height: 72px; padding: 10px;
  border-radius: var(--radius); align-content: flex-start;
}
.slots { background: var(--card); border: 2px dashed var(--brand); }
.slots.correct { border-style: solid; border-color: var(--good); background: var(--good-soft); }
.slots.wrong { border-color: var(--retry); background: var(--retry-soft); }
.slots.vertical, .pool.vertical { flex-direction: column; }
.slots-hint { color: var(--muted); font-size: .9rem; align-self: center; margin: auto; }
.piece {
  min-height: 56px; padding: 4px 14px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; color: var(--ink); font-size: clamp(22px, 6vw, 30px); line-height: 1.9; cursor: pointer;
}
.piece.long { width: 100%; text-align: right; font-size: clamp(20px, 5.4vw, 26px); }
.piece.given { background: var(--brand-soft); border-color: var(--brand-soft); cursor: default; display: inline-flex; align-items: center; }

.feedback { min-height: 1.5em; text-align: center; font-weight: 700; font-size: 1.1rem; }
.feedback.good { color: var(--good); }
.feedback.retry { color: var(--retry); }

/* Result */
.result { text-align: center; padding: 16px 0; display: flex; flex-direction: column; gap: 8px; }
.result-stars { font-size: 3.2rem; }
.result-text { font-size: 1.3rem; font-weight: 700; }

/* PIN */
.pin-box { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pin-prompt { font-weight: 600; }
.pin-dots { display: flex; gap: 12px; min-height: 20px; }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brand); }
.dot.on { background: var(--brand); }
.pin-message { min-height: 1.4em; color: var(--danger); font-weight: 600; text-align: center; }
.pinpad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.key {
  height: 64px; border-radius: 50%; border: 2px solid var(--line); background: #fff;
  font: inherit; font-size: 1.5rem; font-weight: 600; color: var(--ink); cursor: pointer;
}
.key-ok { background: var(--brand); color: #fff; border-color: var(--brand); font-size: 1.1rem; }
.key:disabled { opacity: .4; }

/* Dialog */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.dialog { background: var(--card); border-radius: var(--radius); padding: 20px; max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: 16px; }

/* World */
.world { position: fixed; inset: 0; overflow: hidden; background: #b9d29c; touch-action: none; user-select: none; -webkit-user-select: none; }
.world-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.world-bar { position: absolute; top: 0; left: 0; right: 0; }
.world-top { position: absolute; top: 64px; left: 10px; right: 10px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: 540px; margin: 0 auto; }
.world-top > * { pointer-events: auto; }
.world-flash { box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.world-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.world-chip {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 2px 6px 2px 10px; border-radius: 999px; border: 0;
  background: var(--card); color: var(--brand); font: inherit; font-size: .8rem; font-weight: 700; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.world-chip::after { content: ''; position: absolute; inset: -5px; } /* bigger tap area than the look */
.world-chip .chip-icon { font-size: 1rem; }
.world-chip.icon-only { gap: 4px; padding: 2px 6px 2px 10px; }
.world-chip .count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center;
  background: var(--brand); color: #fff; font-size: .75rem;
}
.world-chip.attn { background: linear-gradient(135deg, #ffcf5c, #ff9d3d); color: #4a2600; animation: attn-pulse 2.2s ease-out infinite; }
.world-chip.attn .count { background: #c2410c; }
.world-chip.calm { background: #e1f3e8; color: #1d5435; }
.world-chip.calm .count { background: #2e7d4f; }
@keyframes attn-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 157, 61, .7), 0 2px 6px rgba(0,0,0,.18); }
  70%, 100% { box-shadow: 0 0 0 10px rgba(255, 157, 61, 0), 0 2px 6px rgba(0,0,0,.18); }
}
.world-prompt {
  position: absolute; left: 0; right: 0; bottom: max(56px, calc(env(safe-area-inset-bottom) + 48px));
  display: flex; justify-content: center; pointer-events: none;
}
.door-btn {
  pointer-events: auto; min-height: 48px; padding: 8px 22px; border-radius: 999px; border: 0;
  background: var(--brand); color: #fff; font: inherit; font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,.2);
}
.door-btn.locked { background: var(--card); color: var(--muted); }
.world-corner {
  position: absolute; left: 10px; bottom: max(10px, env(safe-area-inset-bottom));
  max-width: 60vw; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 253, 247, .88); color: var(--brand); font-size: .8rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 1px 4px rgba(0,0,0,.12); pointer-events: none;
}
.sheet-wrap { position: absolute; inset: 0; background: rgba(0,0,0,.3); display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 560px; background: var(--card); border-radius: 20px 20px 0 0;
  padding: 18px 16px max(18px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px;
  max-height: 75vh; overflow-y: auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; }
.chip:disabled { opacity: .5; cursor: default; }

/* Activities (played over the world) */
.act-layer { position: absolute; inset: 0; background: rgba(20, 35, 30, .35); overflow-y: auto; display: flex; align-items: flex-start; justify-content: center; padding: 12px 10px 24px; z-index: 20; }
.act-layer[hidden] { display: none; }
.act-card { width: 100%; max-width: 560px; background: var(--bg); border-radius: 20px; padding: 12px 14px 18px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.act-head { display: flex; align-items: center; gap: 8px; }
.act-head .stages { flex: 1; padding: 0; }
.act-head .icon-btn { background: var(--line); color: var(--ink); }
.act-head .step-count { font-weight: 700; color: var(--muted); min-width: 36px; text-align: right; }
.act-body .btn.big { width: 100%; }
.act { display: flex; flex-direction: column; gap: 12px; }

/* Bridge */
.river {
  position: relative; border-radius: 16px; padding: 14px 6px;
  background: repeating-linear-gradient(170deg, #8cc6e0 0 14px, #9dcfe6 14px 28px);
}
.deck { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; row-gap: 10px; }
.bank { width: 18px; border-radius: 6px; background: #b6d59a; flex: none; }
.gap {
  min-width: 64px; min-height: 60px; padding: 4px 10px; flex: 1 1 auto;
  border-radius: 10px; border: 3px dashed rgba(255,255,255,.7); background: rgba(255,255,255,.12);
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(22px, 6vw, 30px); line-height: 1.9; color: #fff;
}
.gap.open { border-color: #ffe28a; background: rgba(255, 226, 138, .28); cursor: pointer; box-shadow: 0 0 0 3px rgba(255, 226, 138, .35); }
.gap.hover { background: rgba(255, 226, 138, .55); }
.gap.laid, .plank.laid { border: 0; background: #b98a55; color: #fff; box-shadow: inset 0 -4px 0 rgba(0,0,0,.15); }
.plank.given { opacity: .9; display: flex; align-items: center; padding: 4px 10px; border-radius: 10px; font-size: clamp(22px, 6vw, 30px); line-height: 1.9; }
.gap.shine { animation: shine .7s ease-out; }
.raft { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; min-height: 64px; }
.plank {
  min-height: 60px; padding: 4px 16px; border-radius: 10px; border: 0;
  background: #d9b07c; color: var(--ink); font-size: clamp(22px, 6vw, 30px); line-height: 1.9;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.15), 0 2px 6px rgba(0,0,0,.15);
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.plank.picked { outline: 4px solid #ffe28a; transform: translateY(-4px); }
.plank.dragging { position: relative; z-index: 30; cursor: grabbing; box-shadow: 0 10px 20px rgba(0,0,0,.25); }
.plank.wobble { animation: wobble .5s ease-in-out; }
.walker { display: none; position: absolute; left: 0; right: 0; bottom: 4px; width: 100%; height: 64px; pointer-events: none; }

.board .ayah { font-size: clamp(24px, 6.6vw, 34px); }
.wobble { animation: wobble .5s ease-in-out; }

/* Stepping stones */
.trail { display: flex; justify-content: center; gap: 6px; }
.trail-stone { width: 18px; height: 12px; border-radius: 50%; background: #c9cbc3; }
.trail-stone.crossed { background: #7fae8a; }
.trail-stone.here { background: #ffe28a; box-shadow: 0 0 0 2px #e0b93c; }
.pond {
  position: relative; border-radius: 22px; padding: 18px 12px 54px;
  background: radial-gradient(ellipse at 50% 40%, #9dcfe6 0%, #8cc6e0 60%, #7fbbd6 100%);
}
.stones { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.stone {
  min-height: 68px; padding: 6px 10px; border: 0; border-radius: 48% 52% 45% 55% / 55% 45% 55% 45%;
  background: #b4b6ad; color: var(--ink); font-size: clamp(22px, 6vw, 30px); line-height: 1.8; cursor: pointer;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.15), 0 3px 0 rgba(0,0,0,.1);
}
.stone.s1 { transform: translateY(10px); }
.stone.s2 { transform: translateY(-4px); }
.stone.correct { background: #cfe8b8; box-shadow: 0 0 0 4px #7fae8a; }
.stone:disabled { cursor: default; }
.pond-bank { position: absolute; left: 0; right: 0; bottom: 0; height: 40px; border-radius: 0 0 22px 22px; background: #b6d59a; }
.hopper { display: none; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }

/* Word fruit */
.fruit-tree { position: relative; height: 260px; }
.crown { position: absolute; left: 4%; right: 4%; top: 0; height: 200px; border-radius: 50% 50% 46% 46%; background: radial-gradient(circle at 40% 35%, #8cbc83, #6fa06a 70%); }
.trunk { position: absolute; left: 46%; width: 8%; top: 180px; bottom: 0; border-radius: 6px; background: #8a6a45; }
.fruit {
  position: absolute; min-width: 92px; min-height: 64px; padding: 4px 12px; border: 0; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f59a8e, #e2574c 70%); color: #fff;
  font-size: clamp(20px, 5.6vw, 28px); line-height: 1.8; cursor: pointer; touch-action: none;
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.15), 0 3px 6px rgba(0,0,0,.2);
}
.fruit.f1 { background: radial-gradient(circle at 35% 30%, #ffd27a, #f2a93b 70%); color: var(--ink); }
.fruit.f3 { background: radial-gradient(circle at 35% 30%, #d6a6e8, #a36bc0 70%); }
.fruit.dragging { z-index: 30; box-shadow: 0 10px 20px rgba(0,0,0,.25); }
.fruit.picked-fruit { z-index: 30; }
.basket {
  align-self: center; width: 150px; height: 60px; border-radius: 0 0 40px 40px;
  background: repeating-linear-gradient(90deg, #c7954f 0 10px, #b5843f 10px 20px);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px;
}
.basket.full { box-shadow: 0 0 0 4px #ffe28a; }
.basket-label { font-size: .75rem; font-weight: 700; color: #fff; }

@keyframes shine { 0% { box-shadow: 0 0 0 0 rgba(255, 236, 160, .9); } 100% { box-shadow: 0 0 0 14px rgba(255, 236, 160, 0); } }
@keyframes wobble { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px) rotate(-2deg); } 75% { transform: translateX(6px) rotate(2deg); } }

@media (prefers-reduced-motion: reduce) {
  .w { transition: none; }
  .gap.shine, .plank.wobble, .wobble, .world-chip.attn { animation: none; }
  .stone.s1, .stone.s2 { transform: none; }
  .plank.picked { transform: none; }
}
