/* ═══════════════════════════════════════════════════════════════════
   汉语词汇 — Chinese Vocabulary Review
   Design system: 朱印 / Vermillion Seal
   Paper grounds, ink typography, one seal-red accent, hairline rules.
   Hanzi is always the largest element of any card; pinyin at its side.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Tokens ──────────────────────────────────────────────────────── */
:root {
  --ground:  #F6F5F0;   /* xuan paper */
  --surface: #FFFFFF;
  --ink:     #1B1A18;
  --soft:    #59564F;
  --faint:   #8B877D;
  --hair:    #DEDBD2;
  --seal:    #B93A31;   /* vermillion — brand, pinyin, active, red marks */
  --on-seal: #F6F5F0;

  /* study states (semantic, practice tools only) */
  --green:      #2F6E4A;
  --green-bg:   #E9F1EB;
  --green-line: #9DBFA9;
  --ochre:      #96690B;
  --ochre-bg:   #F6EDD6;
  --ochre-line: #D3B978;
  --red:        #B93A31;
  --red-bg:     #F7E4E1;
  --red-line:   #D9958E;

  --cjk:   "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --latin: "Newsreader", "Iowan Old Style", Palatino, Georgia, serif;
  --ui:    "Instrument Sans", -apple-system, "Helvetica Neue", Arial, sans-serif;

  --radius: 4px;
  --radius-sm: 3px;
  --sidebar-w: 252px;
  --tabbar-h: 58px;
  --transition: 0.15s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground:  #171614;   /* ink stone */
    --surface: #201F1C;
    --ink:     #EAE6DD;
    --soft:    #ABA69B;
    --faint:   #7C786E;
    --hair:    #383630;
    --seal:    #D0574C;
    --on-seal: #F6F5F0;
    --green:      #85C7A0;
    --green-bg:   #20342A;
    --green-line: #3F6650;
    --ochre:      #D5A445;
    --ochre-bg:   #342C18;
    --ochre-line: #6E5B2B;
    --red:        #D0574C;
    --red-bg:     #3B211E;
    --red-line:   #7A423B;
  }
}
:root[data-theme="dark"] {
  --ground:  #171614;
  --surface: #201F1C;
  --ink:     #EAE6DD;
  --soft:    #ABA69B;
  --faint:   #7C786E;
  --hair:    #383630;
  --seal:    #D0574C;
  --on-seal: #F6F5F0;
  --green:      #85C7A0;
  --green-bg:   #20342A;
  --green-line: #3F6650;
  --ochre:      #D5A445;
  --ochre-bg:   #342C18;
  --ochre-line: #6E5B2B;
  --red:        #D0574C;
  --red-bg:     #3B211E;
  --red-line:   #7A423B;
}
:root[data-theme="light"] {
  --ground:  #F6F5F0;
  --surface: #FFFFFF;
  --ink:     #1B1A18;
  --soft:    #59564F;
  --faint:   #8B877D;
  --hair:    #DEDBD2;
  --seal:    #B93A31;
  --on-seal: #F6F5F0;
  --green:      #2F6E4A;
  --green-bg:   #E9F1EB;
  --green-line: #9DBFA9;
  --ochre:      #96690B;
  --ochre-bg:   #F6EDD6;
  --ochre-line: #D3B978;
  --red:        #B93A31;
  --red-bg:     #F7E4E1;
  --red-line:   #D9958E;
}

/* ── Base ────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html { background: var(--ground); }

body {
  margin: 0;
  font-family: var(--latin);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { text-wrap: balance; }

a { color: inherit; }

button { font-family: var(--ui); }

:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Small-caps utility label — the voice of all UI chrome */
.sidebar-section-label,
.word-bank-label,
.sentence-widget-label,
.sentence-prompt-label,
.eyebrow-label {
  font-family: var(--ui);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--faint);
}

/* Hanzi glyph square — the site's iconography */
.glyph {
  width: 30px;
  height: 30px;
  flex: none;
  display: inline-grid;
  place-items: center;
  font-family: var(--cjk);
  font-size: 1rem;
  font-weight: 500;
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: var(--surface);
  line-height: 1;
}

