@layer reset, tokens, base, layout, components, utilities, print;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, figure, ol, ul, dl, dd { margin: 0; }
  button, input { font: inherit; }
  svg { display: block; max-width: 100%; height: auto; }
  [hidden] { display: none !important; }
}

@layer tokens {
  :root {
    --paper: #f6f1e6;
    --paper-bright: #fffaf0;
    --ink: #352830;
    --plum: #583344;
    --green: #294b3e;
    --ochre: #e7c880;
    --blush: #eadbd3;
    --muted: #685751;
    --rule: #b7a695;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    --measure: 65ch;
  }
}

@layer base {
  html { color-scheme: light; scroll-padding-top: 1rem; }
  body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 18px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
  }
  a { color: var(--green); min-width: 44px; text-underline-offset: .25em; text-decoration-thickness: 1px; }
  a:hover { text-decoration-thickness: 2px; }
  a:focus-visible, button:focus-visible {
    outline: 3px solid var(--plum);
    outline-offset: 4px;
  }
  button { cursor: pointer; }
  h1, h2, h3 { color: var(--plum); text-wrap: pretty; }
  h1 {
    font-size: clamp(2.4rem, 4.5vw, 4rem);
    line-height: 1.08;
    font-weight: 650;
    letter-spacing: -.045em;
    max-width: 21ch;
  }
  h2 { font-size: clamp(1.5rem, 2.4vw, 2rem); line-height: 1.2; letter-spacing: -.025em; font-weight: 650; }
  h3 { font-size: 1.35rem; line-height: 1.35; font-weight: 600; letter-spacing: -.02em; }
  p, li, dd { overflow-wrap: break-word; }
  p + p { margin-top: 1rem; }
  strong { font-weight: 650; }
  ::selection { background: var(--ochre); color: var(--ink); }
}

