:root {
  color-scheme: light;
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #20201d;
  --muted: #6e6a61;
  --line: #ded7ca;
  --line-strong: #c8bba8;
  --teal: #116466;
  --teal-soft: #dcefee;
  --coral: #d45d45;
  --gold: #c9902e;
  --green: #4c7c4f;
  --shadow: 0 18px 45px rgba(32, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.66) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.48) 0 1px, transparent 1px 100%),
    var(--bg);
  background-size: 26px 26px;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  min-height: 100vh;
}

.chapter-rail {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-block {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 12px;
  align-items: center;
}

.mark {
  display: grid;
  place-items: center;
  width: 52px;
  aspect-ratio: 1;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-block h1,
.top-bar h2 {
  margin: 0;
}

.brand-block h1 {
  font-size: 24px;
  line-height: 1.05;
}

.brand-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

#appVersionRail {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--teal);
  background: var(--teal-soft);
  font-weight: 800;
}

.search-box {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.search-box svg {
  width: 18px;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  min-width: 0;
}

.chapter-nav,
.topic-list,
.trap-list {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.chapter-nav {
  padding-right: 4px;
}

.chapter-btn,
.topic-btn {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.chapter-btn {
  display: grid;
  gap: 7px;
  padding: 12px;
}

.chapter-btn:hover,
.chapter-btn.active {
  background: var(--teal-soft);
  border-color: #bbd8d6;
}

.chapter-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.mini-meter {
  height: 5px;
  border-radius: 999px;
  background: #ebe3d6;
  overflow: hidden;
}

.mini-meter span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--teal);
}

.rail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.utility-btn,
.icon-btn,
.reader-tool {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
}

.utility-btn {
  padding: 0 10px;
  font-size: 13px;
  white-space: nowrap;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
}

.utility-btn svg,
.icon-btn svg,
.reader-tool svg {
  width: 17px;
  height: 17px;
}

.utility-btn:hover,
.icon-btn:hover,
.reader-tool:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.main-workspace {
  min-width: 0;
  padding: 22px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.top-bar h2 {
  font-size: 28px;
  line-height: 1.1;
}

.top-tools {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.mode-btn {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  font-size: 13px;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--teal);
  color: #fff;
}

.progress-wrap {
  display: grid;
  grid-template-columns: 156px 46px;
  align-items: center;
  gap: 10px;
}

.progress-meter {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #e7ded0;
  border: 1px solid var(--line);
}

.progress-meter span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), var(--green));
}

#progressText {
  font-variant-numeric: tabular-nums;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 238px minmax(360px, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.topic-panel,
.study-pane,
.review-panel {
  min-width: 0;
}

.topic-panel,
.review-block,
.section-reader {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.topic-panel {
  position: sticky;
  top: 22px;
  max-height: calc(100vh - 44px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
}

.head-tools {
  display: inline-flex;
  gap: 6px;
}

.topic-list {
  padding: 10px;
}

.topic-btn {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: center;
  padding: 9px;
  font-size: 13px;
  line-height: 1.25;
}

.topic-btn::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #cabfac;
  justify-self: center;
}

.topic-btn.reviewed::before {
  background: var(--green);
  border-color: var(--green);
}

.topic-btn.active {
  background: #fbecd8;
  border-color: #edc47f;
}

.section-reader {
  min-height: calc(100vh - 116px);
  overflow: hidden;
}

.reader-header {
  display: grid;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.reader-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.reader-header h3 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.reader-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.reader-tool {
  min-width: 40px;
  padding: 0 12px;
}

.reader-tool.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.section-body {
  padding: 10px 20px 30px;
  font-size: 16px;
  line-height: 1.68;
}

.section-body h1,
.section-body h2,
.section-body h3 {
  line-height: 1.25;
}

.section-body h1 {
  font-size: 26px;
}

.section-body h2 {
  margin-top: 28px;
  font-size: 22px;
}

.section-body h3 {
  margin-top: 24px;
  font-size: 18px;
}

.section-body p {
  margin: 12px 0;
}

.section-body ul {
  padding-left: 22px;
}

.section-body li {
  margin: 6px 0;
}

.section-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.section-body th,
.section-body td {
  border: 1px solid var(--line);
  padding: 9px 10px;
  vertical-align: top;
}

.section-body th {
  background: #f2eadf;
  text-align: left;
}

.section-body code {
  background: #f1e6d9;
  border-radius: 5px;
  padding: 2px 5px;
}

.section-body mark {
  background: #ffe08a;
  color: inherit;
  padding: 1px 2px;
  border-radius: 3px;
}

.bilingual-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.lang-panel {
  min-width: 0;
  overflow-x: auto;
}

.lang-panel + .lang-panel {
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.lang-label {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin: 8px 0 6px;
  padding: 0 9px;
  border-radius: 999px;
  background: #f2eadf;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.lang-zh {
  font-family:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Inter, ui-sans-serif,
    system-ui, sans-serif;
}

.bilingual-grid .lang-panel table {
  min-width: 420px;
}

.review-panel {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 22px;
  max-height: calc(100vh - 44px);
  overflow: auto;
}

.review-block {
  overflow: hidden;
}

.video-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.video-controls select {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0 10px;
}

.lesson-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  font-size: 13px;
}

.lesson-link:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.lesson-link svg {
  width: 16px;
  height: 16px;
}

.video-embed {
  background: #171916;
}

.video-frame {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  background: #171916;
}

.video-empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 18px;
  color: #f8f2e8;
  text-align: center;
  line-height: 1.45;
}

.flashcard {
  padding: 14px;
}

.flashcard-question {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff9ee;
}

.flashcard-question strong {
  font-size: 15px;
  line-height: 1.4;
}

.flashcard-answer {
  margin-top: 10px;
  padding: 12px;
  border-left: 4px solid var(--teal);
  background: var(--teal-soft);
  line-height: 1.45;
}

.answer-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  min-height: 38px;
  padding: 0 12px;
}

.trap-list {
  max-height: 260px;
  padding: 12px;
}

.trap-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: start;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.45;
}

.trap-item:last-child {
  border-bottom: 0;
}

.trap-item svg {
  width: 17px;
  height: 17px;
  color: var(--coral);
  margin-top: 2px;
}

.personal-note {
  display: block;
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 0;
  border-top: 1px solid transparent;
  outline: 0;
  padding: 14px;
  background: #fffaf0;
  color: var(--ink);
  line-height: 1.55;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
}

@media (max-width: 1340px) {
  .app-shell {
    grid-template-columns: 258px minmax(0, 1fr);
  }

  .workspace-grid {
    grid-template-columns: 210px minmax(320px, 1fr);
  }

  .review-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .chapter-rail {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .main-workspace {
    padding: 16px;
  }

  .top-bar,
  .reader-title-row {
    display: grid;
  }

  .top-tools {
    justify-items: stretch;
  }

  .mode-toggle {
    width: 100%;
  }

  .mode-btn {
    flex: 1;
  }

  .progress-wrap {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) 46px;
  }

  .workspace-grid,
  .review-panel {
    grid-template-columns: 1fr;
  }

  .bilingual-grid {
    grid-template-columns: 1fr;
  }

  .lang-panel + .lang-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 14px;
  }

  .topic-panel,
  .review-panel {
    position: static;
    max-height: none;
  }
}

@media print {
  body {
    background: #fff;
  }

  .chapter-rail,
  .topic-panel,
  .review-panel,
  .reader-actions {
    display: none;
  }

  .app-shell,
  .workspace-grid {
    display: block;
  }

  .main-workspace {
    padding: 0;
  }

  .section-reader {
    box-shadow: none;
    border: 0;
  }
}
