:root {
  --bg: #f6f4ef;
  --sidebar: #1e3a2f;
  --sidebar-text: #e8f0eb;
  --accent: #c45c26;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --border: #e2ddd4;
  --shadow: 0 8px 30px rgba(30, 58, 47, 0.08);
  --instruction-bg: #f9f7f2;
  --table-head-bg: #f9f7f2;
  --highlight-bg: #ffe4c4;
  --tooltip-bg: #1e3a2f;
  --error: #b42318;
  --search-bg: rgba(255, 255, 255, 0.12);
  --search-placeholder: rgba(255, 255, 255, 0.5);
  --sidebar-hover: rgba(255, 255, 255, 0.14);
  --lesson-num: #f0b48a;
  --vocab-mask-bg: #d4cfc4;
}

[data-theme="dark"] {
  --bg: #121816;
  --sidebar: #0d1814;
  --sidebar-text: #d4ddd8;
  --accent: #e8956a;
  --card: #1a221e;
  --text: #e6ebe8;
  --muted: #9aa39c;
  --border: #2d3a34;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --instruction-bg: #222b26;
  --table-head-bg: #222b26;
  --highlight-bg: #5c4030;
  --tooltip-bg: #2a3832;
  --error: #f87171;
  --search-bg: rgba(255, 255, 255, 0.08);
  --search-placeholder: rgba(255, 255, 255, 0.4);
  --sidebar-hover: rgba(255, 255, 255, 0.1);
  --lesson-num: #e8b88a;
  --vocab-mask-bg: #3d4a44;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

.layout {
  --sidebar-width: 280px;
  --quiz-panel-width: 0px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--quiz-panel-width);
  min-height: 100vh;
  transition: grid-template-columns 0.25s ease;
}

.layout.sidebar-collapsed {
  --sidebar-width: 0px;
}

.layout.learning-mode {
  --quiz-panel-width: 280px;
}

aside.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 1.25rem 1rem 2rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  overflow-x: hidden;
  min-width: 280px;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.layout.sidebar-collapsed aside.sidebar {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  padding: 0;
}

.sidebar-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.icon-btn {
  border: 1px solid var(--sidebar-hover);
  background: var(--search-bg);
  color: var(--sidebar-text);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--sidebar-hover);
}

.sidebar-expand {
  display: none;
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 100;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s;
}

.sidebar-expand:hover {
  border-color: var(--sidebar);
  color: var(--sidebar);
}

.layout.sidebar-collapsed .sidebar-expand {
  display: block;
}

aside.sidebar h1 {
  font-size: 1.1rem;
  margin: 0 0 0.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

aside.sidebar .meta {
  font-size: 0.8rem;
  opacity: 0.75;
  margin-bottom: 0.75rem;
}

.site-nav {
  margin: 0 0 0.85rem;
}

.site-nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.88rem;
  opacity: 0.85;
}

.site-nav a:hover {
  opacity: 1;
  text-decoration: underline;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sidebar-top h1 { margin: 0; }

.theme-toggle { font-size: 1rem; }

.search {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  background: var(--search-bg);
  color: var(--sidebar-text);
}

.search::placeholder { color: var(--search-placeholder); }

.lesson-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.lesson-list li { margin-bottom: 0.15rem; }

.lesson-list button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  line-height: 1.35;
  transition: background 0.15s;
}

.lesson-list button:hover,
.lesson-list button.active {
  background: var(--sidebar-hover);
}

.lesson-list .num {
  display: inline-block;
  min-width: 2rem;
  font-weight: 600;
  color: var(--lesson-num);
}

main {
  padding: 2rem 2.5rem 4rem;
  max-width: 900px;
}

.empty, .loading, .error {
  color: var(--muted);
  padding: 3rem 0;
}

.error { color: var(--error); }

.lesson-header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}

.lesson-header .badge {
  display: inline-block;
  background: var(--sidebar);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}

.lesson-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.85rem;
  font-weight: 700;
  font-family: Georgia, "Times New Roman", serif;
}

.lesson-header .zh {
  font-size: 1.15rem;
  color: var(--accent);
  margin: 0;
}

section {
  background: var(--card);
  border-radius: 14px;
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

section h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--sidebar);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

section h3::before {
  content: "";
  width: 4px;
  height: 1.1em;
  background: var(--accent);
  border-radius: 2px;
}

.passage-vocab-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.passage-vocab-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.passage-vocab-toggle .vocab-switch {
  width: 2.4rem;
  height: 1.35rem;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s;
  border: 1px solid var(--border);
}

.passage-vocab-toggle .vocab-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1rem;
  height: 1rem;
  background: var(--card);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s;
}

.passage-vocab-toggle input:checked + .vocab-switch {
  background: var(--accent);
  border-color: var(--accent);
}

