/* Memory Trainer – calm, big, forgiving. Mobile first. */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1d2740;
  --muted: #6a7794;
  --line: #e3e8f3;
  --accent: #4c6ef5;
  --accent-ink: #ffffff;
  --good: #2fb27a;
  --soft: #eef1fb;
  --warn: #f5a524;
  --danger: #d9534f;
  --radius: 20px;
  --shadow: 0 2px 10px rgba(30, 45, 90, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121624;
    --card: #1b2136;
    --ink: #eef1fb;
    --muted: #9aa7c7;
    --line: #2a3250;
    --accent: #7b95ff;
    --accent-ink: #0f1424;
    --good: #46d69b;
    --soft: #252d4a;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', 'Noto Sans Sinhala', 'Nirmala UI', 'Iskoola Pota', Roboto, sans-serif;
  line-height: 1.45; -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); }
h1, h2, p { margin: 0; }
h1 { font-size: 1.25rem; font-weight: 700; flex: 1; text-align: center; }
h2 { font-size: 1.15rem; }
small { color: var(--muted); }
.muted { color: var(--muted); font-size: .95rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 8px; padding: 6px 0 12px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; background: var(--card); color: var(--ink);
  font-size: 1.25rem; box-shadow: var(--shadow); cursor: pointer; flex: none;
}
.icon-btn.ph { visibility: hidden; }

