/* ── Design Tokens ──────────────────────────────────────── */
:root {
  /* Linear Light */
  --primary:    #5E6AD2;
  --primary-d:  #4C58C0;
  --primary-l:  #ECEEFA;

  --success:    #26A869;
  --success-l:  #EDFAF4;
  --warn:       #C98A2B;
  --warn-l:     #FEF6E7;
  --danger:     #E5534B;
  --danger-l:   #FDECEA;

  --bg:         #F6F7F9;
  --surface:    #FFFFFF;
  --surface2:   #F0F1F4;
  --border:     #E4E5E9;
  --border-d:   #CACDD8;

  --text:       #141416;
  --text2:      #525866;
  --text3:      #9BA4B5;

  --radius:     6px;
  --radius-s:   4px;
  --radius-xs:  3px;
  --shadow:     0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-m:   0 2px 8px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --shadow-l:   0 4px 20px rgba(0,0,0,.10);

  --header-h:   52px;
  --sidebar-w:  200px;
  --max-w:      640px;
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono:       'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
}

.dark {
  --primary:    #5E6AD2;
  --primary-d:  #7B84E0;
  --primary-l:  #13163A;

  --success:    #26A869;
  --success-l:  #081A10;
  --warn:       #C98A2B;
  --warn-l:     #1A1005;
  --danger:     #E5534B;
  --danger-l:   #1A0907;

  --bg:         #0E0F13;
  --surface:    #13151C;
  --surface2:   #1C1F2A;
  --border:     #21222A;
  --border-d:   #2A2D3A;

  --text:       #E8EAF0;
  --text2:      #7B84A0;
  --text3:      #3A3F58;

  --shadow:     0 1px 3px rgba(0,0,0,.40);
  --shadow-m:   0 2px 8px rgba(0,0,0,.55);
  --shadow-l:   0 4px 20px rgba(0,0,0,.70);
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}
button {
  cursor: pointer; border: none; background: none;
  font-family: inherit; font-size: inherit;
  transition: background-color .15s, color .15s, opacity .15s, transform .1s;
}
button:active { transform: scale(.97); }
input, textarea, select {
  font-family: inherit; font-size: inherit;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(94,106,210,.18);
}

/* ── App Shell ──────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100dvh;
}

/* ── Sidebar ────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100dvh;
  position: sticky;
  top: 0;
  display: none;          /* shown at ≥900px via media query */
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 50;
}

.sb-logo {
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
  flex-shrink: 0;
}

.sb-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sb-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 12px 8px 4px;
  display: block;
}
.sb-label:first-child { padding-top: 4px; }

.sb-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 7px 8px 7px 10px;
  border-radius: var(--radius-s);
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  text-align: left;
  position: relative;
  transition: background-color .12s, color .12s;
}
.sb-btn:hover { background: var(--surface2); color: var(--text); }
.sb-btn.active {
  background: var(--surface2);
  color: var(--text);
  font-weight: 600;
}
.sb-btn.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 2px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}
.sb-btn:active { transform: none; }

.sb-count {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  background: var(--surface2);
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  line-height: 1.6;
  transition: background-color .12s, color .12s;
}
.sb-btn.active .sb-count {
  color: var(--primary);
  background: var(--primary-l);
}

.sb-footer {
  padding: 8px;
  flex-shrink: 0;
}
.sb-divider {
  height: 1px;
  background: var(--border);
  margin: 0 0 8px;
}
.sb-theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-s);
  color: var(--text3);
  margin-top: 4px;
  transition: background-color .12s, color .12s;
}
.sb-theme-btn:hover { background: var(--surface2); color: var(--text2); }
.sb-theme-btn svg { width: 15px; height: 15px; }
.sb-theme-btn:active { transform: none; }

/* ── Main content wrapper ───────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Header (mobile) ────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; }
.header-right { display: flex; align-items: center; }
.logo {
  font-size: 15px; font-weight: 700;
  color: var(--text);
  margin-right: 4px;
  white-space: nowrap;
  letter-spacing: -.01em;
}
nav {
  flex: 1; display: flex; justify-content: center;
  gap: 2px;
  overflow-x: auto; scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }
.nav-btn {
  padding: 5px 11px; border-radius: 20px;
  font-size: 13px; font-weight: 500;
  color: var(--text2);
  white-space: nowrap;
  transition: background-color .12s, color .12s;
}
.nav-btn:hover   { background: var(--surface2); color: var(--text); }
.nav-btn.active  { background: var(--primary-l); color: var(--primary); font-weight: 600; }
.nav-btn:active  { transform: none; }
.header-icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  background: var(--surface2);
  transition: background-color .12s;
}
.header-icon-btn svg { width: 16px; height: 16px; }
.header-icon-btn:hover { background: var(--border); }
.header-icon-btn:active { transform: none; }

/* ── Main / Views ───────────────────────────────────────── */
main { flex: 1; }
.view { display: none; max-width: var(--max-w); margin: 0 auto; padding: 20px 16px 80px; }
.view.active { display: block; }

/* ── Section helpers ────────────────────────────────────── */
.section-title {
  font-size: 10px; font-weight: 700;
  color: var(--text3); text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 10px;
}
.settings-section-title {
  font-size: 10px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 14px;
}
.section-block { margin: 24px 0; }

/* ── Today Charts ───────────────────────────────────────── */
#today-charts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tc-donut-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#tc-donut { display: block; color: var(--text); }
#tc-legend { display: flex; flex-direction: column; gap: 4px; }
.tc-legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text2); white-space: nowrap;
}
.tc-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.tc-cnt { margin-left: auto; font-weight: 600; color: var(--text); min-width: 24px; text-align: right; font-size: 11px; }
.tc-heatbar-wrap { min-width: 0; }
.tc-heatbar-title {
  font-size: 10px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px;
}
#tc-heatbar { display: block; width: 100%; }

/* ── Stat grid ──────────────────────────────────────────── */
.stat-grid {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 8px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 12px;
  text-align: center;
  transition: border-color .15s;
}
.stat-card:hover { border-color: var(--border-d); }
.stat-num  { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1.1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 11px; color: var(--text2); margin-top: 5px; }
.big-stat-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 8px; }