.passage-vocab-toggle input:checked + .vocab-switch::after {
  transform: translateX(1.05rem);
}

.passage-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.learning-progress {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

.learning-progress.done {
  color: #2d6a4f;
  font-weight: 600;
}

[data-theme="dark"] .learning-progress.done {
  color: #95d5b2;
}

.btn-reset-learn {
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
}

.btn-reset-learn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.instruction {
  background: var(--instruction-bg);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 1rem;
  white-space: pre-wrap;
}

.question {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 1rem;
  font-family: Georgia, serif;
  font-size: 1.05rem;
}

.passage, .translation {
  white-space: pre-wrap;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.02rem;
}

.page-quiz-panel {
  display: none;
  flex-direction: column;
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 1rem 0.85rem 2rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  min-width: 280px;
}

.layout.learning-mode .page-quiz-panel {
  display: flex;
}

.page-quiz-panel .panel-placeholder {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.vocab-quiz-target.is-active {
  box-shadow: 0 0 0 2px var(--accent);
}

.vocab-highlight {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: var(--accent);
  cursor: help;
  position: relative;
}

.vocab-highlight::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  min-width: 8em;
  max-width: 16em;
  padding: 0.45rem 0.65rem;
  background: var(--tooltip-bg);
  color: var(--sidebar-text);
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 0.82rem;
  line-height: 1.45;
  border-radius: 8px;
  white-space: normal;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s, visibility 0.15s;
  z-index: 20;
}

.vocab-highlight:hover::after,
.vocab-highlight:focus::after {
  opacity: 1;
  visibility: visible;
}

/* 蒙词：背景色遮住（字色与背景同色，悬停也不露出原文） */
.vocab-mask {
  background: var(--vocab-mask-bg);
  color: var(--vocab-mask-bg);
  border-radius: 3px;
  padding: 0 0.12em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  user-select: none;
  -webkit-user-select: none;
}

.vocab-quiz-target {
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.vocab-quiz-target:hover,
.vocab-quiz-target:focus-visible {
  background: var(--vocab-mask-bg);
  color: var(--vocab-mask-bg);
  box-shadow: 0 0 0 2px var(--accent);
  outline: none;
}

.vocab-revealed {
  background: linear-gradient(180deg, transparent 70%, rgba(45, 106, 79, 0.25) 70%);
  border-radius: 2px;
  padding: 0 1px;
  position: relative;
}

.vocab-revealed.flash-ok {
  animation: vocab-flash 0.6s ease;
}

@keyframes vocab-flash {
  0%, 100% { background-color: transparent; }
  40% { background-color: rgba(45, 106, 79, 0.35); }
}

.page-quiz-panel .quiz-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sidebar);
  margin: 0 0 0.15rem;
  flex-shrink: 0;
}

.page-quiz-panel .quiz-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.65rem;
  flex-shrink: 0;
}

.vocab-quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.vocab-quiz-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, serif;
  font-size: 0.95rem;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.vocab-quiz-option:hover {
  border-color: var(--sidebar);
  background: var(--instruction-bg);
}

.vocab-quiz-option .opt-meaning {
  display: block;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.vocab-quiz-option.wrong {
  border-color: var(--error);
  animation: quiz-shake 0.35s ease;
}

@keyframes quiz-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.translation {
  font-family: inherit;
  font-size: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--table-head-bg);
  font-weight: 600;
  color: var(--sidebar);
  font-size: 0.85rem;
}

tr:last-child td { border-bottom: none; }

.word {
  font-family: Georgia, serif;
  font-weight: 600;
}

.pos {
  color: var(--accent);
  font-size: 0.85rem;
}

.nav-buttons {
  display: flex;
  gap: 0.75rem;
  margin-top: 2rem;
}

.nav-buttons button {
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.nav-buttons button:hover:not(:disabled) {
  border-color: var(--sidebar);
  color: var(--sidebar);
}

.nav-buttons button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (max-width: 860px) {
  .layout:not(.sidebar-collapsed) {
    grid-template-columns: 1fr;
  }
  .layout:not(.sidebar-collapsed) aside {
    position: relative;
    height: auto;
    max-height: 40vh;
    min-width: 0;
  }
  .layout.sidebar-collapsed {
    grid-template-columns: 1fr;
  }
  .layout.sidebar-collapsed aside.sidebar {
    display: none;
  }
  main { padding: 1.25rem; }
  .layout.sidebar-collapsed main {
    padding-top: 3.5rem;
  }
  .layout.learning-mode {
    --quiz-panel-width: 0px;
    grid-template-columns: 1fr;
  }
  .layout.learning-mode .page-quiz-panel {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    height: auto;
    max-height: 42vh;
    min-width: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    z-index: 500;
  }
}
