:root {
  --bg: #161325;
  --bg2: #1f1b31;
  --card: #241f38;
  --line: #3a3354;
  --text: #f3efe6;
  --muted: #a79fbf;
  --gold: #e8b04b;
  --good: #4cc38a;
  --bad: #ef6b5b;
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 50% -10%, #2e2650 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  overscroll-behavior-y: none;
}
#view {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
h1 { font-size: 1.6rem; margin: 0; letter-spacing: .01em; }
h2 { font-size: 1.3rem; margin: 0 0 6px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
p { margin: 8px 0; }
.ar { font-family: "Noto Naskh Arabic", "Geeza Pro", "Noto Sans Arabic", serif; font-weight: 500; opacity: .85; }
.sub { margin: 0; color: var(--muted); font-size: .9rem; }
.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }
.lead { color: #ddd6ec; }
button { font: inherit; color: inherit; }

/* Header */
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chips { display: flex; gap: 6px; }
.chip { background: var(--card); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; font-size: .9rem; }

/* Clock */
.clock-wrap { width: 100%; max-width: 440px; margin: 4px auto 0; }
.clock { width: 100%; height: auto; display: block; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.slot { cursor: pointer; transition: opacity .2s, transform .2s; transform-origin: 200px 200px; }
.slot path { opacity: .88; stroke: var(--bg); stroke-width: 2; }
.slot:active { transform: scale(.97); }
.slot.locked path { opacity: .22; }
.slot.locked text { opacity: .55; }
.slot.next path { opacity: 1; filter: drop-shadow(0 0 6px rgba(232,176,75,.6)); }
.slot-name { fill: #fff; font-size: 14px; font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: rgba(0,0,0,.35); stroke-width: 3px; }
.slot-ar { fill: #fff; font-size: 13px; text-anchor: middle; paint-order: stroke; stroke: rgba(0,0,0,.3); stroke-width: 3px; }
.slot-stars { fill: #fff6d8; font-size: 10px; text-anchor: middle; letter-spacing: 1px; }
.fam, .link, .center { cursor: pointer; }
.link-t { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.hand { transform-origin: 200px 200px; transition: transform 1.2s cubic-bezier(.3,1.4,.5,1); }
.c-small { fill: var(--muted); font-size: 10px; letter-spacing: .12em; text-anchor: middle; }
.c-big { fill: var(--text); font-size: 18px; font-weight: 700; text-anchor: middle; }
.hint { text-align: center; color: var(--muted); font-size: .85rem; margin: 6px 8px 12px; }

/* Cards & buttons */
.card { display: block; width: 100%; text-align: start; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
button.card { cursor: pointer; }
.next-card { border-inline-start: 5px solid var(--c); display: grid; gap: 2px; }
.nc-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.nc-title { font-size: 1.3rem; font-weight: 700; }
.nc-sub { color: var(--c); }
.btn { background: #2f2948; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: var(--text); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--c, var(--gold)); color: #17131f; border-color: transparent; font-weight: 700; }
.btn.primary small { font-weight: 400; opacity: .75; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: .85rem; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.danger { border-color: #7a3a3a; color: #ffb3a8; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.icon-btn { background: var(--card); border: 1px solid var(--line); width: 44px; height: 44px; border-radius: 12px; font-size: 1.6rem; line-height: 1; cursor: pointer; flex: none; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.stars .star { color: #4a4364; font-size: 1.1rem; }
.stars .star.on { color: var(--gold); }

/* Lesson */
.lesson-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.lh-title { flex: 1; min-width: 0; }
.lh-title h1 { font-size: 1.4rem; }
.lesson .lh-title h1 { color: var(--c); }
.tabs { display: flex; background: var(--bg2); border-radius: 14px; padding: 4px; gap: 4px; position: sticky; top: env(safe-area-inset-top); z-index: 5; }
.tab { flex: 1; background: none; border: 0; padding: 10px 4px; border-radius: 10px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.on { background: var(--c); color: #17131f; }
.tab-body { padding-top: 12px; }

.mood-card { border-radius: var(--radius); overflow: hidden; background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 35%, #161325)); padding: 18px; min-height: 150px; display: flex; flex-direction: column; justify-content: space-between; }
.swatch span { background: rgba(0,0,0,.25); padding: 3px 10px; border-radius: 999px; font-size: .8rem; }
.words { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 30px; }
.word { font-size: 1.35rem; font-weight: 800; color: #fff; text-shadow: 0 1px 8px rgba(0,0,0,.3); }
.story { font-size: 1.05rem; line-height: 1.6; }

.keyboard { display: flex; align-items: stretch; gap: 0; margin: 14px 0 6px; }
.key { flex: 3 1 0; min-width: 0; background: linear-gradient(#fbf6ea, #e6dcc6); color: #231c33; border: 0; border-radius: 10px; height: 120px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding: 6px 2px; cursor: pointer; touch-action: manipulation; transition: transform .08s, background .15s; }
.key b { font-size: .8rem; line-height: 1.15; text-align: center; overflow-wrap: anywhere; }
[lang="ar"] .key b, [lang="ar"] .jkey b { font-size: .72rem; }
.key small { opacity: .55; font-size: .7rem; }
.key.q { box-shadow: inset 0 0 0 3px var(--c); background: linear-gradient(#fff7e0, #f0dfb4); }
.key.hit, .jkey.hit { transform: translateY(3px) scale(.97); background: var(--c); color: #fff; }
.gap { flex-basis: 0; min-width: 14px; font-size: .62rem; color: var(--muted); align-self: center; text-align: center; }
.qmark { display: inline-block; width: 14px; height: 14px; border-radius: 4px; box-shadow: inset 0 0 0 2px var(--c); color: transparent; vertical-align: middle; }
.progress-line { color: var(--muted); font-size: .9rem; }
.ear .ab, .ab { display: flex; gap: 8px; margin: 8px 0; }
.ab .btn { flex: 1; }

.build-row { display: flex; gap: 8px; }
.hint-box { background: var(--bg2); border-radius: 12px; padding: 10px 12px; margin: 10px 0; font-size: .92rem; }
.slots { display: grid; gap: 8px; margin: 14px 0; }
.slot-box { border: 2px dashed var(--line); border-radius: 14px; padding: 8px 10px; cursor: pointer; }
.slot-box.filled { border-style: solid; border-color: var(--jc); }
.slot-box small { color: var(--muted); display: block; margin-bottom: 4px; }
.slot-box .empty { color: #6d6488; padding: 10px 0; text-align: center; }
.pal-title { margin-top: 8px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.block { position: relative; background: var(--jc); color: #17131f; border: 0; border-radius: 10px; padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; cursor: pointer; min-height: 72px; }
.block::before { content: ""; position: absolute; top: -6px; left: 50%; width: 18px; height: 8px; margin-left: -9px; background: var(--jc); border-radius: 6px 6px 0 0; }
.block b { font-size: .85rem; }
.block span { font-size: .8rem; opacity: .8; }
.block em { font-style: normal; font-size: .68rem; opacity: .75; }
.block.placed { flex-direction: row; gap: 10px; justify-content: center; min-height: 48px; }
.block.placed::before { display: none; }

.songs { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 10px; }
.songs li { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
.songs li div { grid-column: 1 / -1; }
.songs small { display: block; color: var(--muted); }
.badge { font-size: .75rem; padding: 3px 8px; border-radius: 999px; justify-self: start; }
.badge.sure { background: rgba(76,195,138,.15); color: var(--good); }
.badge.check { background: rgba(232,176,75,.15); color: var(--gold); }

/* Games */
.game-card { display: flex; gap: 14px; align-items: center; border-inline-start: 5px solid var(--c); }
.gc-icon { font-size: 2rem; }
.game-card b { display: block; font-size: 1.1rem; }
.game-card small { display: block; color: var(--muted); }
.game-card .best { color: var(--c); margin-top: 2px; }
.score { color: var(--muted); font-variant-numeric: tabular-nums; }
.play-big { display: block; margin: 24px auto 8px; width: 110px; height: 110px; border-radius: 50%; border: 0; background: var(--gold); color: #17131f; font-size: 2.6rem; cursor: pointer; box-shadow: 0 8px 30px rgba(232,176,75,.3); }
.play-big:active, .play-mid:active { transform: scale(.95); }
.play-mid { flex: 1; height: 80px; border-radius: 18px; border: 0; background: #2f2948; font-size: 1.3rem; font-weight: 700; cursor: pointer; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.opt { background: var(--card); border: 2px solid var(--c); border-radius: 14px; padding: 14px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.opt b { color: var(--c); font-size: 1.05rem; }
.opt small { color: var(--muted); font-size: .7rem; }
.opt.right { background: var(--good); border-color: var(--good); }
.opt.right b, .opt.wrong b { color: #fff; }
.opt.wrong { background: var(--bad); border-color: var(--bad); }
.end { text-align: center; padding-top: 30px; }
.end .big { font-size: 3rem; font-weight: 800; margin: 0; color: var(--gold); }

.chips-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.pick { flex: none; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; cursor: pointer; }
.pick.on { background: var(--c); color: #17131f; border-color: transparent; font-weight: 700; }
.pick[disabled] { opacity: .4; }
.jam-keys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 14px 0; }
.jkey { height: 74px; border-radius: 12px; border: 0; background: linear-gradient(#fbf6ea, #e6dcc6); color: #231c33; cursor: pointer; touch-action: manipulation; font-size: .78rem; padding: 0 2px; transition: transform .08s; }
.jkey small { display: block; font-size: .6rem; opacity: .55; }
.jkey.q { box-shadow: inset 0 0 0 3px var(--c); }
.jkey.home { background: linear-gradient(#ffe3a3, var(--gold)); }
.jam-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.jam-controls label { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
select, input[type=range] { width: 100%; font: inherit; }
select { background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
input[type=range] { accent-color: var(--gold); }

/* Progress */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; text-align: center; }
.stat b { display: block; font-size: 1.2rem; }
.stat small { color: var(--muted); }
.prog-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.prog-list li { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 10px 12px; border-inline-start: 4px solid var(--c); cursor: pointer; }
.prog-list .n { color: var(--muted); width: 18px; }
.prog-list .pn { flex: 1; }
.settings .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 10px 0; }
.settings select { width: auto; }
.settings input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--gold); }

/* Bottom nav */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; background: rgba(22,19,37,.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
.bottom-nav a { color: var(--muted); text-decoration: none; display: flex; flex-direction: column; align-items: center; font-size: .72rem; min-width: 64px; padding: 4px; }
.bottom-nav a span { font-size: 1.25rem; line-height: 1.3; }
.bottom-nav a.on { color: var(--gold); }

/* Sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); opacity: 0; transition: opacity .25s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; background: var(--bg2); border-radius: 22px 22px 0 0; padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .25s ease-out; display: flex; flex-direction: column; gap: 8px; }
.sheet .btn { width: 100%; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head h2 { flex: 1; margin: 0; }
.sheet-head .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); }
.sheet .mood { color: var(--muted); margin: 0; }
.sheet .notes { font-size: 1.1rem; letter-spacing: .04em; word-spacing: .3em; margin: 4px 0; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #f3efe6; color: #17131f; padding: 10px 16px; border-radius: 12px; font-weight: 600; opacity: 0; transition: .25s; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { top: 105%; transform: translateX(40px) rotate(540deg); } }

@media (max-width: 360px) {
  .key b { font-size: .7rem; }
  .palette { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Language & note prefs */
.prefs { display: grid; gap: 12px; margin: 6px 0 10px; }
.seg-group { display: grid; gap: 6px; }
.seg-label { color: var(--muted); font-size: .85rem; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; background: none; border: 0; border-radius: 9px; padding: 9px 6px; cursor: pointer; color: var(--muted); font-weight: 600; min-height: 40px; }
.seg button.on { background: var(--gold); color: #17131f; }
button.chip { cursor: pointer; font: inherit; color: inherit; }

/* Install prompt */
.install-card { display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; background: linear-gradient(135deg, #2f2948, #241f38); border: 1px solid var(--gold); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0 4px; cursor: pointer; }
.install-card img, .install-head img { border-radius: 10px; flex: none; }
.install-card span { flex: 1; min-width: 0; }
.install-card b { display: block; }
.install-card small { display: block; color: var(--muted); font-size: .8rem; }
.install-card .go { flex: none; background: var(--gold); color: #17131f; font-weight: 700; padding: 6px 12px; border-radius: 10px; }
.install-head { display: flex; align-items: center; gap: 12px; }
.install-head h2 { margin: 0; }
.steps { background: var(--bg); border-radius: 12px; padding: 12px 14px; line-height: 1.9; }
.share-ic { display: inline-block; border: 1.5px solid currentColor; border-radius: 4px; padding: 0 4px; font-size: .8rem; line-height: 1.3; }

/* Right-to-left (Arabic) */
[dir="rtl"] .back { transform: scaleX(-1); }
[dir="rtl"] body { font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif; }
[dir="rtl"] .nc-label, [dir="rtl"] .c-small { letter-spacing: 0; }
bdi.nn { unicode-bidi: isolate; }
