/*
 * ONSET SHARED SHELL
 * Reusable page-two foundation: tokens, paper, grain, type, masthead, footer.
 * Home-only composition lives in home.css.
 */

:root {
  /* Paper and ink */
  --paper: #f5f1eb;
  --paper-light: #faf7f2;
  --paper-wash: rgba(255, 252, 247, 0.48);
  --paper-glow: rgba(255, 255, 255, 0.17);
  --paper-tone: rgba(177, 151, 114, 0.025);
  --ink: #3D3933;
  /* Display ink: headlines carry near-black authority; gray headlines read as optional. */
  --ink-strong: #211E1A;
  --ink-muted: #777570;
  --ink-faint: #96928a;
  --ink-rule: rgba(79, 79, 78, 0.16);
  --ink-rule-strong: rgba(79, 79, 78, 0.3);
  --ink-focus: rgba(79, 79, 78, 0.7);
  --surface: rgba(255, 253, 249, 0.18);
  --live: #9c5240;
  --focus-ring: rgba(79, 79, 78, 0.075);
  /* Shared dark-action family: warm charcoal derived from the #4F4F4E house ink. */
  --button-light: #4b4a47;
  --button: #454441;
  --button-hover: #3f3e3b;
  --button-deep: #41403d;
  --button-text: #fffdfa;
  --button-border: rgba(255, 255, 255, 0.1);
  --plane-shadow-color: rgba(82, 72, 59, 0.38);

  /* Visible warm paper grain: fine tooth plus soft mottling. */
  --grain-fine-opacity: 0.14;
  --grain-blotch-opacity: 0.085;
  --grain-fine-size: 156px;
  --grain-blotch-size: 560px;
  --grain-blend: multiply;

  /* Type */
  --font-display: "Newsreader", Georgia, serif;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* THE MACHINE SPEAKS MONO (PLAN-web-vibe.md): every datum the engine states — clocks, counts,
     read times, kickers, the folio — wears this face. Prose and headlines stay in the serif. */
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Shared spacing scale */
  --space-1: clamp(4px, 0.25vw, 6px);
  --space-2: clamp(8px, 0.5vw, 10px);
  --space-3: clamp(12px, 0.8vw, 16px);
  --space-4: clamp(16px, 1.1vw, 22px);
  --space-5: clamp(22px, 1.55vw, 30px);
  --space-6: clamp(30px, 2.2vw, 42px);
  --space-7: clamp(42px, 3.2vw, 62px);
  --space-8: clamp(58px, 4.8vw, 92px);
  --space-9: clamp(78px, 6.4vw, 124px);

  /* Container and shell rhythm */
  --container-max: 1720px;
  --container-gutter: clamp(28px, 7vw, 112px);
  --header-top: clamp(28px, 3vw, 54px);
  --header-height: clamp(32px, 2.35vw, 42px);
  --header-block: calc(var(--header-top) + var(--header-height));
  --brand-mark-size: clamp(20px, 1.15vw, 22px);
  --brand-mark-size-compact: clamp(20px, 5.5vw, 22px);
  --hero-pair-max: 1540px;
  --hero-pair-gap: clamp(40px, 6.7vw, 96px);
  --section-gap: clamp(56px, min(6.25vw, 10svh), 96px);

  /* Radius, border, and shadow tokens */
  --radius-small: 7px;
  --radius-control: 10px;
  --radius-control-compact: 9px;
  --radius-card: 18px;
  --radius-card-compact: 13px;
  --border-hairline: 1px;
  --hairline: var(--border-hairline);
  --shadow-focus: 0 0 0 2px var(--focus-ring);
  --shadow-control: 0 16px 36px rgba(74, 62, 44, 0.045), inset 0 1px 4px rgba(74, 62, 44, 0.035);
  --shadow-button: 0 7px 17px rgba(20, 18, 14, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.13);
  --shadow-button-hover: 0 10px 21px rgba(20, 18, 14, 0.21), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  --shadow-card: 0 19px 28px rgba(75, 65, 48, 0.07), 0 2px 3px rgba(75, 65, 48, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.42);
  --shadow-thumb: 0 10px 18px rgba(75, 65, 48, 0.06), 0 1px 2px rgba(75, 65, 48, 0.05);
  --shadow-edition-hover: 0 18px 30px rgba(75, 65, 48, 0.11), 0 3px 5px rgba(75, 65, 48, 0.07);
  --shadow-pill: 0 5px 14px rgba(75, 66, 51, 0.025);

  color-scheme: light;
  font-synthesis: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 46% 31%, var(--paper-wash), transparent 54%),
    linear-gradient(112deg, var(--paper-glow), transparent 38%, var(--paper-tone)),
    var(--paper);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  isolation: isolate;
}

/* Fine grain is intentionally visible at 100% zoom, like warm sketch paper. */
body::before,
body::after {
  position: fixed;
  z-index: 100;
  inset: 0;
  pointer-events: none;
  content: "";
}

