/* Smart Maths Learning. Design tokens first, then layout, then components. Light and dark follow the device. */
:root {
  --bg: #f3f5fc; --card: #ffffff; --ink: #172036; --muted: #5d6a86; --line: #e2e7f3; --soft: #edf0fb;
  --brand: #4f6df5; --brand-2: #8b5cf6; --brand-ink: #ffffff; --brand-soft: #e8edff;
  --grad: linear-gradient(135deg, #4f6df5 0%, #7c5cf0 55%, #a855f7 100%);
  --glow: rgba(124, 92, 240, .13);
  --ok: #1f8a3b; --ok-soft: #e1f6e8; --bad: #cf2f35; --bad-soft: #fde8e9; --warn: #b36b00; --warn-soft: #fff0d3; --info: #4f6df5;
  --focus: #4f6df566;
  --lvl-needs: #ea4d54; --lvl-practising: #f5a524; --lvl-mastered: #2ea44f; --lvl-start: #98a2b8;
  --radius: 20px; --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(23, 32, 54, .05), 0 8px 28px rgba(23, 32, 54, .06);
  --shadow-lg: 0 2px 6px rgba(23, 32, 54, .08), 0 18px 48px rgba(23, 32, 54, .14);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1222; --card: #161c31; --ink: #e9edf9; --muted: #9ba7c4; --line: #252f52; --soft: #1d2542;
    --brand: #8aa0ff; --brand-ink: #0d1222; --brand-soft: #232e58; --glow: rgba(124, 92, 240, .2);
    --ok: #62d27e; --ok-soft: #173424; --bad: #ff8086; --bad-soft: #3b1d23; --warn: #f5b84a; --warn-soft: #3a2d12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px rgba(0, 0, 0, .25); --shadow-lg: 0 18px 48px rgba(0, 0, 0, .5);
    --lvl-start: #6b7794;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; color: var(--ink); font: 17px/1.55 var(--font); min-height: 100vh;
  background: radial-gradient(1100px 520px at 8% -8%, var(--glow), transparent 70%), radial-gradient(900px 480px at 100% 0%, rgba(79, 109, 245, .08), transparent 70%), var(--bg); }
body.stage-open { overflow: hidden; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 3vw, 2.2rem); font-weight: 800; } h2 { font-size: 1.22rem; font-weight: 700; } h3 { font-size: 1.02rem; font-weight: 700; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.big-text { font-size: 1.2rem; }

/* ---------- shell: full width ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--card) 86%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.topbar-in { padding: 10px clamp(16px, 3vw, 48px); display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 10px; }
.brand .logo { width: 36px; height: 36px; border-radius: 11px; background: var(--grad); color: #fff; display: grid; place-items: center; font-size: 1.1rem; box-shadow: 0 6px 16px rgba(124, 92, 240, .35); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.nav a, .nav button { padding: 8px 14px; border-radius: 12px; text-decoration: none; color: var(--muted); background: none; border: 0; cursor: pointer; font-weight: 500; }
.nav a:hover, .nav button:hover { background: var(--soft); color: var(--ink); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
main { padding: 26px clamp(16px, 3vw, 56px) 80px; max-width: 1920px; margin: 0 auto; }
.pagehead { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.pagehead .grow { flex: 1 1 280px; }
.crumbs { font-size: .86rem; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card h2 { display: flex; align-items: center; gap: 8px; }
.card .sub { color: var(--muted); font-size: .92rem; margin: -2px 0 14px; }
.grid { display: grid; gap: 18px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid > .card + .card { margin-top: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; border-radius: 14px; border: 1px solid transparent; background: var(--grad); color: #fff; cursor: pointer; font-weight: 700; text-decoration: none; box-shadow: 0 6px 18px rgba(99, 102, 241, .28); transition: transform .12s, filter .12s; }
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: default; filter: none; transform: none; box-shadow: none; }
.btn.secondary { background: var(--soft); color: var(--ink); border-color: var(--line); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--brand); border-color: var(--line); box-shadow: none; }
.btn.danger { background: var(--bad-soft); color: var(--bad); box-shadow: none; }
.btn.big { padding: 15px 28px; font-size: 1.1rem; border-radius: 16px; }
.btn.small { padding: 7px 13px; font-size: .86rem; border-radius: 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 11px; border-radius: 99px; font-size: .82rem; font-weight: 700; background: var(--soft); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); } .chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); } .chip.info { background: var(--brand-soft); color: var(--brand); }
.chip.btnchip { cursor: pointer; border: 1px solid var(--line); background: var(--card); }
.chip.btnchip:hover { border-color: var(--brand); }
.chip.btnchip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chipbtn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px; padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: .9rem; }
.chipbtn:hover { border-color: var(--brand); color: var(--brand); }
label.field { display: block; margin: 12px 0; font-size: .88rem; color: var(--muted); font-weight: 500; }
label.field > input, label.field > select, label.field > textarea { display: block; width: 100%; margin-top: 5px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: 1rem; }
label.field > textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .86rem; }
label.check { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; font-size: .94rem; color: var(--ink); }
label.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; accent-color: var(--brand); }
.err { color: var(--bad); min-height: 1.3em; font-size: .94rem; margin-top: 6px; }
.notice { padding: 12px 16px; border-radius: 14px; background: var(--brand-soft); color: var(--ink); font-size: .94rem; }
.notice.warn { background: var(--warn-soft); } .notice.bad { background: var(--bad-soft); } .notice.ok { background: var(--ok-soft); }
.empty { text-align: center; padding: 34px 12px; color: var(--muted); }
.empty .big { font-size: 2.4rem; display: block; margin-bottom: 6px; }
table { width: 100%; border-collapse: collapse; font-size: .94rem; }
th { text-align: left; font-weight: 700; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.tablewrap { overflow-x: auto; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal & toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 28, .55); backdrop-filter: blur(3px); z-index: 70; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 24px; max-width: 580px; width: 100%; padding: 24px; box-shadow: var(--shadow-lg); max-height: calc(100vh - 32px); overflow-y: auto; }
.modal.wide { max-width: 860px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 14px; z-index: 80; box-shadow: var(--shadow-lg); max-width: 90vw; font-weight: 600; }

/* ---------- auth ---------- */
.authwrap { max-width: 480px; margin: 36px auto; }
.tabs { display: flex; gap: 6px; background: var(--soft); padding: 5px; border-radius: 14px; margin-bottom: 16px; }
.tabs button { flex: 1; padding: 10px; border: 0; background: none; border-radius: 10px; cursor: pointer; color: var(--muted); font-weight: 700; }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- home ---------- */
.hero { background: var(--grad); color: #fff; border-radius: 28px; padding: clamp(22px, 3vw, 40px); margin-bottom: 24px; position: relative; overflow: hidden; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; box-shadow: 0 20px 50px rgba(99, 102, 241, .3); }
.hero::after { content: "✏️ ➕ ➖ ✖️ ➗"; position: absolute; right: 24px; top: 10px; font-size: 2.6rem; opacity: .13; letter-spacing: 12px; white-space: nowrap; }
.hero h1 { color: #fff; margin: 0 0 4px; font-size: clamp(1.8rem, 3.4vw, 2.6rem); } .hero p { margin: 0; opacity: .9; font-size: 1.05rem; }
.hero .grow { flex: 1 1 320px; position: relative; z-index: 1; }
.hero .btn { background: #fff; color: var(--brand); box-shadow: 0 8px 22px rgba(0, 0, 0, .18); position: relative; z-index: 1; }
.avatar { width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; font-size: 1.6rem; font-weight: 800; color: #fff; flex: none; box-shadow: 0 6px 16px rgba(0, 0, 0, .15); }
.childcard { padding: 0; overflow: hidden; }
.childcard .top { padding: 20px 22px 6px; display: flex; gap: 14px; align-items: center; }
.childcard .body { padding: 6px 22px 22px; }
.childcard h2 { margin: 0; font-size: 1.35rem; }
.meter { height: 12px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--grad); border-radius: 99px; transition: width .5s; }
.meter.ok > i { background: linear-gradient(90deg, #2ea44f, #5fd07a); }
.statline { display: flex; gap: 26px; flex-wrap: wrap; margin: 14px 0; }
.statline b { display: block; font-size: 1.5rem; line-height: 1.2; }
.statline span { color: var(--muted); font-size: .82rem; }

/* ---------- KPI & dashboard layout ---------- */
.kpi { padding: 18px 20px; }
.kpi .label { color: var(--muted); font-size: .86rem; font-weight: 600; }
.kpi .value { font-size: 2.2rem; font-weight: 800; line-height: 1.15; letter-spacing: -.02em; }
.kpi .delta { font-size: .84rem; font-weight: 700; }
.delta.up { color: var(--ok); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }
.dash { display: grid; gap: 18px; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); align-items: start; margin-top: 18px; }
.dash > div > .card + .card { margin-top: 18px; }
@media (max-width: 1100px) { .dash { grid-template-columns: 1fr; } }

/* ---------- topic picker ---------- */
.topicgrid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.topic { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; cursor: pointer; display: flex; gap: 16px; align-items: center; box-shadow: var(--shadow); transition: transform .15s, border-color .15s, box-shadow .15s; }
.topic:hover { border-color: var(--brand); transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.topic b { display: block; font-size: 1.08rem; } .topic span { color: var(--muted); font-size: .86rem; }

/* ---------- verdicts, banners, hints (shared with practice) ---------- */
.verdict { display: flex; gap: 10px; align-items: baseline; padding: 10px 14px; border-radius: 14px; margin: 6px 0; background: var(--soft); }
.verdict .mark { font-weight: 800; width: 1.4em; text-align: center; flex: none; }
.verdict.correct { background: var(--ok-soft); } .verdict.correct .mark { color: var(--ok); }
.verdict.incorrect { background: var(--bad-soft); } .verdict.incorrect .mark { color: var(--bad); }
.verdict.needs_confirmation { background: var(--warn-soft); } .verdict.needs_confirmation .mark { color: var(--warn); }
.verdict.irrelevant, .verdict.incomplete, .verdict.unreadable { color: var(--muted); }
.verdict .txt { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.08rem; word-break: break-word; }
.banner { padding: 14px 16px; border-radius: 14px; margin: 10px 0; font-weight: 700; }
.banner.ok { background: var(--ok-soft); color: var(--ok); } .banner.bad { background: var(--bad-soft); color: var(--bad); } .banner.info { background: var(--brand-soft); color: var(--brand); }
.hint { background: var(--warn-soft); border-radius: 14px; padding: 11px 15px; margin-top: 8px; }
.pop { animation: pop .5s ease-out; }
@keyframes pop { 0% { transform: scale(.88); opacity: 0; } 60% { transform: scale(1.03); } 100% { transform: scale(1); opacity: 1; } }

/* ---------- THE WRITING STAGE: full screen ---------- */
.stage { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: radial-gradient(1000px 500px at 0% -10%, var(--glow), transparent 70%), var(--bg); }
.stage-top { display: flex; align-items: center; gap: 10px; padding: 10px clamp(12px, 2vw, 24px); background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.stage-tally { display: flex; gap: 8px; }
.stage-body { flex: 1; min-height: 0; display: grid; gap: 16px; padding: 16px clamp(12px, 2vw, 24px) 18px;
  grid-template-columns: minmax(360px, 32%) 1fr; grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "prompt canvas" "dock canvas"; }
.stage-prompt { grid-area: prompt; padding: 6px 4px 0; }
.stage-skill { color: var(--muted); font-size: .92rem; font-weight: 600; }
.stage-q { font-size: clamp(1.9rem, 3.6vw, 3.2rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin: 4px 0 6px; word-break: break-word; }
.stage-canvas { grid-area: canvas; position: relative; min-height: 0; }
.stage-dock { grid-area: dock; min-height: 0; overflow-y: auto; padding: 4px 6px 4px 2px; }
.dock-title { font-weight: 800; margin: 2px 0 6px; }
.pad-wrap { position: absolute; inset: 0; border-radius: 26px; border: 2px solid var(--line); background-color: var(--card); box-shadow: var(--shadow-lg); overflow: hidden;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 71px, var(--soft) 71px, var(--soft) 72px); }
.pad-wrap.pad-disabled { opacity: .7; }
.pad-canvas { display: block; touch-action: none; cursor: crosshair; }
.pad-hint { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 6px; color: var(--muted); pointer-events: none; font-size: 1.15rem; font-weight: 600; opacity: .7; }
.pad-hint-ico { font-size: 2.6rem; }
.toolbar { position: absolute; left: 16px; bottom: 16px; display: flex; gap: 8px; z-index: 2; }
.tool { display: inline-flex; gap: 6px; align-items: center; background: color-mix(in srgb, var(--card) 92%, transparent); border: 1px solid var(--line); border-radius: 99px; padding: 9px 16px; cursor: pointer; font-weight: 700; box-shadow: var(--shadow); backdrop-filter: blur(6px); }
.tool:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.tool:disabled { opacity: .4; cursor: default; }
.readback { margin: 2px 0; }
.read-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) 12px 30px; gap: 8px; align-items: center; margin: 7px 0; }
.read-n { width: 26px; height: 26px; border-radius: 50%; background: var(--soft); color: var(--muted); display: grid; place-items: center; font-weight: 700; font-size: .82rem; }
.read-input { width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--card); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.2rem; }
.read-input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 4px var(--focus); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--lvl-start); }
.dot.ok { background: var(--lvl-mastered); } .dot.warn { background: var(--lvl-practising); } .dot.bad { background: var(--lvl-needs); }
.read-x { width: 30px; height: 30px; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; font-size: 1.25rem; line-height: 1; }
.read-x:hover { background: var(--bad-soft); color: var(--bad); }
.alts { grid-column: 2 / -1; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.confirm { background: var(--warn-soft); border-radius: 14px; padding: 12px 14px; margin: 6px 0; display: grid; gap: 8px; }
.tipcard { background: var(--brand-soft); border-radius: 16px; padding: 12px 16px; margin-bottom: 10px; }
.tipcard p { margin: 2px 0 8px; }
.actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }
.feedback { margin-top: 6px; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall 1.5s ease-in forwards; }
@keyframes fall { to { top: 105vh; opacity: .8; } }
.teach-big { font-size: 2rem; font-weight: 800; margin: 12px 0 2px; }
.teach-pad { position: relative; height: min(44vh, 380px); margin-top: 10px; }
@media (max-width: 900px) {
  .stage-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(200px, 1fr) auto; grid-template-areas: "prompt" "canvas" "dock"; gap: 10px; padding-top: 10px; }
  .stage-dock { max-height: 40vh; }
  .stage-q { font-size: 1.8rem; }
  .hero::after { display: none; }
}

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .bar:not([fill]) { fill: var(--brand); } .chart .bar.zero { fill: var(--line); } .chart .bar { transition: opacity .15s; } .chart .bar:hover { opacity: .8; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .goal { stroke: var(--lvl-mastered); stroke-dasharray: 4 4; stroke-width: 1.5; }
.ring text { fill: var(--ink); font-weight: 800; }

/* ---------- skills, mistakes, badges ---------- */
.skillrow { display: grid; grid-template-columns: minmax(150px, 1.3fr) 2fr 118px; gap: 14px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.skillrow:last-child { border-bottom: 0; }
.skillrow .nm b { display: block; font-size: .98rem; } .skillrow .nm span { color: var(--muted); font-size: .82rem; }
.hbar { height: 11px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.hbar > i { display: block; height: 100%; border-radius: 99px; }
.lvl-needs_work { background: var(--lvl-needs); } .lvl-practising { background: var(--lvl-practising); } .lvl-mastered { background: var(--lvl-mastered); } .lvl-getting_started { background: var(--lvl-start); }
.mistake { padding: 12px 0; border-bottom: 1px solid var(--line); }
.mistake:last-child { border-bottom: 0; }
.mistake summary { cursor: pointer; display: flex; gap: 10px; align-items: center; list-style: none; }
.mistake summary::-webkit-details-marker { display: none; }
.mistake .count { margin-left: auto; }
.mistake .body { margin: 8px 0 0 0; color: var(--muted); font-size: .94rem; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.badge { text-align: center; padding: 16px 10px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.badge .ico { font-size: 2.1rem; display: block; }
.badge.locked { opacity: .42; filter: grayscale(1); }
.badge b { display: block; font-size: .9rem; } .badge span { font-size: .78rem; color: var(--muted); }

/* ---------- print (weekly report -> PDF) ---------- */
.printonly { display: none; }
@media print {
  .topbar, .noprint, .toast, .overlay { display: none !important; }
  .printonly { display: block; }
  body { background: #fff; color: #000; font-size: 12px; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  :root { --card: #fff; --ink: #000; --muted: #444; --line: #ccc; --soft: #f2f2f2; }
}
@media (max-width: 640px) {
  .skillrow { grid-template-columns: 1fr; gap: 4px; }
  .nav { margin-left: 0; width: 100%; }
  .grid.c2 { grid-template-columns: 1fr; }
}

/* ---------- dashboard: colour and style ---------- */
.dash-hero { background: var(--grad); color: #fff; border-radius: 28px; padding: clamp(20px, 2.6vw, 34px); display: flex; gap: 24px; align-items: center; justify-content: space-between; flex-wrap: wrap; position: relative; overflow: hidden; box-shadow: 0 22px 54px rgba(99, 102, 241, .32); margin-bottom: 20px; }
.dash-hero::before { content: ""; position: absolute; width: 380px; height: 380px; right: -90px; top: -150px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .22), transparent 70%); }
.dash-hero::after { content: ""; position: absolute; width: 260px; height: 260px; left: 30%; bottom: -170px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .13), transparent 70%); }
.dash-hero > * { position: relative; z-index: 1; }
.dh-main { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.dash-hero h1 { color: #fff; margin: 0; font-size: clamp(1.9rem, 3.2vw, 2.6rem); }
.dh-crumbs { font-size: .86rem; opacity: .85; } .dh-crumbs a { color: #fff; }
.dh-sub { opacity: .88; font-size: .95rem; }
.dash-hero .avatar { width: 72px; height: 72px; border-radius: 22px; font-size: 2rem; border: 3px solid rgba(255, 255, 255, .55); }
.btn.white { background: #fff; color: var(--brand); box-shadow: 0 8px 22px rgba(0, 0, 0, .18); }
.btn.glass { background: rgba(255, 255, 255, .18); color: #fff; border: 1px solid rgba(255, 255, 255, .35); box-shadow: none; backdrop-filter: blur(6px); }
.dh-today { display: flex; gap: 18px; align-items: center; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .28); border-radius: 22px; padding: 14px 22px 14px 16px; backdrop-filter: blur(8px); }
.dh-today .ring text { fill: #fff; }
.dh-today b { font-size: 1.05rem; }

.kpis { margin-top: 0; }
.kpi { position: relative; overflow: hidden; padding: 20px 22px; border: 0; color: var(--ink); }
.kpi .kico { position: absolute; right: 16px; top: 14px; width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; font-size: 1.5rem; background: rgba(255, 255, 255, .6); box-shadow: 0 4px 12px rgba(0, 0, 0, .06); }
.kpi .label { font-weight: 700; }
.kpi .value { font-size: 2.4rem; }
.tint-orange { background: linear-gradient(135deg, #fff1de, #ffe0b8); }
.tint-blue { background: linear-gradient(135deg, #e5ecff, #cddbff); }
.tint-purple { background: linear-gradient(135deg, #f1e8ff, #e0cdff); }
.tint-green { background: linear-gradient(135deg, #e0f8e9, #c4efd3); }
.tint-orange .value { color: #c25e00; } .tint-blue .value { color: #2f4fd8; } .tint-purple .value { color: #6a3fd6; } .tint-green .value { color: #1c7c3b; }
.tint-suggest { background: linear-gradient(135deg, #fff9e6, #fff1cc); border-color: #f6e3a3; }
.tips { margin: 0; padding-left: 0; list-style: none; }
.tips li { position: relative; padding: 8px 0 8px 30px; border-bottom: 1px dashed rgba(0, 0, 0, .1); }
.tips li:last-child { border-bottom: 0; }
.tips li::before { content: "💡"; position: absolute; left: 0; top: 7px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tint-orange { background: linear-gradient(135deg, #3b2a12, #4a3213); } :root:not([data-theme="light"]) .tint-blue { background: linear-gradient(135deg, #1b2750, #22326a); }
  :root:not([data-theme="light"]) .tint-purple { background: linear-gradient(135deg, #2b1f4d, #382866); } :root:not([data-theme="light"]) .tint-green { background: linear-gradient(135deg, #14301f, #1a3f2a); }
  :root:not([data-theme="light"]) .tint-suggest { background: linear-gradient(135deg, #3a2f12, #45381a); border-color: #5a4a1e; }
  :root:not([data-theme="light"]) .kpi .kico { background: rgba(255, 255, 255, .1); }
  :root:not([data-theme="light"]) .tint-orange .value { color: #ffb86b; } :root:not([data-theme="light"]) .tint-blue .value { color: #9db4ff; }
  :root:not([data-theme="light"]) .tint-purple .value { color: #c9a8ff; } :root:not([data-theme="light"]) .tint-green .value { color: #7fe0a0; }
}
.stacked { display: flex; border-radius: 99px; overflow: hidden; background: var(--soft); }
.stacked i { display: block; height: 100%; }
.legend { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sico { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-size: 1.3rem; flex: none; }
.skillrow .nm { display: flex; }
.hbar { height: 12px; }
.lvl-needs_work { background: linear-gradient(90deg, #ff6b6b, #ea4d54); } .lvl-practising { background: linear-gradient(90deg, #ffc233, #f5a524); }
.lvl-mastered { background: linear-gradient(90deg, #56d37a, #2ea44f); } .lvl-getting_started { background: linear-gradient(90deg, #b7c0d6, #98a2b8); }
.mdot { width: 32px; height: 32px; border-radius: 10px; background: var(--warn-soft); display: grid; place-items: center; flex: none; }
.mistake summary b { font-size: 1rem; }
.badge { transition: transform .15s; }
.badge:not(.locked) { background: linear-gradient(160deg, #fff7dc, #ffe9a8); border-color: #f3d36b; box-shadow: 0 8px 20px rgba(245, 180, 40, .25); }
.badge:not(.locked):hover { transform: translateY(-3px) rotate(-1deg); }
.badge:not(.locked) b, .badge:not(.locked) span { color: #6b4a00; }
.badge:not(.locked) .ico { filter: drop-shadow(0 3px 4px rgba(150, 100, 0, .3)); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge:not(.locked) { background: linear-gradient(160deg, #3d3214, #4d3f18); border-color: #6b5a22; } :root:not([data-theme="light"]) .badge:not(.locked) b, :root:not([data-theme="light"]) .badge:not(.locked) span { color: #ffe08a; } }
.card h2 { font-size: 1.25rem; }/* skill rows in the narrow right-hand column: name and level on one line, bar underneath */
.dash > div:nth-child(2) .skillrow { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; }
.dash > div:nth-child(2) .skillrow > :nth-child(1) { grid-column: 1; grid-row: 1; }
.dash > div:nth-child(2) .skillrow > :nth-child(3) { grid-column: 2; grid-row: 1; }
.dash > div:nth-child(2) .skillrow > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; }

/* ---------- phones and tablets / installed app ---------- */
html { overscroll-behavior-y: none; }
body { -webkit-tap-highlight-color: transparent; }
body.stage-open, .stage { overscroll-behavior: none; touch-action: manipulation; }
.btn, .tool, .chipbtn, .topic { min-height: 44px; }                       /* comfortable touch targets */
@supports (padding: max(0px)) {
  .topbar-in { padding-left: max(clamp(16px, 3vw, 48px), env(safe-area-inset-left)); padding-right: max(clamp(16px, 3vw, 48px), env(safe-area-inset-right)); }
  .stage-top, .stage-body { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .stage-body { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) { .noinstall { display: none !important; } }
/* tablets in portrait and large phones in landscape: keep the pad big, side panel narrower */
@media (min-width: 700px) and (max-width: 1100px) and (orientation: landscape) { .stage-body { grid-template-columns: minmax(300px, 36%) 1fr; } .stage-q { font-size: clamp(1.6rem, 3.4vw, 2.4rem); } }
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) { .stage-top { padding-top: 6px; padding-bottom: 6px; } .stage-q { font-size: 1.5rem; } .pad-hint-ico { font-size: 1.8rem; } }

/* ---------- phone layout of the writing stage: the pad gets the biggest share ---------- */
@media (max-width: 700px) {
  .lbl { display: none; }
  .stage-top { padding: 6px 10px; gap: 6px; flex-wrap: nowrap; }
  .stage-top .chipbtn { padding: 7px 11px; }
  .stage-body { grid-template-rows: auto minmax(40vh, 1fr) auto; padding: 8px 10px 10px; gap: 8px; }
  .stage-prompt { padding: 0 2px; }
  .stage-q { font-size: 1.55rem; margin: 0; }
  .stage-skill { font-size: .78rem; }
  .stage-dock { max-height: 32vh; padding: 0; }
  .tipcard { display: none; }
  .dock-title { display: none; }
  .read-row { margin: 4px 0; }
  .read-input { padding: 8px 12px; font-size: 1.05rem; }
  .actions { position: sticky; bottom: 0; background: var(--bg); padding: 6px 0 2px; margin-top: 6px; }
  .actions .btn.big { padding: 12px 18px; font-size: 1rem; }
  .pad-wrap { border-radius: 18px; }
  .toolbar { left: 10px; bottom: 10px; } .tool { padding: 6px 12px; }
}
