:root {
  --bg: #fff8ef; --card: #ffffff; --ink: #2b1b20; --muted: #85736b; --line: #eadfd3;
  --brand: #d9600b; --brand-d: #a64604; --maroon: #8d153a; --maroon-d: #5f0d26;
  --good: #149c4f; --good-d: #0d7139; --good-bg: #e3f7ea;
  --bad: #d93d42; --bad-d: #a5262b; --bad-bg: #fde8e8;
  --gold: #f2b01e; --teal: #00534e; --blue: #2563c9;
  --r: 18px; --shadow: 0 2px 0 var(--line);
  --si: 'Noto Sans Sinhala', 'Sinhala Sangam MN', 'Iskoola Pota', sans-serif;
  --ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif, 'Noto Sans Sinhala', 'Noto Color Emoji';
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--ui); }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; }
a { color: var(--brand-d); }
.si { font-family: var(--si); }
.rom { color: var(--muted); font-style: italic; }
.hidden { display: none !important; }
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- top bar & tabs */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(10px + var(--safe-t)) 16px 8px; display: flex; align-items: center; gap: 12px; }
.top h1 { font-size: 20px; margin: 0; flex: 1; }
.top .pill { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--card); border: 2px solid var(--line); font-size: 15px; }
.pill.fire { color: var(--brand); } .pill.xp { color: var(--gold); }
.main { flex: 1; padding: 4px 16px calc(96px + var(--safe-b)); }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; background: var(--card); border-top: 2px solid var(--line); display: flex; justify-content: center; padding-bottom: var(--safe-b); }
.tabs a { flex: 1; max-width: 112px; text-align: center; padding: 8px 0 7px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.tabs a .ic { display: block; font-size: 22px; line-height: 28px; font-family: var(--si); }
.tabs a.on { color: var(--brand); }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 16px; padding: 14px 18px; font-weight: 800; font-size: 17px; letter-spacing: .02em; cursor: pointer; background: var(--brand); color: #fff; box-shadow: 0 4px 0 var(--brand-d); transition: transform .05s; text-transform: uppercase; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--brand-d); }
.btn.wide { width: 100%; }
.btn.good { background: var(--good); box-shadow: 0 4px 0 var(--good-d); }
.btn.bad { background: var(--bad); box-shadow: 0 4px 0 var(--bad-d); }
.btn.ghost { background: var(--card); color: var(--ink); border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line); }
.btn.maroon { background: var(--maroon); box-shadow: 0 4px 0 var(--maroon-d); }
.btn[disabled] { background: #e7ded6; color: #b3a69c; box-shadow: 0 4px 0 #d6cbc1; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 24px; padding: 6px; cursor: pointer; line-height: 1; color: var(--muted); }
.speak { border: 0; cursor: pointer; width: 52px; height: 52px; border-radius: 14px; background: var(--blue); color: #fff; font-size: 24px; box-shadow: 0 4px 0 #1a4590; display: inline-grid; place-items: center; flex: none; }
.speak:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a4590; }
.speak.small { width: 36px; height: 36px; font-size: 17px; border-radius: 10px; box-shadow: 0 3px 0 #1a4590; }
.speak.slow { background: #6e8fd6; box-shadow: 0 4px 0 #4767ae; }
.speak.playing { animation: pulse .6s infinite alternate; }
@keyframes pulse { to { filter: brightness(1.25); } }

/* ---------- cards */
.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--r); padding: 16px; margin: 12px 0; }
.card h2, .card h3 { margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #f3e9df; color: var(--muted); margin: 2px 4px 2px 0; }
.chip.o-inh { background: #fde7d3; color: #9a4a0a; } .chip.o-skt { background: #f4dde6; color: var(--maroon); }
.chip.o-pali { background: #f7e6c8; color: #87600d; } .chip.o-tam { background: #dcefe9; color: var(--teal); }
.chip.o-por { background: #dfe8fa; color: #234a9a; } .chip.o-dut { background: #ffe6d1; color: #b24c00; }
.chip.o-eng { background: #e7e3f8; color: #4b3a9e; } .chip.o-coin { background: #e8f4d8; color: #3f6b12; }
.chip.unsure { background: #fff3c4; color: #8a6d00; }

/* ---------- course path */
.unit { margin: 18px 0 8px; }
.unit-head { border-radius: var(--r); padding: 14px 16px; color: #fff; background: var(--brand); box-shadow: 0 4px 0 var(--brand-d); }
.unit-head h2 { margin: 0; font-size: 19px; } .unit-head p { margin: 2px 0 0; opacity: .9; font-size: 14px; }
.unit:nth-child(3n+2) .unit-head { background: var(--maroon); box-shadow: 0 4px 0 var(--maroon-d); }
.unit:nth-child(3n+3) .unit-head { background: var(--teal); box-shadow: 0 4px 0 #00332f; }
.unit.locked .unit-head { background: #cfc3b8; box-shadow: 0 4px 0 #b5a89c; }
.path { display: flex; flex-direction: column; align-items: center; padding: 14px 0 4px; }
.node { position: relative; width: 74px; height: 70px; border-radius: 50%; border: 0; cursor: pointer; background: var(--brand); box-shadow: 0 6px 0 var(--brand-d); color: #fff; font-size: 28px; margin: 8px 0 22px; display: grid; place-items: center; }
.node.done { background: var(--gold); box-shadow: 0 6px 0 #c48a00; }
.node.locked { background: #e3d9cf; box-shadow: 0 6px 0 #cbbfb3; color: #b5a89c; cursor: default; }
.node.current { animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
.node .lbl { position: absolute; top: 76px; width: 160px; left: 50%; transform: translateX(-50%); font-size: 13px; font-weight: 700; color: var(--ink); text-align: center; line-height: 1.2; }
.node.locked .lbl { color: var(--muted); }
.node .kind { font-size: 26px; line-height: 1; font-family: var(--si); }

/* ---------- lesson player */
.player { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.player-top { padding: calc(12px + var(--safe-t)) 14px 8px; display: flex; align-items: center; gap: 12px; }
.bar { flex: 1; height: 16px; border-radius: 99px; background: #eee3d8; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 99px; transition: width .35s; box-shadow: inset 0 -4px 0 rgba(0,0,0,.08); }
.stage { flex: 1; overflow-y: auto; padding: 6px 18px 18px; }
.stage h3.prompt { font-size: 19px; margin: 6px 0 14px; }
.foot { padding: 14px 18px calc(16px + var(--safe-b)); border-top: 2px solid transparent; }
.foot.good { background: var(--good-bg); border-color: #bfe8cd; }
.foot.bad { background: var(--bad-bg); border-color: #f6c4c4; }
.foot .verdict { font-weight: 800; font-size: 19px; margin-bottom: 4px; }
.foot.good .verdict { color: var(--good-d); } .foot.bad .verdict { color: var(--bad-d); }
.foot .answer { margin-bottom: 10px; }

.big-glyph { font-family: var(--si); font-size: 120px; line-height: 1.15; text-align: center; margin: 4px 0; }
.big-si { font-family: var(--si); font-size: 40px; line-height: 1.3; }
.mid-si { font-family: var(--si); font-size: 28px; line-height: 1.35; }

.options { display: grid; gap: 10px; }
.options.grid2 { grid-template-columns: 1fr 1fr; }
.opt { border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 14px 12px; cursor: pointer; box-shadow: 0 4px 0 var(--line); text-align: center; font-size: 18px; min-height: 58px; }
.opt.si-opt { font-family: var(--si); font-size: 30px; padding: 8px; }
.opt.sel { border-color: var(--blue); background: #e8f0ff; box-shadow: 0 4px 0 #9fbcf2; }
.opt.right { border-color: var(--good); background: var(--good-bg); box-shadow: 0 4px 0 #9edbb4; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); box-shadow: 0 4px 0 #f0a8a8; }
.opt.gone { visibility: hidden; }
.opt:active { transform: translateY(2px); }

.tiles { display: flex; flex-wrap: wrap; gap: 8px; min-height: 56px; }
.answer-line { border-bottom: 2px solid var(--line); padding: 6px 0 10px; margin-bottom: 16px; min-height: 64px; }
.tile { border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 12px; font-size: 22px; font-family: var(--si); cursor: pointer; box-shadow: 0 3px 0 var(--line); }
.tile.ghost { color: transparent; background: #efe6dd; box-shadow: none; border-color: #efe6dd; }
.tile .g { display: block; font-family: var(--ui); font-size: 11px; color: var(--muted); }

.intro { text-align: center; }
.intro .rom-line { font-size: 22px; color: var(--muted); }
.intro .meaning { font-size: 22px; font-weight: 700; margin: 4px 0 10px; }
.say-box { background: #fff3e4; border-radius: 14px; padding: 12px 14px; text-align: left; margin: 10px 0; }
.ety { text-align: left; background: #f7f1ff; border: 2px solid #e6dcf7; border-radius: 14px; padding: 10px 14px; margin: 10px 0; }
.ety summary { cursor: pointer; font-weight: 700; color: #4b3a9e; }
.parts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; justify-content: center; }
.part { background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 4px 10px; text-align: center; }
.part .si { font-size: 22px; display: block; }
.part .g { font-size: 12px; color: var(--muted); }
.plus { align-self: center; font-weight: 800; color: var(--muted); }

.gloss { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; margin: 8px 0; }
.gloss span { text-align: center; }
.gloss .si { display: block; font-size: 24px; }
.gloss .g { font-size: 12px; color: var(--muted); display: block; }
.tapword { cursor: pointer; border-bottom: 2px dotted #d7c7b8; }

canvas.trace { width: 100%; max-width: 320px; aspect-ratio: 1; display: block; margin: 0 auto; background: var(--card); border: 2px solid var(--line); border-radius: 20px; touch-action: none; }

.done-screen { text-align: center; padding-top: 30px; }
.done-screen .stat { display: inline-block; margin: 10px; padding: 12px 16px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); min-width: 110px; }
.done-screen .stat b { display: block; font-size: 26px; }

/* ---------- sheets & toasts */
.sheet-bg { position: fixed; inset: 0; background: rgba(43,27,32,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); max-height: 88dvh; overflow-y: auto; }
.sheet h3 { margin-top: 0; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-weight: 600; max-width: 90vw; }
input, textarea, select { font: inherit; width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); color: var(--ink); }
input:focus, textarea:focus { outline: none; border-color: var(--brand); }
label { display: block; font-weight: 700; margin: 12px 0 4px; }

/* ---------- letters chart */
.chart { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.cell { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 6px 2px 4px; text-align: center; cursor: pointer; box-shadow: 0 3px 0 var(--line); }
.cell .si { font-size: 30px; display: block; line-height: 1.25; }
.cell .r { font-size: 12px; color: var(--muted); }
.cell.known { border-color: #f2c48f; background: #fff6ea; }
.cell.mixed .si { color: var(--maroon); }
.cell.locked { opacity: .45; }
.seg { display: flex; gap: 6px; background: #efe5da; border-radius: 12px; padding: 4px; margin: 6px 0 12px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 4px; font-weight: 700; color: var(--muted); cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- grammar */
.g-body p { margin: 8px 0; }
.g-body b { color: var(--maroon); }
.g-body .si { font-size: 1.15em; }
.demo { background: #fffdf8; border: 2px dashed #e7c9a8; border-radius: var(--r); padding: 14px; margin: 14px 0; }
.demo h4 { margin: 0 0 8px; color: var(--brand-d); text-transform: uppercase; font-size: 13px; letter-spacing: .06em; }
.table { width: 100%; border-collapse: collapse; }
.table td, .table th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.table .si { font-size: 22px; }
.where-scene { position: relative; height: 150px; margin: 8px 0; }
.where-scene .thing, .where-scene .place { position: absolute; font-size: 60px; transition: all .45s cubic-bezier(.5,1.6,.5,1); left: 50%; transform: translateX(-50%); }
.where-scene .place { bottom: 10px; font-size: 80px; }
.sentence-out { text-align: center; margin: 10px 0; }
.sentence-out .si { font-size: 30px; }

/* ---------- explore */
.word-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.word-row .si { font-size: 24px; min-width: 90px; }
.fam-web { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.fam-web .node-w { border: 2px solid var(--line); background: var(--card); border-radius: 14px; padding: 6px 12px; cursor: pointer; text-align: center; box-shadow: 0 3px 0 var(--line); }
.fam-web .node-w .si { font-size: 22px; display: block; }
.fam-web .node-w .g { font-size: 12px; color: var(--muted); }

/* ---------- sounds lab */
.lab-wrap { background: #fff; border: 2px solid var(--line); border-radius: var(--r); overflow: hidden; }
canvas.lab { width: 100%; aspect-ratio: 600 / 600; display: block; touch-action: none; background: #fff; }
.lab-steps .step { border-left: 4px solid var(--line); padding: 4px 0 4px 12px; margin: 10px 0; }
.lab-steps .step.on { border-color: var(--brand); }

/* ---------- signs */
.signboard { border-radius: 10px; padding: 16px 12px; text-align: center; color: #fff; font-family: var(--si); font-size: 30px; font-weight: 700; border: 4px solid rgba(255,255,255,.75); outline: 2px solid rgba(0,0,0,.15); margin: 10px 0; line-height: 1.3; }
.signboard.blue { background: #1f4fa3; } .signboard.maroon { background: var(--maroon); } .signboard.green { background: #116b3a; }
.signboard.yellow { background: #f6c21b; color: #1d1d1d; } .signboard.white { background: #fafafa; color: #222; border-color: #222; }
.signboard.red { background: #c62828; }

/* ---------- auth */
.auth { padding: 30px 18px; text-align: center; }
.auth form { text-align: left; margin-top: 10px; }
.logo { font-family: var(--si); font-size: 64px; font-weight: 800; color: var(--maroon); line-height: 1.1; }
.err { color: var(--bad-d); font-weight: 700; min-height: 1.4em; margin: 8px 0; }

@media (min-width: 600px) { .tabs a { max-width: 130px; } }

@media (prefers-reduced-motion: reduce) { .node.current { animation: none; } .bar > i { transition: none; } }
