:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-alt: #eef2ef;
  --ink: #18201b;
  --muted: #687169;
  --line: #d8ded9;
  --forest: #1f6b4f;
  --forest-dark: #154c38;
  --forest-soft: #e4f1eb;
  --amber: #b77a16;
  --amber-soft: #fff1d2;
  --rust: #a84131;
  --rust-soft: #f9e6e2;
  --blue: #315f96;
  --blue-soft: #e8eff8;
  --shadow: 0 14px 40px rgba(25, 38, 29, 0.12);
  --radius: 7px;
}

* { box-sizing: border-box; }

.keyword-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); gap: 12px; }
.keyword-item.word-token { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; text-align: left; white-space: normal; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; min-height: 132px; width: 100%; overflow-wrap: anywhere; }
.keyword-item strong { font-size: 19px; line-height: 1.4; }
.keyword-ipa { font-family: "Arial", sans-serif; color: var(--blue); font-size: 16px; line-height: 1.5; }
.keyword-meaning { font-size: 14px; color: var(--muted); line-height: 1.5; }
.word-definition { font-size: 18px; line-height: 1.6; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select { font: inherit; letter-spacing: 0; }

button { color: inherit; cursor: pointer; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(49, 95, 150, 0.28);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(360px, 1fr) minmax(170px, 260px);
  align-items: center;
  gap: 20px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.brand-block { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--forest);
  color: #fff;
  font-weight: 800;
  font-size: 19px;
}

.brand-block h1 { margin: 0; font-size: 17px; line-height: 1.25; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.view-tabs {
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 120px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-alt);
}

.tab-button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  font-size: 13px;
}

