@layer reset, base, layout, components, motion, print;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, p, blockquote, ol { margin: 0; }
  ol { padding: 0; }
  button, a { font: inherit; }
  button { color: inherit; }
}

@layer base {
  :root {
    --paper: #e9e1d3;
    --paper-light: #f3ede3;
    --ink: #25211c;
    --muted: #70685c;
    --rule: rgba(62, 52, 41, 0.22);
    --rust: #853e2d;
    --rust-dark: #642a20;
    --serif: "Newsreader", Georgia, serif;
    --mono: "DM Mono", monospace;
  }

  body {
    min-width: 320px;
    overflow-x: hidden;
    background:
      radial-gradient(circle at 82% 10%, rgba(133, 62, 45, 0.08), transparent 28rem),
      var(--paper);
    color: var(--ink);
    font-family: var(--serif);
    font-size: clamp(1.08rem, 0.96rem + 0.34vw, 1.28rem);
    line-height: 1.72;
  }

  body::before {
    position: fixed;
    z-index: 20;
    inset: 0;
    pointer-events: none;
    opacity: 0.32;
    content: "";
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
    mix-blend-mode: multiply;
  }

  a { color: inherit; }
  ::selection { background: rgba(133, 62, 45, 0.22); }
  :focus-visible { outline: 2px solid var(--rust); outline-offset: 5px; }
}