body::before {
  opacity: var(--grain-fine-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='156' height='156' viewBox='0 0 156 156'%3E%3Cfilter id='fine-grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.88' numOctaves='5' seed='14' stitchTiles='stitch' result='n'/%3E%3CfeColorMatrix in='n' type='matrix' values='.16 0 0 0 .44 0 .14 0 0 .38 0 0 .11 0 .30 0 0 0 .72 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23fine-grain)' opacity='.72'/%3E%3C/svg%3E");
  background-size: var(--grain-fine-size) var(--grain-fine-size);
  mix-blend-mode: var(--grain-blend);
}

/* A second, low-frequency grain layer keeps large areas from reading digitally flat. */
body::after {
  z-index: 99;
  opacity: var(--grain-blotch-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='560' height='560' viewBox='0 0 560 560'%3E%3Cfilter id='soft-grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .018' numOctaves='3' seed='21' stitchTiles='stitch' result='n'/%3E%3CfeGaussianBlur in='n' stdDeviation='1.2' result='b'/%3E%3CfeColorMatrix in='b' type='matrix' values='.18 0 0 0 .53 0 .15 0 0 .45 0 0 .1 0 .34 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23soft-grain)' opacity='.56'/%3E%3C/svg%3E");
  background-size: var(--grain-blotch-size) var(--grain-blotch-size);
  mix-blend-mode: soft-light;
}

a {
  color: inherit;
}

/* EMBER, THE ONE ACCENT (PLAN-web-vibe.md): the selection wash is one of its named slots. */
::selection {
  background: color-mix(in srgb, var(--live) 24%, transparent);
  color: var(--ink-strong, var(--ink));
}

img,
video {
  display: block;
  max-width: 100%;
}

:focus-visible {
  border-radius: 2px;
  outline: 2px solid var(--ink-focus);
  outline-offset: 4px;
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(calc(100% - (2 * var(--container-gutter))), var(--container-max));
  min-height: 100vh;
  margin: 0 auto;
  padding-top: var(--header-top);
  display: flex;
  flex-direction: column;
}

.page-shell > main {
  flex: 1 0 auto;
}

/* Eyebrows and datelines are the engine talking, so they wear the mono face (PLAN-web-vibe.md).
   Mono is already wide: the tracking comes down and the weight drops to a loaded one (500). */
.reader-page .eyebrow,
.reader-page .dateline {
  margin: 0;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

.masthead {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: var(--header-height);
  view-transition-name: onset-masthead;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: clamp(9px, 0.7vw, 13px);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(20px, 1.35vw, 26px);
  font-weight: 500;
  font-optical-sizing: auto;
  line-height: 1;
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: auto;
  height: var(--brand-mark-size);
  transform: translateY(-0.5px); /* Optical alignment with the wordmark's cap height. */
}

.masthead-nav {
  display: flex;
  align-items: center;
  gap: clamp(18px, 2vw, 28px);
}

.nav-link {
  position: relative;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

.nav-link::after,
.site-footer-nav a::after {
  position: absolute;
  right: 0;
  bottom: -5px;
  left: 0;
  height: var(--border-hairline);
  content: "";
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 220ms cubic-bezier(0.22, 0.72, 0.28, 1);
}

/* The nav underline, hovered or active, is an ember slot. The footer colophon stays neutral ink. */
.nav-link::after {
  background: var(--live);
}

.nav-link:hover::after,
.nav-link:focus-visible::after,
.nav-link.is-active::after,
.site-footer-nav a:hover::after,
.site-footer-nav a:focus-visible::after {
  transform: scaleX(1);
}

.app-store-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: clamp(7px, 0.55vw, 10px);
  min-height: var(--header-height);
  /* Padding, not min-width, sets the box: the border hugs the lockup. */
  padding-inline: clamp(13px, 1vw, 17px);
  border: var(--border-hairline) solid var(--ink-rule-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  box-shadow: var(--shadow-pill);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 200ms ease, transform 200ms ease, box-shadow 200ms ease;
}

.app-store-badge:hover,
.app-store-badge:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(75, 66, 51, 0.06);
}

.app-store-badge:active {
  transform: translateY(0);
  box-shadow: var(--shadow-pill);
}

.app-store-apple {
  flex: 0 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  font-size: clamp(17px, 1.1vw, 21px);
  line-height: 1;
  transform: translateY(-0.5px);
}

.app-store-lockup {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  white-space: nowrap;
}

.app-store-kicker {
  font-size: clamp(6.5px, 0.43vw, 8px);
  font-weight: 550;
  letter-spacing: 0.01em;
  line-height: 1;
}

.app-store-name {
  font-size: clamp(11px, 0.76vw, 14px);
  font-weight: 700;
  letter-spacing: -0.018em;
  line-height: 1;
}

@view-transition {
  navigation: auto;
}

/*
 * THE QUIET HANDOFF: a viewport snapshot has stable geometry, so story-to-article
 * navigation only cross-fades. No card-to-hero crop morph and no second content entrance.
 */
@keyframes onset-page-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes onset-page-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

::view-transition-old(root) {
  animation: onset-page-out 110ms ease-in both;
}

::view-transition-new(root) {
  animation: onset-page-in 180ms cubic-bezier(0.22, 0.72, 0.28, 1) both;
}

::view-transition-group(onset-masthead),
::view-transition-old(onset-masthead),
::view-transition-new(onset-masthead) {
  animation: none;
}

/* The front page and its refresh paint already composed; its cards never enter in sequence. */
html.stories-page::view-transition-old(root),
html.stories-page::view-transition-new(root) {
  animation: none;
}

html.stories-page::view-transition-old(root) {
  opacity: 0;
}

html.stories-page::view-transition-new(root) {
  opacity: 1;
}

.site-footer {
  /* THE PAPER FOOTER: the page ends the way a broadsheet does, a strong rule on the same paper,
     never a separate dark app-band. */
  --footer-ink: var(--ink-strong, #211E1A);
  --footer-muted: var(--ink-muted);
  --footer-rule: var(--ink-rule);
  position: relative;
  width: 100vw;
  margin: 0 0 0 calc(50% - 50vw);
  padding: clamp(36px, 3.2vw, 52px) 0 clamp(44px, 4vw, 64px);
  background: transparent;
  border-top: 2px solid var(--ink-strong, var(--ink));
  color: var(--footer-muted);
  font-size: clamp(10px, 0.72vw, 13px);
}

.site-footer-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(28px, 3vw, 54px);
  width: min(calc(100% - (2 * var(--container-gutter))), var(--container-max));
  margin-inline: auto;
}

.site-footer-brand-cluster {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-self: start;
  gap: 9px;
}

.site-footer .site-footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--footer-ink);
  font-family: var(--font-display);
  font-size: clamp(21px, 1.45vw, 27px);
  font-weight: 500;
  line-height: 1;
}

.site-footer-brand img {
  display: block;
  width: 30px;
  height: 30px;
  object-fit: contain;
  opacity: 0.92;
}

.site-footer small {
  color: var(--footer-muted);
  font-size: clamp(9px, 0.62vw, 11px);
  letter-spacing: 0.025em;
}

.site-footer-nav,
.site-footer-socials {
  display: flex;
  align-items: center;
}

.site-footer-nav {
  justify-self: center;
  gap: clamp(24px, 2.2vw, 40px);
}

.site-footer-nav a {
  position: relative;
}

.site-footer-socials {
  justify-self: end;
  gap: 10px;
}

.site-footer a {
  color: var(--footer-muted);
  text-decoration: none;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--footer-ink);
}

