:root {
  --accent: #0088cc;
  --accent-soft: #40a7e3;
  --accent-pressed: #0071b0;
  --outgoing: #2b86fd;
  --outgoing-light: #61b3ff;
  --online: #4dd364;
  --error: #e53935;
  --canvas: #ffffff;
  --paper: #ffffff;
  --wallpaper: #dbe7f4;
  --grouped: #efeff4;
  --section-tint: #f7f7f7;
  --ink: #212121;
  --secondary: #5d646a;
  --timestamp: #707579;
  --line: #dce2e8;
  --incoming-line: #e5e5e5;
  --link: var(--accent-pressed);
  --action: color-mix(in srgb, var(--accent) 82%, #000000);
  --action-ink: #ffffff;
  --note-ink: #123951;
  --note-fill: #e8f4fc;
  --glass: rgb(255 255 255 / 92%);
  --floating-shadow: 0 12px 32px rgb(20 50 70 / 14%);
  --body-font: "Segoe UI", Candara, -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, Helvetica, Arial, sans-serif;
  --mono-font: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --text-size: 18px;
  --small-size: 16px;
  --body-leading: 1.66;
  --measure: 66ch;
  --space-unit: 4px;
  --screen-margin: 24px;
  --space-small: 12px;
  --space-medium: 24px;
  --space-large: 48px;
  --space-section: 64px;
  --radius-small: 6px;
  --radius-button: 10px;
  --radius-note: 17px;
  --radius-sheet: 20px;
  --radius-pill: 24px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(#color-light:checked, #color-dark:checked, #color-oled:checked)) {
    --canvas: #212121;
    --paper: #292c2f;
    --wallpaper: #243442;
    --grouped: #303339;
    --section-tint: #282b2e;
    --ink: #f3f5f7;
    --secondary: #b8c2ca;
    --timestamp: #b1bcc5;
    --line: #454d53;
    --incoming-line: #414a52;
    --link: #72c6f5;
    --action: #8dd5ff;
    --action-ink: #102935;
    --note-ink: #dbf0ff;
    --note-fill: #193b52;
    --glass: rgb(33 33 33 / 94%);
    --floating-shadow: 0 12px 32px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}

:root:has(#color-dark:checked, #color-oled:checked) {
  --canvas: #212121;
  --paper: #292c2f;
  --wallpaper: #243442;
  --grouped: #303339;
  --section-tint: #282b2e;
  --ink: #f3f5f7;
  --secondary: #b8c2ca;
  --timestamp: #b1bcc5;
  --line: #454d53;
  --incoming-line: #414a52;
  --link: #72c6f5;
  --action: #8dd5ff;
  --action-ink: #102935;
  --note-ink: #dbf0ff;
  --note-fill: #193b52;
  --glass: rgb(33 33 33 / 94%);
  --floating-shadow: 0 12px 32px rgb(0 0 0 / 35%);
  color-scheme: dark;
}

:root:has(#color-oled:checked) {
  --canvas: #000000;
  --paper: #111315;
  --grouped: #171a1e;
  --section-tint: #0b0e11;
  --wallpaper: #101e29;
  --line: #363f46;
  --incoming-line: #343d43;
  --glass: rgb(0 0 0 / 94%);
}

* { box-sizing: border-box; }
html { scroll-padding-top: 32px; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--body-font);
  font-size: var(--text-size);
  line-height: var(--body-leading);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { color: #102935; background: var(--accent-soft); }
[hidden] { display: none !important; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 4px; }
a:hover { text-decoration-thickness: 2px; }
a:active { color: var(--accent-pressed); }
a:focus-visible, summary:focus-visible, input:focus-visible {
  outline: 3px solid var(--link);
  outline-offset: 5px;
  border-radius: var(--radius-small);
}
button, input, summary { font: inherit; }
input { accent-color: var(--accent); }
svg { display: block; flex: 0 0 auto; }
.outline-icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
p { margin: 0 0 20px; }
ul { margin: 0 0 24px; padding: 0; }
li { margin-bottom: 12px; }
h1, h2, h3 { margin: 0; font-weight: 650; line-height: 1.18; }
h1 { font-size: clamp(36px, 3.2vw, 46px); font-weight: 700; letter-spacing: -.035em; }
h2 { font-size: 27px; letter-spacing: -.02em; margin-bottom: 24px; }
h3 { font-size: 19px; letter-spacing: -.01em; }
code { font-family: var(--mono-font); }
.skip-link {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 100;
  padding: 12px 20px;
  min-height: 48px;
  color: var(--action-ink);
  background: var(--action);
  border-radius: var(--radius-button);
  transform: translateY(-180%);
}
.skip-link:focus { transform: translateY(0); }
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 90;
  width: 100%;
  height: 4px;
  border: 0;
  appearance: none;
  background: transparent;
  color: var(--accent);
}
.reading-progress::-webkit-progress-bar { background: transparent; }
.reading-progress::-webkit-progress-value { background: var(--accent); }
.reading-progress::-moz-progress-bar { background: var(--accent); }
.site-header { border-bottom: 1px solid var(--line); background: var(--canvas); }
.header-inner {
  width: min(100%, 1360px);
  margin: 0 auto;
  min-height: 100px;
  padding: 20px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.notebook-name {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  line-height: 1.3;
  font-weight: 650;
}
.notebook-name > .outline-icon {
  color: var(--link);
  width: 40px;
  height: 40px;
  padding: 4px;
  background: var(--note-fill);
  border-radius: var(--radius-small);
}
.name-detail { display: block; color: var(--secondary); font-size: 16px; font-weight: 400; }
.guide-label { margin: 0; color: var(--secondary); font-size: var(--small-size); }
.appearance-picker { position: relative; font-size: var(--small-size); }
.appearance-picker > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px 12px;
  list-style: none;
  cursor: pointer;
  color: var(--link);
  border-radius: var(--radius-button);
}
.appearance-picker > summary::-webkit-details-marker { display: none; }
.appearance-picker > summary:hover { background: var(--section-tint); }
.appearance-sheet {
  position: absolute;
  z-index: 80;
  right: 0;
  top: 60px;
  width: 312px;
  margin: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sheet);
  background: var(--glass);
  backdrop-filter: blur(16px);
  box-shadow: var(--floating-shadow);
}
.appearance-sheet legend { float: left; width: 100%; padding: 0; margin-bottom: 12px; font-weight: 600; }
.appearance-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; clear: both; }
.appearance-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding: 8px;
  background: var(--section-tint);
  border: 1px solid var(--line);
  border-radius: var(--radius-button);
  cursor: pointer;
}
.appearance-options label:has(input:checked) { background: var(--note-fill); border-color: var(--link); }
.appearance-options input { width: 44px; height: 44px; margin: 0; flex: 0 0 auto; }
.notebook-layout {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr);
  gap: 48px;
  max-width: 1360px;
  padding: 0 40px;
  margin: 0 auto;
}
.compact-rail { padding-top: 52px; }
.compact-rail nav { position: sticky; top: 32px; }
.rail-label, .rail-caption { font-size: var(--small-size); color: var(--secondary); }
.rail-label { margin-bottom: 12px; padding: 0 12px; }
.compact-rail a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin: 4px 0;
  padding: 8px 12px;
  border-radius: var(--radius-button);
  font-size: var(--small-size);
  color: var(--secondary);
  text-decoration: none;
  line-height: 1.45;
}
.compact-rail a:hover, .compact-rail a:focus-visible { color: var(--link); background: var(--note-fill); }
.rail-dash { width: 12px; height: 2px; flex: 0 0 auto; background: var(--line); }
.compact-rail a:hover .rail-dash { background: var(--link); }
.rail-home { color: var(--link) !important; margin-bottom: 20px !important; border-bottom: 1px solid var(--line); }
.rail-home .outline-icon { width: 20px; height: 20px; }
.rail-caption { margin: 40px 12px 0; line-height: 1.6; }
.notebook-content { min-width: 0; }
main:focus { outline: 0; }
.opening-spread {
  padding: 52px 0 56px;
  display: grid;
  grid-template-columns: minmax(0, 1.38fr) minmax(0, 1fr);
  gap: 40px;
  align-items: center;
}
.eyebrow { color: var(--link); font-size: var(--small-size); font-weight: 600; margin-bottom: 20px; }
.title-deck { display: block; margin-top: 16px; color: var(--link); font-weight: 500; }
.opening-copy > p:not(.eyebrow), .page-opening > p:not(.eyebrow) {
  margin-top: 24px;
  font-size: 20px;
  line-height: 1.6;
  max-width: 54ch;
  color: var(--secondary);
}
.opening-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 28px; }
.primary-link, .quiet-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  gap: 16px;
  padding: 12px 20px;
  border-radius: var(--radius-button);
  font-size: var(--small-size);
  line-height: 1.5;
  text-decoration: none;
  font-weight: 600;
}
.primary-link { background: var(--action); color: var(--action-ink); }
.primary-link:hover { background: var(--accent-pressed); color: #fff; }
.primary-link:active { background: var(--accent-pressed); }
.quiet-link { border: 1px solid var(--line); background: var(--paper); color: var(--link); }
.quiet-link:hover { background: var(--note-fill); }
.editorial-photo { margin: 0; }
.editorial-frame { overflow: hidden; border-radius: var(--radius-note); background: var(--wallpaper); }
.editorial-frame img { display: block; width: 100%; height: 100%; object-fit: cover; color: transparent; font-size: 0; }
.hero-photo .editorial-frame { aspect-ratio: 4 / 3; }
.editorial-photo figcaption { margin-top: 12px; color: var(--secondary); font-size: var(--small-size); line-height: 1.5; }
.article-photo { max-width: 832px; margin: 0 0 48px; }
.article-photo .editorial-frame { aspect-ratio: 2.8 / 1; }
.page-opening { padding: 52px 0 36px; max-width: 840px; }
.page-opening h1 { max-width: 22ch; }
.reading-pages { border-top: 1px solid var(--line); }
.note-chapter { border-bottom: 1px solid var(--line); }
.note-chapter > h2 { max-width: var(--measure); padding-top: 40px; margin-bottom: 0; }
.note-chapter > .notebook-section:first-of-type { padding-top: 28px; }
.note-chapter > .notebook-section:last-child { border-bottom: 0; }
.section-reading h3 { font-size: 22px; line-height: 1.3; margin: 32px 0 20px; }
.section-reading > h3:first-child { margin-top: 0; }
.notebook-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 188px;
  gap: 40px;
  padding: 48px 0;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 28px;
}
.section-reading { max-width: var(--measure); min-width: 0; }
.section-reading > :last-child { margin-bottom: 0; }
.section-reading p { overflow-wrap: break-word; }
.margin-definition { border-left: 3px solid var(--accent); align-self: start; margin-top: 4px; padding-left: 16px; }
.margin-label { font-size: var(--small-size); color: var(--secondary); margin-bottom: 12px; }
.margin-definition dl { margin: 0; font-size: var(--small-size); line-height: 1.6; }
.margin-definition dt { font-weight: 650; color: var(--ink); margin: 0 0 8px; }
.margin-definition dd { margin: 0 0 16px; color: var(--secondary); }
.margin-definition dd:last-child { margin-bottom: 0; }
.question-list { list-style: none; }
.question-list li { position: relative; padding-left: 28px; }
.question-list li::before { content: ""; width: 8px; height: 8px; position: absolute; left: 2px; top: .65em; border: 1px solid var(--link); border-radius: 50%; }
.question-note {
  max-width: 80%;
  margin: 28px 0 0;
  padding: 20px 24px;
  background: var(--note-fill);
  color: var(--note-ink);
  border: 1px solid var(--incoming-line);
  border-radius: var(--radius-note) var(--radius-note) var(--radius-note) var(--radius-small);
}
.question-note .note-label { margin: 0 0 8px; color: var(--link); font-size: var(--small-size); font-weight: 600; }
.question-note p:last-child { margin: 0; }
.source-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  max-width: 100%;
  margin: 4px 0 0;
  padding: 6px 8px 6px 0;
  font-size: var(--small-size);
  line-height: 1.5;
  text-decoration: underline;
}
.source-link .outline-icon { width: 17px; height: 17px; }
.note-index { padding: 56px 0; scroll-margin-top: 28px; }
.index-intro { margin-bottom: 32px; }
.index-intro .eyebrow { margin-bottom: 12px; }
.notebook-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.note-group { min-width: 0; }
.note-group h3 { padding: 0 4px; margin-bottom: 16px; }
.note-group ul { background: var(--section-tint); border: 1px solid var(--line); border-radius: var(--radius-note); overflow: hidden; list-style: none; margin: 0; }
.note-group li { margin: 0; }
.note-group li + li { border-top: 1px solid var(--line); }
.note-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 100px; padding: 16px 20px; text-decoration: none; }
.note-row:hover { background: var(--note-fill); }
.note-row > span { min-width: 0; }
.row-title { display: block; color: var(--link); font-size: 18px; font-weight: 600; line-height: 1.4; }
.row-preview { display: block; color: var(--secondary); font-size: var(--small-size); line-height: 1.5; margin-top: 4px; }
.note-row > .outline-icon { width: 20px; height: 20px; }
.page-turn { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; padding: 48px 0; }
.next-note { display: block; padding: 20px 24px; min-height: 100px; background: var(--note-fill); border: 1px solid var(--incoming-line); border-radius: var(--radius-note); text-decoration: none; }
.next-note:hover { border-color: var(--link); }
.next-label { display: block; font-size: var(--small-size); color: var(--secondary); margin-bottom: 8px; }
.next-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-weight: 600; font-size: 20px; line-height: 1.4; }
.related-notes { padding: 4px 0; }
.related-notes p { color: var(--secondary); margin: 0 0 4px; font-size: var(--small-size); }
.related-notes a { min-height: 44px; display: flex; align-items: center; gap: 12px; padding: 6px 0; font-size: var(--small-size); line-height: 1.5; }
.related-notes .outline-icon { width: 18px; height: 18px; }
.site-footer { padding: 28px 0 40px; border-top: 1px solid var(--line); font-size: var(--small-size); line-height: 1.6; color: var(--secondary); }
.site-footer p { max-width: 70ch; margin-bottom: 16px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.site-footer a { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 0; }
.missing-note { max-width: 920px; margin: 0 auto; padding: 64px var(--screen-margin) 0; }
.missing-note main { margin-bottom: 64px; }
.missing-note main > p:not(.eyebrow) { max-width: 60ch; margin-top: 24px; }

@media (min-width: 1100px) {
  .source-link { display: flex; width: fit-content; }
}

@media (max-width: 1100px) {
  .header-inner { padding-inline: 24px; }
  .notebook-layout { grid-template-columns: 152px minmax(0, 1fr); gap: 24px; padding-inline: 24px; }
  .notebook-section { grid-template-columns: minmax(0, 1fr) 164px; gap: 24px; }
  .opening-spread { grid-template-columns: 1fr; gap: 28px; }
  .hero-photo { max-width: 480px; }
  .hero-photo .editorial-frame { aspect-ratio: 2 / 1; }
  .opening-copy { max-width: 660px; }
  .notebook-groups { grid-template-columns: 1fr; }
  .source-link { display: flex; width: fit-content; }
}

@media (max-width: 780px) {
  :root { --screen-margin: 16px; --space-section: 48px; }
  .header-inner { min-height: 88px; padding: 16px; gap: 8px; }
  .guide-label { display: none; }
  .notebook-name { font-size: 17px; gap: 8px; }
  .name-detail { font-size: 16px; }
  .appearance-picker summary { padding-inline: 8px; }
  .appearance-picker .outline-icon { width: 20px; height: 20px; }
  .appearance-sheet { right: 0; width: min(312px, calc(100vw - 32px)); }
  .notebook-layout { display: block; padding-inline: 16px; }
  .compact-rail { padding: 16px 0 0; }
  .compact-rail nav { position: static; display: flex; flex-wrap: wrap; gap: 4px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
  .rail-label { display: block; width: 100%; padding: 0; margin: 0 0 4px; }
  .compact-rail a { margin: 0; min-height: 44px; padding: 8px 12px; background: var(--section-tint); }
  .rail-home { margin: 0 !important; border-bottom: 0; }
  .rail-dash { display: none; }
  .rail-caption { display: none; }
  .opening-spread { padding: 32px 0 36px; gap: 28px; }
  .eyebrow { margin-bottom: 16px; }
  h1 { font-size: 36px; line-height: 1.16; }
  .title-deck { margin-top: 12px; }
  h2 { font-size: 25px; margin-bottom: 20px; }
  .opening-copy > p:not(.eyebrow), .page-opening > p:not(.eyebrow) { font-size: 19px; margin-top: 20px; }
  .opening-actions { gap: 12px; margin-top: 24px; }
  .primary-link, .quiet-link { padding-inline: 16px; }
  .hero-photo { max-width: none; }
  .hero-photo .editorial-frame { aspect-ratio: 2 / 1; }
  .page-opening { padding: 32px 0; }
  .notebook-section { grid-template-columns: minmax(0, 1fr); gap: 24px; padding: 36px 0; }
  .note-chapter > h2 { padding-top: 28px; }
  .note-chapter > .notebook-section:first-of-type { padding-top: 24px; }
  .margin-definition { margin: 0; max-width: 52ch; background: var(--section-tint); padding: 16px; border-radius: 0 var(--radius-button) var(--radius-button) 0; }
  .margin-label { margin-bottom: 8px; }
  .margin-definition dt { margin-bottom: 4px; }
  .question-note { max-width: 100%; padding: 20px; }
  .article-photo { margin-bottom: 32px; }
  .article-photo .editorial-frame { aspect-ratio: 2 / 1; }
  .note-index { padding: 36px 0; }
  .notebook-groups { gap: 24px; }
  .note-row { min-height: 92px; padding: 16px; }
  .page-turn { grid-template-columns: 1fr; gap: 24px; padding: 36px 0; }
  .site-footer { padding: 24px 0 32px; }
  .site-footer nav { align-items: flex-start; flex-direction: column; gap: 0; }
  .site-footer a { padding-block: 10px; }
  .missing-note { padding-top: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  :root { --canvas: #fff; --paper: #fff; --ink: #111; --secondary: #444; --link: #111; --line: #ddd; --note-fill: #f5f5f5; --note-ink: #111; }
  body { font-size: 16px; }
  .appearance-picker, .compact-rail, .reading-progress, .skip-link, .editorial-photo, .page-turn, .site-footer nav { display: none !important; }
  .header-inner { min-height: 0; padding: 12px 0; }
  .guide-label { display: block; }
  .notebook-layout { display: block; padding: 0; }
  .page-opening, .opening-spread { padding: 28px 0; }
  .notebook-section { padding: 24px 0; grid-template-columns: minmax(0, 1fr) 180px; gap: 24px; break-inside: avoid; }
  .margin-definition { background: #fff; }
  .source-link { min-height: 0; margin: 0; padding: 0; }
  .site-footer { padding: 20px 0; }
  h1 { font-size: 34px; }
  h2 { font-size: 23px; }
  a { text-decoration: none; }
}
