@layer reset, base, layout, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body { margin: 0; }
  img, svg { max-width: 100%; }
}

@layer base {
  :root {
    color-scheme: light dark;
    --bg: #f5f3ef;
    --paper: #fffdfa;
    --ink: #191e29;
    --muted: #58616d;
    --soft: #eae6e0;
    --line: #d6d1ca;
    --red: #a72d42;
    --red-quiet: #f4e7e8;
    --focus: #2774a7;
    --reading: Georgia, "Times New Roman", serif;
    --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #10141b; --paper: #171c25; --ink: #f3f0eb;
      --muted: #b6b9c1; --soft: #232a34; --line: #39414d;
      --red: #f08e99; --red-quiet: #3a242b; --focus: #8cc7ed;
    }
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #10141b; --paper: #171c25; --ink: #f3f0eb;
    --muted: #b6b9c1; --soft: #232a34; --line: #39414d;
    --red: #f08e99; --red-quiet: #3a242b; --focus: #8cc7ed;
  }
  :root[data-theme="light"] { color-scheme: light; }
  body { background: var(--bg); color: var(--ink); font-family: var(--ui); }
  a { color: var(--red); text-underline-offset: .2em; }
  a:hover { text-decoration-thickness: .14em; }
  a:focus-visible, button:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
  .skip { position: absolute; inset-block-start: -5rem; inset-inline-start: 1rem; z-index: 20; padding: .65rem 1rem; background: var(--paper); }
  .skip:focus { inset-block-start: .6rem; }
  ::selection { background: var(--red-quiet); }
}

@layer layout {
  .top-frame { min-height: 4.5rem; display: flex; align-items: center; gap: clamp(1rem, 3vw, 3rem); padding: .7rem max(1rem, calc((100vw - 90rem) / 2)); border-bottom: 1px solid var(--line); background: var(--paper); }
  .brand { color: var(--ink); font-weight: 750; letter-spacing: -.045em; font-size: 1.25rem; text-decoration: none; white-space: nowrap; }
  .brand span:first-child { color: var(--red); padding-inline: .25rem; font-weight: 400; }
  .brand-detail { font-size: .78rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
  .top-frame nav { display: flex; gap: clamp(.75rem, 1.7vw, 1.5rem); margin-inline-start: auto; }
  .top-frame nav a { color: var(--muted); font-size: .82rem; font-weight: 650; text-decoration: none; }
  .top-frame nav a:hover { color: var(--red); }
  .theme { flex: none; padding: .5rem .75rem; border-radius: 999px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); font: 650 .75rem var(--ui); cursor: pointer; }
  .preview-bar { display: flex; justify-content: space-between; gap: .75rem; padding: .55rem max(1rem, calc((100vw - 90rem) / 2)); background: var(--red-quiet); color: var(--red); font: 700 .68rem var(--ui); letter-spacing: .07em; text-transform: uppercase; }
  .layout { max-width: 90rem; margin: auto; display: grid; grid-template-columns: minmax(0, 1fr) 17rem; gap: clamp(2rem, 5vw, 6rem); padding: clamp(2rem, 5vw, 5rem) clamp(1rem, 3vw, 3rem) 7rem; }
  .reading-column { min-width: 0; }
  .eyebrow, .overline { font: 750 .7rem var(--ui); letter-spacing: .19em; text-transform: uppercase; color: var(--red); }
  .eyebrow span { padding-inline: .35rem; color: var(--muted); }
  .edition-switch { display: flex; gap: .4rem; flex-wrap: wrap; margin: 1.1rem 0 1rem; }
  .edition-switch a { border: 1px solid var(--line); color: var(--muted); text-decoration: none; padding: .5rem .8rem; border-radius: 999px; font: 650 .77rem var(--ui); }
  .edition-switch a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
  .edition-note { margin: 1.1rem 0 1rem; font: 650 .77rem/1.45 var(--ui); color: var(--muted); }
  .rail { align-self: start; position: sticky; top: 2rem; max-height: calc(100vh - 4rem); overflow: auto; border-inline-start: 1px solid var(--line); padding-inline-start: 1.25rem; }
  .rail > a, .rail-links a { display: block; font: 500 .75rem/1.4 var(--ui); text-decoration: none; color: var(--muted); padding: .58rem 0; border-bottom: 1px solid var(--line); }
  .rail > a:hover, .rail-links a:hover { color: var(--red); }
  .rail-links { margin-block-start: 2rem; }
  .bottom-frame { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1rem; border-top: 1px solid var(--line); padding: 2rem max(1rem, calc((100vw - 90rem) / 2)); color: var(--muted); font: .72rem var(--ui); }
}

