:root {
  --bg: #f6f4ff;
  --card: #ffffff;
  --ink: #1d1b3a;
  --muted: #6b6890;
  --line: #e7e3fb;
  --brand: #6d4aff;
  --brand2: #ff5c8a;
  --ok: #16a36a;
  --warn: #f59e0b;
  --bad: #e5484d;
  --radius: 22px;
  --shadow: 0 10px 30px rgba(77, 55, 200, 0.12);
  --grad: linear-gradient(135deg, #6d4aff 0%, #a64dff 50%, #ff5c8a 100%);
  font-family: -apple-system, "SF Arabic", "Segoe UI", "Geeza Pro", Tahoma, system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f0d1f; --card: #1b1833; --ink: #f1efff; --muted: #a7a3c9; --line: #2c2850; --shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
body { padding: env(safe-area-inset-top) 0 calc(84px + env(safe-area-inset-bottom)); overscroll-behavior-y: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); }
.en { direction: ltr; unicode-bidi: isolate; font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif; }
.wrap { max-width: 640px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 12px; padding: 8px 4px 16px; }
.top h1 { font-size: 22px; margin: 0; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; flex: none; box-shadow: var(--shadow); }
.avatar.big { width: 96px; height: 96px; }
.back { width: 40px; height: 40px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-size: 20px; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid var(--line); }
.card h2 { margin: 0 0 6px; font-size: 18px; }
.card p { margin: 4px 0; color: var(--muted); line-height: 1.6; }
.hero { background: var(--grad); color: #fff; border: 0; position: relative; overflow: hidden; }
.hero p { color: rgba(255, 255, 255, 0.9); }
.hero::after { content: ""; position: absolute; width: 220px; height: 220px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); left: -60px; top: -90px; }
.row { display: flex; gap: 12px; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--card); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); text-align: start; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.tile .ico { font-size: 28px; }
.tile b { font-size: 16px; }
.tile small { color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: rgba(109, 74, 255, 0.1); color: var(--brand); font-size: 13px; font-weight: 600; }
.hero .pill { background: rgba(255, 255, 255, 0.2); color: #fff; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 20px; border-radius: 16px; font-weight: 700; background: var(--brand); color: #fff; box-shadow: 0 6px 18px rgba(109, 74, 255, 0.35); transition: transform 0.12s; min-height: 52px; }
.btn:active { transform: scale(0.97); }
.btn.white { background: #fff; color: var(--brand); }
.btn.ghost { background: transparent; color: var(--brand); box-shadow: none; border: 2px solid var(--line); }
.btn.soft { background: rgba(109, 74, 255, 0.1); color: var(--brand); box-shadow: none; }
.btn.ok { background: var(--ok); box-shadow: 0 6px 18px rgba(22, 163, 106, 0.3); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 10px 14px; border-radius: 14px; background: var(--card); border: 2px solid var(--line); font-weight: 600; }
.chip.on { border-color: var(--brand); background: rgba(109, 74, 255, 0.1); color: var(--brand); }

/* progress ring */
.ring { width: 92px; height: 92px; flex: none; }
.ring circle { fill: none; stroke-width: 10; }
.ring .bgc { stroke: rgba(255, 255, 255, 0.25); }
.ring .fg { stroke: #fff; stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset 0.6s; }
.ring text { fill: #fff; font-weight: 800; font-size: 22px; }

/* timeline */
.slots { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.slot { flex: none; padding: 8px 12px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); text-align: center; font-size: 13px; }
.slot b { display: block; font-size: 15px; }
.slot.now { border-color: var(--brand); color: var(--brand); }

/* chat (onboarding) */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.bubble { max-width: 85%; padding: 12px 16px; border-radius: 20px; line-height: 1.6; animation: pop 0.25s ease-out; }
.bubble.nour { background: var(--card); border: 1px solid var(--line); border-start-start-radius: 6px; align-self: flex-start; box-shadow: var(--shadow); }
.bubble.me { background: var(--brand); color: #fff; border-start-end-radius: 6px; align-self: flex-end; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.field { width: 100%; padding: 14px 16px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); font-size: 17px; outline: none; }
.field:focus { border-color: var(--brand); }
.lesson-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1.4fr auto; gap: 6px; margin-bottom: 6px; }
.lesson-row .field { padding: 10px 8px; font-size: 14px; }

/* round player */
.stage { text-align: center; padding: 8px 0; }
.qnum { color: var(--muted); font-weight: 700; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 10px 0 18px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dots i.ok { background: var(--ok); }
.dots i.bad { background: var(--bad); }
.dots i.cur { background: var(--brand); transform: scale(1.3); }
.speaker { width: 150px; height: 150px; border-radius: 50%; background: var(--grad); margin: 10px auto 18px; display: grid; place-items: center; color: #fff; font-size: 54px; box-shadow: 0 16px 40px rgba(109, 74, 255, 0.4); position: relative; }
.speaker.playing::before, .mic.live::before { content: ""; position: absolute; inset: -14px; border-radius: 50%; border: 3px solid rgba(109, 74, 255, 0.35); animation: pulse 1.4s infinite; }
@keyframes pulse { from { transform: scale(0.92); opacity: 1; } to { transform: scale(1.18); opacity: 0; } }
.mic { width: 120px; height: 120px; border-radius: 50%; background: var(--brand2); color: #fff; font-size: 46px; margin: 18px auto 8px; display: grid; place-items: center; position: relative; box-shadow: 0 14px 36px rgba(255, 92, 138, 0.45); }
.mic.live { background: var(--bad); }
.level { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; width: 180px; margin: 10px auto; }
.level i { display: block; height: 100%; width: 0; background: var(--grad); transition: width 0.08s; }
.helpers { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.qtext { font-size: 21px; font-weight: 700; margin: 10px 0; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--brand); animation: spin 0.8s linear infinite; margin: 30px auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.said { font-size: 19px; line-height: 2; }
.said span { padding: 2px 4px; border-radius: 6px; }
.w-ok { color: var(--ok); }
.w-mid { color: var(--warn); background: rgba(245, 158, 11, 0.12); }
.w-bad { color: var(--bad); background: rgba(229, 72, 77, 0.12); text-decoration: underline wavy; }
.w-miss { color: var(--muted); text-decoration: line-through; }
.scores { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.score { background: var(--bg); border-radius: 14px; padding: 8px 4px; text-align: center; }
.score b { display: block; font-size: 20px; }
.score small { color: var(--muted); font-size: 11px; }
.fix { border-inline-start: 4px solid var(--warn); padding: 8px 12px; margin: 8px 0; background: var(--bg); border-radius: 12px; }
.fix .wrong { color: var(--bad); text-decoration: line-through; }
.fix .right { color: var(--ok); font-weight: 700; }
.model { background: rgba(22, 163, 106, 0.08); border: 1px solid rgba(22, 163, 106, 0.25); border-radius: 16px; padding: 14px; font-size: 18px; line-height: 1.7; }
.banner { padding: 14px; border-radius: 16px; font-weight: 800; font-size: 18px; text-align: center; margin-bottom: 12px; }
.banner.ok { background: rgba(22, 163, 106, 0.12); color: var(--ok); }
.banner.bad { background: rgba(245, 158, 11, 0.14); color: #b45309; }

/* words */
.wordcard { text-align: center; padding: 26px 18px; }
.wordcard .big { font-size: 34px; font-weight: 800; margin: 6px 0; }
.wordcard .ar { font-size: 22px; }
.typebox { font-size: 26px; text-align: center; letter-spacing: 1px; }
.diff span { font-size: 26px; font-weight: 800; padding: 0 1px; }
.diff .x { color: var(--bad); text-decoration: underline; }
.diff .y { color: var(--ok); }

/* story */
.sentence { padding: 10px 12px; border-radius: 14px; margin: 6px 0; line-height: 1.8; font-size: 18px; transition: background 0.2s; }
.sentence.on { background: rgba(109, 74, 255, 0.12); box-shadow: inset 4px 0 0 var(--brand); }
.sentence .tr { display: block; color: var(--muted); font-size: 15px; direction: rtl; font-family: inherit; }
.gl { border-bottom: 2px dotted var(--brand); }

/* tabs */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-around; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); z-index: 10; }
.tabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 10px; border-radius: 14px; }
.tabs button span { font-size: 22px; }
.tabs button.on { color: var(--brand); background: rgba(109, 74, 255, 0.1); }
.toast { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; z-index: 50; font-weight: 600; box-shadow: var(--shadow); max-width: 90%; }
.center { text-align: center; }
.muted { color: var(--muted); }
.stat { font-size: 30px; font-weight: 800; }
.talk-cta { display: flex; gap: 12px; align-items: center; width: 100%; text-align: start; font: inherit; color: inherit; cursor: pointer; }
.talk-cta small { display: block; color: var(--muted, #777); margin-top: 2px; }
.talk-box { position: sticky; bottom: 0; background: var(--bg, #fff); padding: 10px 0; margin-top: 10px; }
#sugg { margin-top: 6px; }
.talk-cta.due { border: 2px solid #f5b400; box-shadow: 0 0 0 4px #f5b40022; }
.hint-ar { display: block; margin-top: 6px; color: var(--muted, #777); }
.convo-row { width: 100%; gap: 8px; padding: 10px 0; border: 0; border-bottom: 1px solid #0001; background: none; font: inherit; color: inherit; text-align: start; cursor: pointer; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.bar { height: 8px; border-radius: 8px; background: #0001; overflow: hidden; margin-bottom: 8px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #6d4aff, #c04bd6); }
.fam h2 small { font-weight: 400; font-size: 13px; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.confetti i { position: absolute; top: -40px; font-size: 26px; font-style: normal; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
.stars { font-size: 30px; letter-spacing: 4px; margin: 6px 0 10px; }
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.badge { text-align: center; opacity: .3; filter: grayscale(1); }
.badge.on { opacity: 1; filter: none; }
.badge span { font-size: 30px; display: block; }
.badge small { font-size: 11px; }
.choices { display: grid; gap: 10px; width: 100%; margin-top: 16px; }
.right-ans { background: #22c55e !important; color: #fff !important; }
.wrong-ans { background: #ef4444 !important; color: #fff !important; }
.letters .chip { font-size: 22px; min-width: 44px; }
.letters .chip:disabled { opacity: .25; }
.lb { padding: 6px 0; gap: 10px; } .lb.me { font-weight: 700; color: #6d4aff; }
.sentence .w { transition: background .15s; border-radius: 4px; }
.sentence .w.lit { background: #ffe066; color: #000; }
.sentence .pic { display: block; font-size: 34px; letter-spacing: 6px; margin-bottom: 4px; }
.story-cover { font-size: 64px; text-align: center; letter-spacing: 10px; margin: 6px 0 10px; }
.letters, #built { direction: ltr; }