/* ── Done banner ────────────────────────────────────────── */
.done-banner {
  background: var(--success-l);
  border: 1px solid var(--success);
  border-left: 3px solid var(--success);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px;
  text-align: center;
}
.done-title { font-size: 15px; font-weight: 700; color: var(--success); }
.done-sub   { font-size: 12px; color: var(--success); margin-top: 3px; opacity: .75; }
.done-actions { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.done-action-btn {
  padding: 7px 18px; background: var(--primary); color: #fff; border-radius: var(--radius-s);
  font-size: 13px; cursor: pointer; border: none; font-weight: 500;
}
.done-action-btn:hover { background: var(--primary-d); }
.done-action-secondary {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border);
}
.done-action-secondary:hover { background: var(--border); }

/* ── Mode row ───────────────────────────────────────────── */
.mode-row {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.mode-btn {
  flex: 1; min-width: 64px;
  padding: 7px 12px; border-radius: var(--radius-s);
  font-size: 13px; font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text2);
  transition: background-color .12s, color .12s, border-color .12s;
}
.mode-btn:hover  { border-color: var(--primary); color: var(--primary); }
.mode-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.mode-btn:active { transform: none; }

/* ── Start button ───────────────────────────────────────── */
.start-btn {
  width: 100%; padding: 12px;
  background: var(--primary); color: #fff;
  border-radius: var(--radius); font-size: 14px; font-weight: 600;
  transition: background-color .15s, opacity .15s;
}
.start-btn:hover  { background: var(--primary-d); }
.start-btn:active { transform: scale(.99); }
.start-btn:disabled { background: var(--surface2); color: var(--text3); cursor: not-allowed; }
/* 继续上次学习 — sits above the normal start button */
.resume-btn { background: var(--success); margin-bottom: 8px; }
.resume-btn:hover { background: var(--success); opacity: .9; }
.unit-study-bar .resume-btn { margin-bottom: 0; }

/* ── Session header ─────────────────────────────────────── */
.session-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.back-btn {
  font-size: 12px; font-weight: 600; color: var(--text2);
  padding: 5px 10px; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface);
  white-space: nowrap;
  transition: background-color .12s, color .12s;
}
.back-btn:hover { background: var(--surface2); color: var(--text); }
.back-btn:active { transform: none; }
.prev-btn {
  font-size: 11px; font-weight: 500; color: var(--text3);
  padding: 5px 9px; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface);
  white-space: nowrap;
}
.prev-btn:active { transform: none; }
.progress-bar {
  flex: 1; height: 3px; background: var(--surface2); border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 100%; background: var(--primary); border-radius: 2px;
  transform-origin: left; transition: transform .4s cubic-bezier(.4,0,.2,1);
}
.session-count { font-size: 11px; font-weight: 600; color: var(--text3); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ── Flip Card ──────────────────────────────────────────── */
.card-wrapper { perspective: 1000px; margin-bottom: 14px; }
.flip-card {
  position: relative; width: 100%;
  min-height: 200px; cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .18s ease-out;
}
.flip-card.flipped { transform: rotateY(180deg); }
.flip-front, .flip-back {
  position: absolute; inset: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  text-align: center;
}
.flip-back { transform: rotateY(180deg); }
.card-unit { font-size: 10px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 10px; }
.card-zh   { font-size: 22px; font-weight: 600; color: var(--text); line-height: 1.4; margin-bottom: 8px; }
.card-pos  { font-size: 11px; color: var(--text3); font-style: italic; margin-bottom: 8px; }
.back-en   { font-size: 28px; font-weight: 700; color: var(--primary); margin-bottom: 10px; font-family: var(--mono); letter-spacing: -.03em; }
.back-zh   { font-size: 15px; color: var(--text2); }
.back-zh-row { display: flex; align-items: center; gap: 6px; }
.card-pos-back { margin-top: 10px; }
.tap-hint  { font-size: 10px; color: var(--text3); position: absolute; bottom: 12px; }
.tts-btn   { position: absolute; top: 10px; right: 10px; font-size: 16px; opacity: .4;
             transition: opacity .15s; background: none; }
.tts-btn:hover { opacity: 1; }
.tts-btn-back  { top: 10px; left: 10px; right: auto; }
.tts-btn svg   { width: 16px; height: 16px; }
.tts-btn:active { transform: none; }
.streak-dots { font-size: 13px; letter-spacing: 4px; color: var(--primary); margin-top: 4px; }

/* ── AI Section ─────────────────────────────────────────── */
.ai-section { margin-bottom: 10px; }
.ai-row { display: flex; gap: 6px; margin-bottom: 8px; }
.ai-btn {
  flex: 1; padding: 8px 10px; font-size: 12px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s); color: var(--text2);
  display: flex; align-items: center; justify-content: center; gap: 5px;
  transition: background-color .12s, color .12s, border-color .12s;
}
.ai-btn svg { width: 13px; height: 13px; }
.ai-btn:hover { border-color: var(--primary); color: var(--primary); }
.ai-btn:active { transform: none; }
.ai-content {
  background: var(--surface2); border-radius: var(--radius-s);
  padding: 10px 12px; font-size: 13px; color: var(--text2); line-height: 1.6;
  margin-top: 4px; display: none;
}
.ai-content:not(:empty) { display: block; }
.ai-content.show { display: block; }

.ai-block-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.ai-label {
  font-size: 10px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .06em;
}
.ai-block-actions { display: flex; gap: 4px; }
.ai-regen-btn, .ai-edit-btn { width: 22px; height: 22px; font-size: 12px; }
.example-en { font-size: 16px; color: var(--text); line-height: 1.6; margin-bottom: 3px; }
.example-cn { font-size: 14px; color: var(--text2); line-height: 1.5; }
.mnemonic-text { font-size: 16px; color: var(--text); line-height: 1.7; white-space: pre-line; }
.ai-md strong { color: var(--text); font-weight: 700; }
.ai-md em { color: var(--text3); font-style: italic; }
.ai-md code { background: var(--surface); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.ai-edit-area {
  width: 100%; min-height: 56px; padding: 7px 10px;
  border-radius: var(--radius-s); font-size: 12px; resize: vertical;
  margin-bottom: 4px; display: block;
}
.ai-save-btn {
  padding: 6px 16px; background: var(--primary); color: #fff;
  border-radius: var(--radius-s); font-size: 12px; font-weight: 600;
}

/* ── Rating row ─────────────────────────────────────────── */
.rating-row { display: flex; gap: 6px; }
.rate-btn {
  flex: 1; padding: 11px 6px; border-radius: var(--radius-s);
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text2);
  display: flex; align-items: center; justify-content: center; gap: 4px;
  transition: background-color .12s, border-color .12s, color .12s;
}
.rate-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.rate-btn:active { transform: scale(.97); }
.rate-btn.rate-selected { opacity: 1; }
.rate-btn.rate-dimmed   { opacity: .35; }
.rate-0 { border-color: rgba(229,83,75,.4); color: var(--danger); }
.rate-0:hover { background: var(--danger-l); border-color: var(--danger); }
.rate-3 { border-color: rgba(201,138,43,.4); color: var(--warn); }
.rate-3:hover { background: var(--warn-l); border-color: var(--warn); }
.rate-4 { border-color: rgba(38,168,105,.4); color: var(--success); }
.rate-4:hover { background: var(--success-l); border-color: var(--success); }
.rate-5 { border-color: rgba(94,106,210,.4); color: var(--primary); }
.rate-5:hover { background: var(--primary-l); border-color: var(--primary); }

