/* ===================================================
   HSK4 HSK Prep — Shared Styles
   common.css

   Mobile-first responsive design system.
   Breakpoints: sm 480, md 768, lg 1024 (used as min-width).
   =================================================== */

/* === DESIGN TOKENS === */
:root {
  /* Warm parchment — platform palette (landing page uses landing.css) */
  --ink: #1a1614;
  --paper: #f9f4ec;
  --accent: #b84e2e;
  --accent-hover: #9a4026;
  --accent-soft: #f3e0d8;
  --accent-btn: #b84e2e;
  --accent-btn-hover: #9a4026;
  --jade: #2f6349;
  --jade-soft: #d8ebe1;
  --gold: #8a6420;
  --gold-soft: #f5ead0;
  --mist: #d4c9bc;
  --stone: #574f49;
  --correct: #2f6349;
  --wrong: #b84e2e;

  /* Semantic surfaces */
  --surface: #fffdf8;
  --surface-sunken: #efe6d9;
  --invert-bg: #1a1614;
  --invert-fg: #f9f4ec;
  --ok-bg: #e4f0e8;
  --ok-border: #4a8f6a;
  --ok-ink: #2f6a4f;
  --bad-bg: #f8e4dc;
  --bad-bg-2: #faf0ec;
  --bad-ink: #b84a2e;
  --accent-tint: #faf3ee;
  --gold-border: #e0cfa8;
  --border-subtle: rgba(44, 40, 37, 0.12);

  /* Radius & elevation */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 28px rgba(44, 40, 37, 0.07);
  --shadow-lg: 0 16px 44px rgba(44, 40, 37, 0.1);

  /* Spacing scale (4px base) */
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Fluid typography — interpolates 320px viewport -> 1440px viewport.
     Each token genuinely flows (2-6px gain), not stuck at one bound.
     All bounds in rem so users with non-default browser font-size get
     scaled values (WCAG 1.4.4 / SC Resize text). */
  --fs-xs:   clamp(0.6875rem, calc(0.69rem + 0.09vw), 0.75rem);
  --fs-sm:   clamp(0.75rem,   calc(0.71rem + 0.18vw), 0.875rem);
  --fs-base: clamp(0.875rem,  calc(0.84rem + 0.18vw), 1rem);
  --fs-md:   clamp(0.9375rem, calc(0.88rem + 0.27vw), 1.125rem);
  --fs-lg:   clamp(1.0625rem, calc(1rem + 0.27vw),    1.25rem);
  --fs-xl:   clamp(1.25rem,   calc(1.18rem + 0.36vw), 1.5rem);
  --fs-2xl:  clamp(1.375rem,  calc(1.27rem + 0.54vw), 1.75rem);
  --fs-h1:   clamp(1.625rem,  calc(1.375rem + 1.25vw), 2.5rem);

  /* Layout */
  --container: 900px;
  --header-h: 56px;
  --tap: 44px; /* min touch target */
}

/* === DARK THEME ===
   Applied when <html data-theme="dark"> is set (by the no-flash loader in
   each page's <head>, honouring a saved choice or the OS preference).
   Only re-maps the color tokens above — every component inherits the new
   palette through the variables, so light mode stays byte-identical. */
[data-theme="dark"] {
  --ink: #faf6f0;
  --paper: #141210;
  --accent: #e8886a;
  --accent-hover: #d47558;
  --accent-soft: #3d2c26;
  --accent-btn: #e8886a;
  --accent-btn-hover: #d47558;
  --jade: #6bc497;
  --jade-soft: #1c2e26;
  --gold: #e0b85a;
  --gold-soft: #2c2618;
  --mist: #4a443c;
  --stone: #b8afa6;
  --correct: #6bc497;
  --wrong: #e8886a;

  --surface: #262219;
  --surface-sunken: #302c24;
  --invert-bg: #302c24;
  --invert-fg: #faf6f0;
  --ok-bg: #1e2e26;
  --ok-border: #3a6b52;
  --ok-ink: #5daf87;
  --bad-bg: #3a2a24;
  --bad-bg-2: #2e221c;
  --bad-ink: #f0a088;
  --accent-tint: #2a221e;
  --gold-border: #4a3d20;
  --border-subtle: rgba(255, 255, 255, 0.1);

  --shadow: 0 20px 64px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

[data-theme="dark"] .btn-primary {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.12);
}