@layer layout {
  .site-header { border-top: 6px solid var(--green); border-bottom: 1px solid var(--rule); }
  .split-header {
    width: min(1280px, calc(100% - 80px));
    margin-inline: auto;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1.5rem;
    padding-block: 1.1rem;
  }
  .header-links { display: flex; gap: 1.35rem; align-items: center; }
  .header-right { justify-content: flex-end; }
  .header-links a { display: inline-flex; min-height: 48px; align-items: center; padding: .35rem .2rem; font-size: 16px; text-decoration: none; }
  .header-links a:hover { text-decoration: underline; }
  .notebook-mark { display: flex; flex-direction: column; align-items: center; color: var(--green); text-decoration: none; padding: .3rem .6rem; min-height: 64px; }
  .mark-word { font-size: 26px; line-height: 1.2; font-weight: 700; letter-spacing: -.04em; }
  .mark-sub { font-size: 16px; }
  .main-wrap { width: min(1184px, calc(100% - 96px)); margin-inline: auto; padding-block: 1.1rem 4rem; }
  .home { padding-top: 3.5rem; }
  .notebook-layout { display: grid; grid-template-columns: minmax(0, 768px) minmax(200px, 1fr); gap: clamp(3rem, 7vw, 7rem); }
  article { min-width: 0; }
  .chapter-intro { margin-bottom: 2.5rem; padding-top: 1.6rem; }
  .chapter-intro h1 { margin-block: 1rem 1.3rem; }
  .lead { font-size: 20px; line-height: 1.6; max-width: var(--measure); }
  .home .chapter-intro { margin-bottom: 2.75rem; padding-top: 0; }
  .home h1 { max-width: none; }
  .home-title { display: block; font-size: clamp(3rem, 6.5vw, 6rem); line-height: 1.05; }
  .home-invitation { display: block; margin-top: .4rem; font-size: clamp(2.15rem, 4.1vw, 3.8rem); font-weight: 450; line-height: 1.1; letter-spacing: -.04em; }
  .home .lead { max-width: 68ch; }
  .home-opening { display: grid; grid-template-columns: 1fr 1fr; gap: 5rem; align-items: start; margin-bottom: 4rem; }
  .opening-copy { padding-top: .5rem; }
  .opening-copy > p { max-width: 48ch; }
  .opening-copy .button { margin-top: 1.5rem; }
  .home .note-section { max-width: 768px; }
  .note-section { margin-top: 2.5rem; }
  .note-section > h2 { margin-bottom: 1rem; }
  .note-section > p { max-width: var(--measure); }
  .note-section + .note-section { padding-top: 2rem; border-top: 1px solid var(--rule); }
  .margin-notes { align-self: start; margin-top: 2rem; border-top: 5px solid var(--green); padding-top: 1.3rem; }
  .margin-notes ul { padding: 0; list-style: none; margin-block: 1rem; }
  .margin-notes li { border-top: 1px solid var(--rule); }
  .margin-notes li:last-child { border-bottom: 1px solid var(--rule); }
  .margin-notes a { display: flex; align-items: center; justify-content: space-between; gap: .65rem; min-height: 56px; padding: .8rem .1rem; font-size: 16px; text-decoration: none; line-height: 1.5; }
  .margin-notes a:hover { text-decoration: underline; }
  .margin-notes > p:last-child { font-size: 16px; color: var(--muted); }
  .site-footer { background: var(--green); color: var(--paper-bright); padding: 2.5rem 0 2rem; }
  .site-footer > div { width: min(1184px, calc(100% - 96px)); margin-inline: auto; }
  .footer-sentence { font-size: 18px; max-width: 70ch; }
  .site-footer nav { display: flex; flex-wrap: wrap; gap: .35rem 2rem; margin-top: 1.25rem; }
  .site-footer a { color: var(--paper-bright); display: inline-flex; min-height: 48px; align-items: center; padding: .45rem .1rem; font-size: 16px; }
  @media (max-width: 900px) {
    .split-header { width: calc(100% - 40px); gap: 1rem; }
    .header-links { gap: .8rem; }
    .main-wrap { width: calc(100% - 48px); }
    .notebook-layout { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
    .margin-notes { max-width: 768px; }
    .home-opening { gap: 2rem; }
    .site-footer > div { width: calc(100% - 48px); }
  }
  @media (max-width: 650px) {
    body { font-size: 18px; }
    .split-header { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "mark mark" "left right"; gap: .3rem .5rem; padding-block: .8rem .4rem; }
    .notebook-mark { grid-area: mark; }
    .header-left { grid-area: left; }
    .header-right { grid-area: right; }
    .header-links { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .15rem; }
    .header-links a { justify-content: center; text-align: center; line-height: 1.25; padding: .45rem .1rem; min-height: 48px; overflow-wrap: normal; }
    .header-right a span { display: none; }
    .main-wrap { padding-bottom: 2.5rem; }
    .home { padding-top: 2rem; }
    .chapter-intro { padding-top: 1rem; margin-bottom: 2rem; }
    .chapter-intro h1 { margin-top: .9rem; }
    .home-title { font-size: 3rem; max-width: 12ch; }
    .home-invitation { font-size: 2.3rem; margin-top: .65rem; }
    .lead { font-size: 19px; }
    .home-opening { grid-template-columns: minmax(0, 1fr); gap: 2rem; margin-bottom: 2.5rem; }
    .home .chapter-intro { margin-bottom: 1.5rem; }
    .site-footer { padding-block: 2rem; }
    .site-footer nav { display: grid; grid-template-columns: minmax(0, 1fr); gap: .25rem; }
  }
}

@layer components {
  .eyebrow { font-size: 16px; line-height: 1.45; font-weight: 600; color: var(--green); }
  .button { display: inline-flex; align-items: center; justify-content: space-between; gap: 1.25rem; border: 1px solid var(--plum); min-height: 56px; padding: .85rem 1.25rem; border-radius: 3px; font-size: 18px; line-height: 1.4; text-decoration: none; max-width: 100%; }
  .button-dark { color: var(--paper-bright); background: var(--plum); }
  .button-dark:hover { background: var(--ink); color: var(--paper-bright); text-decoration: none; }
  .text-route { display: flex; gap: .75rem; align-items: center; width: fit-content; min-height: 48px; font-size: 16px; margin-top: .5rem; }
  .question-map { background: var(--ochre); border: 1px solid var(--ink); border-radius: 60px 4px 4px 4px; padding: 1.7rem 2rem 1.5rem; box-shadow: 7px 7px 0 var(--blush); }
  .question-map figcaption { font-size: 16px; line-height: 1.4; padding-left: .5rem; margin-bottom: 1.5rem; }
  .question-map ol { list-style: none; padding: 0; }
  .question-map li { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .6rem 1.2rem; border: 1px solid var(--plum); border-radius: 50%; min-height: 62px; position: relative; }
  .question-map li + li { margin-top: 1.25rem; }
  .question-map li + li::before { content: ""; position: absolute; left: 50%; height: 1.25rem; top: -1.25rem; border-left: 1px solid var(--plum); }
  .map-label { font-size: 16px; }
  .question-map strong { font-size: 19px; }
  .question-map > p { font-size: 16px; line-height: 1.55; margin-top: 1.5rem; padding-left: .5rem; }
  .claim-pair { margin-block: 1.25rem; padding: .3rem 0 .3rem 1.35rem; border-left: 3px solid var(--green); }
  .claim-pair > p { max-width: var(--measure); }
  .claim-pair .source-link { margin-top: .65rem; font-size: 16px; line-height: 1.5; }
  .source-link > span { display: block; color: var(--muted); }
  .source-link a { display: inline-flex; align-items: center; min-height: 44px; gap: .35rem; padding-block: .4rem; font-size: 16px; }
  .conversation { background: var(--blush); padding: 1.5rem 1.75rem 1.6rem; border-radius: 4px 35px 4px 4px; margin-top: 1.75rem; }
  .conversation .eyebrow { color: var(--plum); }
  .conversation h3 { margin-block: .5rem .8rem; }
  .conversation > p:last-child { font-size: 18px; margin-top: 0; }
  .page-recap { border-block: 1px solid var(--plum); margin-top: 3rem; padding-block: 1.25rem; }
  .page-recap .eyebrow { color: var(--plum); }
  .page-recap p + p { margin-top: .45rem; font-size: 20px; max-width: var(--measure); line-height: 1.5; }
  .breadcrumbs { margin-bottom: .65rem; }
  .breadcrumbs ol { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem .65rem; list-style: none; padding: 0; }
  .breadcrumbs li { font-size: 16px; }
  .breadcrumbs li + li::before { content: "/"; color: var(--muted); margin-right: .65rem; }
  .breadcrumbs a { display: inline-flex; min-height: 44px; align-items: center; padding-block: .45rem; }
  .breadcrumbs span { color: var(--muted); }
  .chain-diagram { border: 1px solid var(--rule); background: var(--paper-bright); padding: .75rem 1rem 1.25rem; margin-block: 1.5rem; }
  .chain-diagram svg { width: 100%; }
  .chain-link { fill: none; stroke: var(--plum); stroke-width: 3px; }
  .chain-block { fill: var(--ochre); stroke: var(--green); stroke-width: 2px; }
  .chain-diagram figcaption { font-size: 16px; color: var(--muted); text-align: center; }
  .note-list { padding-left: 1.3rem; margin-top: 1.25rem; }
  .note-list li { padding-left: .25rem; margin-block: .6rem; font-size: 18px; }
  .note-list li::marker { color: var(--green); }
  .home-routes { margin-top: 3.25rem; }
  .route-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; margin-top: 1.5rem; }
  .route-grid a { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; min-height: 210px; color: var(--ink); padding: 1.5rem; border: 1px solid var(--plum); text-decoration: none; }
  .route-grid a:first-child { background: var(--ochre); border-radius: 30px 3px 3px 3px; }
  .route-grid a:nth-child(2) { background: var(--blush); border-radius: 3px 30px 3px 3px; }
  .route-grid a:nth-child(3) { background: var(--paper-bright); border-radius: 3px 3px 30px 3px; }
  .route-grid a > span:first-child { font-size: 16px; line-height: 1.5; }
  .route-grid strong { font-size: 24px; line-height: 1.25; letter-spacing: -.025em; margin-block: 1rem; }
  .route-grid a > span:last-child { margin-top: auto; font-size: 24px; color: var(--green); }
  .route-grid a:hover strong { text-decoration: underline; text-underline-offset: .2em; }
  .contents-groups { margin-top: 2rem; }
  .contents-groups section { margin-top: 2rem; }
  .contents-groups h2 { margin-bottom: 1rem; }
  .contents-groups ul { list-style: none; padding: 0; border-top: 1px solid var(--rule); }
  .contents-groups li { border-bottom: 1px solid var(--rule); }
  .contents-groups a { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 64px; padding: .8rem .2rem; font-size: 18px; text-decoration: none; }
  .contents-groups a:hover > span:first-child { text-decoration: underline; }
  .quote-lines { margin-top: 1.5rem; border-top: 1px solid var(--rule); }
  .quote-lines > div { display: grid; grid-template-columns: minmax(140px, .7fr) minmax(0, 1.3fr); gap: 1rem; border-bottom: 1px solid var(--rule); padding-block: 1rem; }
  .quote-lines dt { font-size: 18px; color: var(--plum); font-weight: 600; }
  .quote-lines dd { font-size: 18px; }
  .page-turn { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.5rem; margin-top: 3rem; max-width: 768px; }
  .page-turn a { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .6rem; align-items: center; min-height: 100px; border: 1px solid var(--green); padding: 1rem 1.1rem; text-decoration: none; }
  .page-turn a > span:first-child { grid-column: 1; font-size: 16px; line-height: 1.4; }
  .page-turn a strong { grid-column: 1; font-size: 18px; line-height: 1.4; margin-top: .3rem; }
  .page-turn a > span:last-child { grid-column: 2; grid-row: 1 / 3; font-size: 24px; }
  .page-turn a:hover strong { text-decoration: underline; }
  .print-tools { padding-bottom: 1rem; }
  .print-tools p { font-size: 16px; margin-top: .65rem; }
  .question-sheet > section { margin-top: 2rem; }
  .write-list { list-style: none; padding: 0; margin-top: 1.3rem; }
  .write-list li { position: relative; padding: 1rem 0 1rem 2rem; border-top: 1px solid var(--rule); }
  .write-list li::before { content: ""; position: absolute; left: 0; top: 1.35rem; height: 15px; width: 15px; border: 1px solid var(--green); }
  .write-list p { font-size: 18px; }
  .answer-line { display: block; margin-top: 1.25rem; height: 1rem; border-bottom: 1px dotted var(--rule); }
  @media (max-width: 650px) {
    .question-map { padding: 1.5rem 1.3rem 1.25rem; border-top-left-radius: 45px; box-shadow: 5px 5px 0 var(--blush); }
    .question-map li { padding-inline: 1rem; }
    .question-map strong { font-size: 18px; }
    .route-grid { grid-template-columns: minmax(0, 1fr); }
    .route-grid a { min-height: 175px; }
    .conversation { padding: 1.3rem; }
    .claim-pair { padding-left: 1rem; }
    .source-link a { display: flex; }
    .page-turn { gap: .75rem; }
    .page-turn a { padding: .9rem; }
    .quote-lines > div { grid-template-columns: minmax(0, 1fr); gap: .3rem; }
    .page-recap p + p { font-size: 19px; }
  }
}

