/* ------------------------------------------------------------------
   绿皮书 · 量化面试题库
   亮色纸感 · 墨绿点缀 · 衬线标题 · 简约学习向
------------------------------------------------------------------- */

:root {
  --topbar-h: 60px;

  --paper: #f6f5f0;
  --paper-deep: #f1efe8;
  --surface: #fffefa;
  --ink: #22251f;
  --ink-2: #575c50;
  --ink-3: #8b9082;
  --line: #e3e1d5;
  --line-soft: #ecebe0;

  --accent: #2f6a4d;
  --accent-ink: #24523c;
  --accent-wash: #edf2ec;
  --math-ink: #265741;

  --amber: #9a5b34;
  --amber-soft: #f8f1e7;

  --font-sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --font-serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;

  --shadow-soft: 0 1px 3px rgba(38, 41, 33, 0.05);
  --shadow-float: 0 12px 40px rgba(38, 41, 33, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: #d9e6dc;
}

:focus-visible {
  outline: 2px solid #6f9c85;
  outline-offset: 2px;
}

button {
  font-family: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* 滚动条 ---------------------------------------------------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: #d3d0c2 transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: #d6d3c6;
  border: 3px solid transparent;
  border-radius: 8px;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background-color: #c3c0b1;
}

/* 顶栏 ------------------------------------------------------------ */

.topbar {
  position: relative;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.topbar svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.icon-button {
  display: none;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.icon-button:hover {
  background: var(--paper-deep);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  flex: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(140deg, #3a7a59, #275540);
  color: #f4f3ea;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), var(--shadow-soft);
}

.brand-copy strong {
  display: block;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.brand-copy small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.search-field {
  flex: 1;
  max-width: 460px;
  margin-inline: auto;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-3);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-field:focus-within {
  border-color: #9db8a8;
  box-shadow: 0 0 0 3px rgba(47, 106, 77, 0.1);
}

.search-field input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  outline: none;
}

.search-field input::placeholder {
  color: #a4a898;
}

.search-field kbd {
  font-family: inherit;
  font-size: 11px;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  background: var(--paper);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.pill-toggle {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pill-toggle:hover {
  background: var(--surface);
  border-color: #d3d0c2;
}

.pill-toggle.is-on {
  background: var(--accent-wash);
  border-color: #b8ccbc;
  color: var(--accent-ink);
}

.pill-toggle .slash {
  opacity: 0;
  transition: opacity 0.15s;
}

.pill-toggle.is-on .slash {
  opacity: 1;
}

/* 三栏布局 -------------------------------------------------------- */

.layout {
  display: flex;
  height: calc(100dvh - var(--topbar-h));
}

/* 左栏 · 目录 ------------------------------------------------------ */

.sidebar {
  width: 302px;
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
}

.sidebar-head {
  padding: 14px 16px 4px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: #eceadd;
}

.segmented button {
  border: none;
  border-radius: 8px;
  padding: 6px 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(38, 41, 33, 0.08);
}

.result-meta {
  margin: 10px 4px 4px;
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.entry-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 10px 28px;
}

.chapter-row {
  position: sticky;
  top: 0;
  z-index: 2;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 13px 8px 7px;
  border: none;
  background: var(--paper);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  text-align: left;
}

.chapter-row:hover {
  color: var(--ink);
}

.chapter-row svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: var(--ink-3);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  transition: transform 0.15s;
}

.chapter-row.collapsed svg {
  transform: rotate(-90deg);
}

.chapter-row .ch-no {
  font-size: 11px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

.chapter-row .ch-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.entry-item {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 7px 10px;
  margin-bottom: 1px;
  scroll-margin-top: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--ink-2);
}

.entry-item:hover {
  background: #efede3;
}

.entry-item .num {
  min-width: 24px;
  text-align: right;
  font-size: 11.5px;
  line-height: 1.9;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  flex: none;
}

.entry-copy {
  flex: 1;
  min-width: 0;
}

.entry-title {
  display: block;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.entry-sub .badge {
  font-size: 10px;
  line-height: 1.5;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink-3);
  background: var(--surface);
}

.entry-item.selected {
  background: var(--accent-wash);
}

.entry-item.selected .entry-title {
  color: var(--accent-ink);
  font-weight: 600;
}

.entry-item.selected .num {
  color: var(--accent);
  font-weight: 600;
}

/* 中栏 · 阅读 ------------------------------------------------------ */

.reader {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  outline: none;
}

.reader-inner {
  max-width: 44rem;
  margin: 0 auto;
  padding: 46px 46px 88px;
}

.reader-kicker {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 0;
  font-size: 12.5px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.reader-kicker .k-chapter {
  color: var(--accent);
  font-weight: 600;
}

.reader-kicker > span + span::before {
  content: "·";
  margin: 0 9px;
  color: #c9c6b8;
}

.reader-kicker .k-pos {
  margin-left: auto;
}

.reader-kicker .k-pos::before {
  content: "" !important;
  margin: 0 !important;
}

.reader h1 {
  margin: 14px 0 8px;
  font-family: var(--font-serif);
  font-size: clamp(25px, 2.6vw, 32px);
  font-weight: 600;
  line-height: 1.42;
  letter-spacing: 0.015em;
}

.english-title {
  margin: 0 0 6px;
  font-family: Georgia, "Times New Roman", var(--font-serif);
  font-style: italic;
  font-size: 15px;
  color: var(--ink-3);
}

.reader-header {
  margin-bottom: 34px;
}

.content-section {
  margin: 30px 0;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.section-label {
  margin: 0;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--accent);
}

.section-head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.content-section.solution .section-label {
  color: var(--amber);
}

.prose {
  min-width: 0;
  font-size: 16px;
  line-height: 2.05;
  color: #2c2f28;
  overflow-wrap: anywhere;
}

.prose p {
  margin: 0 0 1.05em;
}

.prose p:last-child {
  margin-bottom: 0;
}

.prose mjx-container,
.source-text mjx-container {
  color: var(--math-ink);
}

/* 独占一行的公式：左对齐缩进，display 样式排版 */
.math-line {
  display: block;
  max-width: 100%;
  margin: 0.35em 0;
  padding-left: 1.25em;
  overflow-x: auto;
  overflow-y: hidden;
}

/* 代码块 */
.code-block {
  margin: 0.2em 0 1.05em;
  padding: 13px 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.75;
  color: #363a30;
  overflow-x: auto;
  tab-size: 4;
}

.source-text p {
  margin: 0 0 0.9em;
}

.source-text p:last-child {
  margin-bottom: 0;
}

/* 自测模式：遮住解析 */

.solution-body {
  position: relative;
}

.solution-body.is-covered .prose {
  filter: blur(8px);
  user-select: none;
  pointer-events: none;
}

.solution-cover {
  position: absolute;
  inset: -10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(246, 245, 240, 0.5);
}

.reveal-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13.5px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.reveal-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reveal-button:hover {
  border-color: #b8ccbc;
  color: var(--accent-ink);
  box-shadow: 0 3px 12px rgba(47, 106, 77, 0.12);
}

/* 翻页 ------------------------------------------------------------ */

.reader-pager {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-top: 48px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.pager-button {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 66px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.pager-button.next {
  text-align: right;
  align-items: flex-end;
}

.pager-button small {
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.05em;
}

.pager-button strong {
  max-width: 100%;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.55;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pager-button:hover {
  border-color: #b3c7b8;
  box-shadow: 0 2px 12px rgba(47, 106, 77, 0.08);
}

.pager-placeholder {
  min-height: 66px;
}

/* 右栏 · 原书核对 -------------------------------------------------- */

.source-pane {
  display: none;
  width: clamp(330px, 30vw, 470px);
  flex: none;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--paper-deep);
}

body.source-open .source-pane {
  display: flex;
}

.source-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.source-head strong {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-2);
  letter-spacing: 0.06em;
}

.source-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  background: #e7e5d8;
}

.source-tabs button {
  border: none;
  border-radius: 7px;
  padding: 4px 13px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
}

.source-tabs button.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(38, 41, 33, 0.08);
}

.source-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.source-figure {
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.source-figure figcaption {
  display: flex;
  justify-content: space-between;
  padding: 8px 13px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.source-figure a {
  display: block;
}

.source-figure img {
  display: block;
  width: 100%;
}

.source-section h2 {
  margin: 6px 2px 10px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--ink-2);
}

.source-text {
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 13.5px;
  line-height: 1.95;
  color: #383c31;
  overflow-wrap: anywhere;
}

.source-text.correction {
  background: var(--amber-soft);
  border-color: #e8d9c4;
  color: #5d4630;
  white-space: pre-wrap;
}

/* 空状态 ---------------------------------------------------------- */

.empty-state {
  padding: 72px 24px;
  text-align: center;
  font-size: 13.5px;
  color: var(--ink-3);
}

/* 浮层 ------------------------------------------------------------ */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  border: none;
  background: rgba(32, 34, 28, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

body.nav-open .scrim {
  opacity: 1;
  pointer-events: auto;
}

/* 响应式 ---------------------------------------------------------- */

@media (max-width: 1200px) {
  .source-pane {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    width: min(450px, 94vw);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-float);
    transform: translateX(105%);
    transition: transform 0.22s ease;
  }

  body.source-open .source-pane {
    transform: none;
  }

  body.source-open .scrim {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 960px) {
  .icon-button {
    display: flex;
  }

  .brand-copy small,
  .search-field kbd {
    display: none;
  }

  .search-field {
    max-width: none;
  }

  .pill-toggle {
    padding: 0 12px;
  }

  .pill-toggle span {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 31;
    width: min(320px, 88vw);
    background: var(--paper);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    border-right: 1px solid var(--line);
    box-shadow: none;
  }

  body.nav-open .sidebar {
    transform: none;
    box-shadow: var(--shadow-float);
  }

  .reader-inner {
    padding: 28px 20px 72px;
  }

  .reader-kicker .k-pos {
    margin-left: 0;
  }

  .reader-kicker .k-pos::before {
    content: "·" !important;
    margin: 0 9px !important;
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 8px;
    padding: 0 10px;
  }

  .brand-copy {
    display: none;
  }

  .icon-button {
    width: 34px;
  }

  .search-field {
    min-width: 0;
    padding: 0 12px;
  }

  .pill-toggle {
    padding: 0 10px;
  }

  .math-line {
    padding-left: 0;
    padding-bottom: 0.2em;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* 打印 ------------------------------------------------------------ */

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

  .topbar,
  .sidebar,
  .source-pane,
  .scrim,
  .reader-pager {
    display: none !important;
  }

  .layout {
    display: block;
    height: auto;
  }

  .reader {
    overflow: visible;
  }

  .solution-body.is-covered .prose {
    filter: none;
  }

  .solution-cover {
    display: none;
  }
}