/* ── Multiple Choice ────────────────────────────────────── */
.mc-question {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px 20px; margin-bottom: 12px;
  text-align: center;
}
.mc-zh   { font-size: 20px; font-weight: 700; margin-bottom: 5px; }
.mc-hint { font-size: 12px; color: var(--text3); margin-bottom: 4px; }
#mc-options { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.mc-option {
  width: 100%; padding: 12px 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s); font-size: 14px; font-weight: 500; color: var(--text);
  display: flex; align-items: center; gap: 10px;
  transition: background-color .12s, border-color .12s, color .12s;
}
.mc-option:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-l); }
.mc-opt-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface2); color: var(--text3);
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background-color .12s, color .12s;
}
.mc-option.correct { border-color: var(--success); background: var(--success-l); color: var(--success); }
.mc-option.correct .mc-opt-num { background: var(--success); color: #fff; }
.mc-option.wrong   { border-color: var(--danger); background: var(--danger-l); color: var(--danger); }
.mc-option.wrong .mc-opt-num   { background: var(--danger); color: #fff; }

.mc-reveal {
  background: var(--surface2); border-radius: var(--radius-s); padding: 10px 14px;
  margin-bottom: 8px; font-size: 13px;
}
.mc-reveal-result { font-weight: 700; margin-bottom: 3px; }
.mc-reveal-result.mc-correct { color: var(--success); }
.mc-reveal-result.mc-wrong   { color: var(--danger); }
.mc-reveal-answer { color: var(--text2); }

/* ── Dictation ──────────────────────────────────────────── */
.dict-zh   { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 5px; }
.dict-hint { font-size: 12px; color: var(--text3); text-align: center; margin-bottom: 12px; }
#dict-letter-row {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 5px; margin-bottom: 12px;
}
.letter-box {
  height: 42px; border-radius: var(--radius-s);
  background: var(--surface); border: 1px solid var(--border-d);
  text-align: center; font-size: 17px; font-weight: 700; color: var(--text); font-family: var(--mono);
  text-transform: lowercase;
  transition: border-color .15s, background-color .15s;
}
.letter-box.fixed   { background: var(--surface2); color: var(--text3); border-color: var(--border); }
.letter-box.correct { background: var(--success-l); border-color: var(--success); color: var(--success); }
.letter-box.wrong   { background: var(--danger-l); border-color: var(--danger); color: var(--danger); }
.letter-box:focus   { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(94,106,210,.18); }
.letter-box:disabled { opacity: 1; }

.dict-btn-row { display: flex; gap: 6px; justify-content: center; margin-bottom: 8px; }
.dict-submit {
  padding: 7px 16px;
  background: var(--surface2); color: var(--text2);
  border-radius: var(--radius-s); font-weight: 500; font-size: 12px;
  border: 1px solid var(--border);
  transition: background-color .12s, border-color .12s;
}
.dict-submit:hover { background: var(--border); color: var(--text); }
.dict-giveup-btn {
  padding: 7px 14px;
  background: var(--surface2); color: var(--text2);
  border-radius: var(--radius-s); font-weight: 600; font-size: 12px;
  border: 1px solid var(--border);
  transition: background-color .12s, border-color .12s;
  white-space: nowrap;
}
.dict-giveup-btn:hover { background: var(--border); color: var(--danger); border-color: var(--danger); }

#dict-reveal { display: flex; flex-direction: column; gap: 8px; align-items: center; margin: 6px 0 10px; }
.dict-reveal-msg {
  width: 100%; background: var(--surface2);
  border-radius: var(--radius-s); text-align: center;
  padding: 10px 14px; display: flex; flex-direction: column; gap: 4px;
}
.dict-reveal-en {
  font-family: var(--mono); font-size: 22px; font-weight: 700;
  color: var(--text); letter-spacing: .03em;
}
.dict-wrong-ch { color: var(--danger); text-decoration: underline; text-underline-offset: 3px; }
.dict-reveal-tip {
  font-size: 11px; color: var(--text3);
}

/* ── Next word bar ──────────────────────────────────────── */
#next-word-bar {
  margin: 10px 0; display: flex; justify-content: center;
}
.next-word-btn {
  width: 100%; padding: 12px;
  background: var(--success); color: #fff;
  border-radius: var(--radius); font-size: 14px; font-weight: 600;
  transition: background-color .15s;
}
.next-word-btn:hover { opacity: .9; }

/* ── Session action bar ─────────────────────────────────── */
#session-action-bar {
  display: flex; gap: 6px; justify-content: center;
  margin-top: 8px; flex-wrap: wrap;
}
#session-action-bar button {
  padding: 6px 12px; font-size: 11px; font-weight: 500;
  border-radius: 20px; color: var(--text3);
  border: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; gap: 4px;
  transition: color .12s, border-color .12s;
}
#session-action-bar button svg { width: 12px; height: 12px; }
#session-action-bar button:hover { color: var(--text); border-color: var(--border-d); }
#session-exclude-btn:hover { color: var(--danger); border-color: var(--danger); }
#session-star-btn:hover    { color: var(--warn);   border-color: var(--warn); }
#session-action-bar button:active { transform: none; }