/* Seal brand mark */
.seal-mark {
  display: grid;
  grid-template-columns: 1fr 1fr;
  place-items: center;
  width: 56px;
  height: 56px;
  flex: none;
  padding: 6px;
  background: var(--seal);
  color: var(--on-seal);
  border-radius: 5px;
  box-shadow: inset 0 0 0 1.5px var(--on-seal), inset 0 0 0 3px var(--seal);
  font-family: var(--cjk);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

/* ── Layout: sidebar rail + main ─────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--ground);
  border-right: 1px solid var(--hair);
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: transform 0.22s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--hair);
}

.sidebar-title {
  font-family: var(--cjk);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
}

.sidebar-subtitle {
  font-family: var(--ui);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 24px;
  scrollbar-width: thin;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--hair); border-radius: 2px; }

.sidebar-section-label { padding: 12px 8px 6px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: var(--ui);
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--soft);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.sidebar-link:hover { color: var(--ink); background: var(--surface); }

.sidebar-link.active { color: var(--ink); }
.sidebar-link.active .glyph {
  background: var(--seal);
  border-color: var(--seal);
  color: var(--on-seal);
}

/* legacy emoji icon span (if any remain) */
.sidebar-link .icon { width: 1.2em; text-align: center; }

/* lesson jump-links: quieter, indented sub-list under the group labels */
.sidebar-link.is-lesson {
  padding: 5px 8px 5px 14px;
  font-size: 0.78rem;
  color: var(--faint);
  border-left: 1px solid var(--hair);
  border-radius: 0;
  margin-left: 6px;
}
.sidebar-link.is-lesson:hover { color: var(--ink); background: transparent; border-left-color: var(--seal); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 16, 0.4);
  z-index: 55;
}
.sidebar-overlay.open { display: block; }

.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 28px;
  background: var(--ground);
  border-bottom: 1px solid var(--hair);
}

.topbar-title {
  font-family: var(--ui);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--soft);
}

.topbar-controls { display: flex; align-items: center; gap: 8px; }

.sidebar-toggle {
  display: none;
  width: 34px;
  height: 34px;
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--cjk);
  font-size: 0.95rem;
  cursor: pointer;
  line-height: 1;
  transition: border-color var(--transition);
}
.theme-toggle:hover { border-color: var(--faint); }

/* ── Mobile bottom tab bar ───────────────────────────────────────── */
.tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  justify-content: space-around;
  align-items: flex-start;
  background: var(--surface);
  border-top: 1px solid var(--hair);
  padding: 7px 4px calc(9px + env(safe-area-inset-bottom, 0px));
}

.tabbar a {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 54px;
  font-family: var(--ui);
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--faint);
  text-decoration: none;
}

.tabbar a .glyph { width: 27px; height: 27px; font-size: 0.95rem; }

.tabbar a.active { color: var(--seal); }
.tabbar a.active .glyph {
  background: var(--seal);
  border-color: var(--seal);
  color: var(--on-seal);
}

/* ── Page scaffolding ────────────────────────────────────────────── */
.page-section { padding: 32px 28px 0; max-width: 940px; }

.section-title {
  font-family: var(--latin);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 6px;
}

.section-subtitle {
  font-size: 0.92rem;
  color: var(--soft);
  margin: 0 0 22px;
  max-width: 68ch;
}

.lesson-group-heading {
  font-family: var(--ui);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 34px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hair);
}
.lesson-group-heading:first-child { margin-top: 0; }

/* ── Homepage: hero + index ──────────────────────────────────────── */
.home-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 36px 28px 8px;
  max-width: 940px;
}