@layer utilities {
  .skip-link { position: fixed; left: 1rem; top: 1rem; z-index: 10; transform: translateY(-180%); display: flex; align-items: center; min-height: 48px; padding: .6rem 1rem; background: var(--paper-bright); border: 2px solid var(--green); font-size: 18px; }
  .skip-link:focus { transform: translateY(0); }
  @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
}

@layer print {
  @media print {
    @page { size: A4; margin: 16mm; }
    body { background: white; color: #222; font-size: 12pt; line-height: 1.5; }
    h1, h2, h3, .eyebrow { color: #222; }
    .site-header, .site-footer, .skip-link, .breadcrumbs, .margin-notes, .page-turn, .print-tools { display: none; }
    .main-wrap { width: 100%; margin: 0; padding: 0; }
    .notebook-layout { display: block; }
    .chapter-intro { padding: 0; margin-bottom: 1.5rem; }
    h1 { font-size: 30pt; max-width: none; }
    .lead { font-size: 12pt; }
    .checklist-page .note-section, .checklist-page .page-recap { display: none; }
    .question-sheet section + section { break-before: page; }
    .question-sheet section { margin-top: 0; }
    .question-sheet h2 { font-size: 18pt; }
    .write-list { margin-top: 1rem; }
    .write-list li { padding: .65rem 0 .65rem 1.5rem; break-inside: avoid; }
    .write-list li::before { top: 1rem; width: 12px; height: 12px; border-color: #222; }
    .write-list p { font-size: 12pt; }
    .answer-line { height: 1.5rem; margin-top: .5rem; border-color: #666; }
    .conversation, .claim-pair, .chain-diagram, .page-recap { break-inside: avoid; }
    .source-link a { color: #222; }
    .question-map, .conversation, .route-grid a { background: white; box-shadow: none; }
  }
}