@layer layout {
  .reading-progress {
    position: fixed;
    z-index: 40;
    inset: 0 0 auto;
    height: 3px;
  }

  .reading-progress span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--rust);
  }

  .site-header {
    position: absolute;
    z-index: 10;
    top: 0;
    left: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    padding: 1.5rem clamp(1.25rem, 4vw, 4rem);
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  .wordmark {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: max-content;
    text-decoration: none;
  }

  .wordmark-mark {
    display: grid;
    width: 2.4rem;
    aspect-ratio: 1;
    place-items: center;
    border: 1px solid var(--ink);
    border-radius: 50%;
    color: var(--rust);
  }

  .wordmark-copy { line-height: 1.3; }
  .reading-time { justify-self: end; }

  .cover {
    position: relative;
    display: grid;
    grid-template-columns: minmax(8rem, 0.55fr) minmax(18rem, 1.55fr) minmax(13rem, 0.7fr);
    grid-template-rows: auto 1fr auto;
    gap: 2rem clamp(2rem, 5vw, 6rem);
    min-height: 100svh;
    padding: clamp(8rem, 14vh, 10rem) clamp(1.25rem, 6vw, 7rem) clamp(2rem, 5vw, 5rem);
    overflow: hidden;
    border-bottom: 1px solid var(--rule);
  }

  .cover-meta {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding-top: 0.7rem;
    font-family: var(--mono);
    font-size: 0.65rem;
    letter-spacing: 0.09em;
    line-height: 1.5;
    text-transform: uppercase;
  }

  .cover-meta span:first-child { color: var(--rust); }
  .cover-title-wrap { align-self: center; }

  .kicker, .chapter-label {
    color: var(--rust);
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.13em;
    text-transform: uppercase;
  }

  h1 {
    margin-top: 1.25rem;
    font-size: clamp(4.4rem, 10.5vw, 10.8rem);
    font-weight: 300;
    letter-spacing: -0.066em;
    line-height: 0.76;
  }

  h1 span { display: block; white-space: nowrap; }
  h1 span:last-child { margin-left: 0.38em; }
  h1 em { position: relative; color: var(--rust); font-weight: 400; }

  h1 em::after {
    position: absolute;
    right: -0.07em;
    bottom: -0.05em;
    left: -0.08em;
    height: 0.05em;
    content: "";
    background: var(--rust);
    transform: rotate(-1.4deg);
  }

  .subtitle {
    max-width: 42rem;
    margin: clamp(2rem, 5vw, 4rem) 0 0 20%;
    color: var(--muted);
    font-size: clamp(1.1rem, 1rem + 0.5vw, 1.5rem);
    line-height: 1.4;
  }

  .epigraph {
    align-self: end;
    max-width: 18rem;
    padding-bottom: 3rem;
  }

  .epigraph::before {
    display: block;
    width: 2.6rem;
    height: 1px;
    margin-bottom: 1.3rem;
    content: "";
    background: var(--rust);
  }

  .epigraph p { font-size: 1.15rem; font-style: italic; line-height: 1.42; }
  .epigraph cite { display: block; margin-top: 0.8rem; color: var(--muted); font-family: var(--mono); font-size: 0.58rem; font-style: normal; letter-spacing: 0.08em; text-transform: uppercase; }

  .begin-link {
    grid-column: 2;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    width: max-content;
    font-family: var(--mono);
    font-size: 0.66rem;
    letter-spacing: 0.1em;
    text-decoration: none;
    text-transform: uppercase;
  }

  .begin-link svg { width: 1.2rem; fill: none; stroke: currentColor; stroke-linecap: round; }

  .shadow-orbit {
    position: absolute;
    right: -17vw;
    bottom: -28vw;
    width: 47vw;
    min-width: 32rem;
    aspect-ratio: 1;
    border: 1px solid rgba(133, 62, 45, 0.3);
    border-radius: 50%;
    box-shadow: inset 0 0 0 6vw rgba(133, 62, 45, 0.025), inset 0 0 0 12vw rgba(133, 62, 45, 0.025);
  }

  .essay {
    position: relative;
    max-width: 94rem;
    margin: 0 auto;
    padding: 5rem clamp(1.25rem, 5vw, 6rem) 9rem;
  }

  .chapter { max-width: 48rem; margin: 0 auto; padding: clamp(5.5rem, 10vw, 9rem) 0; }
  .chapter + .chapter { border-top: 1px solid var(--rule); }

  .chapter-header {
    display: grid;
    grid-template-columns: 4.5rem 1fr;
    gap: 1.5rem;
    margin-bottom: clamp(2.4rem, 5vw, 4.5rem);
  }

  .chapter-number { padding-top: 0.3rem; color: var(--rust); font-family: var(--mono); font-size: 0.73rem; }
  .chapter-label { margin-bottom: 0.6rem; }

  h2 { max-width: 43rem; font-size: clamp(2.5rem, 5vw, 4.6rem); font-weight: 400; letter-spacing: -0.045em; line-height: 0.98; }
  .chapter > p { margin-bottom: 1.5rem; }
  .chapter > p:not(.lead) { text-indent: 2rem; }
  .chapter .lead { font-size: clamp(1.35rem, 1.15rem + 0.55vw, 1.75rem); line-height: 1.56; }
  .chapter .lead::first-letter { float: left; margin: 0.11em 0.1em 0 0; color: var(--rust); font-size: 4.5em; line-height: 0.7; }

  .margin-note {
    position: absolute;
    top: 13rem;
    left: clamp(1.5rem, 4vw, 5rem);
    display: flex;
    flex-direction: column;
    gap: 1.7rem;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.57rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    writing-mode: vertical-rl;
  }
}