/* ── Units View ─────────────────────────────────────────── */
/* ── Libraries grid ─────────────────────────────────────── */
#libraries-grid {
  display: grid; grid-template-columns: 1fr; gap: 10px;
  margin-bottom: 12px;
}
.lib-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 18px 14px;
  cursor: pointer; transition: border-color .15s;
}
.lib-card:hover { border-color: var(--primary); }
.lib-card-name { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.lib-card-desc { font-size: 11px; color: var(--text3); margin-bottom: 8px; }
.lib-card-stats { font-size: 11px; color: var(--text2); margin-bottom: 8px; }
.lib-bar { height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.lib-bar-fill { height: 100%; background: var(--primary); border-radius: 2px; transition: width .3s; }

/* ── Library detail ─────────────────────────────────────── */
.lib-detail-nav {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}
.lib-detail-title {
  font-size: 18px; font-weight: 700; color: var(--text);
}
.lib-study-bar { margin-bottom: 14px; }
#library-units-grid {
  display: grid; grid-template-columns: repeat(2,1fr); gap: 8px;
  margin-bottom: 12px;
}
.lib-picker-row { display: flex; gap: 6px; }

/* ── Units grid (inside library detail) ─────────────────── */
#units-grid {
  display: grid; grid-template-columns: repeat(2,1fr); gap: 8px;
  margin-bottom: 12px;
}
.unit-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 14px;
  cursor: pointer;
  transition: border-color .15s;
}
.unit-card:hover { border-color: var(--primary); }
.unit-name { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.unit-meta, .unit-count { font-size: 10px; color: var(--text3); margin-bottom: 6px; line-height: 1.5; }
.unit-progress-bar, .unit-bar { height: 3px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.unit-progress-fill, .unit-bar-fill { height: 100%; background: var(--primary); border-radius: 2px; }

.unit-card-virtual {
  grid-column: 1 / -1;
  background: var(--warn-l);
  border: 1px solid rgba(201,138,43,.3);
  border-left: 3px solid var(--warn);
}
.unit-card-virtual:hover { border-color: var(--warn); border-left-color: var(--warn); }
.unit-card-virtual .unit-name { color: var(--warn); font-size: 13px; }

/* Unit detail */
#unit-header { margin-bottom: 14px; }
#unit-title { font-size: 18px; font-weight: 700; margin-bottom: 10px; }
.unit-study-bar { display: flex; flex-direction: column; gap: 8px; }
#unit-search-row { display: flex; gap: 6px; margin-bottom: 8px; }
#unit-pos-filter {
  padding: 7px 10px; border-radius: var(--radius-s);
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); min-width: 0; width: 120px;
}
#unit-search { flex: 1; min-width: 0; padding: 7px 10px; border-radius: var(--radius-s); }

/* Word list */
#unit-word-list, #notebook-word-list {
  display: flex; flex-direction: column; gap: 4px;
}
.word-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: 10px 14px;
  transition: border-color .12s;
  flex-wrap: wrap;
}
.word-row:hover { border-color: var(--border-d); }
.word-en  { font-size: 14px; font-weight: 700; color: var(--primary); min-width: 110px; font-family: var(--mono); }
.word-zh  { flex: 1; font-size: 12px; color: var(--text2); }
.word-pos-badge {
  font-size: 10px; font-weight: 600; padding: 1px 5px;
  border-radius: 3px; background: var(--surface2); color: var(--text3);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.word-status-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  background: var(--border);
}
.word-status-dot.started  { background: var(--warn); }
.word-status-dot.mastered { background: var(--success); }
.word-done-today { background: var(--success-l); border-color: rgba(38,168,105,.3); }
.word-excluded-row { opacity: .45; }

.star-btn {
  font-size: 16px; color: var(--text3); padding: 3px 4px;
  border-radius: 4px; transition: color .12s; flex-shrink: 0;
}
.star-btn.starred { color: var(--warn); }
.star-btn:hover   { color: var(--warn); }
.star-btn:active  { transform: none; }

.exclude-word-btn {
  font-size: 10px; padding: 3px 8px; border-radius: 4px;
  background: var(--surface2); color: var(--text3);
  border: 1px solid var(--border); white-space: nowrap; flex-shrink: 0;
  transition: color .12s, border-color .12s;
}
.exclude-word-btn.is-excluded { color: var(--success); border-color: var(--success); }
.exclude-word-btn:hover { color: var(--danger); border-color: var(--danger); }
.exclude-word-btn:active { transform: none; }

.word-mastery {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--border);
}
.word-mastery.m1 { background: rgba(229,83,75,.6); }
.word-mastery.m2 { background: var(--warn); }
.word-mastery.m3 { background: var(--primary); }
.word-mastery.m4 { background: var(--success); }

