/* Maths & Reasoning — soft, rounded, mobile-first (lavender + violet), light and dark themes; A4 print layout. */
:root {
  --bg: #f6f3fd;
  --bg-2: #efe9fd;
  --surface: #ffffff;
  --surface-2: #f6f2ff;
  --ink: #1c1535;
  --muted: #5f5880;
  --line: #a59fc0;
  --hair: #ebe5f8;
  --pri: #6233d9;          /* violet: 6.6:1 on white */
  --pri-2: #8b5cf6;
  --pri-ink: #ffffff;
  --pri-soft: #efe8ff;
  --accent: #f59e0b;
  --ok: #047857;
  --ok-soft: #dcf5ea;
  --bad: #c0262d;
  --bad-soft: #fde7e8;
  --warn-soft: #fff4d6;
  --focus: #f59e0b;
  --shadow: 0 1px 2px rgba(60, 35, 140, .04), 0 8px 24px rgba(60, 35, 140, .08);
  --shadow-lg: 0 14px 34px rgba(98, 51, 217, .28);
  --radius: 22px;
  --radius-sm: 14px;
  --tap: 52px;
  --nav-h: 76px;
  --head: linear-gradient(135deg, #6233d9 0%, #7c4dff 55%, #a78bfa 100%);
  /* figures */
  --fig-ink: #1c1535;
  --fig-grid: #ddd6ee;
  --fig-bar: #8b5cf6;
  --fig-line: #6233d9;
  --fig-face: #ffffff;
  --fig-fill: #ddd0ff;
  --fig-alt: #fde68a;
  --fig-water: #93c5fd;
  /* Latin first, then fonts that render Simplified Chinese well on each platform */
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
          "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC",
          "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #110d1f; --bg-2: #171128; --surface: #1d1733; --surface-2: #251d40;
    --ink: #f1edfb; --muted: #bdb4d8; --line: #6b5f93; --hair: #2f2650;
    --pri: #a78bfa; --pri-2: #8b5cf6; --pri-ink: #160f2a; --pri-soft: #2c2252;
    --ok: #34d399; --ok-soft: #0f3a2c; --bad: #f87171; --bad-soft: #3d1717; --warn-soft: #3a2f10;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --head: linear-gradient(135deg, #4c1d95 0%, #6233d9 60%, #7c4dff 100%);
    --fig-ink: #ede9f8; --fig-grid: #3a3160; --fig-bar: #a78bfa; --fig-line: #c4b5fd; --fig-face: #251d40;
    --fig-fill: #4a3b88; --fig-alt: #6b5416; --fig-water: #1e4f8a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
html:lang(zh-CN) body { line-height: 1.65; }
h1, h2, h3 { line-height: 1.3; margin: 0; letter-spacing: -0.01em; font-weight: 700; }
h2 { font-size: 1.45rem; margin: 0.2rem 0 1rem; }
h3 { font-size: 1.08rem; margin-bottom: 0.4rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- header: greeting + round buttons ---------- */
.top {
  max-width: 36rem; margin: 0 auto;
  padding: max(0.9rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.3rem max(1rem, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
}
.hello { display: flex; align-items: center; gap: 0.7rem; min-width: 0; background: none; border: 0; padding: 0.2rem; color: var(--ink); font: inherit; text-align: left; cursor: pointer; border-radius: 999px; }
.avatar {
  flex: none; width: 48px; height: 48px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #fbbf24, #f472b6 55%, #8b5cf6); color: #fff; font-weight: 700; font-size: 1.25rem;
  box-shadow: 0 0 0 3px var(--surface), 0 6px 14px rgba(98, 51, 217, .25);
}
.hello-text { display: flex; flex-direction: column; min-width: 0; }
.hello-name { font-weight: 700; font-size: 1.12rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hello-sub { font-size: 0.82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 0.5rem; flex: none; }
.round-btn {
  min-width: 46px; height: 46px; padding: 0 0.7rem; border-radius: 16px; border: 0;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  font: inherit; font-weight: 600; font-size: 0.95rem; cursor: pointer;
}
.round-btn[aria-pressed="true"] { background: var(--pri-soft); color: var(--pri); box-shadow: inset 0 0 0 2px var(--pri); }

/* ---------- bottom navigation with a centre button ---------- */
.bottom-nav {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 10;
  width: min(100%, 36rem); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 0.55rem 0.9rem calc(0.55rem + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: center; gap: 0.3rem;
  background: var(--surface); border-radius: 26px 26px 0 0; box-shadow: 0 -6px 26px rgba(60, 35, 140, .1);
}
body.no-nav .bottom-nav { display: none; }
.tab {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 50px; padding: 0 0.3rem; border: 0; border-radius: 16px; background: none;
  font: inherit; font-size: 0.72rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tab .ni { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { background: var(--pri); color: var(--pri-ink); flex-direction: row; gap: 0.35rem; font-size: 0.78rem; box-shadow: 0 6px 14px rgba(98, 51, 217, .3); }
.tab[aria-current="page"] .ni { width: 20px; height: 20px; }
.fab {
  justify-self: center; width: 62px; height: 62px; margin-top: -2.2rem; border-radius: 50%; border: 5px solid var(--bg);
  background: var(--head); color: #fff; box-shadow: var(--shadow-lg); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.fab svg { width: 28px; height: 28px; margin-left: 3px; }
.fab:active { transform: scale(0.96); }

main {
  max-width: 36rem; margin: 0 auto;
  padding: 0.8rem max(1rem, env(safe-area-inset-right)) calc(var(--nav-h) + 1.6rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  outline: none;
}
body.no-nav main { padding-bottom: max(2rem, env(safe-area-inset-bottom)); }

/* ---------- home: hero banner and subject tiles ---------- */
.hero {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 0.5rem;
  background: var(--head); color: #fff; border-radius: 26px; padding: 1.15rem 0.9rem 1.15rem 1.2rem; margin-bottom: 1.3rem;
  box-shadow: var(--shadow-lg);
}
.hero::before, .hero::after { content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .1); }
.hero::before { width: 180px; height: 180px; right: -50px; top: -70px; }
.hero::after { width: 110px; height: 110px; left: -40px; bottom: -60px; }
.hero-text { position: relative; z-index: 1; flex: 1; min-width: 0; }
.hero h2 { margin: 0; font-size: 1.32rem; color: #fff; }
.hero-sub { margin: 0.25rem 0 0.8rem; font-size: 0.85rem; opacity: 0.92; }
.hero-btn { min-height: 42px; padding: 0 1.15rem; border: 0; border-radius: 999px; background: #fff; color: #4c1d95; font: inherit; font-weight: 700; font-size: 0.9rem; cursor: pointer; box-shadow: 0 6px 14px rgba(30, 10, 80, .25); }
.hero-art { position: relative; z-index: 1; flex: none; width: 128px; height: auto; }
@media (max-width: 360px) { .hero-art { width: 96px; } }
.sec-title { display: block; font-size: 1.08rem; font-weight: 700; margin: 0 0 0.7rem; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { position: relative; }
.tile input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tile-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 0.25rem;
  min-height: 128px; padding: 0.9rem 0.5rem; border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow); border: 2px solid transparent; cursor: pointer; user-select: none; transition: transform .12s, border-color .15s, box-shadow .15s;
}
.tile-box:active { transform: scale(0.98); }
.tile-icon { width: 54px; height: 54px; border-radius: 18px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.8rem; margin-bottom: 0.25rem; }
.t0 .tile-icon { background: #ede7ff; } .t1 .tile-icon { background: #e0f2fe; } .t2 .tile-icon { background: #fef3c7; } .t3 .tile-icon { background: #ffe4e6; }
.tile-label { font-weight: 600; font-size: 0.98rem; line-height: 1.25; color: var(--ink); }
.tile-sub { font-size: 0.74rem; color: var(--muted); line-height: 1.3; }
.tile input:checked + .tile-box { border-color: var(--pri); background: var(--pri-soft); box-shadow: 0 8px 20px rgba(98, 51, 217, .18); }
.tile input:checked + .tile-box::after { content: "✓"; position: absolute; top: 10px; right: 12px; width: 24px; height: 24px; border-radius: 50%; background: var(--pri); color: var(--pri-ink); font-size: 0.8rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.tile input:focus-visible + .tile-box { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (prefers-color-scheme: dark) { .t0 .tile-icon, .t1 .tile-icon, .t2 .tile-icon, .t3 .tile-icon { background: var(--surface-2); } }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card h3 { margin-top: 0; }
fieldset { border: 0; margin: 0 0 1.15rem; padding: 0; min-width: 0; }
legend, .label { display: block; font-weight: 700; margin: 0 0 0.5rem; padding: 0; font-size: 0.95rem; letter-spacing: 0.01em; }
.label { margin-top: 0.9rem; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.center { text-align: center; }
.source, .note { color: var(--muted); font-size: 0.9rem; margin: 0.45rem 0 0; }
.bad { color: var(--bad); }
.ok { color: var(--ok); }

/* ---------- chips (radio buttons) ---------- */
.chips { display: grid; gap: 0.5rem; }
.chips-1 { grid-template-columns: 1fr; }
.chips-2 { grid-template-columns: repeat(2, 1fr); }
.chips-3 { grid-template-columns: repeat(3, 1fr); }
.chips-4 { grid-template-columns: repeat(2, 1fr); }  /* 2 × 2 on phones, one row on wider screens */
@media (min-width: 640px) { .chips-4 { grid-template-columns: repeat(4, 1fr); } }
.qhead:has(.marks) { justify-content: flex-start; }
.badge.marks { margin-left: auto; }
.chips-7 { grid-template-columns: repeat(4, 1fr); }
@media (min-width: 30rem) { .chips-7 { grid-template-columns: repeat(7, 1fr); } }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: var(--tap); padding: 0.35rem 0.5rem;
  border: 1.5px solid var(--hair); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
  font-weight: 700; line-height: 1.25; cursor: pointer; user-select: none;
  transition: background .15s, border-color .15s, transform .1s;
}
.chip span:hover { border-color: var(--pri-2); }
.chip span:active { transform: scale(0.98); }
.chip input:checked + span { background: var(--pri); border-color: var(--pri); color: var(--pri-ink); box-shadow: 0 4px 14px rgba(67, 56, 202, .3); }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.subject .chip span { min-height: 64px; font-size: 1rem; }
.diff .chip span { padding: 0.35rem 0.25rem; font-size: 0.95rem; }

/* ---------- inputs & buttons ---------- */
input[type="text"], input[type="password"], select {
  width: 100%; min-height: var(--tap); padding: 0.55rem 0.9rem;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
}
input:focus, select:focus { border-color: var(--pri); outline: 3px solid color-mix(in srgb, var(--pri) 25%, transparent); outline-offset: 0; }
input.answer { font-size: 1.5rem; font-weight: 700; min-height: 62px; letter-spacing: 0.02em; }
.btn {
  display: block; width: 100%; min-height: var(--tap); margin-top: 0.8rem; padding: 0.7rem 1rem;
  border: 1.5px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 700; cursor: pointer; transition: transform .1s, box-shadow .15s, filter .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--pri), var(--pri-2)); color: #fff; box-shadow: 0 6px 16px rgba(67, 56, 202, .28); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { min-height: 58px; font-size: 1.1rem; }
.btn.secondary { background: var(--pri-soft); color: var(--pri); border-color: transparent; }
.btn.ghost { background: none; color: var(--pri); text-decoration: underline; text-underline-offset: 3px; }
.btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }
@media (prefers-color-scheme: dark) { .btn.primary { background: linear-gradient(135deg, #4f46e5, #6366f1); } }
.link { background: none; border: 0; color: var(--pri); text-decoration: underline; font: inherit; min-height: 44px; cursor: pointer; padding: 0; margin-top: 0.5rem; }
.row { display: flex; gap: 0.6rem; }
.row .btn { flex: 1; }
.check { display: flex; gap: 0.6rem; align-items: flex-start; margin: 0.7rem 0; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; margin-top: 0.2rem; accent-color: var(--pri); flex: none; }

/* ---------- selective intro ---------- */
.sel-card { background: linear-gradient(160deg, var(--surface), var(--pri-soft)); }
.rules { margin: 0.4rem 0 0; padding-left: 1.2rem; }
.rules li { margin: 0.25rem 0; }

/* ---------- quiz: top bar ---------- */
.quiz-top { position: sticky; top: 0; z-index: 4; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); margin: 0 -1rem 0.6rem; padding: 0.5rem 1rem 0.6rem; }
.quiz-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.qprogress { margin: 0; font-weight: 700; color: var(--muted); }
.timer { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--ink); color: var(--bg); border-radius: 999px; padding: 0.2rem 0.8rem; font-size: 1rem; }
.timer.low { background: var(--bad); color: #fff; }
.bar { height: 8px; background: var(--hair); border-radius: 6px; overflow: hidden; margin: 0.45rem 0 0.55rem; }
.bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--pri), var(--pri-2)); transition: width .25s; }
.toolbar { display: flex; gap: 0.5rem; align-items: center; justify-content: space-between; }
.seg { display: inline-flex; background: var(--surface); border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.seg-btn { min-height: 40px; padding: 0 0.9rem; border: 0; border-radius: 999px; background: none; color: var(--muted); font: inherit; font-weight: 700; font-size: 0.9rem; cursor: pointer; }
.seg-btn[aria-pressed="true"] { background: var(--pri); color: var(--pri-ink); }
.tool-btn { min-height: 44px; padding: 0 0.9rem; border: 0; border-radius: 999px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font: inherit; font-weight: 700; font-size: 0.9rem; cursor: pointer; }

/* ---------- question cards ---------- */
.qlist { display: grid; gap: 0.9rem; }
.qcard { background: var(--surface); border-radius: var(--radius); padding: 1rem 1.05rem 1.1rem; box-shadow: var(--shadow); border: 1.5px solid transparent; scroll-margin-top: 9rem; }
.qcard.is-ok { border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.qcard.is-bad { border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.qhead { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.4rem; }
.qnum { display: inline-flex; align-items: center; justify-content: center; min-width: 2.2rem; height: 2.2rem; padding: 0 0.5rem; border-radius: 999px; background: var(--pri); color: var(--pri-ink); font-weight: 700; }
.badge { margin: 0; background: var(--pri-soft); color: var(--pri); font-weight: 700; font-size: 0.82rem; padding: 0.22rem 0.7rem; border-radius: 999px; }
.question { font-size: 1.35rem; font-weight: 600; margin: 0.3rem 0 0.4rem; white-space: pre-line; overflow-wrap: anywhere; }
.tip { background: var(--pri-soft); border-left: 4px solid var(--pri); border-radius: 10px; padding: 0.5rem 0.75rem; margin: 0.6rem 0 0; }
.choices { display: grid; gap: 0.55rem; margin-top: 0.8rem; }
.choice {
  display: flex; align-items: center; gap: 0.75rem; width: 100%; min-height: 56px; padding: 0.55rem 0.8rem;
  border: 1.5px solid var(--hair); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink);
  font: inherit; font-weight: 700; font-size: 1.1rem; text-align: left; cursor: pointer; transition: border-color .15s, background .15s;
}
.choice:hover:not(:disabled) { border-color: var(--pri-2); }
.choice .letter { flex: none; width: 2.1rem; height: 2.1rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--surface); color: var(--pri); font-weight: 700; box-shadow: inset 0 0 0 1.5px var(--hair); }
.choice[aria-checked="true"] { border-color: var(--pri); background: var(--pri); color: var(--pri-ink); }
.choice[aria-checked="true"] .letter { background: #fff; color: #312e81; box-shadow: none; }
.choice:disabled { cursor: default; opacity: 1; }
.choice.is-correct { border-color: var(--ok); box-shadow: inset 0 0 0 2px var(--ok); }
.keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.4rem; margin-top: 0.5rem; }
.key { min-height: 46px; border: 1.5px solid var(--hair); border-radius: 12px; background: var(--surface-2); color: var(--ink); font: inherit; font-weight: 700; font-size: 1.05rem; cursor: pointer; }
.key:active { background: var(--pri-soft); }
.feedback { font-weight: 700; font-size: 1.1rem; margin: 0.6rem 0 0; border-radius: 12px; }
.feedback:empty { display: none; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); padding: 0.6rem 0.8rem; }
.feedback.bad { background: var(--bad-soft); color: var(--bad); padding: 0.6rem 0.8rem; }
.parent-box { background: var(--warn-soft); border: 2px dashed #a16207; border-radius: 12px; padding: 0.6rem 0.8rem; font-weight: 700; margin: 0.6rem 0 0; }

/* ---------- figures ---------- */
.figwrap { margin: 0.6rem 0 0.2rem; }
.fig { margin: 0; display: flex; flex-direction: column; align-items: center; }
.fig-svg { width: 100%; max-width: 380px; height: auto; }
.fig-clock .fig-svg, .fig-spinner .fig-svg { max-width: 200px; }
.fig-dial .fig-svg { max-width: 230px; }
.fig-jug .fig-svg { max-width: 190px; }
.fig-svg .ft { fill: var(--fig-ink); font-family: var(--font); font-size: 12px; }
.fig-svg .fs { font-size: 11px; }
.fig-svg .fb { font-weight: 700; font-size: 12.5px; }
.fig-svg .fbig { font-weight: 700; font-size: 22px; }
.fig-svg .fl { stroke: var(--fig-ink); stroke-width: 1; }
.fig-svg .fg { stroke: var(--fig-grid); }
.fig-svg .fax { stroke-width: 1.6; }
.fig-svg .fbar { fill: var(--fig-bar); }
.fig-svg .fline { fill: none; stroke: var(--fig-line); stroke-width: 2.5; stroke-linejoin: round; }
.fig-svg .fdot { fill: var(--fig-line); }
.fig-svg .fface { fill: var(--fig-face); stroke: var(--fig-ink); stroke-width: 2; }
.fig-svg .fneedle { stroke: #dc2626; stroke-width: 3; stroke-linecap: round; }
.fig-svg .fhand { stroke: var(--fig-ink); stroke-width: 3; stroke-linecap: round; }
.fig-svg .fhour { stroke-width: 5; }
.fig-svg .fsector { fill: var(--fig-fill); stroke: var(--fig-ink); stroke-width: 1.5; }
.fig-svg .fsector.alt { fill: var(--fig-alt); }
.fig-svg .fshape { fill: none; stroke: var(--fig-ink); stroke-width: 2; }
.fig-svg .fshape.shaded { fill: var(--fig-fill); }
.fig-svg .fcell.c0 { fill: var(--fig-fill); }
.fig-svg .fcell.c1 { fill: var(--fig-alt); }
.fig-svg .fjug { fill: none; stroke: var(--fig-ink); stroke-width: 2.5; }
.fig-svg .fliquid { fill: var(--fig-water); }
.ftable { border-collapse: collapse; margin: 0.2rem auto; background: var(--surface); }
.ftable th, .ftable td { border: 1.5px solid var(--line); padding: 0.4rem 0.7rem; text-align: left; }
.gridtable td { width: 3.2rem; height: 3.2rem; text-align: center; font-weight: 700; font-size: 1.2rem; }
.picto th { white-space: nowrap; }
.picons { font-size: 1.3rem; letter-spacing: 0.1em; }
.phalf { display: inline-block; width: 0.62em; overflow: hidden; vertical-align: bottom; }
.fkey { margin: 0.3rem 0 0; font-weight: 700; font-size: 0.95rem; }

/* ---------- exam navigation ---------- */
.answered { margin: 0.8rem 0 0; text-align: center; }
.palette { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.35rem; }
.pal { min-height: 44px; border: 1.5px solid var(--hair); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.pal.done { background: var(--pri-soft); border-color: var(--pri); color: var(--pri); }
.pal.current { outline: 3px solid var(--focus); outline-offset: 1px; }
.finish { margin-top: 1rem; }
#pageNav { margin-top: 0.4rem; }

/* ---------- loading ---------- */
.loading { text-align: center; padding: 3rem 1rem; }
.spinner { width: 56px; height: 56px; margin: 0 auto 1.2rem; border: 6px solid var(--hair); border-top-color: var(--pri); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .bar > div, .chip span, .btn { transition: none; } }

/* ---------- results & review ---------- */
.score-card { background: var(--head); color: #fff; border-radius: var(--radius); padding: 1.2rem; text-align: center; box-shadow: var(--shadow-lg); }
.score-card p { margin: 0.2rem 0; }
.score { font-size: 1.7rem; font-weight: 700; }
.score-card .muted { color: rgba(255, 255, 255, .85); }
.res-cats { margin-top: 1rem; background: var(--surface); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.res-cats h3 { margin-top: 0; }
.review { list-style: none; padding: 0; margin: 1rem 0 0; }
.review li { background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow); border-left: 6px solid var(--line); padding: 0.7rem 0.9rem; margin: 0 0 0.6rem; }
.review li.ok { border-left-color: var(--ok); }
.review li.bad { border-left-color: var(--bad); }
.review p { margin: 0.15rem 0; }
.review .q { font-weight: 700; white-space: pre-line; }
.review .mark { font-weight: 700; }
.review .ans { font-weight: 700; color: var(--ink); background: var(--warn-soft); border-radius: 8px; padding: 0.15rem 0.45rem; display: inline-block; }

/* ---------- progress ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-bottom: 1.2rem; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 0.8rem 0.4rem; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.5rem; color: var(--pri); }
.stat span { font-size: 0.85rem; color: var(--muted); }
.tbar { margin: 0 0 0.75rem; }
.tbar .lbl { display: flex; justify-content: space-between; font-weight: 700; font-size: 0.95rem; gap: 0.5rem; }
.tbar .track { height: 12px; background: var(--hair); border-radius: 8px; overflow: hidden; margin-top: 0.25rem; }
.tbar .fill { height: 100%; background: var(--pri); border-radius: 8px; }
.tbar .fill.low { background: var(--bad); }
.tbar .fill.mid { background: #b45309; }
.tbar .fill.high { background: var(--ok); }
.plain { list-style: none; padding: 0; margin: 0 0 1rem; }
.plain li { background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 0.6rem 0.85rem; margin-bottom: 0.45rem; font-size: 0.95rem; }
section h3 { margin-top: 1.2rem; }

/* ---------- dialogs & toast ---------- */
dialog { border: 0; border-radius: 22px; padding: 1.3rem; width: min(92vw, 25rem); color: var(--ink); background: var(--surface); font-family: var(--font); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(5, 10, 30, .6); backdrop-filter: blur(3px); }
#pinInput { font-size: 2rem; text-align: center; letter-spacing: 0.6em; padding-left: 1.2rem; }
.toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(92vw, 32rem); background: #111827; color: #fff; padding: 0.85rem 1rem; border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35); display: flex; gap: 0.8rem; align-items: center; justify-content: space-between; z-index: 20;
}
.toast button { background: #fff; color: #111827; border: 0; border-radius: 10px; min-height: 44px; padding: 0 0.9rem; font: inherit; font-weight: 700; cursor: pointer; }

/* ---------- small phones ---------- */
@media (max-width: 380px) {
  body { font-size: 17px; }
  .hello-name { font-size: 1rem; }
  .avatar { width: 42px; height: 42px; }
  .seg-btn { padding: 0 0.6rem; font-size: 0.85rem; }
  .question { font-size: 1.2rem; }
}
@media (forced-colors: active) { .chip input:checked + span, .choice[aria-checked="true"] { outline: 3px solid CanvasText; } }

/* ---------- print: A4 worksheet ---------- */
.print-area { display: none; }
@media print {
  @page { size: A4; margin: 14mm 13mm 16mm; }
  :root { --fig-ink: #000; --fig-grid: #bbb; --fig-bar: #777; --fig-line: #000; --fig-face: #fff; --fig-fill: #ddd; --fig-alt: #f3f3f3; --fig-water: #ddd; --surface: #fff; --line: #000; }
  html, body { background: #fff !important; color: #000; font-size: 11pt; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block; font-family: var(--font); line-height: 1.4; }
  .p-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 8mm; border-bottom: 2px solid #000; padding-bottom: 3mm; }
  .p-app { margin: 0; font-size: 9pt; text-transform: uppercase; letter-spacing: 0.08em; }
  .p-head h1 { font-size: 15pt; margin: 0; }
  .p-fields { display: flex; flex-direction: column; gap: 2mm; font-size: 10pt; white-space: nowrap; }
  .p-fields i { display: inline-block; width: 42mm; border-bottom: 1px solid #000; }
  .p-fields i.short { width: 18mm; }
  .p-info { font-size: 9.5pt; margin: 2mm 0 4mm; }
  .p-qs { margin: 0; padding-left: 7mm; }
  .p-q { break-inside: avoid; page-break-inside: avoid; margin: 0 0 5mm; padding-left: 1mm; }
  .p-text { white-space: normal; }
  .p-q .fig { align-items: flex-start; margin: 2mm 0; }
  .p-q .fig-svg { width: auto; max-width: 75mm; max-height: 60mm; }
  .p-opts { list-style: none; padding: 0; margin: 2mm 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5mm 6mm; }
  .p-opts.one-col { grid-template-columns: 1fr; }
  .p-opts b { display: inline-block; width: 6mm; height: 6mm; border: 1px solid #000; border-radius: 50%; text-align: center; line-height: 6mm; font-size: 9pt; margin-right: 2mm; }
  .p-line i { display: inline-block; width: 70mm; border-bottom: 1px solid #000; height: 5mm; }
  .p-key { break-before: page; page-break-before: always; }
  .p-key h2 { font-size: 14pt; margin: 0 0 1mm; }
  .p-note { font-size: 9pt; margin: 0 0 3mm; }
  .p-key table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
  .p-key th, .p-key td { border: 1px solid #000; padding: 1.2mm 2mm; text-align: left; vertical-align: top; }
  .p-key tr { break-inside: avoid; }
  .ftable { background: #fff; }
  .ftable th, .ftable td { border-color: #000; padding: 1mm 2.5mm; }
  .gridtable td { width: 10mm; height: 10mm; }
}

/* pie / coordinate / triangle figures */
.fig-svg .fpie { stroke: var(--surface); stroke-width: 2; }
.fig-svg .fpie.p0 { fill: #6366f1; } .fig-svg .fpie.p1 { fill: #f59e0b; } .fig-svg .fpie.p2 { fill: #10b981; }
.fig-svg .fpie.p3 { fill: #ef4444; } .fig-svg .fpie.p4 { fill: #06b6d4; } .fig-svg .fpie.p5 { fill: #a855f7; }
.fig-coord .fig-svg { max-width: 300px; }
@media print { .fig-svg .fpie.p0 { fill: #444; } .fig-svg .fpie.p1 { fill: #888; } .fig-svg .fpie.p2 { fill: #bbb; } .fig-svg .fpie.p3 { fill: #ddd; } .fig-svg .fpie.p4 { fill: #666; } .fig-svg .fpie.p5 { fill: #aaa; } .fig-svg .fpie { stroke: #000; stroke-width: 1; } }
.fig-svg .fpie.pw { fill: var(--surface-2); stroke: var(--fig-ink); stroke-width: 1.5; }
.fig-svg .fpie.p0 { stroke: var(--fig-ink); }

/* ---------- combo boxes (selects) ---------- */
.form-card { padding: 1rem 1rem 0.4rem; }
.field { margin-bottom: 0.9rem; min-width: 0; }
.field .label { margin-top: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
@media (max-width: 360px) { .field-row { grid-template-columns: 1fr; } }
select.combo {
  appearance: none; -webkit-appearance: none;
  width: 100%; min-height: 56px; padding: 0.6rem 2.6rem 0.6rem 0.95rem;
  font: inherit; font-weight: 700; color: var(--ink);
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, transparent 50%, var(--pri) 50%), linear-gradient(135deg, var(--pri) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 15px) 50%;
  background-size: 7px 7px, 7px 7px; background-repeat: no-repeat;
  border: 1.5px solid var(--hair); border-radius: var(--radius-sm); cursor: pointer;
}
select.combo:hover { border-color: var(--pri-2); }
select.combo:focus { border-color: var(--pri); }
.clear-row { margin-top: 1.4rem; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.review li.bad, .review li.ok { color: var(--ink); }
.small-fig .fig-svg { max-width: 300px; }

/* ---------- formulas ---------- */
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 0.12em; font-size: 0.85em; line-height: 1.1; }
.frac .fn { border-bottom: 2px solid currentColor; padding: 0 0.15em; }
.frac .fd { padding: 0 0.15em; }
.mixed { white-space: nowrap; }
sup { font-size: 0.7em; line-height: 0; }
.formula { display: block; margin: 0.55rem 0 0.35rem; padding: 0.7rem 0.9rem; text-align: center; font-size: 1.3em; font-weight: 700; letter-spacing: 0.02em;
  background: var(--surface-2); border: 1.5px solid var(--hair); border-radius: var(--radius-sm); overflow-x: auto; white-space: nowrap; }
.lead { display: block; }
.tail { display: block; font-size: 0.85em; font-weight: 600; color: var(--muted); }
@media print { .formula { background: none; border: 0; text-align: left; padding: 1mm 0 1mm 4mm; font-size: 1.15em; white-space: normal; } .tail { color: #000; } }

/* ---------- profiles, custom count, prompt editor, practice palette ---------- */
.profile-list { list-style: none; padding: 0; margin: 0.6rem 0; display: grid; gap: 0.5rem; }
.profile-list li { display: flex; gap: 0.4rem; align-items: center; }
.profile-pick { flex: 1; min-height: 52px; text-align: left; padding: 0 0.9rem; border-radius: var(--radius-sm); border: 1.5px solid var(--hair); background: var(--surface-2); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.profile-pick[aria-current="true"] { background: var(--pri); color: var(--pri-ink); border-color: var(--pri); }
.icon-btn { min-width: 44px; min-height: 44px; border-radius: 12px; border: 1.5px solid var(--hair); background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
.profile-add { align-items: center; }
.profile-add input { flex: 2; }
.profile-add .btn { margin-top: 0; flex: 1; }
.combo-num { width: 100%; min-height: 52px; margin-top: 0.5rem; padding: 0.55rem 0.9rem; font: inherit; font-weight: 700; color: var(--ink); background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-sm); }
.prompt-text { width: 100%; min-height: 14rem; padding: 0.7rem 0.8rem; font: 0.9rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--ink); background: var(--surface-2); border: 1.5px solid var(--hair); border-radius: var(--radius-sm); resize: vertical; }
.pal.good { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.pal.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

/* ---------- soft, rounded components (v1.5 look) ---------- */
.card, .qcard, .res-cats, .stat { border-radius: var(--radius); }
.form-card { padding: 1.1rem 1.1rem 0.4rem; }
select.combo, input[type="text"], input[type="password"], .combo-num { border-radius: 16px; border-color: var(--hair); background-color: var(--surface-2); font-weight: 500; }
.btn { border-radius: 16px; font-weight: 600; }
.btn.primary { background: var(--head); box-shadow: 0 8px 18px rgba(98, 51, 217, .28); }
.btn.big { border-radius: 18px; }
.btn.secondary { background: var(--pri-soft); color: var(--pri); }
.question { font-weight: 600; font-size: 1.25rem; }
.qnum { font-weight: 700; }
.badge { border-radius: 999px; font-weight: 600; }
.choice { border-radius: 16px; font-weight: 600; }
.seg { box-shadow: var(--shadow); }
.score-card { border-radius: 26px; padding: 1.4rem 1.2rem; }
.score { font-size: 1.8rem; }
.stat b { font-weight: 700; }
.pal { border-radius: 12px; }
legend.sec-title { padding: 0; }
@media (prefers-color-scheme: dark) { .btn.primary { background: var(--head); color: #fff; } }

/* ---------- review: method, ticks and the "practise similar" bar ---------- */
.review li { border-left: 0; border-radius: 20px; padding: 0.9rem 1rem 0.8rem; position: relative; box-shadow: var(--shadow); border: 2px solid transparent; }
.review li.picked { border-color: var(--pri); }
.rv-top { display: flex; align-items: center; gap: 0.45rem; margin-bottom: 0.35rem; flex-wrap: wrap; }
.rv-mark { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem; flex: none; }
.rv-mark.ok { background: var(--ok-soft); color: var(--ok); }
.rv-mark.bad { background: var(--bad-soft); color: var(--bad); }
.rv-num { font-weight: 700; color: var(--muted); font-size: 0.9rem; }
.review .q { font-weight: 600; }
.rv-yours { color: var(--muted); font-size: 0.95rem; }
.tick {
  margin-left: auto; width: 44px; height: 44px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; color: transparent;
}
.tick svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.tick:hover { border-color: var(--pri); color: color-mix(in srgb, var(--pri) 35%, transparent); }
.tick[aria-pressed="true"] { background: var(--pri); border-color: var(--pri); color: #fff; box-shadow: 0 6px 14px rgba(98, 51, 217, .3); }
.method { margin-top: 0.6rem; border-radius: 16px; background: var(--surface-2); border: 1.5px solid var(--hair); }
.method summary {
  list-style: none; cursor: pointer; min-height: 46px; display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.9rem; font-weight: 600; color: var(--pri); border-radius: 16px;
}
.method summary::-webkit-details-marker { display: none; }
.method summary::before { content: "💡"; }
.method summary::after { content: ""; margin-left: auto; width: 9px; height: 9px; border-right: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(45deg); transition: transform .15s; }
.method[open] summary::after { transform: rotate(-135deg); }
.method[open] summary { border-bottom: 1.5px solid var(--hair); border-radius: 16px 16px 0 0; }
.steps { margin: 0; padding: 0.7rem 0.9rem 0.8rem 2.4rem; counter-reset: st; list-style: none; }
.steps li { all: unset; display: block; position: relative; margin: 0 0 0.45rem; line-height: 1.5; counter-increment: st; }
.steps li::before { content: counter(st); position: absolute; left: -1.85rem; top: 0.05rem; width: 1.45rem; height: 1.45rem; border-radius: 50%; background: var(--pri); color: var(--pri-ink); font-size: 0.75rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.steps.one { padding-left: 0.9rem; }
.steps.one li::before { display: none; }
.similar-bar {
  z-index: 6;
  background: var(--surface); border-radius: 22px; padding: 0.85rem 1rem 0.95rem; margin: 0.8rem 0 1rem;
  box-shadow: 0 10px 30px rgba(60, 35, 140, .18); border: 1.5px solid var(--pri-soft);
}
.sb-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.sb-title { margin: 0; font-weight: 700; }
.sb-head .link { margin: 0; min-height: 36px; font-weight: 600; text-decoration: none; }
.sb-info { margin: 0.1rem 0 0.5rem; }
.sb-row { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 0.5rem; align-items: center; }
.sb-row select.combo { min-height: 50px; font-size: 0.92rem; padding-right: 2.2rem; }
.sb-row .btn { margin: 0; min-height: 50px; font-size: 0.95rem; }
.similar-bar.floating { position: fixed; left: 50%; transform: translateX(-50%); width: min(calc(100% - 2rem), 34rem); margin: 0; bottom: calc(var(--nav-h) + 0.8rem + env(safe-area-inset-bottom)); }
.tile input:checked + .tile-box .tile-icon { background: var(--surface); }
.similar-bar.floating { padding: 0.65rem 0.8rem 0.75rem; }
.similar-bar.floating .sb-info { margin: 0; font-weight: 600; color: var(--ink); }
.similar-bar.floating .sb-head { order: 0; }
.sb-head .link { white-space: nowrap; }
.similar-bar.floating .sb-row { margin-top: 0.45rem; }
.similar-bar.floating .sb-row select.combo, .similar-bar.floating .sb-row .btn { min-height: 46px; }
.sb-head { flex-wrap: wrap; }
.sb-head .sb-info { flex: 1 1 100%; order: 3; }
.similar-bar.floating .sb-head .sb-info { flex: 1; order: 0; }

/* ---------- stars, badges ---------- */
.stars { display: flex; justify-content: center; align-items: flex-end; gap: 0.35rem; margin: 0.1rem 0 0.4rem; }
.star svg { display: block; width: 44px; height: 44px; fill: rgba(255, 255, 255, .22); stroke: rgba(255, 255, 255, .45); stroke-width: 1.2; stroke-linejoin: round; }
.stars.big .star.s1 svg { width: 62px; height: 62px; }
.stars.big .star.s1 { margin-bottom: 0.45rem; }
.star.on svg { fill: #fcd34d; stroke: #f59e0b; filter: drop-shadow(0 4px 8px rgba(120, 60, 0, .35)); }
.star.on { animation: starPop .5s cubic-bezier(.2, 1.6, .5, 1) both; }
.star.on.s1 { animation-delay: .15s; } .star.on.s2 { animation-delay: .3s; }
@keyframes starPop { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .star.on { animation: none; } }
.res-badge { display: flex; align-items: center; gap: 0.7rem; text-align: left; margin: 0.9rem auto 0.1rem; max-width: 22rem; background: rgba(255, 255, 255, .16); border: 1.5px solid rgba(255, 255, 255, .35); border-radius: 18px; padding: 0.6rem 0.9rem; font-size: 0.92rem; }
.res-medal { font-size: 2.3rem; line-height: 1; flex: none; animation: starPop .6s .45s cubic-bezier(.2, 1.6, .5, 1) both; }
.badge-shelf { display: flex; align-items: center; gap: 0.9rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.85rem 1rem; margin: 0 0 1.2rem; }
.medal { width: 58px; height: 58px; border-radius: 18px; background: #fef3c7; display: inline-flex; align-items: center; justify-content: center; font-size: 2rem; flex: none; }
.medal.empty { filter: grayscale(1); opacity: .5; }
.shelf-text { display: flex; flex-direction: column; }
.shelf-text span { color: var(--muted); font-size: 0.92rem; }
.avatar-wrap { position: relative; flex: none; }
.avatar-badge { position: absolute; right: -8px; bottom: -6px; background: var(--surface); color: var(--ink); border-radius: 999px; padding: 0 0.35rem; font-size: 0.72rem; font-weight: 700; line-height: 1.5; box-shadow: var(--shadow); white-space: nowrap; }

/* ---------- bottom bar: every slot the same size in every language ---------- */
.bottom-nav { grid-template-columns: repeat(2, minmax(0, 1fr)) 72px repeat(2, minmax(0, 1fr)); }
.tab, .tab[aria-current="page"] { flex-direction: column; gap: 3px; width: 100%; min-width: 0; height: 56px; min-height: 56px; padding: 0 2px; font-size: 0.7rem; box-shadow: none; }
.tab .ni, .tab[aria-current="page"] .ni { width: 23px; height: 23px; flex: none; }
.tab .tl { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.2; }
.tab[aria-current="page"] { background: var(--pri-soft); color: var(--pri); }
.round-btn { width: 46px; min-width: 46px; padding: 0; font-size: 0.85rem; }

/* subject tiles: equal height in every layout, icons on one line, text below */
.tiles { align-items: stretch; }
.tile { display: flex; }
.tile-box { flex: 1; width: 100%; justify-content: flex-start; padding-top: 1.1rem; }
.tile-icon { flex: none; width: 54px; height: 54px; font-size: 1.8rem; line-height: 1; }
.tile-icon svg { width: 34px; height: 34px; display: block; }