@layer components {
  .contents-toggle {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    border: 0;
    background: transparent;
    cursor: pointer;
    letter-spacing: inherit;
    text-transform: inherit;
  }

  .toggle-lines, .toggle-lines::before {
    display: block;
    width: 1.25rem;
    height: 1px;
    content: "";
    background: currentColor;
  }

  .toggle-lines::before { transform: translateY(5px); }

  .contents {
    position: fixed;
    z-index: 50;
    inset: 0;
    display: grid;
    align-content: center;
    padding: clamp(2rem, 7vw, 7rem);
    background: var(--rust-dark);
    color: var(--paper-light);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-2%);
    transition: opacity 260ms ease, transform 360ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .contents.is-open { opacity: 1; pointer-events: auto; transform: none; }
  .contents-heading { position: absolute; top: 2rem; right: clamp(1.5rem, 5vw, 5rem); left: clamp(1.5rem, 5vw, 5rem); display: flex; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,0.3); padding-bottom: 1rem; font-family: var(--mono); font-size: 0.65rem; letter-spacing: 0.12em; text-transform: uppercase; }
  .contents-close { border: 0; background: none; color: inherit; cursor: pointer; font-family: inherit; font-size: inherit; letter-spacing: inherit; text-transform: inherit; }
  .contents ol { list-style: none; }
  .contents li { border-bottom: 1px solid rgba(255,255,255,0.18); }
  .contents a { display: grid; grid-template-columns: 4rem 1fr; align-items: baseline; padding: 0.45rem 0; font-size: clamp(2rem, 5vw, 4.8rem); font-weight: 300; letter-spacing: -0.04em; line-height: 1.15; text-decoration: none; transition: padding-left 180ms ease, color 180ms ease; }
  .contents a span { font-family: var(--mono); font-size: 0.65rem; letter-spacing: 0; }
  .contents a:hover { padding-left: 1rem; color: #dec4b8; }

  .statement {
    position: relative;
    max-width: 58rem;
  }

  .statement > p {
    padding: clamp(2rem, 5vw, 4rem);
    border: 1px solid var(--rust);
    font-size: clamp(1.35rem, 1.05rem + 0.8vw, 2rem);
    line-height: 1.55;
    text-indent: 0;
  }

  .theory { max-width: 60rem; }
  .theory-list { border-top: 1px solid var(--rule); }
  .theory-entry { display: grid; grid-template-columns: 4.5rem 1fr; gap: 1.5rem; padding: 3rem 0; border-bottom: 1px solid var(--rule); }
  .theory-index { padding-top: 0.35rem; color: var(--rust); font-family: var(--mono); font-size: 0.7rem; }
  .theory-entry h3 { font-size: clamp(1.65rem, 1.4rem + 0.6vw, 2.2rem); font-weight: 400; letter-spacing: -0.025em; line-height: 1.1; }
  .theorist { margin: 0.35rem 0 1.2rem; color: var(--rust); font-family: var(--mono); font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase; }
  .theory-entry div > p:last-child { color: #443e36; font-size: 1.05rem; line-height: 1.68; }
  .featured-entry { position: relative; }
  .featured-entry::before { position: absolute; inset: 0 -2rem; z-index: -1; content: ""; background: rgba(133, 62, 45, 0.06); transform: rotate(-0.5deg); }

  .pull-quote { margin: 4rem -7rem 4rem 6rem; padding: 1rem 0 1rem 2rem; border-left: 5px solid var(--rust); color: var(--rust); }
  .pull-quote p { font-size: clamp(2rem, 4vw, 3.5rem); font-style: italic; letter-spacing: -0.035em; line-height: 1.08; }

  .next-step { display: grid; grid-template-columns: 8rem 1fr; gap: 2rem; margin-top: 4rem; padding: 2rem 0; border-block: 1px solid var(--rust); }
  .next-step span { color: var(--rust); font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; }
  .next-step p { font-size: 1.25rem; line-height: 1.5; }

  .references { max-width: 60rem; }
  .references ol { list-style: none; counter-reset: reference; }
  .references li { display: grid; grid-template-columns: 3.5rem 1fr; gap: 1rem; padding: 1.2rem 0; border-bottom: 1px solid var(--rule); color: var(--muted); font-size: 0.98rem; line-height: 1.55; counter-increment: reference; }
  .references li::before { content: counter(reference, decimal-leading-zero); color: var(--rust); font-family: var(--mono); font-size: 0.62rem; }
  .references li span { color: var(--ink); font-weight: 600; }

  .site-footer { display: flex; justify-content: space-between; gap: 2rem; padding: 2rem clamp(1.25rem, 5vw, 5rem); border-top: 1px solid var(--rule); color: var(--muted); font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; }
  .site-footer a { color: var(--rust); text-decoration: none; }
}

@layer motion {
  .reveal { opacity: 0; transform: translateY(18px); animation: reveal 900ms cubic-bezier(0.22, 1, 0.36, 1) forwards; }
  .cover-title-wrap .reveal { animation-delay: 120ms; }
  .subtitle.reveal { animation-delay: 260ms; }
  .epigraph.reveal { animation-delay: 380ms; }
  .begin-link.reveal { animation-delay: 500ms; }
  .begin-link svg { transition: transform 180ms ease; }
  .begin-link:hover svg { transform: translateY(4px); }
  @keyframes reveal { to { opacity: 1; transform: none; } }

  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  }
}