.tab-button:last-child { border-right: 0; }
.tab-button.active { background: var(--forest); color: #fff; font-weight: 700; }

.top-actions { display: flex; justify-content: flex-end; gap: 8px; }
.display-mode { width: 110px; min-height: 38px; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
body[data-display-mode="english"] .translation,
body[data-display-mode="english"] .keyword-meaning { display: none; }
body[data-display-mode="chinese"] .english-line,
body[data-display-mode="chinese"] .pronunciation-note,
body[data-display-mode="chinese"] .keyword-item strong,
body[data-display-mode="chinese"] .keyword-item .keyword-ipa,
body[data-display-mode="chinese"] [data-section-target="section-vocabulary"],
body[data-display-mode="chinese"] #section-vocabulary { display: none; }
body[data-display-mode="chinese"] .translation { color: var(--ink); font-size: 19px; line-height: 1.6; }
body[data-display-mode="chinese"] .keyword-meaning { color: var(--ink); font-size: 17px; }

.icon-button,
.quiet-button,
.primary-button,
.secondary-button,
.filter-button,
.state-button,
.play-button,
.section-button {
  border-radius: var(--radius);
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 18px;
}

.quiet-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
}

.quiet-button.off { color: var(--muted); background: var(--surface-alt); }

.primary-button,
.secondary-button {
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
}

.primary-button { background: var(--forest); color: #fff; }
.primary-button:hover { background: var(--forest-dark); }
.primary-button.complete { background: var(--blue); }

.secondary-button { border-color: var(--line); background: var(--surface); }
.secondary-button:hover { border-color: #aeb9b1; background: var(--surface-alt); }
.wide { width: 100%; }

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.day-rail {
  position: sticky;
  top: 72px;
  align-self: start;
  height: calc(100vh - 72px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: #fbfcfb;
}

.rail-summary { padding: 18px; border-bottom: 1px solid var(--line); }
.rail-summary > div:first-child { display: flex; justify-content: space-between; align-items: end; }
.rail-summary strong { font-size: 24px; }
.rail-summary p { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

.eyebrow {
  display: inline-block;
  color: var(--forest);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 800;
  text-transform: uppercase;
}

.progress-track {
  height: 7px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 4px;
  background: #dde3de;
}

.progress-track span { display: block; width: 0; height: 100%; background: var(--forest); transition: width 220ms ease; }

.day-list { overflow: auto; padding: 8px; }

.day-nav-button {
  width: 100%;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
}

.day-nav-button:hover { background: var(--surface-alt); }
.day-nav-button.active { border-color: #99b9a8; background: var(--forest-soft); }

.day-index {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #e7ebe8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.day-nav-button.active .day-index { background: var(--forest); color: #fff; }
.day-nav-copy { min-width: 0; }
.day-nav-copy strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.day-nav-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.day-score { justify-self: end; color: var(--muted); font-size: 11px; font-weight: 700; }
.day-score.done { color: var(--forest); }

.main-stage { min-width: 0; }
.view { display: none; }
.view.active { display: block; }

.day-heading,
.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding: 30px clamp(24px, 5vw, 70px) 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.day-heading h2,
.page-heading h2 { margin: 5px 0 7px; font-size: clamp(24px, 3vw, 34px); line-height: 1.2; }
.day-heading p,
.page-heading p { max-width: 760px; margin: 0; color: var(--muted); line-height: 1.6; font-size: 14px; }
.day-heading-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.section-nav {
  position: sticky;
  top: 72px;
  z-index: 12;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 11px clamp(24px, 5vw, 70px);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 244, 0.96);
  backdrop-filter: blur(10px);
}

.section-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.section-button:hover { border-color: #99b9a8; color: var(--forest); }

.study-content,
.review-content,
.library-content {
  width: min(1040px, 100%);
  padding: 8px clamp(24px, 5vw, 70px) 80px;
}

.learning-section { scroll-margin-top: 132px; padding: 30px 0; border-bottom: 1px solid var(--line); }
.learning-section:last-child { border-bottom: 0; }

.section-heading { display: flex; justify-content: space-between; gap: 18px; align-items: end; margin-bottom: 16px; }
.section-heading h3 { margin: 0; font-size: 19px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.section-count { color: var(--muted); font-size: 12px; }

.phrase-list { display: grid; gap: 9px; }

.phrase-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 15px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-left: 4px solid #aeb9b1;
  border-radius: var(--radius);
  background: var(--surface);
}

.phrase-card[data-state="A"] { border-left-color: var(--forest); }
.phrase-card[data-state="B"] { border-left-color: var(--amber); }
.phrase-card[data-state="C"] { border-left-color: var(--rust); }

.english-line { margin: 0; font-size: 17px; line-height: 1.75; font-weight: 650; }
.translation { margin: 5px 0 0; color: #4f5952; font-size: 14px; line-height: 1.6; }
.translation.hidden { display: none; }
.pronunciation-note { margin: 6px 0 0; color: var(--blue); font-size: 12px; line-height: 1.55; }

.word-token {
  display: inline;
  margin: 0;
  padding: 1px 2px;
  border: 0;
  border-bottom: 1px dotted transparent;
  border-radius: 3px;
  background: transparent;
  font: inherit;
  font-weight: inherit;
}

.word-token:hover,
.word-token.noted { border-bottom-color: var(--blue); background: var(--blue-soft); color: #244c7a; }

.phrase-actions {
  min-width: 176px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  align-content: start;
}

.play-button,
.state-button {
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12px;
}

.play-button:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.state-strip { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.state-button { min-width: 0; padding: 5px; color: var(--muted); }
.state-button[data-value="A"].active { border-color: var(--forest); background: var(--forest-soft); color: var(--forest-dark); }
.state-button[data-value="B"].active { border-color: var(--amber); background: var(--amber-soft); color: #7b4e07; }
.state-button[data-value="C"].active { border-color: var(--rust); background: var(--rust-soft); color: #7d2c20; }

.plain-list { margin: 0; padding-left: 22px; }
.plain-list li { margin: 9px 0; line-height: 1.65; }
.vocab-block { padding: 16px; border-left: 4px solid var(--blue); background: var(--blue-soft); line-height: 1.8; font-size: 14px; }

.task-list { display: grid; gap: 8px; }
.task-item { display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; line-height: 1.55; }
.task-item input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--forest); }

.roleplay-band { padding: 18px; border: 1px solid #d0b879; border-radius: var(--radius); background: #fff8e8; }
.roleplay-band p { margin: 0; line-height: 1.7; }
.roleplay-band .secondary-button { margin-top: 12px; }

.filter-row { display: flex; gap: 8px; padding: 18px clamp(24px, 5vw, 70px) 0; }
.filter-button { min-height: 34px; padding: 6px 12px; border: 1px solid var(--line); background: var(--surface); font-size: 12px; }
.filter-button.active { border-color: var(--forest); background: var(--forest-soft); color: var(--forest-dark); font-weight: 700; }

.empty-state { padding: 44px 0; color: var(--muted); text-align: center; }
.empty-state strong { display: block; margin-bottom: 7px; color: var(--ink); font-size: 18px; }

.library-heading { align-items: end; }
.search-box {
  width: min(360px, 100%);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; }
.library-day { padding: 24px 0; border-bottom: 1px solid var(--line); }
.library-day h3 { margin: 0 0 12px; font-size: 17px; }

.drawer { position: fixed; inset: 0; z-index: 60; display: none; }
.drawer.open { display: block; }
.drawer-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(14, 22, 17, 0.42); }
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(420px, 92vw);
  height: 100%;
  overflow: auto;
  padding: 24px;
  background: #fff;
  box-shadow: var(--shadow);
}

.drawer-header { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 22px; }
.drawer-header h2 { margin: 5px 0 0; font-size: 30px; overflow-wrap: anywhere; }
.word-context { margin: 18px 0; padding: 14px; border-left: 4px solid var(--blue); background: var(--blue-soft); line-height: 1.6; }
.word-status { display: grid; gap: 9px; margin: 0 0 18px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.word-status legend { padding: 0 6px; color: var(--muted); font-size: 12px; }
.word-status label { display: flex; gap: 8px; align-items: center; }
.word-status input { accent-color: var(--forest); }

.note-field,
.select-field,
.range-field { display: grid; gap: 7px; margin: 18px 0; }
.note-field span,
.select-field span,
.range-field span { color: var(--muted); font-size: 12px; font-weight: 700; }
.note-field textarea,
.select-field select { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; resize: vertical; }
.range-field input { width: 100%; accent-color: var(--forest); }
.toggle-field { display: flex; align-items: center; gap: 10px; margin: 20px 0; }
.toggle-field input { width: 18px; height: 18px; accent-color: var(--forest); }
.settings-actions { display: grid; gap: 8px; margin-top: 28px; }
.file-button { display: grid; place-items: center; cursor: pointer; }
.file-button input { display: none; }
.privacy-note { margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 1.6; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 90;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: var(--radius);
  background: #17211b;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .topbar { grid-template-columns: minmax(220px, 1fr) auto; }
  .view-tabs { grid-column: 1 / -1; grid-row: 2; width: 100%; grid-template-columns: repeat(3, 1fr); }
  .top-actions { grid-column: 2; grid-row: 1; }
  .workspace { grid-template-columns: 220px minmax(0, 1fr); }
  .day-rail { top: 120px; height: calc(100vh - 120px); }
  .section-nav { top: 120px; }
  .day-heading { flex-direction: column; }
  .day-heading-actions { justify-content: flex-start; }
}

@media (max-width: 720px) {
  .topbar { position: static; min-height: 0; padding: 10px 14px; gap: 9px; grid-template-columns: minmax(0, 1fr) auto; }
  .display-mode { width: 100px; font-size: 13px; }
  .brand-block h1 { font-size: 15px; }
  .brand-block p { display: none; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .top-actions .quiet-button { display: none; }
  .view-tabs { grid-row: 2; }
  .workspace { display: block; }
  .day-rail {
    position: static;
    width: 100%;
    height: auto;
    display: block;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .rail-summary { display: none; }
  .day-list { display: flex; gap: 6px; overflow-x: auto; padding: 9px 12px; }
  .day-nav-button { width: 50px; min-width: 50px; min-height: 42px; display: block; padding: 4px; text-align: center; }
  .day-index { margin: auto; }
  .day-nav-copy,
  .day-score { display: none; }
  .day-heading,
  .page-heading { padding: 22px 16px 18px; }
  .day-heading h2,
  .page-heading h2 { font-size: 25px; }
  .day-heading-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .section-nav { top: 0; padding: 9px 12px; }
  .study-content,
  .review-content,
  .library-content { padding: 4px 16px 64px; }
  .learning-section { scroll-margin-top: 58px; padding: 24px 0; }
  .phrase-card { display: block; padding: 14px; }
  .phrase-actions { width: 100%; min-width: 0; margin-top: 12px; grid-template-columns: repeat(2, 1fr); }
  .filter-row { padding: 14px 16px 0; overflow-x: auto; }
  .filter-button { flex: 0 0 auto; }
  .library-heading { display: block; }
  .search-box { margin-top: 16px; }
  .drawer-panel { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
/* Listening and expression share the existing day navigation and progress store. */
.practice-modes { display: flex; gap: 4px; padding-right: 14px; border-right: 1px solid var(--border, #d8dfdb); }
.practice-modes [aria-pressed="true"] { background: #216b53; color: white; border-color: #216b53; }
.listening-meta { color: #626f69; font-size: 14px; line-height: 1.65; }
.source-notice { border-left: 3px solid #ba783b; padding: 8px 14px; line-height: 1.7; background: #fff7ec; }
.listening-sources { display: grid; gap: 24px; margin: 24px 0; }
.listening-source { background: #fff; border: 1px solid #d8dfdb; border-radius: 8px; padding: 24px; min-width: 0; }
.listening-source h4 { font-size: 21px; line-height: 1.4; margin: 0; }
.listening-source h5 { font-size: 16px; margin: 22px 0 10px; }
.listening-source p, .listening-transfer p { line-height: 1.7; }
.listening-source .section-heading { align-items: flex-start; flex-wrap: wrap; gap: 14px; }
.source-link { color: #1b634d; font-weight: 650; text-underline-offset: 4px; }
.listening-section details { border-top: 1px solid #e0e6e2; padding: 16px 0; }
.listening-section summary { cursor: pointer; color: #216b53; font-weight: 650; }
.listening-note { display: grid; gap: 8px; margin: 12px 0 18px; }
.listening-note textarea { width: 100%; resize: vertical; min-height: 90px; padding: 12px; border: 1px solid #c6d0ca; border-radius: 6px; font: inherit; background: #fff; color: #202923; }
.listening-record { display: flex; align-items: center; flex-wrap: wrap; gap: 20px; }
.listening-record label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.listening-record select { max-width: 100%; padding: 8px; border: 1px solid #c6d0ca; border-radius: 4px; font: inherit; background: white; }
.listening-transfer { padding: 24px 0; border-top: 1px solid #cad5ce; }
.listening-transfer h3 { font-size: 21px; }
@media (max-width: 600px) { .listening-source { padding: 18px; } .practice-modes { border-right: 0; } }
.listening-player { min-height: 170px; margin: 16px 0; display: grid; align-items: center; }
.listening-player > button { justify-self: start; }
.listening-player iframe { width: 100%; height: 170px; border: 0; }
.listening-player.video-player { aspect-ratio: 16 / 9; }
.listening-player.video-player iframe { height: 100%; min-height: 200px; }
.listening-recap span { display: block; margin: 6px 0; }
.listening-access { display: flex; flex-wrap: wrap; gap: 12px 24px; margin: 16px 0 8px; }
.listening-access a { display: inline-flex; min-height: 44px; align-items: center; }