/* Unit filter bar */
#unit-filter-bar {
  display: flex; gap: 5px; flex-wrap: nowrap;
  overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 8px; padding-bottom: 3px;
}
#unit-filter-bar::-webkit-scrollbar { display: none; }
.filter-btn {
  padding: 5px 12px; border-radius: 20px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text3);
  white-space: nowrap; flex-shrink: 0;
  transition: background-color .12s, color .12s, border-color .12s;
}
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filter-btn.cat1 { border-color: rgba(229,83,75,.4); color: var(--danger); }
.filter-btn.cat1.active { background: var(--danger); color: #fff; border-color: var(--danger); }
.filter-btn.cat2 { border-color: rgba(201,138,43,.4); color: var(--warn); }
.filter-btn.cat2.active { background: var(--warn); color: #fff; border-color: var(--warn); }
.filter-btn.cat3 { border-color: rgba(229,83,75,.4); color: var(--danger); }
.filter-btn.cat3.active { background: var(--danger); color: #fff; border-color: var(--danger); }
.filter-btn.na { opacity: .35; cursor: not-allowed; }
.filter-btn:active { transform: none; }

/* ── Progress View ──────────────────────────────────────── */
.progress-sections { display: flex; flex-direction: column; gap: 8px; }
.progress-unit-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: 10px 12px;
}
.progress-unit-name { font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.progress-unit-meta { font-size: 11px; color: var(--text3); margin-bottom: 5px; }

.prog-unit-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.prog-unit-name { font-size: 12px; font-weight: 600; color: var(--text); width: 72px; flex-shrink: 0; }
.prog-bar-wrap  { flex: 1; height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.prog-bar-fill  { height: 100%; width: 100%; background: var(--primary); border-radius: 2px; transform-origin: left; transition: transform .4s cubic-bezier(.4,0,.2,1); }
.prog-pct       { font-size: 11px; color: var(--text3); width: 34px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* ── Stats View ─────────────────────────────────────────── */

/* Blocks */
.stats-block {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px;
}
.stats-block-hd { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.stats-block-title { font-size: 12px; font-weight: 600; color: var(--text); letter-spacing: .02em; text-transform: uppercase; }
.stats-block-sub   { font-size: 11px; color: var(--text3); }

/* Metric cards */
.stats-metric-cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin-bottom: 10px;
}
.smc-card {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; background: var(--surface);
}
.smc-icon { color: var(--primary); flex-shrink: 0; }
.smc-icon svg { width: 18px; height: 18px; }
.smc-body { min-width: 0; }
.smc-value { font-size: 20px; font-weight: 700; color: var(--text); font-family: var(--mono); line-height: 1; }
.smc-unit  { font-size: 11px; font-weight: 400; color: var(--text3); margin-left: 2px; }
.smc-label { font-size: 11px; color: var(--text3); margin-top: 3px; }

/* Library mastery bars */
.lib-mastery-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background-color .1s;
}
.lib-mastery-row:last-child { border-bottom: none; }
.lib-unit-row { cursor: default; }
.lib-mastery-row:not(.lib-unit-row):hover { background: var(--surface2); border-radius: 4px; }
.lib-mastery-name { font-size: 12px; color: var(--text2); width: 110px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-mastery-bar-wrap { flex: 1; height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.lib-mastery-bar-fill { height: 100%; background: var(--success); border-radius: 3px; }
.lib-mastery-pct { font-size: 11px; font-weight: 600; color: var(--text); width: 34px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.lib-mastery-cnt { font-size: 10px; color: var(--text3); width: 54px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.lib-mastery-chevron { color: var(--text3); flex-shrink: 0; }
.lib-mastery-chevron svg { width: 13px; height: 13px; }
.stats-back-btn {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text3); padding: 4px 0; margin-bottom: 10px;
  background: none; border: none; cursor: pointer;
}
.stats-back-btn:hover { color: var(--text); }

/* Donut */
.stats-donut-row { display: flex; align-items: center; gap: 20px; }
.donut-legend { display: flex; flex-direction: column; gap: 7px; }
.donut-legend-item { display: flex; align-items: center; gap: 7px; }
.donut-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.donut-label { font-size: 12px; color: var(--text2); flex: 1; }
.donut-cnt { font-size: 12px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.donut-pct { font-weight: 400; color: var(--text3); font-size: 11px; }

/* SVG charts (hourly, ebbinghaus, pos) */
.stats-svg { width: 100%; display: block; overflow: visible; }

/* Heatmap */
.heatmap-month-row { display: flex; gap: 0; margin-bottom: 3px; padding-left: 20px; }
.heatmap-month-lbl { width: 40px; font-size: 9px; color: var(--text3); flex-shrink: 0; }
.heatmap-wrap { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; }
.heatmap-wrap::-webkit-scrollbar { display: none; }
.heatmap-col  { display: flex; flex-direction: column; gap: 3px; flex-shrink: 0; }
.heatmap-cell { width: 13px; height: 13px; border-radius: 2px; }
.h0     { background: var(--surface2); }
.h1     { background: rgba(38,168,105,.25); }
.h2     { background: rgba(38,168,105,.5); }
.h3     { background: rgba(38,168,105,.75); }
.h4     { background: var(--success); }
.hfuture { background: var(--border); opacity: .3; }

/* Weak words */
.weak-word-row { border-bottom: 1px solid var(--border); }
.weak-word-row:last-child { border-bottom: none; }
.weak-word-main {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; cursor: pointer;
}
.weak-word-main:hover .weak-word-en { color: var(--primary); }
.weak-word-en   { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--text); flex: 1; }
.weak-word-cnt  { font-size: 11px; color: var(--danger); font-weight: 600; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.weak-word-chevron { color: var(--text3); flex-shrink: 0; transition: transform .15s; }
.weak-word-chevron svg { width: 13px; height: 13px; }
.weak-word-row.expanded .weak-word-chevron { transform: rotate(180deg); }
.weak-word-detail { display: none; padding: 0 0 10px 0; }
.weak-word-row.expanded .weak-word-detail { display: flex; align-items: center; gap: 8px; }
.weak-word-zh  { font-size: 12px; color: var(--text2); flex: 1; }
.weak-word-pos { font-size: 10px; color: var(--text3); background: var(--surface2); border-radius: 3px; padding: 1px 5px; }

/* Stats empty state */
.stats-empty { color: var(--text3); font-size: 12px; padding: 12px 0; }

/* Mobile: collapse to 2-column metric grid */
@media (max-width: 600px) {
  .stats-metric-cards { grid-template-columns: repeat(2, 1fr); }
  .smc-value { font-size: 17px; }
}

/* ── Notebooks ──────────────────────────────────────────── */
.nb-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.new-nb-btn {
  padding: 6px 12px; border-radius: 20px;
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 600;
  transition: background-color .15s;
}
.new-nb-btn:hover { background: var(--primary-d); }
.new-nb-form {
  display: flex; gap: 6px; margin-bottom: 12px; align-items: center;
}
.nb-name-input { flex: 1; padding: 7px 10px; border-radius: var(--radius-s); }
.nb-save-btn   { padding: 7px 14px; background: var(--primary); color: #fff; border-radius: var(--radius-s); font-weight: 600; }
.nb-cancel-btn { padding: 7px 12px; background: var(--surface2); color: var(--text2); border-radius: var(--radius-s); }
.notebooks-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 8px; }
.nb-card, .notebook-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 14px; cursor: pointer;
  transition: border-color .15s; position: relative;
}
.nb-card:hover, .notebook-card:hover { border-color: var(--primary); }
.nb-card-name, .notebook-card-name  { font-size: 13px; font-weight: 700; margin-bottom: 5px; padding-right: 22px; }
.nb-card-cnt, .notebook-card-count  { font-size: 11px; color: var(--text3); }
.notebook-title-edit { font-size: 18px; font-weight: 700; margin-bottom: 10px; }

.notebook-card-del {
  position: absolute; top: 10px; right: 10px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface2); color: var(--text3);
  font-size: 10px; display: flex; align-items: center; justify-content: center;
  transition: background-color .12s, color .12s;
}
.notebook-card-del:hover { background: var(--danger-l); color: var(--danger); }
.notebook-card-del:active { transform: none; }

.nb-detail-actions { display: flex; gap: 6px; margin-bottom: 12px; }
.nb-action-btn {
  padding: 6px 12px; border-radius: var(--radius-s); font-size: 12px; font-weight: 600;
  background: var(--surface2); color: var(--text2); border: 1px solid var(--border);
  transition: border-color .12s, color .12s;
}
.nb-action-btn:hover { border-color: var(--primary); color: var(--primary); }
.nb-action-btn:active { transform: none; }
.nb-title-input {
  font-size: 18px; font-weight: 700; padding: 3px 7px;
  border-radius: var(--radius-s); width: 100%; margin-bottom: 10px;
}

/* Notebook picker */
#notebook-picker {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; z-index: 300;
}
#notebook-picker > * { width: 100%; }
.nb-picker-header {
  background: var(--surface); border-radius: 12px 12px 0 0;
  padding: 12px 14px; font-weight: 700; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
#nb-picker-list { background: var(--surface); max-height: 220px; overflow-y: auto; }
.nb-picker-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
  font-size: 13px;
  transition: background-color .12s;
}
.nb-picker-item:hover { background: var(--surface2); }
.nb-picker-new-row { background: var(--surface); padding: 8px 12px; display: flex; gap: 6px; }
.nb-picker-name-input { flex: 1; padding: 7px 10px; border-radius: var(--radius-s); }
#nb-picker-create { padding: 7px 12px; background: var(--primary); color: #fff; border-radius: var(--radius-s); font-weight: 600; }
#nb-picker-close  {
  width: 100%; background: var(--surface); padding: 12px;
  font-size: 14px; color: var(--danger); font-weight: 600;
  border-top: 1px solid var(--border);
}
#nb-picker-close:active { transform: none; }

/* ── Export overlay ─────────────────────────────────────── */
#export-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; z-index: 300;
}
#export-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; width: 300px;
}
.export-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 700; font-size: 14px; }
#export-close { font-size: 16px; color: var(--text3); }
.export-options { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.exp-opt { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.export-fmt-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; font-size: 13px; }
#export-download-btn { width: 100%; padding: 10px; background: var(--primary); color: #fff; border-radius: var(--radius-s); font-weight: 600; }

/* ── Settings View ──────────────────────────────────────── */
.settings-wrap { max-width: 600px; }
.settings-title { font-size: 20px; font-weight: 700; margin-bottom: 18px; }
.settings-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 14px; margin-bottom: 10px;
}
.settings-group { margin-bottom: 10px; }
.settings-label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 5px; }
.settings-input { width: 100%; padding: 8px 10px; border-radius: var(--radius-s); }
.settings-input-sm { width: 90px; }
.settings-key-row { display: flex; gap: 6px; }
.settings-key-row .settings-input { flex: 1; }
.settings-eye-btn {
  padding: 0 9px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-s); font-size: 15px;
  transition: background-color .12s;
}
.settings-eye-btn:active { transform: none; }
.settings-btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.settings-save-btn {
  padding: 8px 16px; background: var(--primary); color: #fff;
  border-radius: var(--radius-s); font-weight: 600; font-size: 13px;
  transition: background-color .15s;
}
.settings-save-btn:hover { background: var(--primary-d); }
.settings-test-btn {
  padding: 8px 16px; background: var(--surface2); color: var(--text2);
  border: 1px solid var(--border); border-radius: var(--radius-s);
  font-weight: 600; font-size: 13px;
  transition: background-color .12s;
}
.settings-test-btn:hover { background: var(--border); }
.settings-cancel-btn {
  padding: 8px 16px; background: var(--surface2); color: var(--danger);
  border: 1px solid rgba(229,83,75,.4); border-radius: var(--radius-s);
  font-weight: 600; font-size: 13px;
}
.settings-status { margin-top: 8px; font-size: 12px; color: var(--text3); min-height: 18px; }
.settings-status.ok  { color: var(--success); }
.settings-status.err { color: var(--danger); }
.settings-about-text { font-size: 12px; color: var(--text2); line-height: 1.7; }

