:root {
  color-scheme: light;
  --background: #f8f7fc;
  --surface: #fff;
  --ink: #201b38;
  --body: #423b58;
  --muted: #655f7b;
  --border: #e8e4f0;
  --accent: #5644ce;
  --accent-deep: #4531b4;
  --tint: #eeebff;
  --radius: 25px;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--background);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; }
button, select { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; }
button:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #7764ee;
  outline-offset: 3px;
}
h1, h2, h3, p { margin: 0; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sr-only, .select-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-inner {
  max-width: 1184px;
  min-height: 77px;
  margin: auto;
  padding: 10px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; gap: 11px; align-items: center; font-size: 21px; font-weight: 800; line-height: 1.2; }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .08em; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, #735ff1, #5040c8);
}
.brand-mark .icon { width: 26px; height: 26px; }
.tabs { display: flex; align-items: center; gap: 4px; padding: 4px; background: #f1eef8; border-radius: 14px; }
.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 13px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}
.tab[aria-pressed="true"] { color: var(--accent-deep); background: white; box-shadow: 0 1px 5px #21174914; }
.tab .icon { width: 17px; height: 17px; }
.tab-count { background: var(--tint); padding: 1px 6px; color: var(--accent-deep); border-radius: 20px; font-size: 11px; }

.layout {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  gap: 34px;
  max-width: 1184px;
  margin: 0 auto;
  padding: 38px 32px 24px;
}
.sidebar { min-width: 0; }
.side-panel { padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; }
.side-heading { display: flex; align-items: center; gap: 8px; padding: 3px 5px 13px; font-size: 14px; }
.side-heading .icon { color: var(--accent); width: 17px; height: 17px; }
.sources, #chapter-buttons, .saved-list { display: grid; gap: 3px; }
.list-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 39px;
  padding: 8px 9px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--body);
  font-size: 13px;
  line-height: 1.35;
}
.list-button:hover { background: #f7f5fc; }
.list-button[aria-pressed="true"] { color: var(--accent-deep); background: var(--tint); font-weight: 700; }
.list-button .name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-button .number { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.deck-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #7260d7; }
[data-deck="mistakes"] .deck-dot, .card-tag[data-deck="mistakes"]::before { background: #cb5f85; }
[data-deck="shanxiang"] .deck-dot, .card-tag[data-deck="shanxiang"]::before { background: #8261e2; }
[data-deck="technology"] .deck-dot, .card-tag[data-deck="technology"]::before { background: #228d80; }
.chapters { margin-top: 15px; padding-top: 13px; border-top: 1px solid var(--border); }
.side-subheading { padding: 0 7px 6px; color: var(--muted); font-size: 12px; }
#chapter-select, #saved-select { display: none; }
.saved-list { max-height: 52dvh; overflow-y: auto; }
.saved-list .list-button { min-width: 0; }
.side-footnote { padding: 15px 6px; color: var(--muted); font-size: 11px; letter-spacing: .05em; }

.workspace { min-width: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 10px; margin: 0 0 13px; }
.eyebrow { display: flex; gap: 7px; align-items: center; color: var(--accent-deep); font-size: 12px; font-weight: 750; letter-spacing: .09em; margin-bottom: 5px; }
.eyebrow span { width: 6px; height: 6px; background: #8e7aef; border-radius: 50%; }
h1 { font-size: clamp(27px, 4vw, 38px); font-weight: 850; letter-spacing: -.035em; line-height: 1.2; }
.counter { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; color: var(--muted); }
.counter b { font-size: 21px; color: var(--ink); }
.progress { appearance: none; display: block; width: 100%; height: 5px; margin-bottom: 15px; border: 0; border-radius: 4px; overflow: hidden; color: var(--accent); background: var(--border); }
.progress::-webkit-progress-bar { background: var(--border); }
.progress::-webkit-progress-value { background: var(--accent); border-radius: 4px; }
.progress::-moz-progress-bar { background: var(--accent); border-radius: 4px; }

.carousel, .placeholder { height: clamp(330px, calc(100dvh - 302px), 660px); }
.carousel {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border-radius: var(--radius);
  touch-action: pan-y pinch-zoom;
}
.carousel.dragging { cursor: grabbing; user-select: none; }
.track { position: absolute; inset: 0; }
.carousel.dragging .track, .carousel.animating .track { will-change: transform; }
.card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.card[data-slot="-1"] { transform: translateX(calc(-100% - 12px)); }
.card[data-slot="1"] { transform: translateX(calc(100% + 12px)); }
.card::before { content: ""; display: block; flex: none; height: 4px; background: linear-gradient(90deg, #6b54e5 0%, #ab97fa 72%, #e8e0ff 100%); }
.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  min-width: 0;
  padding: 18px 24px 13px 27px;
}
.card-tag {
  display: flex;
  align-items: center;
  flex: none;
  gap: 6px;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 6px;
  background: #f2effb;
  color: #514478;
  font-size: 12px;
  font-weight: 750;
}
.card-tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.card-chapter { min-width: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta > .icon { width: 13px; height: 13px; color: #827a99; }
.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  background: #f8f6fc;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--accent-deep);
}
.bookmark { margin-left: auto; }
.bookmark[aria-pressed="true"] { background: #fff3d8; border-color: #f7dfaa; color: #85520a; }
.bookmark[aria-pressed="true"] .icon { fill: #f9bd47; }
.card-scroll { flex: 1; min-height: 0; overflow: auto; touch-action: pan-y pinch-zoom; overscroll-behavior-y: contain; padding: 7px 34px 32px; scrollbar-width: thin; scrollbar-color: #d5ccec transparent; }
.card-scroll h2 { font-size: clamp(24px, 4vw, 35px); line-height: 1.45; letter-spacing: -.025em; font-weight: 800; color: var(--ink); }
.card-scroll h2.long { font-size: clamp(18px, 3vw, 24px); font-weight: 550; line-height: 1.65; letter-spacing: 0; }
.card-scroll h2, .node-text, .note { white-space: pre-wrap; overflow-wrap: anywhere; }
.card-scroll.simple { display: flex; flex-direction: column; }
.card-scroll.simple h2 { margin: auto 0; padding-bottom: 30px; max-width: 28ch; }
.branch-list, .node-list { list-style: none; padding: 0; margin: 0; }
.branch-list { display: grid; gap: 9px; margin-top: 21px; }
.branch {
  padding: 10px 13px;
  border: 1px solid #ebe6f6;
  border-radius: 11px;
  background: #faf9fd;
}
.branch > .node-text { font-size: 16px; font-weight: 750; color: #382b62; line-height: 1.55; }
.node-list { border-left: 1px solid #ded7ef; margin: 6px 0 0 2px; padding-left: 12px; }
.node-list .node-list { padding-left: 9px; }
.node-list li { position: relative; margin: 4px 0; color: var(--body); font-size: 15px; line-height: 1.65; }
.node-list li::before { content: ""; position: absolute; width: 6px; height: 1px; background: #d9d0ec; top: .85em; left: -11px; }
.node-list .node-list li::before { left: -8px; }
.node-text strong, .note strong, h2 strong { color: var(--accent-deep); }
.note { margin: 9px 0; padding: 8px 10px; border-left: 2px solid #ad9fe1; background: #f7f4ff; color: var(--body); font-size: 14px; line-height: 1.6; }
.note::before { content: "备注"; display: block; color: var(--accent-deep); font-weight: 750; font-size: 11px; }
.image-button {
  display: block;
  max-width: 100%;
  margin: 12px 0 0;
  padding: 0;
  text-align: left;
  background: #f8f6fb;
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
}
.image-button img { display: block; width: auto; height: auto; max-width: 100%; max-height: 420px; object-fit: contain; }
.image-button span { display: block; padding: 7px 9px; color: var(--accent-deep); font-size: 12px; font-weight: 700; }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 15px; }
.nav-button, .primary { min-height: 45px; padding: 0 15px; border: 1px solid var(--border); border-radius: 12px; background: white; font-size: 14px; font-weight: 750; }
.nav-button { display: flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.nav-button .icon { width: 17px; height: 17px; }
.nav-button:disabled { color: #766f88; background: #f1eef6; }
.primary { background: var(--accent); color: white; border-color: var(--accent); }
.primary:hover:not(:disabled) { background: var(--accent-deep); }
.gesture-hint { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; text-align: center; }
.keyboard-hint { display: inline-flex; gap: 4px; align-items: center; }
kbd { display: inline-grid; place-items: center; width: 19px; height: 18px; border: 1px solid #dfdaeb; border-radius: 4px; background: #fff; font-size: 13px; }

.placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; border: 1px solid var(--border); border-radius: var(--radius); background: white; }
.placeholder-icon { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 18px; color: var(--accent); background: var(--tint); }
.placeholder-icon .icon { width: 28px; height: 28px; }
.placeholder h2 { font-size: 20px; }
.placeholder p { color: var(--muted); font-size: 14px; }
.placeholder .primary { margin-top: 5px; }
#image-dialog { max-width: min(1040px, calc(100% - 22px)); max-height: calc(100dvh - 24px); width: max-content; margin: auto; padding: 0; border: 0; border-radius: 15px; color: var(--ink); background: white; }
#image-dialog::backdrop { background: #211932b8; }
.dialog-bar { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 16px; background: white; padding: 7px 10px 7px 15px; font-size: 14px; font-weight: 750; }
.dialog-image { padding: 0 8px 8px; }
.dialog-image img { display: block; max-width: 100%; height: auto; margin: auto; }
.noscript { margin: 16px; color: var(--ink); }

@media (max-width: 740px) {
  .header-inner { min-height: 62px; padding: 7px 14px; }
  .brand { gap: 7px; font-size: 19px; white-space: nowrap; }
  .brand small { display: none; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand-mark .icon { width: 22px; height: 22px; }
  .tabs { gap: 2px; padding: 3px; border-radius: 11px; }
  .tab { min-height: 37px; padding: 0 8px; gap: 4px; font-size: 13px; }
  .tab .icon { width: 15px; height: 15px; }
  .layout { display: block; padding: 14px 14px max(14px, env(safe-area-inset-bottom)); }
  .sidebar { margin-bottom: 15px; }
  .sidebar:has(.side-panel[hidden] + .side-panel[hidden]) { display: none; }
  .side-panel { padding: 0; border: 0; border-radius: 0; background: transparent; }
  .side-heading, .side-subheading, #chapter-buttons, .saved-list, .side-footnote { display: none; }
  .sources { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; }
  .sources .list-button { justify-content: center; gap: 5px; flex: 1 0 auto; width: auto; min-height: 35px; padding: 5px 7px; text-align: center; background: white; border-color: var(--border); }
  .sources .list-button[aria-pressed="true"] { background: var(--tint); border-color: #dcd4ff; }
  .sources .name { flex: none; }
  .sources .deck-dot { width: 5px; height: 5px; }
  .chapters { margin-top: 7px; padding: 0; border: 0; }
  #chapter-select, #saved-select { display: block; width: 100%; min-height: 38px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 9px; background: white; color: var(--body); font-size: 16px; }
  .section-heading { margin-bottom: 9px; }
  .eyebrow { margin-bottom: 4px; font-size: 10px; }
  h1 { font-size: 27px; }
  .counter { font-size: 12px; }
  .counter b { font-size: 18px; }
  .progress { margin-bottom: 10px; }
  .carousel, .placeholder { height: clamp(250px, calc(100dvh - 264px), 660px); }
  .layout:has(.chapters:not([hidden])) .carousel { height: clamp(240px, calc(100dvh - 309px), 660px); }
  .carousel, .card, .placeholder { --radius: 19px; }
  .card-meta { padding: 10px 12px 8px 15px; gap: 6px; }
  .card-scroll { padding: 5px 16px 22px; }
  .card-scroll h2 { font-size: 24px; }
  .card-scroll h2.long { font-size: 18px; }
  .branch-list { margin-top: 14px; gap: 7px; }
  .branch { padding: 8px 9px; }
  .branch > .node-text, .node-list li { font-size: 14px; }
  .controls { margin-top: 10px; }
  .nav-button { padding: 0 11px; gap: 5px; }
  .keyboard-hint { display: none; }
  .gesture-hint { font-size: 11px; }
}
@media (pointer: coarse) { .keyboard-hint { display: none; } }