.home-hero h1 {
  font-family: var(--cjk);
  font-size: clamp(1.5rem, 4vw, 1.9rem);
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

.home-hero .home-sub {
  font-family: var(--ui);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 4px 0 0;
}

/* Sentence of the day */
.sentence-widget {
  margin: 24px 28px 0;
  max-width: 884px;
  padding: 24px 26px 20px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  position: relative;
}

.sentence-widget-label { color: var(--seal); display: block; margin-bottom: 12px; }

.sentence-zh {
  font-family: var(--cjk);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 500;
  line-height: 1.35;
  margin-bottom: 4px;
}

.sentence-pinyin {
  font-family: var(--latin);
  font-style: italic;
  font-size: 1.02rem;
  color: var(--seal);
  margin-bottom: 4px;
}

.sentence-en { color: var(--soft); font-size: 0.95rem; }

.sentence-widget-actions { position: absolute; top: 16px; right: 16px; }

/* Tool index — replaces the tool-card grid */
.tool-index {
  margin: 28px 28px 0;
  max-width: 884px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  overflow: hidden;
}

.tool-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hair);
  text-decoration: none;
  color: var(--ink);
  transition: background var(--transition);
}
.tool-row:last-child { border-bottom: 0; }
.tool-row:hover { background: var(--ground); }
.tool-row:hover .glyph { border-color: var(--seal); color: var(--seal); }

.tool-row .glyph { width: 36px; height: 36px; font-size: 1.15rem; }

.tool-row-name {
  font-family: var(--ui);
  font-size: 0.92rem;
  font-weight: 600;
}

.tool-row-desc {
  font-size: 0.84rem;
  color: var(--soft);
  margin-top: 1px;
}

.tool-row-arrow {
  margin-left: auto;
  color: var(--faint);
  font-family: var(--ui);
  font-size: 0.9rem;
}

/* Legacy tool-card classes (kept harmless if referenced) */
.tool-cards { display: none; }

/* ── Accordions (homepage + shared) ──────────────────────────────── */
.accordion-group { padding: 28px 28px 80px; max-width: 940px; }

.accordion {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.accordion-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 18px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--latin);
  font-size: 0.98rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.accordion-trigger:hover { background: var(--ground); }

.accordion-chevron {
  font-size: 0.6rem;
  color: var(--faint);
  transition: transform var(--transition);
}
.accordion-trigger.open .accordion-chevron { transform: rotate(180deg); }

.accordion-body {
  display: none;
  padding: 0 18px 18px;
  border-top: 1px solid var(--hair);
}
.accordion-body.open { display: block; }

.lesson-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border: 1px solid var(--seal);
  border-radius: 2px;
  font-family: var(--ui);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--seal);
  vertical-align: 2px;
}

/* ── Lessons page ────────────────────────────────────────────────── */
.lessons-page { padding: 32px 28px 80px; max-width: 940px; }

.builder-header { margin-bottom: 4px; }

.lesson-toc-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
}

.lesson-toc-bar label {
  font-family: var(--ui);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.lesson-toc-select {
  flex: 1;
  min-width: 180px;
  padding: 8px 10px;
  font-family: var(--ui);
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
}

.lesson-toc-actions { display: flex; gap: 8px; }

/* Vocab cards — the entry molecule */
.vocab-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 12px;
  padding-top: 16px;
}

.vocab-card {
  background: var(--ground);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  padding: 16px 16px 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.vc-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }

.vc-hanzi {
  font-family: var(--cjk);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.2;
}

.vc-pinyin {
  font-family: var(--latin);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--seal);
}

.vc-def { font-size: 0.92rem; color: var(--ink); }

.vc-example {
  border-top: 1px solid var(--hair);
  padding-top: 8px;
  margin-top: 2px;
  font-size: 0.84rem;
}
.vc-example .ex-zh { font-family: var(--cjk); font-size: 0.95rem; color: var(--ink); margin-bottom: 1px; }
.vc-example .ex-pinyin { font-style: italic; color: var(--soft); margin-bottom: 1px; }
.vc-example .ex-en { color: var(--soft); }

.vc-tags { margin-top: 2px; }