/* Import */
.import-tab-row { display: flex; gap: 6px; margin-bottom: 12px; }
.import-tab {
  flex: 1; padding: 7px; border-radius: var(--radius-s); font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text2);
  display: flex; align-items: center; justify-content: center; gap: 4px;
  transition: background-color .12s, color .12s, border-color .12s;
}
.import-tab svg { width: 12px; height: 12px; }
.import-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.import-tab:active { transform: none; }
.import-panel { display: block; }
.import-help { font-size: 11px; color: var(--text3); line-height: 1.6; margin-bottom: 8px; }
.import-help code { background: var(--surface2); border-radius: 3px; padding: 0 4px; font-size: 10px; }
.import-file-row { margin-bottom: 8px; }
.import-file-label {
  display: inline-block; padding: 8px 14px;
  background: var(--surface2); border: 1px dashed var(--border);
  border-radius: var(--radius-s); cursor: pointer; font-size: 12px; color: var(--text2);
  width: 100%; text-align: center;
  transition: border-color .12s, color .12s;
}
.import-file-label:hover { border-color: var(--primary); color: var(--primary); }
.import-textarea {
  width: 100%; min-height: 100px; padding: 8px 10px;
  border-radius: var(--radius-s); resize: vertical;
  font-size: 13px; line-height: 1.6; margin-bottom: 8px;
}
.import-preview-header {
  display: flex; align-items: center; gap: 8px; margin: 10px 0 6px;
  flex-wrap: wrap;
}
#import-preview-count { font-size: 12px; font-weight: 600; color: var(--text2); flex: 1; }
.import-preview-table { overflow-x: auto; margin-top: 6px; }
.import-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.import-table th { background: var(--surface2); color: var(--text3); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.import-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); color: var(--text); }
.import-table tr:last-child td { border-bottom: none; }
.import-del-btn { padding: 3px 8px; background: var(--danger-l); color: var(--danger); border-radius: 4px; font-size: 11px; font-weight: 600; }

.imported-units-list { display: flex; flex-direction: column; gap: 6px; }
.imported-unit-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.imported-unit-name { flex: 1; font-size: 13px; font-weight: 600; }
.imported-unit-cnt  { font-size: 11px; color: var(--text3); }
.imported-unit-view { padding: 4px 10px; background: var(--primary-l); color: var(--primary); border-radius: 4px; font-size: 11px; font-weight: 600; }

/* Shortcuts */
.shortcuts-table { display: grid; gap: 1px; }
.shortcuts-group-label {
  font-size: 10px; font-weight: 700; color: var(--text3); text-transform: uppercase;
  letter-spacing: .06em; padding: 9px 0 3px;
}
.shortcut-row {
  display: flex; align-items: center; gap: 10px; padding: 5px 0;
  border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text2);
}
.shortcut-key {
  display: inline-block; min-width: 80px; padding: 2px 7px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 3px; font-family: monospace;
  font-size: 11px; color: var(--text); text-align: center; flex-shrink: 0;
}

