@layer base, notebook, islands, responsive;

@layer base {
  :root {
    color-scheme: light;
    --cover: #23473f;
    --cover-ink: #f6f0e2;
    --paper: #fbf7ed;
    --ink: #293a32;
    --muted: #596459;
    --rule: #d7d0bf;
    --link: #285c4b;
    --clay: #81412e;
    --warm: #f0e6d4;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 18px;
  }
  * { box-sizing: border-box; }
  html { scroll-padding-top: 1.5rem; }
  body { margin: 0; background: var(--cover); color: var(--ink); line-height: 1.65; }
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: repeating-linear-gradient(90deg, transparent 0 2px, #fff 2px 3px),
      repeating-linear-gradient(0deg, transparent 0 2px, #000 2px 3px);
    opacity: .045;
    pointer-events: none;
  }
  h1, h2, h3 { line-height: 1.16; margin: 0 0 1rem; text-wrap: balance; letter-spacing: -.035em; }
  h1 { font-size: clamp(2.3rem, 4.3vw, 3.6rem); font-weight: 650; }
  h2 { font-size: clamp(1.5rem, 2.2vw, 2rem); font-weight: 650; }
  h3 { font-size: 1.15rem; font-weight: 650; }
  p { margin: 0 0 1rem; max-width: 68ch; }
  p:last-child { margin-bottom: 0; }
  a { color: var(--link); text-underline-offset: .2em; text-decoration-thickness: 1px; }
  a[href] { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; overflow-wrap: anywhere; }
  a:hover { text-decoration-thickness: 2px; }
  button { font: inherit; cursor: pointer; min-width: 44px; min-height: 44px; }
  button, [data-role="action"] { border-radius: 4px; }
  :focus-visible { outline: 3px solid #936b1e; outline-offset: 5px; }
  main:focus { outline: none; }
  ul, ol { padding-left: 1.5rem; }
  li { margin-bottom: .65rem; }
  img { max-width: 100%; height: auto; display: block; }
  figure, dl, dd { margin: 0; }
  figcaption { font-size: 1rem; color: var(--muted); }
  [hidden] { display: none !important; }
  ::selection { color: #19352e; background: #dfcf9c; }
}

@layer notebook {
  [data-role="cover-bar"] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: 1180px;
    margin: 0 auto;
    padding: 1.2rem 1.2rem 1.8rem;
    color: var(--cover-ink);
  }
  [data-role="cover-bar"] a { color: inherit; text-decoration: none; }
  [data-role="cover-bar"] a:focus-visible, [data-role="directory"] a:focus-visible { outline-color: #efd19e; }
  [data-role="notebook-name"] { flex-direction: column; align-items: flex-start !important; line-height: 1.25; font-weight: 650; letter-spacing: .01em; }
  [data-role="notebook-name"] span { font-size: .9rem; font-weight: 400; }
  [data-role="directory-jump"] { gap: .8rem; border-bottom: 1px solid #b0bcab; font-size: 1rem; }
  [data-role="skip-link"] {
    position: absolute;
    z-index: 5;
    top: 8px;
    left: 1rem;
    padding: .6rem 1rem;
    background: var(--paper);
    transform: translateY(-180%);
  }
  [data-role="skip-link"]:focus { transform: none; }
  [data-role="notebook"] {
    position: relative;
    isolation: isolate;
    max-width: 1180px;
    margin: 0 auto;
    background: var(--paper);
    border: 1px solid #e2d8c5;
    border-radius: 7px 12px 6px 7px;
    box-shadow: 2px 4px 0 #d9cebb, 5px 8px 0 #e9e0ce, 7px 12px 0 #cbbfa7, 0 18px 38px #102c2780;
  }
  [data-role="notebook"]::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 26px;
    width: 1px;
    border-right: 1px solid #cab9a2;
    box-shadow: 8px 0 0 #eadfca;
    pointer-events: none;
    z-index: -1;
  }
  [data-role="notebook"]::after {
    content: "";
    position: absolute;
    top: 29px;
    left: -10px;
    width: 22px;
    height: 10px;
    border: 2px solid #a59c88;
    border-radius: 8px;
    background: linear-gradient(0deg, #a49b86, #eee6d8 45%, #a49b86);
    box-shadow: 0 65px 0 #a9a18e, 0 130px 0 #a9a18e;
  }
  [data-role="page-opening"] { padding: 3.8rem 4rem 3rem 4.7rem; border-bottom: 1px solid var(--rule); }
  [data-role="page-opening"]:has(figure) { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 2.6rem; align-items: center; }
  [data-role="opening-copy"] { min-width: 0; }
  [data-role="eyebrow"] { font-size: 1rem; color: var(--clay); margin-bottom: 1.1rem; font-weight: 600; }
  [data-role="page-opening"] h1 { max-width: 19ch; }
  [data-role="page-opening"] p { max-width: 60ch; }
  [data-role="opening-copy"] > p:not([data-role]) { font-size: 1.15rem; line-height: 1.6; }
  [data-role="opening-note"] { padding-top: .25rem; color: var(--muted); }
  [data-role="opening-actions"] { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.6rem; }
  [data-role="action"] { font-weight: 600; padding: .7rem 1rem; border: 1px solid #a7b7a6; text-decoration: none; box-shadow: 0 2px 0 #c5bca7; background: #f1eddf; gap: .5rem; }
  [data-role="action"]:first-child { background: var(--cover); border-color: var(--cover); color: var(--cover-ink); box-shadow: 0 3px 0 #142e27; }
  [data-role="action"]:hover { background: #e5dfcf; }
  [data-role="action"]:first-child:hover { background: #31594b; }
  [data-role="page-body"] { padding: 0 3.8rem 0 4.7rem; }
  [data-role="answer"] { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2.35fr); column-gap: 2.6rem; padding: 2.7rem 0; border-bottom: 1px solid var(--rule); }
  [data-role="answer-copy"] { grid-column: 2; min-width: 0; }
  [data-role="answer-copy"] > p { max-width: 66ch; }
  [data-role="myth"] { align-self: start; padding: 1.1rem; position: relative; background: var(--warm); border: 1px solid #dcd1bd; border-radius: 2px; box-shadow: 0 3px 4px #675e3612; }
  [data-role="myth"]::before { content: ""; position: absolute; height: 12px; width: 44px; top: -7px; left: calc(50% - 22px); background: #dac79f99; border: 1px solid #d5c191; transform: rotate(-4deg); }
  [data-role="myth"] p { font-size: 1.05rem; line-height: 1.5; }
  [data-role="myth-label"] { color: var(--clay); margin-bottom: .5rem; font-weight: 600; font-size: .9rem !important; }
  [data-role="page-link"], [data-role="source-link"] { gap: .8rem; margin-top: .15rem; padding: .35rem 0; line-height: 1.4; }
  [data-role="page-link"] { font-weight: 600; }
  [data-role="note-mark"] { margin-top: .4rem; font-size: .9rem; font-weight: 500; color: var(--muted); border-bottom: 1px dashed #a9b0a2; text-decoration: none; }
  [data-role="next-page"] { padding: 1.5rem 3.8rem 1.9rem 4.7rem; border-top: 1px solid var(--rule); display: flex; align-items: baseline; gap: 1.4rem; flex-wrap: wrap; }
  [data-role="next-page"] > p { color: var(--muted); margin: 0; font-size: .95rem; }
  [data-role="directory"] { max-width: 1180px; margin: 3rem auto 0; padding: 2rem 1.2rem 1rem; color: var(--cover-ink); }
  [data-role="directory-heading"] p { margin-bottom: .4rem; color: #d3dbc9; }
  [data-role="directory-heading"] h2 { font-size: 1.8rem; margin-bottom: 1.5rem; }
  [data-role="directory"] nav ul { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0; padding: 0; list-style: none; gap: .7rem 1.3rem; }
  [data-role="directory"] nav li { margin: 0; border-top: 1px solid #71897d; }
  [data-role="directory"] nav a { color: var(--cover-ink); width: 100%; min-height: 56px; justify-content: space-between; text-decoration: none; padding: .6rem 0; }
  [data-role="directory"] nav a:hover { text-decoration: underline; }
  [data-role="directory"] nav a[aria-current] { color: #efd19e; font-weight: 650; }
  [data-role="footer-base"] { border-top: 1px solid #71897d; margin-top: 2rem; padding-top: 1rem; display: flex; gap: 2rem; align-items: start; justify-content: space-between; }
  [data-role="footer-base"] p { max-width: 60ch; font-size: .95rem; }
  [data-role="footer-base"] a { color: var(--cover-ink); font-size: .95rem; flex-shrink: 0; }
}

@layer islands {
  [data-role="still-life"] { padding: .6rem .6rem .5rem; border: 1px solid #c8bca5; background: #f0e8d7; box-shadow: 3px 6px 12px #433c2526; transform: rotate(1.6deg); }
  [data-role="image-well"] { position: relative; aspect-ratio: 1.364; overflow: hidden; background: #d9ccb4; }
  [data-scene="budget"] [data-role="image-well"], [data-scene="sources"] [data-role="image-well"] { aspect-ratio: 1.5; }
  [data-role="still-life"] img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; opacity: 0; }
  [data-role="still-life"] img[data-loaded] { opacity: 1; }
  [data-role="still-life"] figcaption { margin-top: .6rem; font-size: .9rem; line-height: 1.4; text-align: center; }
  [data-role="still-life-fallback"] { position: absolute; inset: 0; background: linear-gradient(120deg, #e2d5be, #cab69c); }
  [data-role="cloth"] { position: absolute; bottom: 4%; right: -5%; width: 48%; height: 46%; transform: rotate(-12deg); border: 1px solid #324e40; background: #426451; box-shadow: 4px 6px 4px #5a4d3650; }
  [data-role="blank-book"] { position: absolute; top: 15%; left: 12%; width: 67%; height: 63%; transform: rotate(-8deg); background: linear-gradient(90deg, #fbf7e8 0 48%, #d5cbb7 49%, #f3edda 51%, #fff7e7 100%); border: 1px solid #a3957b; border-radius: 2px 7px 5px 2px; box-shadow: 1px 3px 0 #c5b79c, 2px 5px 0 #e6d9c1, 4px 8px 9px #76634744; }
  [data-role="stone"] { position: absolute; top: 7%; right: 5%; width: 18%; height: 25%; background: linear-gradient(125deg, #d5d3c2, #b1ae9b); border-radius: 48% 56% 39% 58%; box-shadow: 2px 5px 4px #554c3338; transform: rotate(16deg); }
  [data-role="clip"] { position: absolute; bottom: 20%; left: 16%; width: 8%; height: 17%; border: 3px solid #978344; border-radius: 10px; transform: rotate(-12deg); box-shadow: 1px 1px 0 #f0dea1, 2px 4px 4px #4b412133; }
  [data-role="pencil-note"] { margin: 2rem 0 2.6rem 31.8%; padding: 1.5rem 1.65rem; background: #f2e7bf; border: 1px solid #dfcea1; border-radius: 2px; box-shadow: 2px 5px 6px #6557371a; transform: rotate(-.4deg); }
  [data-role="pencil-note"] [data-role="answer-copy"] { max-width: 63ch; }
  [data-role="pencil-note"] h2 { font-size: 1.35rem; }
  [data-role="check-steps"] { list-style: none; counter-reset: check; padding: 0; margin: 1.5rem 0; }
  [data-role="check-steps"] li { position: relative; margin: 0 0 1.5rem; padding: .25rem 0 .25rem 3.2rem; counter-increment: check; }
  [data-role="check-steps"] li::before { content: counter(check); position: absolute; left: 0; top: 0; width: 2.2rem; height: 2.2rem; line-height: 2.2rem; text-align: center; border: 1px solid #a7b09b; border-radius: 50%; color: var(--link); background: #eeefdf; font-weight: 650; }
  [data-role="footnotes"] { margin: 0 3.8rem 0 4.7rem; padding: 2rem 0; }
  [data-role="evidence-heading"] { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
  [data-role="evidence-heading"] p { margin-bottom: .2rem; color: var(--muted); font-size: .95rem; }
  [data-role="evidence-heading"] h2 { font-size: 1.45rem; margin: 0; }
  [data-role="drawer-open"] { padding: .5rem .8rem; border: 1px solid #a6af9e; border-radius: 4px; background: #edeadb; color: var(--link); box-shadow: 0 2px 0 #c9c1ac; text-decoration: none; }
  [data-role="footnote"] { border-top: 1px solid var(--rule); padding: .6rem 0 .9rem; scroll-margin-top: 1.5rem; }
  [data-role="footnote"] dt { display: flex; gap: .8rem; align-items: center; }
  [data-role="note-letter"] { flex: 0 0 1.75rem; width: 1.75rem; height: 1.75rem; text-align: center; line-height: 1.75rem; border: 1px solid #b3b8a7; border-radius: 50%; color: var(--muted); font-size: .95rem; }
  [data-role="footnote"] dd { padding-left: 2.55rem; }
  [data-role="footnote"] p { font-size: .95rem; line-height: 1.6; color: var(--muted); }
  [data-role="footnote"] a { font-size: 1rem; }
  [data-role="evidence-drawer"] { position: fixed; inset: 0 0 0 auto; width: min(560px, 100%); max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; padding: 1.6rem; border: 0; border-left: 1px solid #b7aa91; color: var(--ink); background: var(--paper); box-shadow: -8px 0 34px #0d272d40; overscroll-behavior: contain; }
  [data-role="evidence-drawer"]::backdrop { background: #142e2770; }
  [data-role="drawer-heading"] { display: flex; align-items: start; gap: 1rem; justify-content: space-between; border-bottom: 1px solid var(--rule); padding-bottom: 1rem; margin-bottom: 1rem; }
  [data-role="drawer-heading"] h2 { font-size: 1.5rem; margin: 0; }
  [data-role="drawer-close"] { background: #ebe4d3; border: 1px solid #a6af9e; padding: .45rem .7rem; color: var(--ink); flex-shrink: 0; }
  [data-role="drawer-content"] { max-width: 100%; }
  [data-role="drawer-content"] [data-role="footnote"] dd { padding-left: 0; }
  [data-role="drawer-content"] a { overflow-wrap: anywhere; }
  [data-role="footnote"]:target { background: #f2e7bf; outline: 1px solid #dfcea1; outline-offset: 7px; }
  html[data-drawer-open] { overflow: hidden; }
}

@layer responsive {
  @media (max-width: 1000px) {
    [data-role="notebook"] { margin-inline: 1.1rem; }
    [data-role="page-opening"] { padding: 2.6rem 2rem 2.5rem 3rem; }
    [data-role="page-opening"]:has(figure) { gap: 1.4rem; }
    [data-role="page-body"] { padding-inline: 3rem 2rem; }
    [data-role="answer"] { gap: 1.8rem; grid-template-columns: minmax(0, 1fr) minmax(0, 2.3fr); }
    [data-role="footnotes"] { margin-inline: 3rem 2rem; }
    [data-role="next-page"] { padding-inline: 3rem 2rem; }
  }
  @media (max-width: 700px) {
    :root { font-size: 17px; }
    h1 { font-size: 2.5rem; }
    [data-role="cover-bar"] { padding: .85rem .9rem 1.3rem; }
    [data-role="notebook-name"] span, [data-role="directory-jump"] { font-size: 16px; }
    [data-role="directory-jump"] { gap: .6rem; }
    [data-role="notebook"] { margin-inline: .7rem; border-radius: 4px 8px 4px 4px; box-shadow: 1px 3px 0 #d9cebb, 2px 6px 0 #e9e0ce, 3px 9px 0 #cbbfa7, 0 13px 25px #102c2780; }
    [data-role="notebook"]::before { left: 15px; box-shadow: 4px 0 0 #eadfca; }
    [data-role="notebook"]::after { left: -7px; width: 15px; height: 8px; }
    [data-role="page-opening"] { padding: 2rem 1.2rem 2rem 1.85rem; }
    [data-role="page-opening"]:has(figure) { grid-template-columns: minmax(0, 1fr); gap: 1.8rem; }
    [data-role="page-opening"] h1 { max-width: 18ch; }
    [data-role="eyebrow"] { font-size: 16px; }
    [data-role="opening-copy"] > p:not([data-role]) { font-size: 1.08rem; }
    [data-role="opening-actions"] { flex-direction: column; }
    [data-role="action"] { justify-content: space-between; width: 100%; }
    [data-role="still-life"] { transform: none; max-width: 100%; padding: .45rem; }
    [data-role="still-life"] figcaption { font-size: 16px; }
    [data-role="image-well"] { aspect-ratio: 1.6; }
    [data-role="page-body"] { padding-inline: 1.85rem 1.2rem; }
    [data-role="answer"] { display: block; padding-block: 2rem; }
    [data-role="myth"] { margin-bottom: 1.4rem; padding: .9rem 1rem; }
    [data-role="myth-label"], [data-role="note-mark"], [data-role="next-page"] > p { font-size: 16px !important; }
    [data-role="answer-copy"] h2 { font-size: 1.6rem; }
    [data-role="pencil-note"] { margin: 1.7rem 0; padding: 1.15rem; transform: none; }
    [data-role="pencil-note"] h2 { font-size: 1.25rem; }
    [data-role="footnotes"] { margin-inline: 1.85rem 1.2rem; padding-block: 1.7rem; }
    [data-role="footnote"] dt { align-items: start; gap: .6rem; }
    [data-role="note-letter"] { margin-top: .45rem; font-size: 16px; }
    [data-role="footnote"] dd { padding-left: 0; }
    [data-role="footnote"] p, [data-role="evidence-heading"] p { font-size: 16px; }
    [data-role="next-page"] { padding: 1.4rem 1.2rem 1.6rem 1.85rem; gap: .2rem; }
    [data-role="directory"] { margin-top: 2rem; padding: 1.5rem 1.1rem 1rem; }
    [data-role="directory"] nav ul { grid-template-columns: minmax(0, 1fr); gap: .1rem; }
    [data-role="directory"] nav a { min-height: 52px; }
    [data-role="footer-base"] { flex-direction: column; gap: .5rem; }
    [data-role="footer-base"] p, [data-role="footer-base"] a { font-size: 16px; }
    [data-role="evidence-drawer"] { padding: 1.1rem; }
    [data-role="drawer-heading"] h2 { font-size: 1.35rem; }
    [data-role="drawer-heading"] { gap: .6rem; }
    [data-role="check-steps"] li { padding-left: 2.9rem; }
  }
  @media (prefers-reduced-motion: no-preference) {
    [data-role="action"], [data-role="drawer-open"] { transition: background-color 120ms ease; }
  }
  @media print {
    body { background: white; }
    [data-role="cover-bar"], [data-role="directory"], [data-role="drawer-open"], [data-role="next-page"], [data-role="still-life"] { display: none; }
    [data-role="notebook"] { margin: 0; box-shadow: none; border: none; max-width: none; }
    [data-role="notebook"]::before, [data-role="notebook"]::after { display: none; }
    [data-role="page-opening"], [data-role="page-body"], [data-role="footnotes"] { padding: 1rem; margin: 0; }
    [data-role="answer"] { break-inside: avoid; }
  }
}