/* ── Metadata line (replaces rainbow tag pills) ──────────────────── */
.tag-chip {
  display: inline-block;
  font-family: var(--ui);
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
  margin-right: 4px;
  white-space: nowrap;
}
.tag-chip:not(:last-child)::after { content: "·"; margin-left: 6px; color: var(--hair); }
/* state hues retired — one quiet voice for all metadata */
.tag-chip.type, .tag-chip.hsk, .tag-chip.topic { color: var(--faint); background: none; border: none; }

/* ── Tables (glossary + lesson tables) ───────────────────────────── */
.vocab-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.9rem;
}

.vocab-table thead th {
  font-family: var(--ui);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--faint);
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hair);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.vocab-table thead th.sorted { color: var(--seal); }

.sort-indicator { margin-left: 4px; color: var(--hair); }
th.sorted .sort-indicator { color: var(--seal); }

.vocab-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--hair);
  vertical-align: baseline;
}
.vocab-table tbody tr:last-child td { border-bottom: 0; }

.cell-hanzi { font-family: var(--cjk); font-size: 1.3rem; font-weight: 500; white-space: nowrap; }
.cell-pinyin { font-family: var(--latin); font-style: italic; color: var(--seal); font-size: 0.92rem; white-space: nowrap; }
.cell-def { color: var(--ink); }
.cell-tags { max-width: 230px; }

.cell-example { color: var(--soft); font-size: 0.8rem; max-width: 300px; }
.cell-example .ex-zh { font-family: var(--cjk); font-size: 0.92rem; color: var(--ink); margin-bottom: 1px; }
.cell-example .ex-pinyin { font-style: italic; margin-bottom: 1px; }

/* ── Glossary controls ───────────────────────────────────────────── */
.glossary-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 9px 14px;
  font-family: var(--ui);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
}
.search-input:focus { outline: 2px solid var(--seal); outline-offset: -1px; border-color: var(--seal); }
.search-input::placeholder { color: var(--faint); }

.filter-select {
  padding: 9px 10px;
  font-family: var(--ui);
  font-size: 0.84rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  max-width: 230px;
}

.results-count {
  font-family: var(--ui);
  font-size: 0.76rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-family: var(--ui);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--ground);
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--transition), border-color var(--transition), color var(--transition);
}
.btn:hover { opacity: 0.85; }

.btn-primary { /* ink-filled is the default */ }

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--hair);
}
.btn-secondary:hover { opacity: 1; border-color: var(--faint); }

.btn-ghost {
  background: transparent;
  color: var(--faint);
  border-color: transparent;
}
.btn-ghost:hover { opacity: 1; color: var(--ink); }

.btn-sm { padding: 6px 12px; font-size: 0.68rem; }

/* ── Sentence Builder ────────────────────────────────────────────── */
.builder-page { padding: 32px 28px 80px; max-width: 940px; }

.mode-tabs {
  display: inline-flex;
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 22px;
}

.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 18px;
  border: 0;
  background: var(--surface);
  color: var(--soft);
  font-family: var(--ui);
  cursor: pointer;
  line-height: 1.2;
  transition: background var(--transition), color var(--transition);
}
.mode-tab + .mode-tab { border-left: 1px solid var(--hair); }
.mode-tab.active { background: var(--ink); color: var(--ground); }
.mode-tab:hover:not(.active) { color: var(--ink); }

/* hanzi + pinyin over the English action, mirroring the vocab-chip stack */
.mode-tab-word {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--cjk);
  font-size: 1rem;
  font-weight: 500;
}
.mode-tab-py {
  font-family: var(--latin);
  font-style: italic;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--seal);
}
.mode-tab.active .mode-tab-py { color: var(--ground); opacity: 0.72; }
.mode-tab-act {
  font-family: var(--ui);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
}

.sentence-display {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 22px;
}

.sentence-prompt-label { color: var(--seal); display: block; margin-bottom: 10px; }

.sentence-prompt-text {
  font-family: var(--cjk);
  font-size: clamp(1.2rem, 3.5vw, 1.55rem);
  font-weight: 500;
  line-height: 1.4;
}