@media (max-width: 900px) {
  .site-header { grid-template-columns: 1fr auto; }
  .reading-time { display: none; }
  .cover { grid-template-columns: 1fr; grid-template-rows: auto auto auto 1fr; min-height: 100svh; gap: 2rem; padding-top: 8rem; }
  .cover-title-wrap, .epigraph, .begin-link { grid-column: 1; }
  .cover-title-wrap { align-self: start; }
  .cover-meta { flex-direction: row; flex-wrap: wrap; gap: 0.5rem 1.2rem; }
  h1 { font-size: clamp(4rem, 15vw, 8rem); }
  h1 span:last-child { margin-left: 0.12em; }
  .subtitle { margin-left: 0; }
  .epigraph { justify-self: end; padding-bottom: 0; }
  .begin-link { align-self: end; }
  .margin-note { display: none; }
  .pull-quote { margin-right: 0; margin-left: 2rem; }
}

@media (max-width: 600px) {
  body { font-size: 1.05rem; }
  .wordmark-copy, .contents-toggle span:first-child { display: none; }
  .site-header { padding-top: 1rem; }
  .cover { padding-top: 6.5rem; }
  .cover-meta span:last-child { display: none; }
  h1 { font-size: clamp(3.6rem, 19vw, 6.4rem); line-height: 0.82; }
  .subtitle { font-size: 1.05rem; }
  .shadow-orbit { right: -22rem; bottom: -22rem; }
  .essay { padding-top: 1rem; padding-bottom: 5rem; }
  .chapter { padding: 5rem 0; }
  .chapter-header, .theory-entry { grid-template-columns: 2.7rem 1fr; gap: 0.7rem; }
  .chapter > p:not(.lead) { text-indent: 1.4rem; }
  .chapter .lead::first-letter { font-size: 3.8em; }
  .statement > p { padding: 1.5rem; }
  .featured-entry::before { right: -1.25rem; left: -1.25rem; }
  .pull-quote { margin: 3rem 0; padding-left: 1rem; }
  .next-step { grid-template-columns: 1fr; gap: 0.7rem; }
  .references li { grid-template-columns: 2rem 1fr; gap: 0.6rem; }
  .contents a { grid-template-columns: 2.5rem 1fr; font-size: clamp(1.8rem, 9vw, 3rem); padding: 0.7rem 0; }
  .site-footer { flex-direction: column; }
}

@layer print {
  @media print {
    body { background: white; color: black; font-size: 11pt; }
    body::before, .site-header, .reading-progress, .contents, .begin-link, .shadow-orbit, .margin-note { display: none; }
    .cover { display: block; min-height: auto; padding: 5cm 1cm 3cm; border: 0; page-break-after: always; }
    .cover-meta, .epigraph { margin-bottom: 2cm; }
    .cover-title-wrap { margin: 3cm 0; }
    h1 { font-size: 58pt; }
    .subtitle { margin-left: 0; }
    .essay { padding: 0; }
    .chapter { max-width: none; padding: 1.5cm 0; break-before: page; }
    .chapter:first-of-type { break-before: auto; }
    .theory-entry, .references li { break-inside: avoid; }
    .featured-entry::before { display: none; }
    .site-footer { padding: 1cm 0 0; }
  }
}