/* === READABLE SURFACES ===
   Page-specific <style> blocks often hardcode background:white, which
   stays white in dark mode while --ink flips to a light cream — invisible
   text. These rules re-bind common card/panel classes to theme tokens. */

.hero h1,
.dash-head h1,
.progress-title,
.modal-title,
.stat-num,
.dash-stat-num {
  color: var(--ink);
}

.progress-dashboard,
.filter-bar,
.vocab-card,
.tip-card,
.trap-card,
.trap-quiz-item,
.grammar-card,
.grammar-point,
.related-card,
.q-item,
.q-opt,
.fill-item,
.fill-check-btn,
.sentence-row,
.toc-pill,
.quiz-item,
.nf-link,
.content-card,
.option-btn,
.question-card,
.results-card,
.test-card,
.path-card,
.toolkit-card,
.plan-phase,
.topics-cluster,
.dash-stat-card,
.modal,
.pattern-box,
.conv-card,
.sort-tile,
.dd-tile,
.gen-tab:not(.active),
.conv-btn:not(.active),
.pr-filter:not(.active),
.word-card,
.topic-card,
.ex-card,
.level-card,
.writing-card,
.paragraph-card,
.strategy-card,
.trap-quiz-item,
.tq-opt,
.mistakes-box,
.format-table,
.compare-table td,
table.prog,
.prog td,
.seo-content h2,
.seo-content h3 {
  background: var(--surface);
  color: var(--ink);
}

.pill:not(.active),
.toggle-btn:not(.active) {
  background: var(--surface);
  color: var(--ink);
}

.progress-stats,
.dash-stat-label,
.stat-label,
.filter-label,
.vocab-count,
.hero p,
.dash-head p {
  color: var(--stone);
}

.progress-stats strong {
  color: var(--ink);
}

/* Dark mode: override hardcoded white in page-specific inline styles */
[data-theme="dark"] [style*="background:white"],
[data-theme="dark"] [style*="background: white"],
[data-theme="dark"] [style*="background:white;"],
[data-theme="dark"] [style*="background: white;"] {
  background: var(--surface) !important;
  color: var(--ink);
}

[data-theme="dark"] .progress-dashboard,
[data-theme="dark"] .progress-title,
[data-theme="dark"] .filter-bar,
[data-theme="dark"] .vocab-card,
[data-theme="dark"] .pill:not(.active),
[data-theme="dark"] .toggle-btn:not(.active),
[data-theme="dark"] .tip-card,
[data-theme="dark"] .trap-card,
[data-theme="dark"] .related-card,
[data-theme="dark"] .q-item,
[data-theme="dark"] .q-opt:not(.selected):not(.correct):not(.wrong),
[data-theme="dark"] .fill-item,
[data-theme="dark"] .fill-check-btn,
[data-theme="dark"] .sentence-row,
[data-theme="dark"] .quiz-item,
[data-theme="dark"] .grammar-card,
[data-theme="dark"] .modal,
[data-theme="dark"] .option-btn:not(.selected):not(.correct):not(.wrong),
[data-theme="dark"] .question-card,
[data-theme="dark"] .results-card,
[data-theme="dark"] .test-card,
[data-theme="dark"] .path-card,
[data-theme="dark"] .toolkit-card,
[data-theme="dark"] .dash-stat-card,
[data-theme="dark"] .tq-opt:not(.correct):not(.wrong),
[data-theme="dark"] .mistakes-box,
[data-theme="dark"] table.prog,
[data-theme="dark"] .format-table,
[data-theme="dark"] .compare-table td {
  background: var(--surface) !important;
  color: var(--ink);
}

/* Floating dark-mode toggle (injected on every page before </body>).
   Sits bottom-left so it never collides with the back-to-top button. */