.sentence-prompt-pinyin {
  font-family: var(--latin);
  font-style: italic;
  color: var(--soft);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* Session accuracy sits inside the sentence card, under the prompt */
.sentence-display .progress-row {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--hair);
}

.word-bank-label { display: block; margin-bottom: 10px; }

/* Answer slots — 田字格 practice squares when empty */
.slots-area {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch;
  min-height: 64px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  margin-bottom: 18px;
}

.slot {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 58px;
  min-height: 58px;
  padding: 5px 10px;
  border: 1px dashed var(--faint);
  border-radius: var(--radius-sm);
  background: transparent;
  position: relative;
  user-select: none;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

/* dashed cross guides inside empty squares */
.slot:not(.filled)::before,
.slot:not(.filled)::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.slot:not(.filled)::before { left: 50%; top: 7px; bottom: 7px; border-left: 1px dashed var(--hair); }
.slot:not(.filled)::after  { top: 50%; left: 7px; right: 7px; border-top: 1px dashed var(--hair); }

.slot.drag-over {
  border-color: var(--seal);
  background: var(--red-bg);
  transform: scale(1.05);
}
.slot.drag-over::before, .slot.drag-over::after { display: none; }

.slot.filled {
  border-style: solid;
  border-color: var(--hair);
  background: var(--ground);
  color: var(--ink);
  cursor: grab;
  touch-action: none;   /* filled slots are drag sources */
}

.slot.correct {
  border-color: var(--green-line);
  background: var(--green-bg);
}
.slot.correct .chip-py { color: var(--green); }

.slot.misplaced {
  border-color: var(--ochre-line);
  background: var(--ochre-bg);
}
.slot.misplaced .chip-py { color: var(--ochre); }

.slot.incorrect {
  border-color: var(--red-line);
  background: var(--red-bg);
}

.slot .remove-btn {
  display: none;
  position: absolute;
  top: -7px;
  right: -7px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 1px solid var(--hair);
  background: var(--surface);
  color: var(--soft);
  font-size: 0.6rem;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.slot.filled:hover .remove-btn { display: flex; }
@media (hover: none) {
  .slot.filled .remove-btn { display: flex; }
}

/* Word bank */
.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  margin-bottom: 18px;
  min-height: 60px;
}

.word-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 14px 6px;
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  background: var(--ground);
  color: var(--ink);
  cursor: grab;
  user-select: none;
  line-height: 1.2;
  touch-action: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--transition);
}

.word-chip:hover { border-color: var(--faint); }

.word-chip.dragging { opacity: 0.35; cursor: grabbing; }

.word-chip.used { opacity: 0.28; pointer-events: none; }

.word-chip.red {
  border-color: var(--red-line);
  background: var(--red-bg);
}
.word-chip.red .chip-py { color: var(--red); }

.word-chip.yellow {
  border-color: var(--ochre-line);
  background: var(--ochre-bg);
}
.word-chip.yellow .chip-py { color: var(--ochre); }

.chip-zh { font-family: var(--cjk); font-size: 1.15rem; font-weight: 500; }
.chip-py { font-family: var(--latin); font-style: italic; font-size: 0.66rem; color: var(--soft); }
.chip-en { font-family: var(--ui); font-size: 0.85rem; }

.slot .chip-zh { font-size: 1.15rem; }
.slot .chip-py { font-size: 0.62rem; }

/* Drag ghost — compositor-only positioning, the one shadow on the site */
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  pointer-events: none;
  will-change: transform;
  transition: none;
  opacity: 0.95;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 7px 14px 6px;
  border: 1px solid var(--seal);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  line-height: 1.2;
  box-shadow: 0 6px 18px rgba(20, 18, 16, 0.22);
}

.drag-ghost.bounce {
  transition: transform 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
  opacity: 0.8;
  border-color: var(--red-line);
}

@keyframes chip-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
.word-chip.shake { animation: chip-shake 0.35s ease; }