.site-footer a:focus-visible {
  outline: var(--border-hairline) solid var(--footer-ink);
  outline-offset: 4px;
}

.site-footer-socials a {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: var(--border-hairline) solid var(--footer-rule);
  border-radius: 50%;
}

.site-footer-socials a:hover,
.site-footer-socials a:focus-visible {
  border-color: var(--ink-rule-strong);
  background: var(--paper-wash);
}

.site-footer-socials svg {
  display: block;
  width: 16px;
  height: 16px;
  overflow: visible;
}

.site-footer-socials a:first-child svg {
  fill: currentColor;
}

.site-footer-socials a:not(:first-child) svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.45;
}

.site-footer-socials .site-footer-social-dot {
  fill: currentColor;
  stroke: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 560px) {
  :root {
    --container-gutter: clamp(24px, 6.5vw, 30px);
    --header-top: clamp(22px, 6vw, 28px);
    --header-height: 34px;
  }

  .brand {
    gap: 9px;
    font-size: clamp(21px, 5.7vw, 24px);
  }

  .brand-mark {
    height: var(--brand-mark-size-compact);
  }

  .masthead-nav {
    gap: clamp(12px, 4vw, 18px);
  }

  .nav-link {
    font-size: 12px;
  }

  /* THE MOBILE MASTHEAD: one brand, one useful route. The App Store status lockup repeats
   * the fold and turns the phone header into three competing weights. Desktop keeps it. */
  .app-store-badge {
    display: none;
  }

  .app-store-apple {
    font-size: 15px;
  }

  .app-store-lockup {
    gap: 0.5px;
  }

  .app-store-kicker {
    font-size: 5.5px;
  }

  .app-store-name {
    font-size: 10px;
  }

  .site-footer {
    padding: 48px 0 52px;
    font-size: 11px;
  }

  .site-footer-inner {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    row-gap: 28px;
  }

  .site-footer-brand-cluster {
    align-items: center;
    justify-self: center;
  }

  .site-footer-brand {
    font-size: 24px;
  }

  .site-footer-nav,
  .site-footer-socials {
    justify-self: center;
  }

  .site-footer-nav {
    gap: clamp(22px, 7vw, 30px);
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }

  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }

  .masthead,
  main,
  .hero-figure img {
    view-transition-name: none !important;
  }

  .nav-link::after,
  .site-footer-nav a::after {
    transform: scaleX(0) !important;
  }

  .nav-link:hover::after,
  .nav-link:focus-visible::after,
  .nav-link.is-active::after,
  .site-footer-nav a:hover::after,
  .site-footer-nav a:focus-visible::after {
    transform: scaleX(1) !important;
  }

  .app-store-badge:hover,
  .app-store-badge:focus-visible {
    transform: none;
  }

  ::view-transition-group(*),
  ::view-transition-image-pair(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}