.theme-toggle {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--mist);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 95;
  opacity: 0.85;
  transition: opacity 0.15s, transform 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover { opacity: 1; transform: translateY(-2px); border-color: var(--accent); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .ic-sun { display: none; }
.theme-toggle .ic-moon { display: block; }
[data-theme="dark"] .theme-toggle .ic-sun { display: block; }
[data-theme="dark"] .theme-toggle .ic-moon { display: none; }
@media (prefers-reduced-motion: reduce) { .theme-toggle { transition: none; } }

/* === RESET & BASE === */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg, video { max-width: 100%; height: auto; }
audio { width: 100%; max-width: 480px; }

.chinese { font-family: 'Noto Sans SC', 'Noto Serif SC', sans-serif; }
.serif-cn { font-family: 'Noto Serif SC', serif; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* Focus ring (a11y) — outline only, so element's own border-radius and
   box-shadow are preserved. The 3px outline + 2px offset gives a visible
   gap on light backgrounds without touching the element's own styling. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
/* Red buttons sit on the paper page background. A red ring on a red
   button is invisible; a paper ring would melt into the page. Use ink. */
.btn-primary:focus-visible,
.btn-jade:focus-visible {
  outline-color: var(--ink);
}
/* Dark ink header needs a light ring to contrast. */
header :focus-visible {
  outline-color: var(--invert-fg);
}

/* === HEADER === */
header {
  background: var(--invert-bg);
  color: var(--invert-fg);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--invert-fg);
  flex-shrink: 0;
  min-height: var(--tap);
}

.logo-mark {
  height: 32px;
  width: auto;
  max-width: 108px;
  flex-shrink: 0;
  display: block;
  object-fit: contain;
}

.logo-text {
  font-weight: 700;
  font-size: var(--fs-base);
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.logo-text span { color: var(--accent); }

/* Mobile: horizontal scroll nav (Pinterest/RedNote pattern).
   Primary IA stays visible — never hide nav behind a hamburger.
   Last visible chip half-cuts at the viewport edge, which is itself the
   "more content" affordance — no mask, no snap (snap feels jittery for
   free-browse chip navs). */
.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  /* 6px vertical padding gives clearance for the 3+2px focus outline
     on .nav-link, which would otherwise be clipped by overflow-y: hidden. */
  padding: 6px 0;
}
.site-nav::-webkit-scrollbar { display: none; }

.nav-link, .gh-link {
  position: relative;
  color: var(--invert-fg);
  opacity: 0.72;
  text-decoration: none;
  font-size: var(--fs-base);
  font-weight: 500;
  transition: opacity 0.2s, background 0.2s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px;
  min-height: var(--tap);
}
.nav-link:hover, .gh-link:hover { opacity: 1; }
.nav-link[aria-current="page"], .nav-link.is-active { opacity: 1; }
.nav-link[aria-current="page"]::after, .nav-link.is-active::after {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

/* Icon-only link needs a 44px hit area on its own */
.gh-link { min-width: var(--tap); }
.gh-link svg { width: 18px; height: 18px; fill: currentColor; }

/* Mobile (<768px): hamburger menu. With 11 links plus a wide logo, a
   horizontal scroll row shows only one chip on a 400px screen — worse
   discoverability than one tap into a full vertical panel. CSS-only
   (checkbox hack): no JS dependency, links stay in the DOM for crawlers.
   The checkbox is visually hidden but focusable, so keyboard users can
   toggle the panel with Space/Enter. */
.nav-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.nav-burger { display: none; }

@media (max-width: 767px) {
  .header-inner { position: relative; }

  .nav-burger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--tap);
    height: var(--tap);
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 8px;
  }
  .nav-burger-bar {
    position: relative;
    display: block;
    width: 20px;
    height: 2px;
    background: var(--invert-fg);
    border-radius: 1px;
    transition: background 0.2s;
  }
  .nav-burger-bar::before,
  .nav-burger-bar::after {
    content: '';
    position: absolute;
    left: 0;
    width: 20px;
    height: 2px;
    background: var(--invert-fg);
    border-radius: 1px;
    transition: transform 0.2s;
  }
  .nav-burger-bar::before { top: -6px; }
  .nav-burger-bar::after { top: 6px; }
  .nav-toggle:checked ~ .nav-burger .nav-burger-bar { background: transparent; }
  .nav-toggle:checked ~ .nav-burger .nav-burger-bar::before { transform: translateY(6px) rotate(45deg); }
  .nav-toggle:checked ~ .nav-burger .nav-burger-bar::after { transform: translateY(-6px) rotate(-45deg); }
  .nav-toggle:focus-visible ~ .nav-burger { outline: 3px solid var(--accent); outline-offset: 2px; }

  /* Dropdown panel anchored under the sticky header */
  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 4px 0 10px;
    background: var(--invert-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
    max-height: calc(100vh - 64px);
    overflow-y: auto;
  }
  .nav-toggle:checked ~ .site-nav { display: flex; }

  .nav-link, .gh-link {
    width: 100%;
    justify-content: flex-start;
    padding: 13px 20px;
    min-height: 48px;
    font-size: 15px;
    opacity: 0.85;
  }
  .nav-link[aria-current="page"], .nav-link.is-active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 3px 0 0 var(--accent);
  }
  .nav-link[aria-current="page"]::after, .nav-link.is-active::after { display: none; }
}