/* Legend chips in the builder subtitle */
.legend-chip {
  display: inline-block;
  padding: 0 7px;
  border-radius: 2px;
  font-family: var(--ui);
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid;
}
.legend-green  { background: var(--green-bg); border-color: var(--green-line); color: var(--green); }
.legend-yellow { background: var(--ochre-bg); border-color: var(--ochre-line); color: var(--ochre); }
.legend-red    { background: var(--red-bg);   border-color: var(--red-line);   color: var(--red); }

/* Builder controls + feedback + progress */
.builder-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch; /* equal height even when one button's label wraps
                            to two lines and another doesn't (mobile) */
  margin-bottom: 20px;
}
.builder-controls .btn { text-align: center; }

.feedback-bar {
  display: none;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  margin-bottom: 18px;
  border: 1px solid;
}
.feedback-bar.show { display: block; }
.feedback-bar.correct { background: var(--green-bg); color: var(--green); border-color: var(--green-line); }
.feedback-bar.correct { font-family: var(--latin); }
.feedback-bar.incorrect { background: var(--red-bg); color: var(--red); border-color: var(--red-line); }

.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--ui);
  font-size: 0.78rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.progress-bar-wrap {
  flex: 1;
  height: 4px;
  background: var(--hair);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--ink);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ── Tone Trainer ────────────────────────────────────────────────── */
.trainer-page { max-width: 680px; margin: 0 auto; padding: 32px 24px 80px; }

.trainer-score {
  text-align: center;
  font-family: var(--ui);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 18px;
  font-variant-numeric: tabular-nums;
}

.trainer-sentence {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  padding: 30px 26px;
  text-align: center;
  font-family: var(--cjk);
  font-size: clamp(1.35rem, 4vw, 1.8rem);
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 16px;
}

.trainer-blank {
  color: var(--seal);
  border-bottom: 2px solid var(--seal);
  padding: 0 6px;
}

.trainer-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.trainer-option {
  padding: 15px 12px;
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--latin);
  font-style: italic;
  font-size: 1.15rem;
  cursor: pointer;
  transition: border-color var(--transition);
}
.trainer-option:hover:not(:disabled) { border-color: var(--faint); }
.trainer-option:disabled { cursor: default; }
.trainer-option.correct { border-color: var(--green-line); background: var(--green-bg); color: var(--green); }
.trainer-option.incorrect { border-color: var(--red-line); background: var(--red-bg); color: var(--red); }

.trainer-feedback {
  display: none;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 0.92rem;
  text-align: center;
  margin-bottom: 16px;
}
.trainer-feedback.show { display: block; }
.trainer-feedback.correct { background: var(--green-bg); color: var(--green); border-color: var(--green-line); }
.trainer-feedback.incorrect { background: var(--red-bg); color: var(--red); border-color: var(--red-line); }

.trainer-controls { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(20,18,16,0.15); }
  .sidebar-toggle { display: block; }
  .main { margin-left: 0; padding-bottom: calc(var(--tabbar-h) + 24px); }
  .tabbar { display: flex; }

  .topbar { padding: 10px 16px; }
  .page-section, .accordion-group, .lessons-page, .builder-page { padding-left: 16px; padding-right: 16px; }
  .home-hero { padding-left: 16px; padding-right: 16px; }
  .sentence-widget, .tool-index { margin-left: 16px; margin-right: 16px; }
  .vocab-card-grid { grid-template-columns: 1fr; }
  .trainer-options { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .mode-tabs { width: 100%; }
  .mode-tab { flex: 1; }
}

@media (max-width: 480px) {
  .builder-controls .btn { flex: 1; }
  .slots-area { padding: 10px; }
  .glossary-controls .filter-select { max-width: none; flex: 1; }
}

/* Touch devices: larger targets */
@media (hover: none) {
  .word-chip { padding: 9px 16px 8px; }
  .slot { min-width: 62px; min-height: 62px; }
  .slot .remove-btn { width: 22px; height: 22px; font-size: 0.75rem; top: -9px; right: -9px; }
}

/* ── Utilities ───────────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

[id] { scroll-margin-top: 62px; }
