:root {
  --bg: #efefef;
  --surface: #ffffff;
  --surface-soft: #f7f7f7;
  --text: #0f2a3b;
  --muted: #536d80;
  --line: #c7d5e2;
  --primary: #2f8fd2;
  --primary-dark: #1f6da5;
  --primary-soft: #e8f4fd;
  --success: #41ad3f;
  --success-dark: #2f7e2e;
  --error: #d64a4a;
  --error-dark: #a93232;
  --shadow: 0 10px 30px rgba(23, 52, 75, 0.08);
  --radius: 20px;
  --radius-sm: 12px;
  --container: 1340px;
}

:root[data-theme="dark"] {
  --bg: #0f1720;
  --surface: #14202c;
  --surface-soft: #182635;
  --text: #e8f2fa;
  --muted: #9db5c7;
  --line: #264055;
  --primary: #49a2e1;
  --primary-dark: #8cc9f2;
  --primary-soft: rgba(73, 162, 225, 0.14);
  --success: #4eba63;
  --success-dark: #3f9b54;
  --error: #e05f5f;
  --error-dark: #c94f4f;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .2s ease, color .2s ease;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.container { width: min(var(--container), calc(100% - 2rem)); margin: 0 auto; }
.hidden { display: none !important; }
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
  backdrop-filter: blur(10px);
}
.header-inner, .footer-inner {
  display:flex; align-items:center; justify-content:space-between; gap:1rem; padding: 1rem 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .85rem;
  min-height: 48px;
}
.brand-mark {
  position: relative;
  width: 14px;
  height: 34px;
  flex: 0 0 auto;
}
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  transform-origin: center;
  border-radius: 999px;
}
.brand-mark::before {
  width: 4px;
  height: 100%;
  top: 0;
  transform: translateX(-50%) rotate(11deg);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--primary) 82%, white 18%) 0%,
    color-mix(in srgb, var(--primary-dark) 84%, var(--text) 16%) 48%,
    color-mix(in srgb, var(--primary) 68%, black 32%) 100%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--primary) 10%, transparent);
  opacity: .95;
}
.brand-mark::after {
  width: 11px;
  height: 8px;
  bottom: 2px;
  transform: translateX(-30%) rotate(-20deg);
  background: color-mix(in srgb, var(--primary) 78%, var(--text) 22%);
  filter: blur(.2px);
  opacity: .88;
}
.brand-wordmark {
  position: relative;
  display: inline-block;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  font-size: clamp(1.45rem, 1.25rem + 0.62vw, 1.95rem);
  font-weight: 600;
  letter-spacing: .045em;
  text-transform: none;
  color: var(--text);
  line-height: 1;
  padding: .1rem 0 .12rem;
}
.brand-wordmark::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--primary) 0%, transparent),
    color-mix(in srgb, var(--primary) 58%, var(--text) 42%),
    color-mix(in srgb, var(--primary) 0%, transparent));
  opacity: .42;
}
.main-nav { display:flex; gap:.45rem; flex-wrap: wrap; }
.main-nav a {
  padding: .72rem 1rem; border-radius: 999px; color: var(--muted); transition: .18s ease;
}
.main-nav a:hover, .main-nav a.active { background: color-mix(in srgb, var(--surface) 84%, var(--primary-soft) 16%); color: var(--primary-dark); }
.page-layout { padding: 2rem 0 3rem; }
.page-heading { margin-bottom: 1.25rem; }
.eyebrow {
  display:inline-flex; align-items:center; padding:.35rem .7rem; border-radius:999px;
  background: var(--primary-soft); color: var(--primary-dark); text-transform: uppercase;
  font-weight: 700; font-size: .82rem; letter-spacing: .03em; margin: 0 0 .9rem;
}
h1 { margin:0 0 .9rem; font-size: clamp(2rem, 3vw, 3rem); line-height: 1.06; }
h2 { margin:0 0 .85rem; font-size: 1.35rem; line-height:1.2; }
p { margin: 0 0 1rem; line-height: 1.6; }
.lead { max-width: 78ch; color: #29475c; font-size: 1.05rem; }
.card {
  background: var(--surface); border: 1px solid #dbe6f0; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.3rem;
}
.button, .text-link, .mode-tile, .topic-tile {
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease;
}
.button {
  display:inline-flex; align-items:center; justify-content:center; gap:.5rem;
  border: 2px solid var(--primary); background: #fff; color: var(--primary-dark);
  padding: .9rem 1.15rem; border-radius: 14px; cursor: pointer; min-height: 52px;
}
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--primary); color: #fff; }
.button.success { background: var(--success); border-color: var(--success); color:#fff; }
.button.danger { border-color: var(--error); color: var(--error-dark); }
.button-stack { display:flex; gap:.75rem; flex-wrap:wrap; }
.inline-actions { display:flex; gap:.75rem; flex-wrap:wrap; align-items:center; }
.hero-panel { margin-bottom: 1.2rem; }
.selection-shell { display:grid; gap: 1.1rem; }
.selection-banner {
  display:grid; gap: 1rem; grid-template-columns: 1.2fr .8fr; align-items:start;
}
.info-list { margin: 0; padding-left: 1.1rem; color: var(--muted); }
.selection-grid { display:grid; gap: 1.1rem; }
.level-row { display:grid; gap: 1rem; }
.level-section { display:grid; gap:.7rem; }
.level-section-header { display:flex; flex-direction:column; gap:.2rem; padding:.15rem .1rem; }
.level-section-title { margin:0; font-size:1rem; color: var(--primary-dark); }
.level-section-subtitle { margin:0; color: var(--muted); font-size:.9rem; }
.level-band-grid { display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap:.85rem; }
.mode-row, .wide-row {
  display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem;
}
.wide-row.single { grid-template-columns: 1fr; }
.mode-tile, .topic-tile {
  appearance:none; border: 4px solid var(--primary); background: #fff; color: var(--primary-dark);
  border-radius: 0; padding: .95rem 1rem; text-align:center; cursor:pointer;
  min-height: 72px; width: 100%; display:flex; align-items:center; justify-content:center; flex-direction:column;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.mode-tile .tile-title, .topic-tile .tile-title { font-size: 1.02rem; font-weight: 700; }
.mode-tile .tile-subtitle, .topic-tile .tile-subtitle { font-size: .9rem; color: #5e7e97; }
.mode-tile.is-active, .topic-tile.is-active {
  background: var(--primary); color: #fff;
}
.mode-tile.is-active .tile-subtitle, .topic-tile.is-active .tile-subtitle { color: rgba(255,255,255,.92); }
.topic-columns { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .85rem; }
.topic-column-title {
  text-align:center; color: var(--primary-dark); font-size: clamp(1.25rem, 2vw, 1.9rem); margin-bottom: .6rem;
}
.topic-column { display:grid; gap: .85rem; align-content:start; }
.selection-footer { display:flex; justify-content:center; padding-top: .8rem; }
.primary-launch {
  min-width: 220px; min-height: 70px; border-radius: 18px; font-size: 1.2rem; font-weight:700;
  box-shadow: 0 10px 0 rgba(32, 106, 164, .15);
}
.selector-note { color: var(--muted); font-size: .95rem; }
.badge {
  display:inline-flex; align-items:center; justify-content:center;
  min-width: 34px; padding: .22rem .55rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark);
  font-size: .84rem; font-weight:700;
}
.badge.soft { background: #eef4f8; color: #507189; }
.entry-meta { margin-bottom: .5rem; display:flex; justify-content:flex-end; }
.kpi-grid { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.kpi-card { padding: .95rem; border-radius: 18px; background: var(--surface-soft); border: 1px solid #dfe8ef; }
.kpi-card strong { display:block; font-size: 1.5rem; margin-bottom: .25rem; }
.kpi-card span { color: var(--muted); font-size: .92rem; }

.quiz-shell { display:grid; gap: 1rem; }
.quiz-topbar {
  display:flex; justify-content:space-between; gap:1rem; align-items:flex-start; flex-wrap:wrap;
}
.quiz-actions { display:flex; gap:.75rem; flex-wrap: wrap; }
.live-stats { display:grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .7rem; }
.stat-box { background:#fff; border:1px solid #dbe6f0; border-radius:16px; padding:.9rem; text-align:center; }
.stat-box strong { display:block; font-size: 1.35rem; color: var(--primary-dark); }
.stat-box span { color: var(--muted); font-size: .88rem; }
.quiz-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .9rem; }
.quiz-card {
  background: var(--primary); border-radius: 18px; padding: 1rem; min-height: 210px; display:flex; flex-direction:column;
  border: 3px solid var(--primary); color:#fff; box-shadow: var(--shadow);
}
.quiz-card.is-correct { background: var(--success); border-color: var(--success-dark); }
.quiz-card.is-wrong { background: var(--error); border-color: var(--error-dark); }
.quiz-card-header { display:flex; justify-content:space-between; gap:.5rem; align-items:flex-start; margin-bottom: .75rem; }
.quiz-card-number { font-size: .78rem; letter-spacing:.04em; text-transform: uppercase; opacity: .88; }
.quiz-card-topic { font-size: .76rem; padding: .2rem .45rem; border-radius: 999px; background: rgba(255,255,255,.18); }
.quiz-prompt {
  flex:1; display:grid; place-items:center; text-align:center; font-size: clamp(1.55rem, 2.5vw, 2.45rem); font-weight:700;
}
.quiz-input-stack { display:grid; gap: .55rem; }
.sr-only { position:absolute !important; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.quiz-input-label { display:grid; gap: .3rem; }
.quiz-input-label span { font-size: .8rem; font-weight: 700; letter-spacing: .02em; }
.quiz-input {
  width:100%; border:none; border-radius: 10px; min-height: 52px; padding: .8rem .9rem; text-align:center;
  background: #f5f8fb; color: var(--text); outline: none;
}
.quiz-input:focus { box-shadow: 0 0 0 4px rgba(255,255,255,.28); }
.quiz-input:disabled { background: rgba(255,255,255,.86); color: #1d5320; font-weight: 700; }
.quiz-helper { min-height: 24px; margin-top: .7rem; font-size: .84rem; text-align:center; }
.quiz-legend { color: var(--muted); font-size: .96rem; }
.quiz-legend ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.feedback-strip {
  border-radius: 16px; padding: .95rem 1rem; border:1px solid #dbe6f0; background:#fff;
}
.feedback-strip.success { border-color: #bfe3bf; background:#eef9ee; color: #216321; }
.feedback-strip.error { border-color: #f0c0c0; background:#fff0f0; color: #8e2424; }
.summary-panel { margin-top: .6rem; }
.summary-table-wrap { overflow:auto; }
.summary-table { width:100%; border-collapse: collapse; min-width: 780px; }
.summary-table th, .summary-table td { padding: .8rem .75rem; border-bottom: 1px solid #e2ebf2; text-align:left; vertical-align: top; }
.summary-answer-line + .summary-answer-line { margin-top: .35rem; }
.summary-table th { font-size: .86rem; color: var(--muted); text-transform: uppercase; letter-spacing:.03em; }
.table-state { font-weight: 700; }
.table-state.ok { color: var(--success-dark); }
.table-state.bad { color: var(--error-dark); }
.table-state.pending { color: var(--muted); }

.filter-bar, .panel-grid, .editor-grid { display:grid; gap: 1rem; }
.panel-grid { grid-template-columns: 1fr; }
.filter-bar { grid-template-columns: 1.1fr .55fr .7fr; margin-bottom: 1rem; }
.field-group { display:flex; flex-direction:column; gap:.45rem; }
.field-group label { font-weight:600; color: var(--primary-dark); }
.field-group input, .field-group select, .field-group textarea {
  width:100%; border: 1px solid #cddae5; border-radius: 14px; padding: .9rem 1rem; background: #fff;
}
.dictionary-results, .saved-entries-list { display:grid; gap: 1rem; }
.topic-block { display:grid; gap: .75rem; }
.topic-block-header { display:flex; gap: .8rem; align-items:center; justify-content:space-between; flex-wrap: wrap; }
.entry-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .85rem; }
.entry-card { background:#fff; border:1px solid #dbe6f0; border-radius: 18px; padding: 1rem; box-shadow: var(--shadow); }
.entry-character { font-size: 2rem; color: var(--primary-dark); font-weight:700; margin-bottom: .45rem; }
.entry-pinyin { color: var(--primary); font-weight: 700; margin-bottom: .25rem; }
.entry-meaning { color: #29475c; }
.entry-extra-grid { margin-top: .75rem; display:grid; gap:.45rem; font-size:.9rem; color: var(--muted); }
.entry-extra-grid span { background: var(--surface-soft); border:1px solid var(--line); border-radius: 12px; padding: .55rem .7rem; }
.entry-extra-grid strong { color: var(--text); margin-right: .35rem; }
.entry-notes { margin-top: .5rem; color: var(--muted); font-size: .94rem; }
.entry-card-simple {
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  text-align:center;
  gap: .75rem;
  min-height: 240px;
  padding: 1.6rem 1.25rem;
}
.entry-card-simple .entry-character {
  margin-bottom: 0;
  font-size: clamp(2rem, 3vw, 3.2rem);
  line-height: 1;
}
.entry-card-simple .entry-pinyin {
  margin-bottom: 0;
  font-size: clamp(1.1rem, 1.5vw, 1.4rem);
  line-height: 1.15;
}
.entry-card-simple .entry-meaning {
  font-size: clamp(1rem, 1.2vw, 1.2rem);
  line-height: 1.25;
}
.info-box, .empty-state, .status-box {
  background:#fff; border:1px solid #dbe6f0; border-radius: 18px; padding: 1rem;
}
.empty-state h2, .empty-state p:last-child { margin-bottom: 0; }
.saved-entry {
  display:flex; justify-content:space-between; gap:1rem; flex-wrap:wrap; align-items:flex-start;
  background:#fff; border:1px solid #dbe6f0; border-radius:18px; padding:1rem;
}
.site-footer { margin-top: 2rem; border-top:1px solid rgba(47,143,210,.14); }
.footer-inner p { color: var(--muted); }

.footer-links { display:flex; align-items:center; gap:.9rem; flex-wrap:wrap; }
.footer-links a { color: var(--primary-dark); font-weight:600; }
.footer-links a:hover { text-decoration: underline; text-underline-offset: 3px; }
.footer-links .footer-separator { color: var(--muted); }

@media (max-width: 1040px) {
  .selection-banner, .topic-columns, .mode-row, .level-row, .filter-bar { grid-template-columns: 1fr; }
  .live-stats, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .header-inner, .footer-inner, .quiz-topbar { align-items:flex-start; }
  .footer-inner { flex-direction:column; }
  .main-nav { width: 100%; }
  .container { width: min(var(--container), calc(100% - 1rem)); }
  .quiz-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: 1fr; }
}


.info-box {
  padding: .95rem 1rem;
  border-radius: 16px;
  background: #fff;
  border: 1px solid #dbe6f0;
  color: var(--text);
}
.selection-options-card { padding: 1rem 1.2rem; }
.selection-options-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
}
.toggle-option {
  display: flex;
  align-items: flex-start;
  gap: .85rem;
  cursor: pointer;
  color: var(--text);
}
.toggle-option input {
  width: 22px;
  height: 22px;
  margin-top: .1rem;
  accent-color: var(--primary);
}
.toggle-option span { display: grid; gap: .15rem; }
.toggle-option small { color: var(--muted); font-size: .92rem; }

.quiz-session-card { padding: 1rem 1.3rem; }
.quiz-topbar-compact { align-items: center; }
.quiz-page-title {
  font-size: clamp(1.7rem, 2.2vw, 2.4rem);
  margin-bottom: .35rem;
}
.quiz-legend.compact {
  margin: 0;
  font-size: .94rem;
  line-height: 1.45;
}
.quiz-grid {
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 1rem;
}
.quiz-card {
  min-height: 255px;
  justify-content: space-between;
  border-radius: 16px;
}
.quiz-card-simple {
  display: flex;
  flex-direction: column;
  gap: .8rem;
  height: 100%;
}
.quiz-prompt {
  min-height: 120px;
  padding-top: .2rem;
  font-size: clamp(2rem, 3vw, 3.2rem);
}
.quiz-input-stack {
  display: grid;
  gap: .6rem;
}
.quiz-input-label {
  display: block;
}
.quiz-input-label span {
  display: none;
}
.quiz-input {
  min-height: 56px;
  border-radius: 10px;
  font-size: 1rem;
}
.quiz-input::placeholder {
  color: #6f879b;
}
.quiz-helper {
  min-height: 0;
  margin-top: 0;
  font-size: .84rem;
  text-align: center;
}
.quiz-helper.is-hidden {
  display: none;
}
.quiz-helper.is-error {
  color: rgba(255,255,255,.95);
  font-weight: 700;
}
.quiz-helper.is-success {
  color: rgba(255,255,255,.95);
  font-weight: 700;
}

@media (max-width: 920px) {
  .selection-options-row { align-items: flex-start; }
}


.header-right { display:flex; align-items:center; gap:1rem; flex-wrap:wrap; justify-content:flex-end; }
.header-controls { display:flex; align-items:center; gap:.65rem; flex-wrap:wrap; }
.header-control { display:flex; align-items:center; gap:.45rem; color: var(--muted); }
.header-control span { font-size: .9rem; font-weight: 600; }
.header-control.language-control {
  flex-direction: column-reverse;
  align-items: center;
  gap: .24rem;
}
.header-control.language-control span {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-align: center;
  line-height: 1.1;
}
.header-control.language-control select {
  min-width: 138px;
  text-align: center;
}
.header-control select {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: .7rem .9rem;
  min-height: 46px;
}
.button-compact { min-height: 46px; padding: .7rem .95rem; }

:root[data-theme="dark"] .main-nav a:hover,
:root[data-theme="dark"] .main-nav a.active { background: var(--surface); color: var(--primary-dark); }
:root[data-theme="dark"] .mode-tile,
:root[data-theme="dark"] .topic-tile,
:root[data-theme="dark"] .button,
:root[data-theme="dark"] .info-box,
:root[data-theme="dark"] .empty-state,
:root[data-theme="dark"] .status-box,
:root[data-theme="dark"] .stat-box,
:root[data-theme="dark"] .entry-card,
:root[data-theme="dark"] .saved-entry,
:root[data-theme="dark"] .field-group input,
:root[data-theme="dark"] .field-group select,
:root[data-theme="dark"] .field-group textarea,
:root[data-theme="dark"] .header-control select,
:root[data-theme="dark"] .summary-table th,
:root[data-theme="dark"] .summary-table td {
  border-color: var(--line);
}
:root[data-theme="dark"] .button { background: var(--surface); color: var(--primary-dark); }
:root[data-theme="dark"] .button.primary { background: var(--primary); color: #fff; }
:root[data-theme="dark"] .button.danger { color: #ffb1b1; }
:root[data-theme="dark"] .mode-tile,
:root[data-theme="dark"] .topic-tile { background: var(--surface); color: var(--primary-dark); }
:root[data-theme="dark"] .mode-tile .tile-subtitle,
:root[data-theme="dark"] .topic-tile .tile-subtitle { color: var(--muted); }
:root[data-theme="dark"] .mode-tile.is-active,
:root[data-theme="dark"] .topic-tile.is-active { background: var(--primary); color: #fff; }
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .stat-box,
:root[data-theme="dark"] .entry-card,
:root[data-theme="dark"] .saved-entry,
:root[data-theme="dark"] .info-box,
:root[data-theme="dark"] .empty-state,
:root[data-theme="dark"] .status-box { background: var(--surface); }
:root[data-theme="dark"] .kpi-card { background: var(--surface-soft); border-color: var(--line); }
:root[data-theme="dark"] .field-group input,
:root[data-theme="dark"] .field-group select,
:root[data-theme="dark"] .field-group textarea { background: var(--surface-soft); color: var(--text); }
:root[data-theme="dark"] .quiz-input { background: rgba(255,255,255,.92); color: #123044; caret-color: #123044; -webkit-text-fill-color: #123044; }
:root[data-theme="dark"] .quiz-input::placeholder { color: #6f879b; -webkit-text-fill-color: #6f879b; }
:root[data-theme="dark"] .summary-table th { color: var(--muted); }
:root[data-theme="dark"] .site-footer { border-top-color: color-mix(in srgb, var(--primary) 20%, transparent); }

@media (max-width: 1040px) {
  .header-right { justify-content:flex-start; width:100%; }
}
@media (max-width: 720px) {
  .header-controls { width:100%; justify-content:space-between; }
  .header-control.language-control { flex:1; }
  .header-control.language-control select { width:100%; }
  .button-compact { flex:1; }
}

:root[data-theme="dark"] .brand-wordmark { color: var(--text); }
:root[data-theme="dark"] .brand-mark::before { opacity: .9; }
:root[data-theme="dark"] .brand-mark::after { opacity: .82; }
:root[data-theme="dark"] .brand-wordmark::after { opacity: .56; }


.selection-language-note {
  display: inline-block;
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 640px) {
  .brand { gap: .65rem; }
  .brand-mark { width: 12px; height: 28px; }
  .brand-wordmark { font-size: 1.5rem; letter-spacing: .035em; }
}


/* Responsive refinement v13 */
html { -webkit-text-size-adjust: 100%; }

@media (max-width: 960px) {
  .site-header { position: sticky; }
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: .85rem;
    padding: .8rem 0;
  }
  .brand {
    min-height: 42px;
  }
  .header-right {
    width: 100%;
    display: grid;
    gap: .75rem;
  }
  .main-nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem;
  }
  .main-nav a {
    text-align: center;
    padding: .78rem .65rem;
    background: color-mix(in srgb, var(--surface) 88%, var(--primary-soft) 12%);
  }
  .header-controls {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .6rem;
    align-items: stretch;
  }
  .header-control.language-control {
    min-width: 0;
  }
  .header-control.language-control select,
  .button-compact {
    width: 100%;
  }
  .selection-banner {
    grid-template-columns: 1fr;
  }
  .mode-row {
    grid-template-columns: 1fr;
  }
  .topic-columns {
    grid-template-columns: 1fr 1fr;
  }
  .quiz-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .quiz-actions {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .container {
    width: min(var(--container), calc(100% - .85rem));
  }
  .page-layout {
    padding: 1rem 0 2rem;
  }
  h1 {
    font-size: clamp(1.75rem, 7vw, 2.2rem);
    line-height: 1.1;
  }
  p {
    margin-bottom: .85rem;
  }
  .card,
  .quiz-session-card {
    padding: 1rem;
    border-radius: 18px;
  }
  .site-header {
    backdrop-filter: blur(14px);
  }
  .header-inner {
    gap: .65rem;
    padding: .7rem 0;
  }
  .brand {
    gap: .55rem;
    min-height: 0;
  }
  .brand-mark {
    width: 11px;
    height: 26px;
  }
  .brand-wordmark {
    font-size: 1.36rem;
    letter-spacing: .03em;
  }
  .header-right {
    gap: .55rem;
  }
  .main-nav {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: .5rem;
    padding-bottom: .12rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .main-nav::-webkit-scrollbar {
    display: none;
  }
  .main-nav a {
    flex: 0 0 auto;
    min-width: 124px;
    padding: .72rem .9rem;
    border-radius: 999px;
  }
  .header-controls {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .55rem;
    align-items: center;
  }
  .header-control {
    width: 100%;
    min-width: 0;
  }
  .header-control span {
    display: none;
  }
  .header-control.language-control span {
    display: block;
  }
  .header-control select,
  .button-compact,
  .field-group input,
  .field-group select,
  .field-group textarea,
  .quiz-input {
    font-size: 16px;
  }
  .header-control select {
    min-height: 44px;
    padding: .65rem .85rem;
  }
  .button-compact {
    min-height: 44px;
    padding: .65rem .9rem;
    white-space: nowrap;
  }
  .selection-grid,
  .selection-shell,
  .quiz-shell {
    gap: .9rem;
  }
  .selection-options-card {
    padding: .95rem 1rem;
  }
  .selection-options-row {
    align-items: stretch;
  }
  .toggle-option {
    gap: .7rem;
  }
  .level-band-grid,
  .topic-columns,
  .entry-grid,
  .kpi-grid,
  .live-stats,
  .filter-bar,
  .button-stack {
    grid-template-columns: 1fr;
  }
  .mode-tile,
  .topic-tile {
    min-height: 64px;
    padding: .82rem .85rem;
  }
  .mode-tile .tile-title,
  .topic-tile .tile-title {
    font-size: .98rem;
  }
  .mode-tile .tile-subtitle,
  .topic-tile .tile-subtitle,
  .selector-note,
  .lead {
    font-size: .95rem;
  }
  .topic-column {
    gap: .7rem;
  }
  .topic-column-title {
    font-size: 1.04rem;
    margin-bottom: .35rem;
  }
  .primary-launch {
    width: 100%;
    min-width: 0;
    min-height: 60px;
    font-size: 1.05rem;
    box-shadow: 0 6px 0 rgba(32, 106, 164, .12);
  }
  .quiz-topbar,
  .quiz-topbar-compact {
    gap: .85rem;
    align-items: stretch;
  }
  .quiz-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: .55rem;
  }
  .quiz-actions .button {
    width: 100%;
  }
  .quiz-grid {
    grid-template-columns: 1fr;
    gap: .8rem;
  }
  .quiz-card {
    min-height: 0;
    padding: .95rem;
  }
  .quiz-prompt {
    min-height: 86px;
    font-size: clamp(1.95rem, 11vw, 2.55rem);
  }
  .quiz-input-stack {
    gap: .5rem;
  }
  .quiz-input {
    min-height: 52px;
    padding: .78rem .85rem;
  }
  .stat-box {
    padding: .75rem;
  }
  .summary-table-wrap {
    overflow: visible;
  }
  .summary-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 .8rem;
  }
  .summary-table thead {
    display: none;
  }
  .summary-table,
  .summary-table tbody,
  .summary-table tr,
  .summary-table td {
    display: block;
    width: 100%;
  }
  .summary-table tr {
    background: var(--surface);
    border: 1px solid #dbe6f0;
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .summary-table td {
    border-bottom: none;
    padding: .72rem .9rem;
  }
  .summary-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: .32rem;
    color: var(--muted);
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
  }
  .summary-table td + td {
    border-top: 1px solid #e2ebf2;
  }
  .summary-answer-line + .summary-answer-line {
    margin-top: .28rem;
  }
  .saved-entry {
    padding: .95rem;
  }
}

@media (max-width: 420px) {
  .main-nav a {
    min-width: 112px;
    padding: .68rem .8rem;
  }
  .brand-wordmark {
    font-size: 1.28rem;
  }
  .button-compact {
    padding: .65rem .8rem;
  }
  .quiz-prompt {
    min-height: 78px;
    font-size: clamp(1.8rem, 12vw, 2.2rem);
  }
  .eyebrow {
    font-size: .75rem;
  }
}

:root[data-theme="dark"] .summary-table tr {
  border-color: var(--line);
}

:root[data-theme="dark"] .summary-table td + td {
  border-top-color: color-mix(in srgb, var(--line) 88%, transparent);
}


.flashcard-results { display:grid; gap: 1rem; }
.flashcard-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .85rem; }
.flashcard-card {
  width: 100%;
  min-height: 220px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  perspective: 1200px;
  border-radius: 18px;
  text-align: inherit;
}
.flashcard-card-inner {
  position: relative;
  display: block;
  width: 100%;
  min-height: 220px;
  transform-style: preserve-3d;
  transition: transform .5s ease;
}
.flashcard-card.is-flipped .flashcard-card-inner { transform: rotateY(180deg); }
.flashcard-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 72%, white 28%);
  outline-offset: 4px;
}
.flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .9rem;
  padding: 1.2rem;
  border-radius: 18px;
  backface-visibility: hidden;
  box-shadow: var(--shadow);
  border: 1px solid #dbe6f0;
}
.flashcard-front {
  background: #fff;
  color: var(--text);
}
.flashcard-back {
  background: var(--primary-soft);
  color: var(--text);
  transform: rotateY(180deg);
}
.flashcard-character {
  font-size: clamp(2.1rem, 3vw, 2.8rem);
  line-height: 1.05;
  font-weight: 700;
  color: var(--primary-dark);
}
.flashcard-pinyin {
  font-size: clamp(1.1rem, 1.45vw, 1.35rem);
  line-height: 1.2;
  font-weight: 700;
  color: var(--primary-dark);
  text-align: center;
}
.flashcard-meaning {
  font-size: clamp(1rem, 1.2vw, 1.18rem);
  line-height: 1.35;
  text-align: center;
  color: var(--text);
}
.flashcard-hint {
  font-size: .82rem;
  line-height: 1.2;
  color: var(--muted);
  text-align: center;
}
:root[data-theme="dark"] .flashcard-front {
  background: var(--surface);
  border-color: var(--line);
}
:root[data-theme="dark"] .flashcard-back {
  border-color: var(--line);
}


/* Brand refresh: logo image */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0;
  min-height: 56px;
  padding: .1rem 0;
}
.brand-logo {
  display: block;
  height: 54px;
  width: auto;
  max-width: min(42vw, 320px);
}
.brand-logo-dark { display: none; }
:root[data-theme="dark"] .brand-logo-light { display: none; }
:root[data-theme="dark"] .brand-logo-dark { display: block; }
@media (max-width: 680px) {
  .brand { min-height: 46px; }
  .brand-logo { height: 42px; max-width: min(70vw, 250px); }
}
@media (max-width: 420px) {
  .brand-logo { height: 38px; max-width: min(74vw, 220px); }
}

/* Brand update: text-only wordmark */
.brand.brand-text-only {
  gap: 0;
  min-height: 56px;
  padding: .1rem 0;
}
.brand.brand-text-only .brand-wordmark {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(2.2rem, 1.9rem + 1vw, 3.05rem);
  font-weight: 800;
  letter-spacing: -0.028em;
  line-height: .96;
  color: var(--text);
  text-shadow: 0 1px 0 rgba(255,255,255,.08), 0 8px 18px rgba(0,0,0,.18);
  padding: 0;
}
.brand.brand-text-only .brand-wordmark::after {
  display: none;
}
:root[data-theme="dark"] .brand.brand-text-only .brand-wordmark {
  color: #eef3ff;
  text-shadow: 0 1px 0 rgba(255,255,255,.08), 0 8px 18px rgba(0,0,0,.42);
}
@media (max-width: 680px) {
  .brand.brand-text-only { min-height: 46px; }
  .brand.brand-text-only .brand-wordmark {
    font-size: clamp(1.85rem, 1.55rem + 1vw, 2.35rem);
  }
}
@media (max-width: 420px) {
  .brand.brand-text-only .brand-wordmark {
    font-size: clamp(1.6rem, 1.42rem + .8vw, 2rem);
  }
}