/* Very narrow screens: keep the logo clear of the burger */
@media (max-width: 374px) {
  .logo-mark { height: 26px; }
  .logo-text { font-size: 13px; }
}

/* Mobile: any table wider than the viewport scrolls instead of breaking
   the page layout (word tables, comparison tables, answer grids). */
@media (max-width: 640px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }
}

/* Tablet & up: relax scroll, allow wrap if needed */
@media (min-width: 768px) {
  .header-inner { padding: var(--space-4) var(--space-6); }
  .logo-mark { height: 36px; }
  .logo-text { font-size: 16px; }
  .site-nav {
    overflow: visible;
    flex: 0 1 auto;
    gap: var(--space-4);
  }
  .nav-link, .gh-link { padding: 6px 2px; }
}

/* === MAIN LAYOUT === */
main {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-4);
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
}

@media (min-width: 768px) {
  main { padding: var(--space-6); }
}

/* === HERO === */
.hero {
  text-align: center;
  padding: var(--space-8) 0 var(--space-6);
}

@media (min-width: 768px) {
  .hero { padding: var(--space-12) 0 var(--space-10); }
}

.hero-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 6px var(--space-4);
  border-radius: 100px;
  margin-bottom: var(--space-5);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.hero h1 {
  font-family: 'Noto Serif SC', serif;
  font-size: var(--fs-h1);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: var(--space-3);
  color: var(--ink);
}

.hero h1 .accent { color: var(--accent); }

.hero p {
  font-size: var(--fs-md);
  color: var(--stone);
  max-width: 560px;
  margin: 0 auto;
}

/* === SECTION TITLE === */
.section-title {
  font-size: var(--fs-base);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--stone);
  margin: var(--space-10) 0 var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--mist);
}

/* === STATS ROW === */
.stats-row {
  display: flex;
  justify-content: center;
  gap: var(--space-5);
  margin-top: var(--space-6);
  flex-wrap: wrap;
}

@media (min-width: 768px) { .stats-row { gap: var(--space-8); } }

.stat { text-align: center; min-width: 80px; }

.stat-num {
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--ink);
}

.stat-label {
  font-size: var(--fs-sm);
  color: var(--stone);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px var(--space-5);
  min-height: var(--tap);
  border-radius: 10px;
  font-size: var(--fs-base);
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s;
  font-family: 'DM Sans', sans-serif;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent-btn);
  color: #fff;
  border: 1px solid transparent;
  box-shadow: 0 4px 14px rgba(196, 92, 58, 0.22);
}
.btn-primary:hover { background: var(--accent-btn-hover); }
.btn-secondary {
  background: var(--surface-sunken);
  color: var(--ink);
  border: 1px solid var(--mist);
}
.btn-secondary:hover { background: #e8dfd4; }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--mist);
}
.btn-ghost:hover {
  background: var(--surface-sunken);
  border-color: var(--stone);
}
.btn-jade { background: var(--jade); color: white; }
.btn-jade:hover { background: #245a42; }

/* Full-width on small screens for primary CTAs */
.btn-block { width: 100%; }
@media (max-width: 479px) {
  .btn-block-sm { width: 100%; }
}

/* === CTA BANNER === */
.cta-banner {
  background: var(--invert-bg);
  color: var(--invert-fg);
  border-radius: var(--radius);
  padding: var(--space-6) var(--space-5);
  text-align: center;
  margin: var(--space-10) 0;
}

@media (min-width: 768px) {
  .cta-banner { padding: var(--space-10); margin: var(--space-12) 0; }
}

.cta-banner h2,
.cta-banner h3 {
  font-family: 'Noto Serif SC', serif;
  font-size: var(--fs-xl);
  margin-bottom: var(--space-2);
}

.cta-banner p {
  opacity: 0.7;
  font-size: var(--fs-base);
  margin-bottom: var(--space-5);
  color: var(--invert-fg);
}

/* === FOOTER === */
footer {
  padding: var(--space-8) var(--space-4);
  padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
  color: var(--stone);
  font-size: var(--fs-sm);
  border-top: 1px solid var(--mist);
  margin-top: var(--space-5);
}

footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Parent-brand block: surfaces "HSK Prep" as the publisher of this
   sub-property. Stacks vertically on mobile, side-by-side on tablet+. */
.footer-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  max-width: var(--container);
  margin: 0 auto var(--space-6);
  text-align: center;
}
@media (min-width: 768px) {
  .footer-brand {
    flex-direction: row;
    justify-content: center;
    gap: var(--space-8);
    text-align: left;
  }
}

