:root {
  --bg: #0b1020;
  --panel: #151b36;
  --panel-2: #1d2549;
  --line: #2a3363;
  --text: #eef1ff;
  --muted: #9aa3c7;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --gold: #facc15;
  --good: #22c55e;
  --bad: #f43f5e;
  --warn: #f59e0b;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #1b1f4a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Gurmukhi", sans-serif;
  min-height: 100vh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
sub { font-size: .7em; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; line-height: 1.25; }
.back {
  width: 42px; height: 42px; border-radius: 14px; flex: none;
  background: var(--panel); border: 1px solid var(--line); font-size: 1.2rem;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-weight: 700; font-size: .9rem; white-space: nowrap;
}

/* ---------- Cards & buttons ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
.stack > * + * { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 18px; border-radius: 14px; font-weight: 800; letter-spacing: .2px;
  background: var(--grad); color: #fff; box-shadow: 0 6px 18px rgba(124, 92, 255, .35);
  transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--panel-2); box-shadow: none; border: 1px solid var(--line); }
.btn.good { background: var(--good); box-shadow: 0 6px 18px rgba(34, 197, 94, .3); }
.btn.bad { background: var(--bad); box-shadow: 0 6px 18px rgba(244, 63, 94, .3); }
.btn:disabled { opacity: .45; }

.bar { height: 10px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--grad); border-radius: 99px; transition: width .4s; }

/* ---------- Home ---------- */
.hello { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.avatar {
  width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; font-size: 30px;
  background: var(--grad); box-shadow: var(--shadow); flex: none;
}
.hello h1 { margin: 0; font-size: 1.3rem; }
.levelcard { background: linear-gradient(135deg, #2b1f6b, #123a52); border: 0; }
.levelcard .lv { font-size: 2rem; font-weight: 900; line-height: 1; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; min-height: 120px; display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden;
}
.tile .ic { font-size: 2rem; }
.tile b { font-size: 1.05rem; }
.tile::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px; border-radius: 50%;
  background: var(--c, var(--accent)); opacity: .18;
}
.tile:active { transform: scale(.98); }
.tile.locked { opacity: .55; }
.tile.wide { grid-column: span 2; min-height: 0; flex-direction: row; align-items: center; gap: 14px; }

.chapter {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.chapter .num {
  width: 46px; height: 46px; border-radius: 14px; background: var(--grad); display: grid; place-items: center;
  font-weight: 900; font-size: 1.2rem; flex: none;
}

details.notes summary { cursor: pointer; font-weight: 800; list-style: none; }
details.notes summary::-webkit-details-marker { display: none; }
details.notes ul { margin: 10px 0 0; padding-left: 20px; }
details.notes li { margin-bottom: 8px; }

/* ---------- Flashcards ---------- */
.flip-wrap { perspective: 1200px; margin: 8px 0 16px; }
.flip {
  position: relative; min-height: 300px; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3, .7, .3, 1.2);
}
.flip.flipped { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 24px; padding: 24px; display: flex; flex-direction: column; justify-content: center;
  box-shadow: var(--shadow); white-space: pre-line;
}
.face.side-q { background: linear-gradient(160deg, #2a2170, #17204a); border: 1px solid #3b3a8a; font-size: 1.3rem; font-weight: 800; text-align: center; }
.face.side-a { background: linear-gradient(160deg, #0f3b4a, #13234a); border: 1px solid #1f5b6e; transform: rotateY(180deg); font-size: 1.05rem; }
.face .tag { position: absolute; top: 14px; left: 16px; font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.face .hint { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font-size: .8rem; color: var(--muted); font-weight: 500; }

/* ---------- Quiz ---------- */
.qtext { font-size: 1.2rem; font-weight: 800; margin: 6px 0 16px; white-space: pre-line; }
.opt {
  display: block; width: 100%; text-align: left; padding: 14px 16px; margin-bottom: 10px; border-radius: 14px;
  background: var(--panel); border: 2px solid var(--line); font-weight: 600; transition: transform .08s;
}
.opt:active { transform: scale(.98); }
.opt.right { border-color: var(--good); background: rgba(34, 197, 94, .15); }
.opt.wrong { border-color: var(--bad); background: rgba(244, 63, 94, .15); }
.timer > i { background: linear-gradient(90deg, var(--good), var(--gold)); }
.timer.low > i { background: var(--bad); }
.explain { border-left: 4px solid var(--accent-2); }
.combo { color: var(--gold); font-weight: 900; }

/* ---------- Practice ---------- */
.pfield { display: block; margin-bottom: 12px; }
.pfield span { display: block; font-weight: 700; font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.pfield input { font-size: 1.2rem; font-weight: 700; }
.pfield input.right { border-color: var(--good); background: rgba(34, 197, 94, .12); }
.pfield input.wrong { border-color: var(--bad); background: rgba(244, 63, 94, .12); }
.graph svg { display: block; width: 100%; height: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 14px; }
.keys { display: flex; gap: 8px; margin: -2px 0 14px; }
.keys button { flex: 1; padding: 10px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 800; font-size: 1.05rem; }

/* ---------- Match ---------- */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .col { display: flex; flex-direction: column; gap: 10px; }
.mi {
  min-height: 64px; padding: 10px 12px; border-radius: 14px; background: var(--panel); border: 2px solid var(--line);
  font-weight: 700; font-size: .92rem; text-align: center; transition: all .2s;
}
.mi.sel { border-color: var(--accent-2); background: rgba(34, 211, 238, .12); transform: scale(1.03); }
.mi.done { border-color: var(--good); background: rgba(34, 197, 94, .12); opacity: .5; pointer-events: none; }
.glow { animation: glow 1.6s ease; }
@keyframes glow { 0%, 60% { border-color: var(--good); box-shadow: 0 0 0 4px rgba(34, 197, 94, .35); } 100% { box-shadow: none; } }
.shake { animation: shake .35s; border-color: var(--bad) !important; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---------- Balance lab ---------- */
.equation { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center; gap: 12px 6px; padding: 10px 0; }
.eqside { display: flex; align-items: flex-end; gap: 6px; }
.term { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.term .f { font-size: 1.25rem; font-weight: 800; }
.step { display: flex; align-items: center; background: var(--panel-2); border-radius: 12px; border: 1px solid var(--line); }
.step button { width: 30px; height: 38px; font-size: 1.2rem; font-weight: 900; }
.step span { min-width: 22px; text-align: center; font-weight: 900; font-size: 1.15rem; color: var(--gold); }
.op { font-size: 1.3rem; font-weight: 900; color: var(--muted); padding-bottom: 2px; }
table.atoms { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.atoms th, table.atoms td { padding: 8px; text-align: center; border-bottom: 1px solid var(--line); }
table.atoms td.ok { color: var(--good); font-weight: 800; }
table.atoms td.no { color: var(--bad); font-weight: 800; }

/* ---------- Written answers ---------- */
textarea {
  width: 100%; min-height: 170px; resize: vertical; border-radius: 14px; padding: 14px;
  background: var(--panel-2); border: 1px solid var(--line); line-height: 1.5;
}
textarea:focus, input:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.kp { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kp input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--good); flex: none; }
.model { white-space: pre-line; border-left: 4px solid var(--good); }
.marks { font-size: .75rem; font-weight: 800; padding: 3px 8px; border-radius: 99px; background: var(--panel-2); color: var(--gold); }

/* ---------- Results / badges ---------- */
.big-emoji { font-size: 4.5rem; line-height: 1; margin: 10px 0; }
.stars { font-size: 2.2rem; letter-spacing: 6px; }
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { text-align: center; padding: 12px 6px; border-radius: 16px; background: var(--panel-2); border: 1px solid var(--line); font-size: .78rem; font-weight: 700; }
.badge .e { font-size: 1.9rem; display: block; }
.badge.off { opacity: .3; filter: grayscale(1); }
.topicrow { margin-bottom: 12px; }
.topicrow .bar > i.weak { background: var(--bad); }
.topicrow .bar > i.ok { background: var(--warn); }
.topicrow .bar > i.strong { background: var(--good); }

/* ---------- Feedback ---------- */
.moods { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.moods button { font-size: 2rem; padding: 4px 8px; border-radius: 14px; border: 2px solid transparent; transition: transform .1s; }
.moods button:active { transform: scale(1.2); }
.moods button.sel { border-color: var(--accent-2); background: rgba(34, 211, 238, .12); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 8px 12px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 600; font-size: .9rem; }
.chips button.sel { border-color: var(--accent-2); background: rgba(34, 211, 238, .15); }
a { color: var(--accent-2); }

/* ---------- Onboarding ---------- */
.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.avatars button { font-size: 1.8rem; padding: 6px 0; border-radius: 14px; background: var(--panel-2); border: 2px solid transparent; }
.avatars button.sel { border-color: var(--accent-2); }
input[type=text] { width: 100%; padding: 14px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); }

/* ---------- Toast & confetti ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  background: #fff; color: #111; padding: 12px 18px; border-radius: 14px; font-weight: 800; box-shadow: var(--shadow);
  transition: transform .3s, opacity .3s; z-index: 20; max-width: calc(100% - 32px); text-align: center;
  opacity: 0; visibility: hidden;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; width: 100%; height: 100%; }

.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.9); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Punjabi: bigger Gurmukhi and listen buttons */
.pa { font-size: 1.3em; line-height: 1.6; }
.say { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.say button {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel-2); font-size: 1.3rem; cursor: pointer;
}
.say button:active { transform: scale(.92); }

/* Chapter levels (Punjabi: Basic / Medium / Advanced) */
details.level { margin-bottom: 14px; }
details.level summary {
  display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none;
  padding: 12px 4px; font-size: 1.1rem;
}
details.level summary::-webkit-details-marker { display: none; }
details.level summary::before { content: '▸'; color: var(--muted); transition: transform .2s; }
details.level[open] summary::before { transform: rotate(90deg); }
