:root {
  --bg: #f7f7f5;
  --paper: #ffffff;
  --paper-soft: #fbfaf8;
  --ink: #1f2328;
  --muted: #656d76;
  --subtle: #d8d2ca;
  --line: #e7e1d8;
  --accent: #a52323;
  --accent-strong: #841b1b;
  --accent-soft: #f5e7e5;
  --ok: #286c45;
  --shadow: 0 18px 45px rgba(39, 31, 24, 0.08);
  --radius: 8px;
  --rail: 268px;
  --progress: 300px;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(165, 35, 35, 0.045) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(47, 36, 24, 0.035) 0 1px, transparent 1px 100%),
    var(--bg);
  background-size: 48px 48px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr) auto;
  grid-template-areas:
    "topbar topbar"
    "rail main"
    "footer footer";
}

.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 24px;
  background: rgba(247, 247, 245, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  font-weight: 800;
}

.brand-mark,
.entry-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  line-height: 1;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.ghost-button,
.primary-button,
.tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  padding: 0;
}

.icon-button svg,
.search-field svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ghost-button,
.primary-button {
  padding: 0 14px;
  font-size: 14px;
  font-weight: 700;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button:hover,
.icon-button:hover,
.tab:hover {
  border-color: #c8bdb1;
}

.course-rail {
  grid-area: rail;
  position: sticky;
  top: 64px;
  align-self: start;
  height: calc(100vh - 64px);
  padding: 24px 16px;
  background: rgba(255, 255, 255, 0.58);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.rail-title,
.section-label,
.panel-title,
.result-line,
.card-topline,
.question-meta,
.progress-meta,
.course-entry small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.rail-title,
.panel-title,
.section-label {
  letter-spacing: 0;
}

.course-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.course-entry strong,
.course-entry small {
  display: block;
}

.course-entry strong {
  font-size: 14px;
  line-height: 1.35;
}

.course-entry.active {
  border-color: rgba(165, 35, 35, 0.25);
  background: var(--accent-soft);
}

.course-entry.disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.course-entry.disabled .entry-icon {
  background: #94877a;
}

.workspace {
  grid-area: main;
  min-width: 0;
  padding: 28px;
}

.course-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 18px;
}

.section-label {
  margin: 0 0 4px;
  color: var(--accent);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(30px, 4vw, 54px);
  line-height: 1.08;
  letter-spacing: 0;
}

.course-desc {
  max-width: 680px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
}

.head-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 10px;
  flex: 0 0 min(360px, 42vw);
}

.head-stats div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.head-stats strong {
  display: block;
  font-size: 26px;
  line-height: 1;
}

.head-stats span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.toolbar {
  position: sticky;
  top: 64px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 24px rgba(39, 31, 24, 0.04);
  backdrop-filter: blur(14px);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 420px;
  min-width: 180px;
  color: var(--muted);
}

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

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-soft);
}

.tab {
  min-height: 32px;
  padding: 0 14px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.tab.active {
  background: var(--paper);
  color: var(--accent);
  box-shadow: 0 6px 16px rgba(39, 31, 24, 0.06);
}

.content-grid {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) var(--progress);
  gap: 18px;
  align-items: start;
}

.chapter-nav,
.progress-panel {
  position: sticky;
  top: 146px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.chapter-nav,
.progress-panel {
  padding: 16px;
}

.chapter-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.chapter-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.chapter-button strong,
.chapter-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-button strong {
  font-size: 13px;
}

.chapter-button span {
  color: var(--muted);
  font-size: 12px;
}

.chapter-button.active {
  border-color: rgba(165, 35, 35, 0.24);
  background: var(--accent-soft);
  color: var(--accent);
}

.study-area {
  min-width: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.result-line {
  margin-bottom: 10px;
}

.question-list,
.overview-list {
  display: grid;
  gap: 12px;
}

.question-card,
.flash-card,
.overview-chapter {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 32px rgba(39, 31, 24, 0.06);
}

.question-card {
  padding: 18px;
}

.question-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
}

.question-card h2,
.flash-card h2 {
  margin-bottom: 10px;
  font-size: 20px;
  line-height: 1.42;
  letter-spacing: 0;
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.meta-chip {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-soft);
}

.answer {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.answer.hidden {
  display: none;
}

.answer p,
.card-answer p {
  margin-bottom: 0;
  color: #34302c;
}

.answer p.subpoint,
.card-answer p.subpoint {
  color: var(--ink);
  font-weight: 800;
}

.master-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.master-toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.question-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.flash-card {
  min-height: 430px;
  padding: 28px;
}

.card-topline {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.card-answer {
  display: grid;
  gap: 9px;
  max-height: 46vh;
  overflow: auto;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-soft);
}

.card-answer.hidden {
  min-height: 170px;
  border-style: dashed;
}

.card-answer.hidden::before {
  content: "先试着回忆答案，再点击显示答案。";
  display: grid;
  place-items: center;
  min-height: 140px;
  color: var(--muted);
  font-weight: 700;
}

.card-actions,
.deck-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.deck-controls {
  justify-content: center;
}

.overview-chapter {
  padding: 18px;
}

.overview-chapter h2 {
  margin-bottom: 10px;
  font-size: 22px;
}

.overview-chapter ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.overview-chapter li {
  padding-left: 2px;
}

.progress-ring {
  display: grid;
  place-items: center;
  width: 168px;
  height: 168px;
  margin: 18px auto;
  border-radius: 50%;
  background: conic-gradient(var(--accent) 0deg, var(--line) 0deg);
}

.progress-ring > div {
  display: grid;
  place-items: center;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: var(--paper);
}

.progress-ring strong {
  font-size: 30px;
  line-height: 1;
}

.progress-ring span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.chapter-progress {
  display: grid;
  gap: 12px;
}

.progress-row {
  display: grid;
  gap: 6px;
}

.progress-row header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--ok);
}

.site-footer {
  grid-area: footer;
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
}

.empty-state {
  padding: 48px 20px;
  border: 1px dashed var(--subtle);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.6);
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

@media (max-width: 1180px) {
  :root {
    --progress: 260px;
    --rail: 230px;
  }

  .content-grid {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .progress-panel {
    grid-column: 1 / -1;
    position: static;
  }
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "rail"
      "main"
      "footer";
  }

  .topbar,
  .toolbar {
    position: static;
  }

  .course-rail {
    position: static;
    height: auto;
    display: flex;
    gap: 10px;
    padding: 12px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rail-title {
    display: none;
  }

  .course-entry {
    width: 235px;
    flex: 0 0 auto;
    margin-top: 0;
  }

  .workspace {
    padding: 18px;
  }

  .course-head,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .head-stats {
    flex-basis: auto;
  }

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

  .chapter-nav {
    position: static;
  }

  .chapter-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  body {
    font-size: 14px;
  }

  .topbar {
    padding: 0 14px;
  }

  .top-actions .ghost-button {
    display: none;
  }

  .head-stats,
  .chapter-list {
    grid-template-columns: 1fr;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .question-header {
    grid-template-columns: 1fr;
  }

  .question-actions,
  .card-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .flash-card {
    min-height: 360px;
    padding: 20px;
  }
}

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

  .topbar,
  .course-rail,
  .toolbar,
  .chapter-nav,
  .progress-panel,
  .question-actions,
  .site-footer {
    display: none !important;
  }

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

  .workspace {
    padding: 0;
  }

  .question-card {
    break-inside: avoid;
    border: 0;
    box-shadow: none;
  }

  .answer.hidden {
    display: grid;
  }
}
