:root {
  --bg: #fdf6e9;
  --bg2: #fbe9c9;
  --card: #ffffff;
  --ink: #33302a;
  --muted: #8a8174;
  --line: #eadfca;
  --primary: #0f9d8a;
  --primary-dark: #0b7a6b;
  --primary-soft: #d5f3ee;
  --accent: #f29a2e;
  --accent-soft: #fde7c8;
  --good: #2fb36a;
  --good-soft: #dcf6e6;
  --bad: #e5574f;
  --bad-soft: #fde1df;
  --blue: #3567d6;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(120, 90, 40, .12), 0 10px 24px rgba(120, 90, 40, .08);
  --arabic: 'Scheherazade New', 'Amiri', 'Traditional Arabic', serif;
  --ui: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  color: var(--ink);
  font-family: var(--ui);
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; opacity: .5; }
.hidden { display: none !important; }

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(110px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; min-height: 52px; }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title small { display: block; color: var(--muted); font-weight: 700; font-size: 13px; }
.topbar .title b { display: block; font-size: 19px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 46px; height: 46px; flex: none; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 20px;
}
.icon-btn:active { transform: translateY(2px); }
.pill { background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 800; box-shadow: var(--shadow); font-size: 14px; white-space: nowrap; }

/* ---------- home ---------- */
.hero {
  display: flex; align-items: center; gap: 14px;
  background: var(--primary); color: #fff; border-radius: 28px; padding: 18px 20px; margin-bottom: 18px;
  box-shadow: 0 6px 0 var(--primary-dark);
}
.hero h1 { margin: 0; font-size: clamp(22px, 5vw, 30px); font-weight: 900; }
.hero p { margin: 4px 0 0; opacity: .92; font-weight: 600; }
.mascot { font-size: 46px; line-height: 1; flex: none; }
.mascot.big { font-size: 64px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 18px; border-radius: 999px; background: var(--card); font-weight: 800; white-space: nowrap; box-shadow: 0 3px 0 var(--line); }
.tab.on { background: var(--accent); color: #fff; box-shadow: 0 3px 0 #c97614; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.scard {
  background: var(--card); border-radius: var(--radius); padding: 14px 14px 12px; text-align: left;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; position: relative; min-height: 132px;
  transition: transform .1s;
}
.scard:active { transform: translateY(3px); }
.scard .no { position: absolute; top: 10px; left: 12px; font-size: 12px; font-weight: 900; color: var(--primary); background: var(--primary-soft); border-radius: 10px; padding: 2px 8px; }
.scard .ar { font-family: var(--arabic); font-size: 30px; text-align: right; line-height: 1.4; color: var(--primary-dark); }
.scard .nm { font-weight: 900; font-size: 16px; }
.scard .mn { color: var(--muted); font-size: 13px; font-weight: 700; }
.stars { color: #f5b301; letter-spacing: 1px; font-size: 14px; }
.stars .off { color: #e4d9c4; }

/* ---------- surah menu ---------- */
.surah-hero { text-align: center; background: var(--card); border-radius: 28px; padding: 22px 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.surah-hero .ar { font-family: var(--arabic); font-size: clamp(42px, 10vw, 60px); color: var(--primary-dark); line-height: 1.3; }
.surah-hero h2 { margin: 2px 0; font-size: 24px; font-weight: 900; }
.surah-hero p { margin: 0; color: var(--muted); font-weight: 700; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.mode {
  display: flex; align-items: center; gap: 14px; text-align: left; padding: 16px; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
}
.mode:active { transform: translateY(3px); }
.mode .ic { width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; font-size: 30px; flex: none; }
.mode b { display: block; font-size: 18px; font-weight: 900; }
.mode span { color: var(--muted); font-weight: 700; font-size: 14px; }

/* ---------- story / kenalan ---------- */
.stage { display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; padding-top: 6px; }
.badge-circle {
  width: min(52vw, 220px); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ffd88a, var(--accent)); box-shadow: 0 8px 0 #c97614, inset 0 -8px 0 rgba(0,0,0,.08);
  font-size: min(24vw, 100px);
}
.ayah-ar { font-family: var(--arabic); font-size: clamp(28px, 6.4vw, 46px); line-height: 2; direction: rtl; text-align: center; color: var(--ink); }
.ayah-tr { font-size: clamp(16px, 3.8vw, 20px); font-weight: 700; color: var(--muted); max-width: 640px; }
.speech { display: flex; align-items: flex-end; gap: 10px; width: 100%; max-width: 640px; text-align: left; }
.speech .bubble { flex: 1; background: var(--card); border-radius: 22px 22px 22px 6px; padding: 14px 16px; font-weight: 800; font-size: 17px; box-shadow: var(--shadow); line-height: 1.45; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--primary); width: 22px; border-radius: 6px; }

/* ---------- bottom action bar ---------- */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(251,233,201,0), var(--bg2) 30%);
}
.bottom .in { max-width: 920px; margin: 0 auto; display: flex; gap: 10px; }
.btn {
  flex: 1; padding: 15px 18px; border-radius: 18px; font-weight: 900; font-size: 17px;
  background: var(--primary); color: #fff; box-shadow: 0 5px 0 var(--primary-dark);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn.soft { background: var(--card); color: var(--ink); box-shadow: 0 5px 0 var(--line); flex: none; }
.btn.orange { background: var(--accent); box-shadow: 0 5px 0 #c97614; }
.btn.small { min-height: 44px; padding: 10px 14px; font-size: 15px; border-radius: 14px; }

/* ---------- belajar kata ---------- */
.progress { height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; flex: 1; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }
.words { display: flex; flex-wrap: wrap; direction: rtl; justify-content: center; gap: 10px 8px; }
.word {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 12px 10px; border-radius: 18px;
  background: var(--card); box-shadow: 0 4px 0 var(--line); min-width: 64px; transition: background .15s, transform .1s;
}
.word .a { font-family: var(--arabic); font-size: clamp(26px, 6vw, 40px); line-height: 1.6; }
.word .m { direction: ltr; font-size: 13px; font-weight: 800; color: var(--muted); max-width: 140px; line-height: 1.2; }
.word.on { background: var(--accent-soft); box-shadow: 0 4px 0 #f0c98f; }
.word.on .a { color: #c26a00; }
.word:active { transform: translateY(2px); }
.meaning-pop { min-height: 64px; display: flex; justify-content: center; }
.meaning-pop .chip {
  background: var(--primary); color: #fff; padding: 12px 22px; border-radius: 18px; font-weight: 900; font-size: 22px; box-shadow: 0 5px 0 var(--primary-dark);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.toolrow { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ---------- quiz ---------- */
.q-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.q-prompt { display: flex; align-items: center; gap: 12px; justify-content: center; font-weight: 900; font-size: clamp(18px, 4.4vw, 22px); text-align: center; margin: 6px 0 14px; }
.q-card { background: var(--card); border-radius: 26px; padding: 18px; box-shadow: var(--shadow); text-align: center; margin-bottom: 16px; }
.q-word { font-family: var(--arabic); font-size: clamp(46px, 13vw, 76px); line-height: 1.5; color: var(--primary-dark); }
.options { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .options.two { grid-template-columns: 1fr 1fr; } }
.opt {
  display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 20px; padding: 10px 12px; min-height: 66px;
  box-shadow: 0 5px 0 var(--line); border: 3px solid transparent; text-align: left; width: 100%;
}
.opt .say { width: 46px; height: 46px; border-radius: 50%; background: var(--primary-soft); display: grid; place-items: center; font-size: 20px; flex: none; }
.opt .txt { flex: 1; font-weight: 800; font-size: 18px; }
.opt .txt.ar { font-family: var(--arabic); font-size: clamp(24px, 5.6vw, 34px); direction: rtl; text-align: right; line-height: 1.7; font-weight: 400; }
.opt.speaking { border-color: var(--accent); background: var(--accent-soft); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* train / susun */
.train { display: flex; direction: rtl; gap: 6px; align-items: flex-end; overflow-x: auto; padding: 8px 4px 22px; min-height: 120px; justify-content: flex-start; scrollbar-width: thin; }
.loco { font-size: 52px; line-height: 1; flex: none; transform: scaleX(-1); }
.car {
  flex: none; min-width: 74px; padding: 8px 10px; border-radius: 14px; background: var(--card); border: 3px solid var(--primary);
  font-family: var(--arabic); font-size: clamp(22px, 5vw, 30px); line-height: 1.6; position: relative; text-align: center;
}
.car::after { content: '● ●'; position: absolute; bottom: -20px; left: 0; right: 0; font-size: 14px; color: #555; letter-spacing: 6px; direction: ltr; }
.car.empty { border-style: dashed; border-color: var(--line); color: var(--muted); font-family: var(--ui); font-size: 18px; font-weight: 900; display: grid; place-items: center; min-height: 60px; }
.car.new { animation: pop .25s ease; }
.pool { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; direction: rtl; }
.pool .word { min-width: 72px; }
.pool .word.used { visibility: hidden; }

/* result */
.result { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 30px; }
.result .big-stars { font-size: 54px; letter-spacing: 6px; color: #f5b301; }
.result .big-stars .off { color: #e4d9c4; }
.result h2 { margin: 0; font-size: 28px; font-weight: 900; }
.result p { margin: 0; color: var(--muted); font-weight: 800; font-size: 18px; }

/* murojaah */
.player { background: var(--card); border-radius: 24px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; display: flex; flex-direction: column; gap: 12px; }
.player .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: center; }
.seg { display: inline-flex; background: var(--bg); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { padding: 8px 12px; border-radius: 10px; font-weight: 800; font-size: 14px; }
.seg button.on { background: var(--primary); color: #fff; }
.ayah-list { display: flex; flex-direction: column; gap: 12px; }
.ayah-item { background: var(--card); border-radius: 22px; padding: 12px 16px 14px; box-shadow: 0 4px 0 var(--line); text-align: right; border: 3px solid transparent; width: 100%; }
.ayah-item .num { float: left; font-family: var(--ui); font-weight: 900; color: var(--primary); background: var(--primary-soft); border-radius: 12px; padding: 2px 10px; font-size: 14px; }
.ayah-item .a { font-family: var(--arabic); font-size: clamp(24px, 5.4vw, 34px); line-height: 2; direction: rtl; }
.ayah-item .t { text-align: left; color: var(--muted); font-weight: 700; font-size: 15px; }
.ayah-item.on { border-color: var(--accent); background: #fffaf0; }
.ayah-item.blur .a { filter: blur(9px); transition: filter .2s; }
.ayah-item.blur.peek .a { filter: none; }

/* settings sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(40, 30, 10, .4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; border-radius: 28px 28px 0 0; padding: 20px 18px calc(24px + env(safe-area-inset-bottom)); max-height: 88dvh; overflow: auto; }
@media (min-width: 640px) { .sheet-bg { align-items: center; } .sheet { border-radius: 28px; } }
.sheet h3 { margin: 0 0 14px; font-size: 22px; font-weight: 900; }
.field { background: var(--card); border-radius: 18px; padding: 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 12px; }
.field label { flex: 1; font-weight: 800; }
.field small { display: block; color: var(--muted); font-weight: 700; }
.field select { font: inherit; font-weight: 700; padding: 8px; border-radius: 10px; border: 2px solid var(--line); background: #fff; max-width: 52%; }
.switch { width: 58px; height: 34px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.switch.on { background: var(--primary); }
.switch.on::after { left: 28px; }
.credit { color: var(--muted); font-size: 13px; font-weight: 700; line-height: 1.5; }
.credit a { color: var(--primary-dark); }

.range-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }
.range-chips button { padding: 10px 14px; border-radius: 14px; background: var(--card); font-weight: 800; box-shadow: 0 3px 0 var(--line); }
.range-chips button.on { background: var(--accent); color: #fff; box-shadow: 0 3px 0 #c97614; }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 800; max-width: 90vw; text-align: center;
}
.feedback { position: fixed; inset: auto 0 0 0; z-index: 20; padding: 16px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)); animation: up .2s ease; }
.feedback .in { max-width: 920px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.feedback.good { background: var(--good-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback .msg { flex: 1 1 200px; font-weight: 900; font-size: 19px; }
.feedback.good .msg { color: #16794a; }
.feedback.bad .msg { color: #b0332c; }
.feedback .msg small { display: block; font-weight: 700; font-size: 15px; color: var(--ink); }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }

@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* susun ayat: arti ayat, sambungan ayat, gerbong berarti */
.ayah-meaning { display: flex; gap: 8px; align-items: flex-start; text-align: left; background: var(--primary-soft); border-radius: 16px; padding: 10px 14px; font-weight: 800; font-size: 15px; line-height: 1.45; color: var(--primary-dark); margin-bottom: 12px; }
.done-words { display: flex; flex-wrap: wrap; direction: rtl; justify-content: center; gap: 4px 10px; margin-bottom: 4px; }
.done-words .dw { display: flex; flex-direction: column; align-items: center; opacity: .75; }
.done-words .a { font-family: var(--arabic); font-size: clamp(20px, 4.6vw, 28px); line-height: 1.6; }
.done-words .m { direction: ltr; font-size: 12px; font-weight: 800; color: var(--muted); max-width: 110px; text-align: center; line-height: 1.2; }
.done-words .more { font-size: 22px; color: var(--muted); justify-content: center; }
.car { display: flex; flex-direction: column; align-items: center; }
.car .ca { line-height: 1.5; }
.car .cm { direction: ltr; font-family: var(--ui); font-size: 11px; font-weight: 800; color: var(--muted); max-width: 110px; line-height: 1.15; }
.car.empty { display: grid; }

/* susun ayat: drag and drop */
#pool .word, #train .car[data-slot] { touch-action: none; user-select: none; -webkit-user-select: none; }
#train .car:not(.empty) { cursor: grab; }
.car.over { border-color: var(--accent) !important; background: var(--accent-soft); border-style: solid; }
.car.good { border-color: var(--good); background: var(--good-soft); }
.car.bad { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s; }
.dragging { opacity: .35; }
.ghost {
  position: fixed; z-index: 100; pointer-events: none; margin: 0; transform: scale(1.08) rotate(-2deg);
  box-shadow: 0 12px 28px rgba(80, 60, 20, .3); opacity: .96; background: var(--card); border-radius: 18px;
}
.ghost.car::after { display: none; }
.train.rows { flex-wrap: wrap; overflow: visible; justify-content: center; row-gap: 28px; }
.train.rows .car { min-width: 100px; }

/* sorotan kata yang sedang terdengar */
.kw { border-radius: 12px; padding: 0 4px; transition: background .12s, color .12s; }
.kw.hl { background: var(--accent-soft); color: #c26a00; }
.hl.word, .hl.car, .hl.dw { background: var(--accent-soft) !important; border-color: var(--accent) !important; box-shadow: 0 0 0 4px rgba(242, 154, 46, .35); opacity: 1; transform: translateY(-2px); }
.hl.word .a, .hl.car .ca, .hl.dw .a { color: #c26a00; }
.dw { border-radius: 12px; padding: 0 6px; transition: background .12s; }