.footer-brand-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--ink);
}
.footer-brand-link:hover { text-decoration: none; }
.footer-brand-link:hover .footer-brand-name { color: var(--accent); }

.footer-logo {
  height: 44px;
  width: auto;
  max-width: 108px;
  display: block;
  object-fit: contain;
}

.footer-brand-name {
  font-family: 'Noto Serif SC', serif;
  font-weight: 700;
  font-size: var(--fs-md);
  color: var(--ink);
  line-height: 1.2;
  transition: color 0.2s;
}

.footer-tagline {
  font-size: var(--fs-xs);
  color: var(--stone);
  margin-top: 2px;
}

.footer-cta {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
}

.footer-links {
  text-align: center;
  max-width: var(--container);
  margin: 0 auto;
  line-height: 1.9;
}

/* Promoted from index.html: tertiary link beneath a primary CTA button. */
.cta-link {
  display: inline-block;
  color: var(--invert-fg);
  opacity: 0.7;
  font-size: var(--fs-sm);
  margin-top: var(--space-3);
  text-decoration: none;
  transition: opacity 0.2s;
}
.cta-link:hover { opacity: 1; text-decoration: underline; }

/* === LOADING === */
.loading {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--stone);
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--mist);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto var(--space-4);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === SHARED CONTENT GRIDS ===
   Used by strategies/, compare/, vocabulary/, sentences/, etc. */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin: var(--space-6) 0;
}
@media (min-width: 480px) {
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-4); }
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--mist);
  border-radius: var(--radius);
  padding: var(--space-5);
  text-decoration: none;
  color: var(--ink);
  display: block;
  /* If a future variant animates color or background, add them here —
     the explicit list (vs `transition: all`) avoids animating layout. */
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.2s;
}
.content-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}

/* === BREADCRUMB === */
.breadcrumb {
  font-size: var(--fs-sm);
  color: var(--stone);
  margin-bottom: var(--space-2);
  word-break: break-word;
}
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* === RESPONSIVE TABLES (used by topics/, words/) ===
   Wrap any <table> in <div class="table-wrap"> for horizontal scroll on mobile. */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: var(--space-5) 0;
  border-radius: var(--radius-sm);
}
.table-wrap table { min-width: 100%; }

/* === A11Y / MOTION === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .content-card:hover, .test-card:hover { transform: none; }
}

/* === CHARACTER WRITER (used by /characters/) === */
.char-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin: var(--space-5) 0 var(--space-4);
}
.char-toolbar input[type="search"] {
  flex: 1 1 220px;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--mist);
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  background: var(--surface);
}
.char-toolbar input[type="search"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.char-toolbar select {
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--mist);
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  background: var(--surface);
}
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--space-3);
  margin: var(--space-5) 0;
}
.char-card {
  background: var(--surface);
  border: 1px solid var(--mist);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-2);
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
}
.char-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.char-card .char-glyph {
  font-family: 'Noto Serif SC', serif;
  font-size: 36px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}
.char-card .char-pinyin {
  font-size: var(--fs-xs);
  color: var(--accent);
  letter-spacing: 0.02em;
}
.char-card.is-hidden { display: none; }
.char-empty {
  color: var(--stone);
  font-size: var(--fs-sm);
  text-align: center;
  padding: var(--space-6);
}

