/* ========== Design tokens ========== */
:root {
  /* Neutral scale (zinc-like) */
  --gray-1: #fafafa;
  --gray-2: #f4f4f5;
  --gray-3: #e4e4e7;
  --gray-4: #d4d4d8;
  --gray-5: #a1a1aa;
  --gray-6: #71717a;
  --gray-7: #52525b;
  --gray-8: #3f3f46;
  --gray-9: #27272a;
  --gray-10: #18181b;
  --gray-11: #0a0a0a;

  /* Accent (indigo-violet, Linear-leaning) */
  --accent: #7c8cff;
  --accent-hover: #6877ff;
  --accent-soft: rgba(124, 140, 255, 0.12);
  --accent-strong: #5a6bff;

  /* State colors */
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);

  /* Semantic surfaces */
  --bg: var(--gray-1);
  --bg-elevated: #ffffff;
  --bg-soft: var(--gray-2);
  --bg-inset: #ededee;
  --text: var(--gray-10);
  --text-muted: var(--gray-6);
  --text-faint: var(--gray-5);
  --border: var(--gray-3);
  --border-strong: var(--gray-4);

  /* Compatibility aliases (for legacy classnames not yet migrated) */
  --surface: var(--bg-elevated);
  --soft: var(--bg-soft);
  --muted: var(--text-muted);
  --line: var(--border);
  --dark: var(--text);
  --dark-hover: var(--gray-9);

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(15, 17, 21, 0.05);
  --shadow-md: 0 4px 14px rgba(15, 17, 21, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 17, 21, 0.10);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  --font-serif: 'Newsreader', 'Source Serif Pro', Georgia, "Times New Roman", serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 120ms;
  --dur-base: 180ms;

  --sidebar: 64px;
}

[data-theme="dark"] {
  --bg: var(--gray-11);
  --bg-elevated: #131316;
  --bg-soft: var(--gray-10);
  --bg-inset: #1f1f23;
  --text: var(--gray-1);
  --text-muted: var(--gray-5);
  --text-faint: var(--gray-6);
  --border: var(--gray-9);
  --border-strong: var(--gray-8);

  --accent-soft: rgba(124, 140, 255, 0.18);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.18);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);

  --dark: var(--gray-1);
  --dark-hover: var(--gray-2);
}

/* ========== Reset & base ========== */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--dur-base) var(--ease), color var(--dur-base) var(--ease);
}

a { color: inherit; text-decoration: none; }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  border: 0;
  cursor: pointer;
  background: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input[type="text"], input[type="number"], input[type="password"], textarea, select {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  outline: none;
  background: var(--bg-elevated);
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

::selection { background: var(--accent-soft); }

/* ========== App shell ========== */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 30;
}

.sidebar-logo {
  width: 100%;
  height: 56px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
  margin: 12px 0 18px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  width: 100%;
}

.sidebar-link {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.sidebar-link:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.sidebar-link.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.sidebar-link.signed-in {
  color: var(--text);
}

.sidebar-link[hidden] { display: none; }

.sidebar-bottom {
  margin: auto 0 16px;
  display: grid;
  gap: 8px;
  place-items: center;
}

.sidebar-account.signed-in::after {
  content: "";
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 0 2px var(--bg-elevated);
}

.account-icon {
  position: relative;
  width: 18px;
  height: 18px;
  display: block;
}

.account-icon::before,
.account-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  border: 1.8px solid currentColor;
  transform: translateX(-50%);
}

.account-icon::before {
  top: 2px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
}

.account-icon::after {
  bottom: 2px;
  width: 13px;
  height: 7px;
  border-radius: 9px 9px 4px 4px;
}

.sidebar-settings {
  font-size: 1.08rem;
}

.app-shell {
  margin-left: var(--sidebar);
  padding: 56px 36px 96px;
  min-height: 100vh;
}

.theme-toggle {
  position: fixed;
  top: 18px;
  right: 22px;
  z-index: 40;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 1rem;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.theme-toggle:hover {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--border-strong);
}

