/* ---------- tokens ---------- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #15171c;
  --muted: #646b78;
  --border: #dde1e8;
  --accent: #3156d3;
  --accent-text: #ffffff;
  --accent-soft: #e5ebff;
  --good: #16803c;
  --good-soft: #e3f5e9;
  --warn: #9a6200;
  --warn-soft: #fff3d6;
  --bad: #c22b2b;
  --bad-soft: #fde8e8;
  --flame: #e8590c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Bengali", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --text: #eceef2;
    --muted: #9aa1ad;
    --border: #2c313a;
    --accent: #7b9cff;
    --accent-text: #0f1115;
    --accent-soft: #1f2a4a;
    --good: #4cc97a;
    --good-soft: #15301f;
    --warn: #f0b544;
    --warn-soft: #33290f;
    --bad: #ff7272;
    --bad-soft: #3a1717;
    --flame: #ff8a3d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 88px);
}
.page.study { padding-bottom: calc(env(safe-area-inset-bottom) + 16px); min-height: 100dvh; display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: .5rem; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 6px);
  z-index: 10;
}
.tabbar a {
  flex: 1; text-align: center; color: var(--muted);
  font-size: .75rem; padding: 4px 0;
}
.tabbar a .ico { display: block; font-size: 1.3rem; line-height: 1.3; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: 600 1rem var(--font); cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
input[type=text], input[type=password], select {
  width: 100%;
  font: 18px var(--font); /* >=16px stops iOS from zooming */
  padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
input[type=text]:focus, input[type=password]:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
label.field { display: block; }
label.field > span { display: block; font-weight: 600; margin-bottom: .3rem; }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.good > i { background: var(--good); }

.pill {
  display: inline-block; font-size: .75rem; font-weight: 600;
  padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
}
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.flash { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 10px; }

/* ---------- home ---------- */
.streak { display: flex; align-items: center; gap: 12px; }
.streak .flame { font-size: 2rem; }
.streak .num { font-size: 1.6rem; font-weight: 700; }
.lang-card .head { display: flex; align-items: center; gap: .6rem; }
.lang-card .flag { font-size: 1.6rem; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .75rem 0; text-align: center; }
.stats3 b { display: block; font-size: 1.2rem; }
.stats3 span { font-size: .75rem; color: var(--muted); }
.reco { border: 2px solid var(--accent); }

/* ---------- study ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.topbar .bar { flex: 1; }
.combo { font-weight: 700; color: var(--flame); min-width: 2.5rem; text-align: right; font-size: .9rem; }
.iconbtn { background: none; border: 0; font-size: 1.3rem; color: var(--muted); padding: 6px; cursor: pointer; min-width: 40px; min-height: 40px; }

.stage { flex: 1; display: flex; flex-direction: column; }
.prompt-label { font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: .5rem; }
.word { font-size: 2.2rem; font-weight: 700; line-height: 1.15; word-break: break-word; }
.word.bn { font-size: 2.4rem; }
.rom { color: var(--muted); font-size: 1.05rem; }
.meta { color: var(--muted); font-size: .9rem; }
.sentence { font-size: 1.15rem; margin-top: .75rem; }
.sentence .rom { font-size: .95rem; }
.sentence .tr { color: var(--muted); font-size: .95rem; margin-top: .2rem; }
.sentence mark { background: var(--accent-soft); color: inherit; border-radius: 4px; padding: 0 2px; }
.blank { display: inline-block; min-width: 3.5em; border-bottom: 2px solid var(--accent); text-align: center; color: var(--accent); }
.hint { color: var(--muted); font-size: .9rem; margin-top: .4rem; }

.options { display: grid; gap: 10px; margin-top: 1rem; }
.opt {
  text-align: left; min-height: 54px; padding: 10px 14px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: 500 1.05rem var(--font); cursor: pointer; touch-action: manipulation;
}
.opt .rom { display: block; font-size: .85rem; }
.opt.correct { background: var(--good-soft); border-color: var(--good); }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); }

.answer-row { margin-top: 1rem; }
.actions { margin-top: auto; padding-top: 1rem; display: grid; gap: 10px; }

.feedback { border-radius: var(--radius); padding: 14px 16px; margin-top: 1rem; }
.feedback.good { background: var(--good-soft); }
.feedback.warn { background: var(--warn-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback .title { font-weight: 700; margin-bottom: .25rem; }
.feedback.good .title { color: var(--good); }
.feedback.warn .title { color: var(--warn); }
.feedback.bad .title { color: var(--bad); }
.feedback .expected { font-size: 1.2rem; font-weight: 700; }

.tiles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: .75rem; min-height: 52px; }
.tiles.built { padding: 8px; border-radius: 12px; border: 1px dashed var(--border); }
.tile {
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); font: 500 1.05rem var(--font); color: var(--text); cursor: pointer;
}
.tile .rom { display: block; font-size: .75rem; }
.tile.used { visibility: hidden; }

.summary .big { font-size: 2.6rem; font-weight: 800; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: .35rem 1rem; }

/* placement */
.yn { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: auto; }
.yn .btn { min-height: 64px; font-size: 1.1rem; }