/* generic */
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; display: flex; flex-direction: column; gap: 12px; }
.section-title { margin: 8px 4px 10px; color: var(--muted); font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; }
.chip { display: inline-block; align-self: flex-start; padding: 4px 12px; border-radius: 99px; background: var(--soft); font-size: .85rem; font-weight: 600; }
.chip.good { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--good); }
.chip.fire { background: #fff1e0; color: #c25e00; }
@media (prefers-color-scheme: dark) { .chip.fire { background: #3a2a14; color: #ffb35c; } }

.btn {
  min-height: 52px; padding: 12px 20px; border-radius: 16px; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.soft { background: var(--soft); border-color: transparent; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.big { min-height: 64px; font-size: 1.15rem; width: 100%; }
.btn:disabled { opacity: .5; }

/* home */
.hero { align-items: center; text-align: center; background: linear-gradient(135deg, #4c6ef5, #7b61ff); color: #fff; }
.hero .chip { align-self: center; background: rgba(255,255,255,.22); color: #fff; }
.hero .chip.fire { background: rgba(255,255,255,.9); color: #b45a00; }
.hero-emoji { font-size: 3rem; }
.greet { font-size: 1.15rem; font-weight: 600; }
.plan { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plan-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--soft); cursor: pointer; }
.plan-item .pi { font-size: 1.5rem; }
.plan-item .pn { flex: 1; font-weight: 600; }
.plan-item .pc { color: var(--muted); font-size: 1.2rem; }
.plan-item.done { opacity: .6; }
.plan-item.done .pc { color: var(--good); font-weight: 700; }
.success { text-align: center; font-weight: 700; color: var(--good); padding: 8px; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mcard-menu {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 16px; border-radius: var(--radius); border: 0; background: var(--card); color: var(--ink);
  box-shadow: var(--shadow); font: inherit; cursor: pointer; min-height: 110px;
}
.mcard-menu .mi { font-size: 1.8rem; }
.mcard-menu.soon { opacity: .55; }

/* lists */
.list { display: flex; flex-direction: column; gap: 10px; }
.row-card, .prow {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); border: 0; text-align: left; color: var(--ink); font: inherit;
}
.row-card { cursor: pointer; }
.row-card.locked { opacity: .55; }
.ri { font-size: 1.7rem; min-width: 2.4rem; text-align: center; }
.rt { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.stats { flex-direction: row; justify-content: space-around; text-align: center; }
.stats b { font-size: 1.5rem; display: block; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 34px; width: 80px; }
.spark i { flex: 1; background: var(--accent); border-radius: 3px; opacity: .8; }

/* settings */
.srow { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sl { display: flex; flex-direction: column; gap: 2px; }
.switch { width: 54px; height: 32px; border-radius: 99px; border: 0; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--good); }
.switch.on i { transform: translateX(22px); }
.segs { display: inline-flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 2px; }
.seg { border: 0; background: transparent; color: var(--ink); font: inherit; font-weight: 600; padding: 6px 12px; border-radius: 10px; cursor: pointer; min-height: 36px; }
.seg.on { background: var(--accent); color: var(--accent-ink); }
.topbar .segs { flex: none; }

/* play shell */
.play { display: flex; flex-direction: column; gap: 10px; min-height: calc(100dvh - 24px); }
.prog { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); }
.prog-bar { flex: 1; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.prog-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }
.banner { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--ink); padding: 8px 14px; border-radius: 12px; text-align: center; font-weight: 600; font-size: .95rem; }
.banner.good { background: color-mix(in srgb, var(--good) 22%, transparent); }
.banner.static { margin: 4px 0; }
.status { min-height: 2.2rem; text-align: center; font-size: 1.2rem; font-weight: 600; }
.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.actions { display: flex; justify-content: center; min-height: 0; }
.actions .btn { min-width: 200px; }
.easier { margin-top: auto; align-self: center; min-height: 44px; font-size: .95rem; opacity: .9; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600; box-shadow: var(--shadow); z-index: 10; }

.intro, .results { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.intro .chip, .intro .btn, .results .btns { align-self: stretch; }
.intro .chip { align-self: center; }
.intro-icon { font-size: 4rem; }
.check { display: flex; align-items: center; gap: 8px; font-size: 1rem; }
.check input { width: 22px; height: 22px; }
.stars { font-size: 3rem; letter-spacing: .1em; }
.results .btns { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

/* timer + breathing */
.timerbar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.timerbar i { display: block; height: 100%; width: 100%; background: var(--accent); animation: shrink linear forwards; }
@keyframes shrink { to { width: 0; } }
.breathe { width: 140px; height: 140px; margin: 10px auto; border-radius: 50%; background: radial-gradient(circle, var(--accent), transparent 70%); opacity: .6; animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(.7); } 50% { transform: scale(1.1); } }
.big-emoji { font-size: 7rem; text-align: center; line-height: 1.1; }

/* Watch & Repeat */
.pads { display: grid; gap: 14px; }
.pads.p3 { grid-template-columns: repeat(3, 1fr); }
.pads.p4 { grid-template-columns: repeat(2, 1fr); }
.pad {
  min-height: 120px; border-radius: 24px; border: 0; background: color-mix(in srgb, var(--c) 45%, var(--card));
  color: #fff; font-size: 2.6rem; cursor: pointer; transition: transform .12s, filter .12s, box-shadow .12s;
}
.pads.p3 .pad { min-height: 150px; }
.pad .shape { opacity: .85; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.pad.lit { background: var(--c); transform: scale(1.06); box-shadow: 0 0 28px var(--c); filter: brightness(1.1); }
.pad:disabled { cursor: default; }

/* What's Missing / Pairs / choices */
.board { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 12px; }
.slot { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 3rem; background: var(--card); border-radius: 18px; box-shadow: var(--shadow); }
.slot.empty { background: transparent; box-shadow: none; border: 3px dashed var(--line); }
.board.cards { gap: 10px; }
.mcard { aspect-ratio: 1; border: 0; border-radius: 16px; background: var(--accent); color: #fff; font-size: 2.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; transition: transform .15s; }
.mcard .face { display: none; }
.mcard.up, .mcard.done { background: var(--card); box-shadow: var(--shadow); }
.mcard.up .face, .mcard.done .face { display: block; }
.mcard.up .back, .mcard.done .back { display: none; }
.mcard.done { outline: 3px solid var(--good); }
.choices { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 12px; }
.choice { aspect-ratio: 1; border-radius: 20px; border: 3px solid var(--line); background: var(--card); font-size: 3.2rem; cursor: pointer; box-shadow: var(--shadow); transition: transform .1s; color: var(--ink); }
.choice:active { transform: scale(.95); }
.choice.good { border-color: var(--good); background: color-mix(in srgb, var(--good) 20%, var(--card)); }
.choice.dim { opacity: .3; }

/* Number Echo */
.digits-show { font-size: 3.6rem; font-weight: 800; text-align: center; letter-spacing: .12em; word-break: break-all; }
.digits-show.sm { font-size: 2.2rem; }
.digits-show.good { color: var(--good); }
.compare { display: flex; justify-content: space-around; text-align: center; }
.dboxes { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.dbox { width: 44px; height: 56px; border-radius: 12px; border: 3px solid var(--line); background: var(--card); display: flex; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: 700; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { min-height: 62px; border-radius: 16px; border: 0; background: var(--card); color: var(--ink); font: inherit; font-size: 1.6rem; font-weight: 700; box-shadow: var(--shadow); cursor: pointer; }
.key:active { transform: scale(.95); }
.key-ok { background: var(--good); color: #fff; }
.key-ok:disabled { opacity: .35; }

/* N-back */
.nb { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(100%, 340px, 44dvh); }
.cell { aspect-ratio: 1; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); transition: background .1s; }
.cell.on { background: var(--accent); box-shadow: 0 0 22px var(--accent); }
.cell.ghost { outline: 3px dashed color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -6px; }
.cell.target { outline: 3px solid var(--good); outline-offset: -5px; }
.speaker { width: 140px; height: 140px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; transition: background .1s; }
.speaker.small { width: 84px; height: 84px; }
.speaker .sp-ico { font-size: 2.6rem; }
.speaker.small .sp-ico { font-size: 1.7rem; }
.speaker .sp-letter { font-size: 2rem; font-weight: 800; min-height: 1.2em; }
.speaker.on { background: var(--accent); box-shadow: 0 0 22px var(--accent); }
.speaker.on .sp-letter { color: var(--accent-ink); }
.ghost-txt { min-height: 1.4rem; font-size: .95rem; color: var(--muted); }
.fb { min-height: 1.6rem; font-weight: 700; text-align: center; }
.fb.good { color: var(--good); }
.fb.soft { color: var(--muted); }
.resp { display: grid; grid-template-columns: 1fr; gap: 12px; width: 100%; }
.resp.two { grid-template-columns: 1fr 1fr; }
.resp-btn { min-height: 84px; font-size: 1.3rem; position: relative; user-select: none; touch-action: manipulation; }
.resp-btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.resp-btn.neutral { background: var(--soft); }
.resp-btn kbd { position: absolute; top: 6px; right: 10px; font-size: .7rem; opacity: .5; font-family: inherit; }
@media (pointer: coarse) { .resp-btn kbd { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .breathe { animation: none; }
  .pad, .btn, .choice { transition: none; }
}

/* ---------- Phase 2 ---------- */
.choice.text { aspect-ratio: auto; min-height: 84px; font-size: 1.4rem; font-weight: 700; }
.slot.chg { outline: 3px solid var(--warn); outline-offset: -4px; }

/* Block Tap (Corsi) */
.corsi-board { position: relative; width: min(100%, 360px, 48dvh); aspect-ratio: 1; margin: 0 auto; background: var(--soft); border-radius: 24px; }
.cblock { position: absolute; width: 21%; aspect-ratio: 1; transform: translate(-50%, -50%); border: 0; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); cursor: pointer; transition: transform .12s, background .12s; padding: 0; }
.cblock.lit { background: var(--accent); transform: translate(-50%, -50%) scale(1.12); box-shadow: 0 0 26px var(--accent); }
.cblock:disabled { cursor: default; }

/* tap-in-order tiles (words, numbers + letters) */
.tiles { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 10px; }
.tile { position: relative; min-height: 64px; padding: 10px 8px; border-radius: 16px; border: 3px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 1.25rem; font-weight: 700; cursor: pointer; box-shadow: var(--shadow); }
.tile.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--card)); }
.tile .badge { position: absolute; top: 4px; right: 6px; min-width: 1.3em; font-style: normal; font-size: .8rem; font-weight: 800; color: var(--accent); }
.word-show { font-size: 3rem; font-weight: 800; text-align: center; word-break: break-word; }
.word-show.sm { font-size: 1.6rem; }
.answer { text-align: center; display: flex; flex-direction: column; gap: 6px; }

/* N-back colour channel */
.cell.on.col { background: var(--c); box-shadow: 0 0 22px var(--c); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 2rem; }
.cell.ghost.gcol { outline-color: var(--gc); color: var(--gc); display: flex; align-items: center; justify-content: center; font-size: 1.6rem; opacity: .9; }
.resp.three { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.resp.three .resp-btn { font-size: 1.05rem; padding: 10px 4px; }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 9px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--accent); opacity: .9; }
.chart .bar.zero { fill: var(--line); }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .dot { fill: var(--accent); }
.weekgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.weekgrid > div { display: flex; flex-direction: column; gap: 2px; }
.weekgrid b { font-size: 1.35rem; }
.pgame { display: flex; flex-direction: column; }
.pgame .prow { width: 100%; cursor: pointer; }
.pdetail { background: var(--card); border-radius: 0 0 var(--radius) var(--radius); padding: 10px 14px 14px; margin: -8px 6px 0; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
