@layer reset, paper, layout, workbook, interaction, small-screen, print;

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

@layer paper {
  :root {
    color-scheme: light;
    --paper: #fbf8f1;
    --ink: #40364b;
    --muted: #62576b;
    --purple: #68458c;
    --lavender: #eee5f7;
    --line: #d5c8df;
    --green: #e4ecdf;
    --yellow: #f4e5a6;
  }
  html { scroll-padding-top: 24px; }
  body {
    background: var(--paper);
    color: var(--ink);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 18px;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
  }
  h1, h2, h3 { font-weight: 400; text-wrap: balance; }
  h1 { font-size: clamp(2.65rem, 4.6vw, 4.6rem); line-height: 1.08; letter-spacing: -0.035em; }
  h2 { font-size: clamp(1.95rem, 3vw, 2.85rem); line-height: 1.15; letter-spacing: -0.025em; }
  h3 { font-size: 1.5rem; line-height: 1.25; }
  p, li, dd { text-wrap: pretty; }
  a { color: var(--purple); text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
  a:hover { text-decoration-thickness: 2px; }
  a, button, summary, input { -webkit-tap-highlight-color: #dfc7f2; }
  :focus-visible { outline: 3px solid #73529b; outline-offset: 5px; }
  ::selection { background: var(--yellow); color: var(--ink); }
}

@layer layout {
  .page-width { width: min(1184px, calc(100% - 80px)); margin-inline: auto; }
  .masthead { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding-block: 30px 22px; }
  .masthead-name { font-size: 1.5rem; line-height: 1.25; }
  .masthead-note { color: var(--muted); font-style: italic; }
  .breadcrumb { margin-bottom: 24px; font-size: 1rem; }
  .breadcrumb-items { display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; padding: 0; list-style: none; }
  .breadcrumb-link { display: inline-flex; align-items: center; min-height: 44px; }
  .breadcrumb-current { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted); }
  .hero { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 60px; align-items: center; padding-block: 22px 70px; }
  .hero-copy { padding-block: 12px; }
  .opener-label { display: inline-block; margin-bottom: 24px; padding: 5px 16px; border-radius: 100px; background: var(--lavender); font-size: 1rem; }
  .hero-lead { margin-top: 26px; font-size: 1.22rem; line-height: 1.5; max-width: 34ch; }
  .hero-explanation { max-width: 43ch; margin-top: 16px; color: var(--muted); }
  .hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 22px; margin-top: 30px; }
  .next-link { display: inline-flex; align-items: center; justify-content: center; gap: 12px; min-height: 56px; padding: 12px 24px; border: 2px solid var(--purple); border-radius: 100px; background: var(--purple); color: #fffdf8; text-decoration: none; line-height: 1.35; }
  .next-link:hover { background: #573575; border-color: #573575; text-decoration: none; }
  .quiet-link { display: inline-flex; align-items: center; gap: 12px; min-height: 48px; padding-block: 10px; }
  .hero-figure { position: relative; padding: 16px 16px 26px; background: var(--lavender); border-radius: 160px 160px 40px 40px; }
  .photo-window { overflow: hidden; border-radius: 146px 146px 28px 28px; background: #e5ded0; aspect-ratio: 15 / 17; }
  .editorial-photo { display: block; width: 100%; height: 100%; object-fit: cover; color: var(--muted); font-size: 1rem; }
  .photo-caption { max-width: 27ch; margin: 20px auto 0; text-align: center; font-size: 1rem; line-height: 1.5; }
  .paper-tab { position: absolute; top: 58%; left: -26px; width: 130px; padding: 17px 12px; border-radius: 22px; background: var(--yellow); text-align: center; font-style: italic; transform: rotate(-6deg); line-height: 1.35; }
  .chapter { padding-block: 64px; border-top: 2px solid var(--line); }
  .chapter-grid { display: grid; grid-template-columns: 0.7fr 1.3fr; gap: 72px; }
  .chapter-heading { max-width: 16ch; }
  .chapter-opener { margin-top: 22px; color: var(--muted); max-width: 30ch; }
  .reading-column { min-width: 0; max-width: 69ch; }
  .reading-column > * + * { margin-top: 20px; }
  .chapter-word { display: block; margin-bottom: 16px; color: var(--purple); font-size: 1rem; font-style: italic; }
  .source-note { color: var(--muted); font-size: 1rem; line-height: 1.5; }
  .source-links { display: flex; flex-wrap: wrap; column-gap: 22px; }
  .source-link { display: inline-flex; align-items: center; min-height: 44px; padding-block: 8px; }
  .recap { margin-top: 28px; padding: 20px 24px; border-radius: 8px 26px 26px 26px; background: var(--green); }
  .recap-label { display: block; margin-bottom: 4px; font: inherit; font-style: italic; }
  .page-turn { display: flex; align-items: center; justify-content: space-between; gap: 32px; padding: 36px 40px; margin-block: 22px 64px; border-radius: 32px; background: var(--lavender); }
  .page-turn-copy { max-width: 40ch; }
  .page-turn-copy > p { margin-top: 12px; }
  .site-footer { display: flex; align-items: center; justify-content: space-between; gap: 26px; padding-block: 28px 40px; border-top: 2px solid var(--line); font-size: 1rem; }
  .footer-line { max-width: 65ch; }
  .footer-link { display: inline-flex; align-items: center; min-height: 44px; padding-block: 8px; white-space: nowrap; }
  .skip-link { position: absolute; z-index: 10; inset: 8px auto auto 16px; transform: translateY(-180%); display: inline-flex; align-items: center; min-height: 48px; padding: 10px 20px; border-radius: 20px; background: var(--yellow); color: var(--ink); }
  .skip-link:focus { transform: none; }
  .question-hero { max-width: 820px; padding-block: 24px 44px; }
  .question-lead { max-width: 54ch; margin-top: 24px; font-size: 1.22rem; }
  .workbook-intro { margin-top: 16px; max-width: 62ch; color: var(--muted); }
  .error-page { min-height: 55vh; display: grid; align-content: center; gap: 24px; max-width: 720px; padding-block: 60px; }
}

@layer workbook {
  .name-list { padding: 0; }
  .name-entry { padding-block: 22px; border-bottom: 1px solid var(--line); }
  .name-entry:first-child { padding-top: 0; }
  .medicine-name { font-size: 1.35rem; line-height: 1.35; margin-bottom: 10px; text-wrap: wrap; }
  .care-routes { padding-left: 24px; }
  .care-routes > li + li { margin-top: 18px; }
  .myth { padding-block: 22px; border-bottom: 1px solid var(--line); }
  .myth-question { min-height: 48px; cursor: pointer; font-size: 1.22rem; line-height: 1.45; padding: 8px 8px 8px 0; }
  .myth-answer { padding: 20px 0 4px 24px; }
  .myth-answer > * + * { margin-top: 14px; }
  .reveal-all { border: 2px solid var(--purple); border-radius: 100px; padding: 10px 22px; min-height: 48px; background: transparent; color: var(--purple); cursor: pointer; }
  .reveal-all:hover { background: var(--lavender); }
  .workbook-page { margin-block: 8px 60px; padding: 8px 44px 32px; border: 2px solid var(--line); border-radius: 12px 44px 44px 12px; background: #fffdf8; }
  .workbook-chapter { padding-block: 38px; }
  .workbook-chapter + .workbook-chapter { border-top: 2px solid var(--line); }
  .workbook-heading { display: grid; grid-template-columns: 62px 1fr; gap: 20px; align-items: start; margin-bottom: 24px; }
  .chapter-mark { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%; background: var(--lavender); font-size: 1.6rem; }
  .workbook-heading-copy > p { margin-top: 14px; max-width: 65ch; color: var(--muted); }
  .workbook-body { margin-left: 82px; max-width: 70ch; }
  .workbook-body > * + * { margin-top: 18px; }
  .ask-line { padding: 20px 24px; background: var(--lavender); border-radius: 24px 24px 24px 6px; }
  .ask-question { font: inherit; text-wrap: pretty; }
  .ask-label { display: block; margin-bottom: 6px; font-style: italic; }
  .check-line { display: flex; align-items: flex-start; gap: 14px; padding-block: 12px; min-height: 48px; cursor: pointer; }
  .check-input { appearance: none; width: 44px; height: 44px; min-width: 44px; flex-shrink: 0; margin: 2px 0 0; border: 2px solid var(--purple); border-radius: 7px; background: #fffdf8; cursor: pointer; }
  .check-input:checked { background: var(--purple); box-shadow: inset 0 0 0 5px #fffdf8; }
  .check-input:checked + span { text-decoration: underline; text-underline-offset: 5px; text-decoration-color: var(--line); }
  .note-line { display: block; height: 30px; border-bottom: 1px solid #b8a8c1; }
  .cost-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(100px, 0.65fr); gap: 20px; padding-block: 10px; }
  .cost-label { align-self: end; }
  .cost-note { padding: 22px 24px; border-radius: 26px; background: var(--yellow); }
  .price-context-heading { font-size: 1.5rem; line-height: 1.25; font-weight: 400; text-wrap: balance; }
  .cost-note > * + * { margin-top: 12px; }
  .question-list { padding-left: 24px; }
  .question-list > li + li { margin-top: 12px; }
  .urgent-note { padding: 20px 24px; border-left: 5px solid var(--purple); background: var(--lavender); border-radius: 0 20px 20px 0; }
}

@layer interaction {
  @media (prefers-reduced-motion: no-preference) {
    a, button { transition: background-color 140ms ease, text-decoration-thickness 140ms ease; }
  }
  @media (forced-colors: active) {
    .check-input { appearance: auto; }
  }
}

@layer small-screen {
  @media (max-width: 900px) {
    .hero { gap: 36px; }
    .paper-tab { left: -12px; width: 112px; }
    .chapter-grid { grid-template-columns: 1fr 1.5fr; gap: 36px; }
    .workbook-page { padding-inline: 28px; }
    .page-turn { padding-inline: 30px; }
  }
  @media (max-width: 680px) {
    .page-width { width: calc(100% - 40px); }
    .masthead { align-items: flex-start; padding-top: 24px; gap: 14px; }
    .masthead-name { font-size: 1.3rem; }
    .masthead-note { max-width: 12ch; font-size: 1rem; text-align: right; }
    .breadcrumb { margin-bottom: 12px; }
    .hero { grid-template-columns: 1fr; gap: 36px; padding-block: 14px 44px; }
    .hero-copy { padding: 0; }
    .opener-label { margin-bottom: 20px; }
    .hero-lead { font-size: 1.2rem; }
    .hero-actions { align-items: flex-start; flex-direction: column; gap: 8px; margin-top: 24px; }
    .next-link { max-width: 100%; padding-inline: 22px; }
    .hero-figure { margin-inline: 10px; border-radius: 130px 130px 32px 32px; }
    .photo-window { border-radius: 118px 118px 22px 22px; }
    .paper-tab { top: 55%; left: -16px; }
    .chapter { padding-block: 40px; }
    .chapter-grid { grid-template-columns: 1fr; gap: 28px; }
    .chapter-heading, .chapter-opener { max-width: none; }
    .chapter-opener { margin-top: 18px; }
    .source-links { flex-direction: column; align-items: flex-start; }
    .recap { padding: 20px; }
    .page-turn { flex-direction: column; align-items: flex-start; padding: 28px 24px; margin-block: 12px 40px; gap: 22px; }
    .site-footer { flex-direction: column; align-items: flex-start; gap: 12px; padding-block: 24px 30px; }
    .question-hero { padding-block: 18px 30px; }
    .question-lead { font-size: 1.2rem; }
    .workbook-page { margin-bottom: 36px; padding: 4px 20px 12px; border-radius: 8px 30px 30px 8px; }
    .workbook-chapter { padding-block: 28px; }
    .workbook-heading { grid-template-columns: 42px minmax(0, 1fr); gap: 12px; }
    .chapter-mark { width: 40px; height: 40px; font-size: 1.25rem; }
    .workbook-heading h2 { font-size: 1.85rem; }
    .workbook-body { margin-left: 0; }
    .ask-line, .cost-note, .urgent-note { padding: 18px; }
    .cost-row { grid-template-columns: 1fr 90px; gap: 10px; }
    .check-line { gap: 12px; }
  }
}

@layer print {
  @media print {
    body { background: white; color: black; font-size: 12pt; }
    .page-width { width: 100%; }
    .skip-link, .hero-actions, .hero-figure, .reveal-all, .page-turn, .footer-link { display: none; }
    .workbook-page { padding: 0; border: 0; }
    .workbook-body { max-width: none; }
    .workbook-chapter { break-inside: avoid; }
    h1 { font-size: 30pt; }
    h2 { font-size: 22pt; }
    a { color: black; }
    .check-input { print-color-adjust: exact; }
    .source-link::after { content: ' (' attr(href) ')'; font-size: 10pt; overflow-wrap: anywhere; }
    .source-link { display: block; }
  }
}