.loading, .empty {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.panel, .wide-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ========== Buttons ========== */
.dark-btn {
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 0.94rem;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.dark-btn:hover {
  background: var(--gray-8);
  transform: translateY(-1px);
}

[data-theme="dark"] .dark-btn:hover {
  background: var(--gray-3);
}

.dark-btn.small {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.secondary {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 16px;
  font-weight: 600;
  font-size: 0.94rem;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.secondary:hover {
  background: var(--bg-inset);
  border-color: var(--border-strong);
}

.text-btn {
  background: transparent;
  color: var(--accent-strong);
  padding: 4px 0;
  font-weight: 600;
  font-size: 0.9rem;
}

.text-btn:hover { text-decoration: underline; }

.muted-copy {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ========== Home ========== */
.dashboard {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.dashboard-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 42px;
}

.dashboard-head h1 {
  margin: 0;
  font-size: clamp(2.4rem, 4vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.course-kicker {
  margin: 0 0 8px;
  color: var(--text-faint);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.course-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 14px 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  font-weight: 650;
}

.flag {
  width: 30px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: white;
  font-size: 0.62rem;
  font-weight: 800;
  background: linear-gradient(135deg, #1d3f8f 0 46%, #f6f7f8 46% 54%, #c0392b 54%);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 72px;
  align-items: start;
}

.resume-button {
  width: 100%;
  min-height: 92px;
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  border-radius: 18px;
  background: var(--text);
  color: var(--bg);
  text-align: left;
}

.resume-mark {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 50%;
  position: relative;
}

.resume-mark::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: inherit;
  background: currentColor;
}

.resume-copy {
  display: grid;
  gap: 3px;
}

.resume-copy small {
  color: color-mix(in srgb, var(--bg) 68%, transparent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.resume-copy strong {
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.resume-arrow {
  font-size: 1.5rem;
}

.progress-section,
.course-list {
  margin-top: 42px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.05rem;
}

.section-heading span {
  color: var(--text-faint);
  font-size: 0.82rem;
  font-weight: 700;
}

.track {
  height: 7px;
  display: flex;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-inset);
}

.track span { display: block; height: 100%; }
.track-mastered { background: var(--success); }
.track-learning { background: var(--accent); }

.progress-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 18px;
}

.progress-stats button,
.progress-stats span {
  display: grid;
  gap: 2px;
  text-align: left;
}

.progress-stats strong {
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.progress-stats span span,
.progress-stats button span {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.course-row {
  width: 100%;
  min-height: 74px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.course-row:last-child { border-bottom: 1px solid var(--border); }
.course-row.active { color: var(--text); }
.course-row small { display: block; margin-top: 3px; color: var(--text-muted); }
.course-index, .course-row b { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.course-row strong { font-size: 1rem; }

.goal-rail {
  position: sticky;
  top: 28px;
  display: grid;
  justify-items: center;
  gap: 18px;
}

.goal-ring {
  width: 168px;
  height: 168px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--bg) 0 61%, transparent 62%),
    conic-gradient(var(--accent) calc(var(--goal) * 1%), var(--bg-inset) 0);
}

.goal-ring strong {
  font-size: 2.4rem;
  line-height: 1;
  letter-spacing: -0.05em;
}

.goal-ring span { color: var(--text-muted); font-size: 0.85rem; }

.goal-copy {
  width: 100%;
  text-align: center;
}

.goal-copy h2 { margin: 0 0 8px; font-size: 1rem; }
.goal-copy p { margin: 3px 0; color: var(--text-muted); font-size: 0.9rem; }

.goal-week {
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
}

.goal-week li {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg-inset);
  color: var(--text-faint);
  font-size: 0.72rem;
  font-weight: 700;
}

.goal-week .done { background: var(--accent); color: white; }
.goal-week .today { outline: 2px solid var(--text); outline-offset: 2px; }

.goal-edit {
  color: var(--accent-strong);
  font-weight: 750;
}

/* ========== Learn page ========== */
.learn-stage {
  min-height: calc(100vh - 150px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 120px;
}

.learn-card {
  width: min(880px, 100%);
  margin-top: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: cardIn var(--dur-base) var(--ease);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-top {
  height: 64px;
  padding: 22px 24px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.step-dots {
  display: flex;
  gap: 6px;
}

.step-dots span {
  width: 22px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border);
}

.step-dots span.on {
  background: var(--accent);
}

.menu-dot {
  background: transparent;
  color: var(--text-faint);
  font-size: 1.4rem;
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
}

.menu-dot:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.sentence {
  min-height: 140px;
  padding: 18px 36px 28px;
  text-align: center;
  font-family: var(--font-serif);
  font-size: clamp(1.7rem, 3.4vw, 2.6rem);
  line-height: 1.4;
  color: var(--text-muted);
  letter-spacing: -0.01em;
}

.sentence .blank-input {
  width: min(var(--blank-ch, 10ch), 52vw);
  min-width: 7ch;
  max-width: 28ch;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  padding: 6px 14px;
  text-align: center;
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.sentence .blank-input:focus {
  background: var(--accent-soft);
  box-shadow: none;
}

.sentence .blank-input.correct {
  background: var(--success-soft);
  color: var(--success);
}

.sentence .blank-input.wrong {
  background: var(--danger-soft);
  color: var(--danger);
  text-decoration: line-through;
}

.answer-cues {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 36px 28px;
}

.pos-chip {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  letter-spacing: 0.01em;
}

.pos-chip span {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.def-chip {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

[data-theme="dark"] .def-chip {
  color: var(--accent);
}

.hint-row {
  min-height: 24px;
  padding: 0 36px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.hint-row .ipa {
  margin-right: 12px;
  font-style: italic;
}

.feedback {
  width: calc(100% - 72px);
  margin: 0 auto 22px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  text-align: center;
  font-size: 0.92rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.feedback.correct {
  background: var(--success-soft);
  color: var(--success);
  border-color: var(--success-soft);
}

.feedback.wrong {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-soft);
}

.reveal-panel {
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 22px 36px 26px;
  color: var(--text);
  animation: revealFade var(--dur-base) var(--ease);
}

@keyframes revealFade {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.reveal-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 10px;
}

.reveal-headword {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.reveal-head .ipa {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.95rem;
  font-family: var(--font-mono);
}

.reveal-tts {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.reveal-tts:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: var(--accent);
}

.reveal-def {
  color: var(--text);
  margin: 6px 0;
  font-size: 0.95rem;
}

.reveal-translation {
  color: var(--text-muted);
  margin: 6px 0;
  font-style: italic;
  font-family: var(--font-serif);
  font-size: 0.95rem;
}

.reveal-meta {
  color: var(--text-faint);
  font-size: 0.82rem;
  margin-top: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.translation { color: var(--text-muted); }

.muted-line {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.learn-dock {
  position: fixed;
  left: calc(var(--sidebar) + 36px);
  right: 36px;
  bottom: 24px;
  width: min(880px, calc(100vw - var(--sidebar) - 72px));
  margin: 0 auto;
  min-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 10px 14px 10px 22px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  z-index: 20;
}

.dock-progress {
  display: grid;
  grid-template-columns: auto minmax(140px, 220px) auto;
  gap: 12px;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-family: var(--font-mono);
}

.dock-bar {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
  overflow: hidden;
}

.dock-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width var(--dur-base) var(--ease);
}

.dock-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.icon-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.dock-submit {
  min-width: 110px;
  min-height: 38px;
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 16px;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.dock-submit:hover {
  background: var(--gray-8);
  transform: translateY(-1px);
}

[data-theme="dark"] .dock-submit:hover { background: var(--gray-3); }

.dock-skip {
  min-height: 38px;
  font-size: 0.88rem;
}

.session-done {
  width: min(640px, 100%);
  margin: 64px auto;
  padding: 44px 24px;
  text-align: center;
}

.session-done h2 {
  margin: 0 0 8px;
  font-size: 1.4rem;
  font-weight: 600;
}

.session-done p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin: 28px 0;
}

.stat .num {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono);
}

.stat .lbl {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ========== Articles ========== */
.article-list {
  display: grid;
  gap: 12px;
  max-width: 880px;
  margin: 0 auto;
}

.article-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--dur-base) var(--ease), border-color var(--dur-base) var(--ease);
}

.article-card:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

.article-card h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 600;
}

.meta {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.topic {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 600;
}

[data-theme="dark"] .topic { color: var(--accent); }

.article-detail {
  max-width: 880px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-sm);
}

.article-detail h1 {
  margin: 8px 0 6px;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.back-link {
  display: inline-block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
}

.back-link:hover { color: var(--text); }

.small-action {
  margin-left: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
}

.small-action:hover { background: var(--bg-inset); }

.article-body {
  margin-top: 22px;
  line-height: 1.85;
  font-size: 1rem;
  font-family: var(--font-serif);
}

.article-body p {
  margin: 0 0 1.1em;
}

.awl-word {
  padding: 0 3px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-strong);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}

[data-theme="dark"] .awl-word { color: var(--accent); }

.awl-word:hover { background: var(--accent); color: white; }
[data-theme="dark"] .awl-word:hover { color: var(--gray-11); }

.awl-word.learning {
  background: var(--warning-soft);
  color: var(--warning);
}
.awl-word.mastered {
  background: var(--bg-soft);
  color: var(--text-faint);
}
.awl-word.at_risk {
  background: var(--danger-soft);
  color: var(--danger);
}

.article-source {
  margin-top: 24px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.popover {
  position: fixed;
  z-index: 50;
  max-width: 320px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
}

.pop-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.pop-word {
  font-weight: 700;
  letter-spacing: -0.01em;
}

.pop-pos, .pop-ipa {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.pop-ipa {
  margin: 4px 0;
  font-style: italic;
  font-family: var(--font-mono);
}

.pop-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.pop-actions button {
  border-radius: var(--radius-md);
  padding: 7px 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ========== Progress page ========== */
.progress-grid {
  max-width: 880px;
  margin: 0 auto 18px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.progress-card, .heatmap, .sublist-list, .word-list {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.progress-card {
  padding: 20px;
  text-align: center;
}

.progress-card .num {
  font-size: 1.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
}

.progress-card .lbl {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.progress-card.mastered .num { color: var(--success); }
.progress-card.learning .num { color: var(--accent); }
.progress-card.at_risk .num { color: var(--danger); }

.heatmap, .sublist-list, .word-list {
  max-width: 880px;
  margin: 0 auto 16px;
  padding: 22px;
}

.heatmap h2, .sublist-list h2 {
  margin: 0 0 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.heatmap-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.heatmap-cell {
  width: 44px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.heatmap-cell.l1 { background: rgba(124, 140, 255, 0.18); color: var(--accent-strong); }
.heatmap-cell.l2 { background: rgba(124, 140, 255, 0.36); color: var(--accent-strong); }
.heatmap-cell.l3 { background: rgba(124, 140, 255, 0.65); color: white; }
.heatmap-cell.l4 { background: var(--accent); color: white; }

[data-theme="dark"] .heatmap-cell.l1,
[data-theme="dark"] .heatmap-cell.l2 { color: var(--accent); }

.sublist-row {
  display: grid;
  grid-template-columns: 110px minmax(80px, 1fr) max-content;
  gap: 12px;
  align-items: center;
  padding: 6px 0;
}

.sublist-row .name {
  font-weight: 600;
  font-size: 0.92rem;
}

.sublist-row .pct {
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  white-space: nowrap;
}

.sublist-row .bar {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
  overflow: hidden;
}

.sublist-row .bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.word-list details {
  margin: 6px 0;
}

.word-list summary {
  cursor: pointer;
  font-weight: 600;
  padding: 8px;
  font-size: 0.92rem;
}

.word-item {
  display: grid;
  grid-template-columns: 140px 1fr 150px;
  gap: 12px;
  padding: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}

.word-item .w {
  font-weight: 700;
}

.word-item .d, .word-item .info {
  color: var(--text-muted);
}

.word-item .info {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

/* ========== Settings page ========== */
.page-head {
  max-width: 880px;
  margin: 0 auto 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-head h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settings-grid {
  max-width: 880px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Theme segmented control */
.theme-segments {
  display: inline-flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.theme-segments button {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.theme-segments button.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* TTS voice select */
.voice-select {
  min-width: 180px;
}

/* ========== Auth & admin ========== */
.auth-card {
  width: min(440px, 100%);
  margin: 48px auto;
  padding: 32px;
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-form, .admin-form {
  display: grid;
  gap: 14px;
}

.auth-form label, .admin-form label {
  display: grid;
  gap: 6px;
  font-weight: 500;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.auth-form input, .admin-form input, .admin-form textarea, .admin-form select {
  width: 100%;
}

.admin-form textarea {
  min-height: 70px;
  font-family: var(--font-serif);
  resize: vertical;
}

.admin-sentence-form {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.admin-sentence-form .form-wide {
  grid-column: 1 / -1;
}

.sentence-suggest {
  margin-top: 6px;
}

.sentence-submit-row {
  display: flex;
  align-items: end;
  gap: 10px;
}

.sentence-submit-row .form-message {
  margin: 0;
}

.auth-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.form-message {
  min-height: 22px;
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.form-message.error { color: var(--danger); }
.form-message.success { color: var(--success); }

.admin-layout {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
}

.admin-form, .admin-users, .admin-sentences {
  padding: 22px;
}

.admin-form h2, .admin-users h2, .admin-sentences h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
}

.admin-sentences {
  grid-column: 1 / -1;
}

.user-list, .sentence-list {
  display: grid;
  gap: 10px;
}

.user-row, .sentence-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
}

.sentence-row {
  grid-template-columns: 1fr auto;
}

.user-row strong, .sentence-row strong {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
}

.user-row span, .sentence-row span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.sentence-row .preview {
  font-family: var(--font-serif);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.user-stats {
  display: flex;
  gap: 8px;
}

.user-actions, .sentence-actions {
  display: flex;
  gap: 8px;
}

.settings-panel {
  padding: 22px;
}

.settings-panel.wide {
  grid-column: 1 / -1;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.account-row strong {
  display: block;
  font-weight: 600;
}

.account-row .muted-copy {
  margin: 4px 0 0;
}

.account-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.settings-panel h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
}

.field-row, .switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 12px 0;
  font-weight: 500;
  font-size: 0.92rem;
}

.field-row input[type="number"] {
  width: 110px;
}

.field-row input[type="range"] {
  width: min(220px, 52vw);
  accent-color: var(--accent);
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.range-value {
  text-align: right;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

.sublist-picker {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
}

.sublist-toggle {
  position: relative;
}

.sublist-toggle input {
  position: absolute;
  opacity: 0;
}

.sublist-toggle span {
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.sublist-toggle span:hover { background: var(--bg-inset); }

.sublist-toggle input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

[data-theme="dark"] .sublist-toggle input:checked + span { color: var(--accent); }

/* ========== Responsive ========== */
@media (max-width: 1000px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 42px;
  }

  .goal-rail {
    position: static;
  }
}

@media (max-width: 760px) {
  :root { --sidebar: 0px; }

  .sidebar {
    inset: auto 0 0 0;
    width: auto;
    height: 56px;
    flex-direction: row;
    justify-content: space-around;
    border-right: 0;
    border-top: 1px solid var(--border);
  }

  .sidebar-logo {
    display: none;
  }

  .sidebar-nav {
    flex-direction: row;
    gap: 4px;
    flex: 1;
    justify-content: space-around;
  }

  .sidebar-link {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }

  .sidebar-link.active::before { display: none; }

  .sidebar-settings {
    margin: 0;
  }

  .sidebar-bottom {
    margin: 0 8px 0 0;
    grid-auto-flow: column;
    gap: 4px;
  }

  .app-shell {
    margin-left: 0;
    padding: 18px 12px 84px;
  }

  .theme-toggle { top: 12px; right: 12px; }

  .dashboard-head {
    align-items: start;
    flex-direction: column;
    margin-bottom: 28px;
  }

  .resume-button {
    min-height: 78px;
    grid-template-columns: 16px 1fr auto;
    padding: 0 16px;
  }

  .progress-stats {
    gap: 8px;
  }

  .settings-grid, .progress-grid {
    grid-template-columns: 1fr;
  }

  .settings-panel.wide {
    grid-column: auto;
  }

  .sublist-picker {
    grid-template-columns: repeat(5, 1fr);
  }

  .sentence {
    padding: 8px 18px 28px;
    font-size: 1.45rem;
    line-height: 1.5;
  }

  .sentence .blank-input {
    width: min(var(--blank-ch, 10ch), 64vw);
  }

  .answer-cues {
    padding: 0 18px 22px;
  }

  .pos-chip, .def-chip {
    width: 100%;
    min-width: 0;
    justify-content: center;
  }

  .feedback {
    width: calc(100% - 36px);
  }

  .reveal-panel {
    padding-left: 18px;
    padding-right: 18px;
  }

  .learn-dock {
    left: 12px;
    right: 12px;
    bottom: 70px;
    width: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
  }

  .dock-progress {
    grid-template-columns: auto 1fr auto;
  }

  .dock-actions {
    justify-content: center;
    flex-wrap: wrap;
  }

  .dock-submit {
    flex: 1 1 150px;
  }

  .dock-skip {
    flex: 1 1 96px;
  }

  .sublist-row, .word-item {
    grid-template-columns: 1fr;
  }

  .sublist-row .pct, .word-item .info {
    text-align: left;
  }

  .sublist-row .pct {
    justify-self: start;
  }

  .account-row {
    align-items: stretch;
    flex-direction: column;
  }

  .page-head {
    align-items: flex-start;
    gap: 14px;
    flex-direction: column;
  }

  .auth-card {
    margin: 10px auto;
    padding: 22px;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-sentence-form {
    grid-template-columns: 1fr;
  }

  .admin-sentence-form .form-wide,
  .sentence-submit-row {
    grid-column: auto;
  }

  .sentence-submit-row {
    align-items: stretch;
    flex-direction: column;
  }

  .user-row, .sentence-row {
    grid-template-columns: 1fr;
  }

  .user-stats, .user-actions, .sentence-actions {
    flex-wrap: wrap;
  }
}