/* === CHARACTER DETAIL PAGE === */
.char-header {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--mist);
  border-radius: var(--radius);
  padding: var(--space-6);
  margin: var(--space-5) 0;
}
.char-hero-glyph {
  font-family: 'Noto Serif SC', serif;
  font-size: clamp(72px, 14vw, 110px);
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  flex: 0 0 auto;
}
.char-meta {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.char-meta .char-pinyin-big {
  font-size: var(--fs-xl);
  color: var(--accent);
  font-weight: 600;
}
.char-meta .char-meaning {
  font-size: var(--fs-md);
  color: var(--ink);
  line-height: 1.5;
}
.char-meta .char-stats {
  font-size: var(--fs-sm);
  color: var(--stone);
  margin-top: 4px;
}

.writer-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-6) 0;
}
.writer-target {
  width: min(380px, 86vw);
  height: min(380px, 86vw);
  background:
    linear-gradient(to right, transparent calc(50% - 0.5px), var(--mist) calc(50% - 0.5px), var(--mist) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), var(--mist) calc(50% - 0.5px), var(--mist) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    white;
  border: 2px solid var(--mist);
  border-radius: var(--radius-sm);
  position: relative;
  touch-action: none;
}
.writer-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
}
.writer-status {
  font-size: var(--fs-sm);
  color: var(--stone);
  min-height: 22px;
  text-align: center;
}
.writer-status.is-success { color: var(--jade); font-weight: 600; }
.writer-status.is-mistake { color: var(--accent); font-weight: 600; }

.char-vocab-list {
  display: grid;
  gap: var(--space-3);
  margin: var(--space-4) 0;
}
.char-vocab-item {
  background: var(--surface);
  border: 1px solid var(--mist);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
}
.char-vocab-item .vw-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: 6px;
}
.char-vocab-item .vw-word {
  font-family: 'Noto Serif SC', serif;
  font-size: var(--fs-lg);
  font-weight: 600;
}
.char-vocab-item .vw-word .hl { color: var(--accent); }
.char-vocab-item .vw-pinyin { color: var(--accent); font-size: var(--fs-sm); }
.char-vocab-item .vw-meaning { color: var(--stone); font-size: var(--fs-sm); }
.char-vocab-item .vw-example {
  border-top: 1px dashed var(--mist);
  padding-top: 8px;
  margin-top: 6px;
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--stone);
}
.char-vocab-item .vw-example .ex-cn { color: var(--ink); }

.char-pager {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-8) 0 var(--space-5);
  flex-wrap: wrap;
}

/* Hide platform chrome until auth guard confirms session */
html.hsk-auth-pending body.app > *:not(script) {
  visibility: hidden;
}
html.hsk-auth-pending body.app::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--paper);
  z-index: 9999;
}
/* B3: a static first-paint spinner on the veil so a just-authenticated user sees
   motion (not a blank paper) during the Supabase session round-trip. Pseudo-
   elements of body.app aren't hidden by the `> *:not(script)` rule above. */
html.hsk-auth-pending body.app::after {
  content: '';
  position: fixed;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 3px solid var(--mist, #e7ded3);
  border-top-color: var(--accent, #b84e2e);
  border-radius: 999px;
  z-index: 10000;
  animation: hsk-spin 0.8s linear infinite;
}
@keyframes hsk-spin { to { transform: rotate(360deg); } }

/* === iOS focus-zoom guard ===
   iPhone Safari auto-zooms the viewport when a focused field's font-size is
   < 16px, and several inputs are styled .9–.95rem. Floor form controls on touch
   devices only — the !important beats their inline font-size, while pointer:fine
   (mouse) desktops keep the designed sizes. Use max(16px, …) rather than a flat
   16px so it never SHRINKS a field that is already ≥16px: iPads match this query
   too (hover:none/pointer:coarse) and load the desktop client, whose inputs use
   var(--fs-md) — which clamps above 16px on wide viewports and must stay put
   (iPadOS doesn't focus-zoom anyway). */
@media (hover: none) and (pointer: coarse) {
  input, textarea, select { font-size: max(16px, var(--fs-md)) !important; }
}