/* progress chart */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 90px; margin-top: .5rem; }
.chart i { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.chart i.zero { background: var(--surface-2); }
.bands { display: grid; gap: 6px; }
.bands .row span:first-child { width: 4.5rem; font-size: .8rem; color: var(--muted); }
.bands .bar { flex: 1; }

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-weight: 600;
  z-index: 20; max-width: calc(100vw - 32px);
}

/* script course */
.glyph { font-family: "Noto Sans Bengali", "Kohinoor Bangla", var(--font); font-weight: 600; line-height: 1.2; }
.opt.opt-glyph { font-size: 2.2rem; text-align: center; min-height: 72px; }
.rom-toggle { padding: 0; min-height: 28px; font-size: .8rem; }
.script-row { display: flex; align-items: center; gap: .75rem; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.script-row .bar { flex: 1; }

/* motivation */
.quest { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.quest .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; color: var(--good); flex: none; }
.quest.done .check { border-color: var(--good); background: var(--good-soft); }
.league-mini { display: block; color: var(--text); }
.league-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.league-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.league-table tr.me td { font-weight: 700; color: var(--accent); }
.league-table tr.promo td:first-child { box-shadow: inset 3px 0 var(--good); }
.league-table tr.demo td:first-child { box-shadow: inset 3px 0 var(--bad); }
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge { text-align: center; padding: 10px 4px; border-radius: 12px; background: var(--surface-2); font-size: .75rem; }
.badge .ico { font-size: 1.6rem; display: block; }
.badge.locked { opacity: .35; filter: grayscale(1); }
.delta-up { color: var(--good); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }

/* library + reader */
.segmented { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font: 600 .95rem var(--font); color: var(--muted); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); color: var(--text); }
.list-row:last-child { border-bottom: 0; }
.list-row .t { flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-2); flex: none; }
.dot.learning { background: var(--warn); }
.dot.known { background: var(--good); }
.md h3, .md h4 { margin: 1rem 0 .4rem; }
.md p { margin: .5rem 0; }
.md ul { margin: .4rem 0; padding-left: 1.2rem; }
.md blockquote { margin: .5rem 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 6px; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.table-wrap { overflow-x: auto; margin: .5rem 0; }
.md-table { border-collapse: collapse; font-size: .9rem; min-width: 100%; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; white-space: nowrap; }
.md-table th { background: var(--surface-2); }
.reading p { font-size: 1.15rem; line-height: 1.7; margin: 0 0 .9rem; }
.reading .w { cursor: pointer; border-radius: 4px; }
.reading .w.new { text-decoration: underline dotted var(--accent); text-underline-offset: 4px; }
.reading .w.sel { background: var(--accent-soft); }
.reading .rom { display: block; font-size: .9rem; margin-top: -.5rem; margin-bottom: .9rem; }
.reading .tr { color: var(--muted); font-size: .95rem; margin: -.4rem 0 1rem; }
.popover { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); z-index: 30; max-width: 536px; margin: 0 auto; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; margin: 6px 0; }
.bubble.npc { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.you { background: var(--accent); color: var(--accent-text); margin-left: auto; border-bottom-right-radius: 4px; }
.bubble .tr { font-size: .85rem; opacity: .75; }
.chat { display: flex; flex-direction: column; }

/* keep wide tables inside the phone width */
.stage, .actions, .actions > *, .card { min-width: 0; }
.table-wrap { max-width: 100%; }
html, body { overflow-x: hidden; }

/* ---- arcade ---- */
.locked { opacity: .6; }
.skill-ico { font-size: 1.8rem; width: 2.4rem; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 99px; padding: 6px 10px; font-size: .8rem; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.arcade-mini { display: block; color: var(--text); }
.stars { color: #e0a100; letter-spacing: 1px; }
.drill-q { font-size: 2.4rem; font-weight: 700; text-align: center; margin: 1.5rem 0 .5rem; word-break: break-word; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .04em; }
.drill-q.mono { font-size: 1.8rem; }
.staff-wrap { text-align: center; color: var(--text); margin: .5rem 0; }
.staff-wrap svg { width: 100%; max-width: 320px; height: auto; }
.staff-wrap svg.piano { max-width: 360px; }
.fact-img { display: block; max-width: 100%; max-height: 38vh; margin: 0 auto; border-radius: 10px; object-fit: contain; }
.fact-img:not(.photo) { max-height: 160px; border: 1px solid var(--border); border-radius: 4px; background: #fff; }
.src { font-size: .75rem; color: var(--muted); }