/* ── Chat Panel ─────────────────────────────────────────── */
#chat-fab {
  position: fixed; bottom: 22px; right: 18px; z-index: 200;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .15s;
}
#chat-fab svg { width: 20px; height: 20px; }
#chat-fab:hover { opacity: .9; }
#chat-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: var(--surface); border-radius: 14px 14px 0 0;
  border: 1px solid var(--border); border-bottom: none;
  display: flex; flex-direction: column;
  max-height: 70vh; height: 60vh;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
}
#chat-panel.open { transform: translateY(0); }
#chat-handle {
  width: 36px; height: 3px; background: var(--border-d); border-radius: 2px;
  margin: 0 auto; flex-shrink: 0; cursor: grab;
  padding: 12px 36px; box-sizing: content-box;
}
#chat-header { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#chat-title   { font-weight: 700; font-size: 14px; flex: 1; }
#chat-context { font-size: 10px; color: var(--text3); flex: 1; font-family: var(--mono); }
#chat-close   { font-size: 16px; color: var(--text3); }
#chat-close svg { width: 16px; height: 16px; }
#chat-close:active { transform: none; }
#chat-messages { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }

/* JS creates .msg classes (not .chat-bubble) */
.msg, .chat-bubble {
  max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5;
}
.msg.user, .chat-bubble.user { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 3px; }
.msg.ai, .chat-bubble.ai   { background: var(--surface2); color: var(--text); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.loading, .chat-bubble.thinking { display: flex; gap: 4px; align-items: center; }
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text3);
  animation: dotBounce .8s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }

#chat-input-row { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); flex-shrink: 0; }
#chat-input { flex: 1; padding: 8px 10px; border-radius: var(--radius-s); }
#chat-send { padding: 8px 16px; background: var(--primary); color: #fff; border-radius: var(--radius-s); font-weight: 600; font-size: 13px; }

/* ── Misc / Utilities ───────────────────────────────────── */
.icon-btn {
  width: 26px; height: 26px; border-radius: var(--radius-s);
  background: var(--surface2); color: var(--text3); font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); transition: background-color .12s, color .12s;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn:active { transform: none; }
.zh-edit-btn { font-size: 11px; }
.zh-inline-edit { font-size: 15px; color: var(--text2); border-radius: var(--radius-s); padding: 3px 7px; }

/* ── Toast ──────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(20,20,22,.92); color: #fff;
  padding: 9px 18px; border-radius: 20px;
  font-size: 13px; font-weight: 500;
  pointer-events: none; opacity: 0; z-index: 500;
  backdrop-filter: blur(8px);
  white-space: nowrap;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-8px); }
.dark #toast { background: rgba(30,32,44,.95); }
.toast-undo-btn {
  background: rgba(255,255,255,.16); color: #fff; border: 1px solid rgba(255,255,255,.3);
  border-radius: 3px; padding: 2px 9px; font-size: 11px; cursor: pointer; margin-left: 7px;
  vertical-align: middle;
}
.toast-undo-btn:hover { background: rgba(255,255,255,.26); }

/* ── Shortcut bar ───────────────────────────────────────── */
#shortcut-bar {
  position: fixed; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 5px; z-index: 100; pointer-events: none; opacity: .55;
  transition: opacity .25s;
}
.sc-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px 9px; font-size: 11px; color: var(--text3);
  display: flex; align-items: center; gap: 5px;
}
.sc-key {
  background: var(--surface2); border: 1px solid var(--border-d);
  border-radius: 3px; padding: 1px 5px; font-size: 10px; font-family: monospace;
  color: var(--text2);
}
/* Legacy chip */
.shortcut-chip {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px 9px; font-size: 11px; color: var(--text3);
}

/* ── Loading / error / empty states ─────────────────────── */
.view-loading-msg {
  color: var(--text3); font-size: 13px; text-align: center;
  padding: 36px 0; grid-column: 1 / -1;
}
.view-loading-msg.error { color: var(--danger); }
.retry-btn {
  display: inline-block; margin-left: 7px; padding: 2px 10px; font-size: 12px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 5px; cursor: pointer;
}
.retry-btn:hover { background: var(--border); }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 36px 18px; color: var(--text3); }
.empty-state-text { font-size: 14px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }
.empty-state-sub  { font-size: 12px; margin-bottom: 14px; }
.empty-state-btn  {
  padding: 7px 18px; background: var(--primary); color: #fff; border-radius: var(--radius-s);
  font-size: 13px; cursor: pointer; border: none;
}
.empty-state-btn:hover { opacity: .85; }

/* Unit group headers */
.unit-group-header {
  grid-column: 1 / -1; font-size: 10px; font-weight: 700; color: var(--text3);
  letter-spacing: .07em; text-transform: uppercase; padding: 8px 2px 3px;
  border-bottom: 1px solid var(--border); margin-bottom: 1px;
}

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-d); }

/* ── Animations ─────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes dotBounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-4px); }
}
.view.active > * { animation: fadeIn .2s ease; }
.spinning { animation: spin .7s linear infinite; }

/* AI content blocks */
.ai-content.show { display: block; }