@layer components {
  .article { max-width: 46rem; color: var(--ink); font-family: var(--reading); font-size: clamp(1rem, 1.08vw, 1.16rem); line-height: 1.68; }
  .article h1 { max-width: 15ch; margin: 1.7rem 0 .7rem; font: 500 clamp(3.4rem, 7.5vw, 7.5rem)/.98 var(--reading); letter-spacing: -.07em; text-wrap: balance; }
  .article h1::first-letter { color: var(--red); }
  .article h2:first-of-type { max-width: 27ch; margin: 0 0 3.5rem; font: 400 clamp(1.25rem, 2.2vw, 2rem)/1.25 var(--reading); color: var(--muted); letter-spacing: -.025em; }
  .article h2:not(:first-of-type) { margin: 4.5rem 0 1.4rem; padding-top: 1.1rem; border-top: 1px solid var(--line); font: 500 clamp(1.75rem, 2.8vw, 2.55rem)/1.15 var(--reading); letter-spacing: -.035em; text-wrap: balance; scroll-margin-top: 1rem; }
  .article h3 { margin: 3rem 0 1rem; font: 650 1.15rem/1.35 var(--ui); }
  .article p { margin: 0 0 1.35rem; max-width: 70ch; }
  .article p:has(> strong:only-child) { color: var(--red); font-size: clamp(1.4rem, 2vw, 1.85rem); line-height: 1.3; letter-spacing: -.035em; margin-block: 2.6rem; max-width: 35ch; }
  .article li { margin-block: .65rem; overflow-wrap: anywhere; }
  .article ul { padding-inline-start: 1.5rem; }
  .article hr { border: 0; border-top: 1px solid var(--line); margin: 4rem 0; }
  .article a { overflow-wrap: anywhere; }
  .article .quote { margin: 3rem auto; max-width: 25rem; }
  .article .quote img, .article .quote svg { display: block; width: 100%; height: auto; border: 1px solid var(--line); }
  .article .quote figcaption { font: .76rem/1.5 var(--ui); color: var(--muted); padding-block: .8rem; }
  .visual-notes { max-width: 57rem; margin-top: 7rem; border-top: 3px solid var(--red); padding-top: 2rem; }
  .visual-notes h2 { font: 500 clamp(2rem, 4vw, 3.6rem)/1.1 var(--reading); letter-spacing: -.05em; margin: 0 0 2rem; }
  .study-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
  .study { margin: 0; padding: 1.4rem; border: 1px solid var(--line); background: var(--paper); min-width: 0; }
  .study:last-child { grid-column: 1 / -1; }
  .study figcaption { font: 700 .8rem var(--ui); color: var(--red); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 1.4rem; }
  .study ol { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .55rem; counter-reset: stage; }
  .study li { counter-increment: stage; display: flex; align-items: center; gap: .5rem; min-width: 0; padding: .6rem .7rem; border: 1px solid var(--line); background: var(--soft); font: 650 .8rem/1.3 var(--ui); }
  .study li::before { content: counter(stage, decimal-leading-zero); color: var(--red); font-size: .62rem; }
  .study .layers { display: grid; grid-template-columns: 1fr; }
  .study .layers li { justify-content: space-between; }
  .branch { display: inline-block; color: var(--red); border-inline-start: 2px solid var(--red); padding-inline-start: .8rem; margin: 1rem 0 0 1rem; font: 650 .78rem var(--ui); }
}

@layer responsive {
  @media (max-width: 64rem) { .layout { grid-template-columns: minmax(0, 1fr) 13rem; gap: 2rem; } }
  @media (max-width: 48rem) {
    .top-frame { flex-wrap: wrap; }
    .top-frame nav { order: 3; margin: 0; width: 100%; overflow-x: auto; padding-block: .3rem; }
    .theme { margin-inline-start: auto; }
    .layout { display: block; padding-block-start: 2rem; }
    .rail { position: static; max-height: none; border: 0; border-top: 1px solid var(--line); padding: 1.5rem 0 0; margin-top: 3rem; }
    .rail > a { display: inline-block; margin-inline-end: 1rem; max-width: 16rem; }
    .preview-bar { flex-wrap: wrap; }
  }
  @media (max-width: 36rem) {
    .brand-detail { font-size: .65rem; }
    .article h1 { font-size: clamp(2.9rem, 12vw, 4rem); }
    .study-grid { display: block; }
    .study + .study { margin-top: .75rem; }
    .study ol { display: grid; grid-template-columns: 1fr; }
  }
  @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
  @media print {
    :root { color-scheme: light !important; }
    .top-frame, .preview-bar, .rail, .theme, .edition-switch, .visual-notes { display: none !important; }
    .layout { display: block; padding: 0; }
    .article { max-width: none; color: #000; }
    a { color: #000; }
  }
}