/* ── Safe area ──────────────────────────────────────────── */
@supports (padding: max(0px)) {
  header {
    padding-left:  max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  #chat-fab {
    bottom: calc(22px + env(safe-area-inset-bottom));
    right:  max(18px, env(safe-area-inset-right));
  }
  #chat-panel { padding-bottom: env(safe-area-inset-bottom); }
  .view { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ── Mobile narrow (<520px) ─────────────────────────────── */
@media (max-width: 520px) {
  .logo { font-size: 13px; margin-right: 0; }
  nav { gap: 0; padding: 0 2px; }
  .nav-btn { padding: 4px 8px; font-size: 12px; }

  .card-zh { font-size: 18px; }
  .back-en { font-size: 22px; }
  .flip-card { min-height: 170px; }
  .rate-btn { font-size: 11px; padding: 9px 4px; }
  .mc-option { padding: 11px 10px; font-size: 13px; }
  #dict-letter-row { gap: 3px; }
  .letter-box { height: 38px; font-size: 15px; }
  .dict-giveup-btn, .dict-submit { padding: 6px 10px; font-size: 11px; }
  #session-action-bar { gap: 4px; }
  #session-action-bar button { padding: 5px 9px; font-size: 10px; }
  #units-grid, #library-units-grid { grid-template-columns: 1fr; }
  #libraries-grid { grid-template-columns: 1fr; }
  .exclude-word-btn { display: none; }
  .word-zh { font-size: 11px; }
  .filter-btn { padding: 4px 9px; font-size: 10px; }
  .settings-btn-row { flex-direction: column; }
  .settings-save-btn, .settings-test-btn, .settings-cancel-btn { width: 100%; }
  .import-tab { padding: 6px; font-size: 11px; }
  .notebooks-grid { grid-template-columns: 1fr; }
  .quality-bar-label { width: 84px; font-size: 10px; }
  .big-stat-grid { grid-template-columns: repeat(2, 1fr); }
  .unit-mastery-name { width: 46px; }
  .prog-unit-name { width: 50px; font-size: 10px; }
  #today-charts { grid-template-columns: 1fr; }
  .tc-donut-wrap { justify-content: center; }
}

/* ── Touch targets ──────────────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  .nav-btn    { min-height: 38px; }
  .mode-btn   { min-height: 42px; }
  .rate-btn   { min-height: 46px; }
  .mc-option  { min-height: 50px; }
  .star-btn   { padding: 7px; min-width: 34px; text-align: center; }
  .filter-btn { min-height: 36px; }
  .ai-btn     { min-height: 42px; }
  .back-btn   { min-height: 38px; }
}

/* ── Desktop sidebar layout (≥900px) ────────────────────── */
@media (min-width: 900px) {
  #sidebar { display: flex; }
  header   { display: none; }

  .view {
    max-width: 800px;
    padding: 28px 32px 48px;
  }

  /* Grids expand */
  #units-grid, #library-units-grid { grid-template-columns: repeat(3, 1fr); }
  #libraries-grid { grid-template-columns: repeat(2, 1fr); }
  .notebooks-grid { grid-template-columns: repeat(3, 1fr); }
  #mc-options     { display: grid; grid-template-columns: 1fr 1fr; }
  .flip-card { min-height: 220px; }
  .back-en   { font-size: 32px; }
  .card-zh   { font-size: 24px; }
  .stat-num  { font-size: 30px; }

  /* Today view: mode selector + start button in one row */
  #today-dashboard {
    display: grid;
    grid-template-columns: 1fr auto;
    column-gap: 16px;
    align-items: end;
  }
  #today-dashboard .stat-grid,
  #today-dashboard #today-charts,
  #today-dashboard #done-banner { grid-column: 1 / -1; }
  #today-dashboard .section-block {
    grid-column: 1; margin: 16px 0 0; align-self: end;
  }
  #today-dashboard .section-block .mode-row { margin-bottom: 0; }
  #today-dashboard .section-block .section-title { margin-bottom: 7px; }
  #today-dashboard > #start-btn {
    width: auto; padding: 11px 24px; white-space: nowrap;
    grid-column: 2; align-self: end; margin-top: 16px;
  }

  /* Chat panel: corner window */
  #chat-panel {
    left: auto;
    right: 18px;
    bottom: 18px;
    width: 360px;
    border-radius: 10px;
    border: 1px solid var(--border);
    max-height: 560px;
    height: 520px;
  }
  #chat-handle { display: none; }
}

/* ── Wider desktop (≥1200px) ────────────────────────────── */
@media (min-width: 1200px) {
  .view { max-width: 960px; }

  #units-grid, #library-units-grid { grid-template-columns: repeat(4, 1fr); }
  #libraries-grid { grid-template-columns: repeat(3, 1fr); }
  .notebooks-grid { grid-template-columns: repeat(4, 1fr); }

  #unit-word-list, #notebook-word-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  /* Flash 2-pane layout */
  #flash-area {
    display: grid;
    grid-template-columns: 1fr 280px;
    grid-template-areas: "card ai" "card rating";
    gap: 14px;
    align-items: start;
  }
  #flash-area .card-wrapper { grid-area: card; }
  #flash-area .ai-section   { grid-area: ai; }
  #flash-area .rating-row   { grid-area: rating; }

  .flip-card { min-height: 280px; }
  .back-en   { font-size: 36px; }
  .card-zh   { font-size: 26px; }
  .stat-num  { font-size: 32px; }

  .progress-sections {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .settings-wrap { max-width: none; }
}

/* ── Auth overlay ───────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}

.auth-panel {
  width: 100%; max-width: 360px;
  padding: 40px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.auth-logo {
  font-size: 28px; font-weight: 700; color: var(--text);
  text-align: center; letter-spacing: -.5px; margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 13px; color: var(--text3);
  text-align: center; margin-bottom: 32px;
}

.auth-form { display: flex; flex-direction: column; gap: 12px; }

.auth-input {
  width: 100%; box-sizing: border-box;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none; transition: border-color .15s;
}
.auth-input:focus { border-color: var(--primary); }
.auth-input::placeholder { color: var(--text3); }

.auth-submit-btn {
  width: 100%; padding: 11px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
  margin-top: 4px;
}
.auth-submit-btn:hover:not(:disabled) { opacity: .85; }
.auth-submit-btn:disabled { opacity: .5; cursor: not-allowed; }

.auth-error {
  font-size: 12px; color: var(--danger);
  min-height: 18px; text-align: center;
}

.auth-switch {
  text-align: center; margin: 20px 0 0; font-size: 13px;
  color: var(--text3);
}

.auth-link-btn {
  background: none; border: none; padding: 0;
  color: var(--primary); font-size: 13px;
  cursor: pointer; text-decoration: underline;
}
.auth-link-btn:hover { opacity: .8; }

/* ── Sidebar user row ────────────────────────────────────── */
.sb-user-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; margin-top: 4px;
  border-top: 1px solid var(--border);
}

.sb-user-name {
  flex: 1; font-size: 12px; color: var(--text2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.sb-logout-btn {
  background: none; border: none; padding: 4px 8px;
  color: var(--text3); font-size: 12px;
  cursor: pointer; border-radius: 4px; transition: background .15s;
  white-space: nowrap;
}
.sb-logout-btn:hover { background: var(--surface2); color: var(--text); }

/* ── Invite code display ─────────────────────────────────── */
.invite-code-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 6px;
}

.invite-code-text {
  flex: 1; font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px; color: var(--text);
  letter-spacing: .04em;
}

.invite-code-meta {
  font-size: 11px; color: var(--text3); white-space: nowrap;
}

/* ── Reduced motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration:  .01ms !important;
  }
  .flip-card { transition: none; }
  #chat-panel { transition: none; }
  .view.active > * { animation: none; }
}
