/* Layout: one serif reading column on warm white. Labels and the portrait hang in a
   rail to its left, blue-pencil notes hang in the margin to its right; both fold into
   the column below 1160px. */
:root {
  color-scheme: light;
  --paper: #fdfbf6;   /* a warm white that suits the portrait's palette */
  --ink: #17150f;
  --text: #2f2c26;
  --muted: #6e6a60;
  --hair: #e7e3d9;
  --pencil: #2f50d8;
  --pencil-wash: rgba(47, 80, 216, 0.07);
  --pencil-sel: rgba(47, 80, 216, 0.15);
  --pencil-line: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 16' preserveAspectRatio='none'%3E%3Cpath d='M3 10.4C34 7.2 78 11.6 128 8.6S222 5.6 297 9.2' fill='none' stroke='%232f50d8' stroke-width='2.2' stroke-linecap='round' vector-effect='non-scaling-stroke' opacity='.92'/%3E%3Cpath d='M26 13.6C92 11.2 176 14.4 282 11.4' fill='none' stroke='%232f50d8' stroke-width='1.5' stroke-linecap='round' vector-effect='non-scaling-stroke' opacity='.55'/%3E%3C/svg%3E");

  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Schibsted Grotesk", "Helvetica Neue", Helvetica, Arial, sans-serif;

  --fs-label: 0.75rem;
  --fs-small: 0.875rem;
  --fs-body: 1.1875rem;
  --fs-h3: 1.5rem;
  --fs-item: clamp(1.4375rem, 2.8vw, 1.75rem);
  --fs-deck: clamp(1.3125rem, 2.4vw, 1.5rem);
  --fs-hello: clamp(1.875rem, 4.4vw, 2.625rem);
  --fs-title: clamp(2.5rem, 6.2vw, 4rem);

  --col: 36rem;
  --rail: 10rem;
  --rail-gap: 3rem;
  --margin: 13rem;
  --margin-gap: 3rem;
  --ease: cubic-bezier(0.2, 0.75, 0.2, 1);
  --gutter: clamp(20px, 5vw, 48px);   /* side padding of the page */
}

/* ---------- Base ---------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding-inline: var(--gutter);
  background: var(--paper);
  color: var(--text);
  font: 400 var(--fs-body)/1.6 var(--serif);
  font-optical-sizing: auto;
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--pencil-sel); color: var(--ink); }

a { color: inherit; }
img { max-width: 100%; }

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

.skip {
  position: absolute;
  left: 12px;
  top: -60px;
  padding: 8px 12px;
  background: var(--ink);
  color: var(--paper);
  font: 500 var(--fs-small)/1 var(--sans);
  text-decoration: none;
  border-radius: 4px;
  z-index: 10;
}
.skip:focus { top: calc(12px + env(safe-area-inset-top, 0px)); }

.sheet {
  max-width: var(--col);
  margin-inline: auto;
}

.label {
  font: 600 var(--fs-label)/1.35 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: lining-nums tabular-nums;
}

/* Rail: labels sit above their block on narrow screens and hang left on wide ones. */
.has-rail { position: relative; }
.rail { margin: 0 0 14px; }

/* ---------- Masthead & footer ---------- */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding-block: 28px 0;
  view-transition-name: masthead;
}

.wordmark {
  font: italic 400 1.375rem/1 var(--serif);
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  transition: color 0.2s;
}
.wordmark:hover { color: var(--pencil); }

.mast-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px 18px;
}

.mast-link {
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s;
}
.mast-link:hover { color: var(--pencil); }

.foot {
  margin-top: clamp(96px, 14vh, 144px);
  padding-block: 22px 44px;
  border-top: 1px solid var(--hair);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  font: 400 var(--fs-small)/1.5 var(--sans);
  color: var(--muted);
  font-variant-numeric: lining-nums;
}
.foot p { margin: 0; }
.foot a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--hair);
  text-underline-offset: 3px;
}
.foot a:hover { color: var(--pencil); text-decoration-color: currentColor; }

/* ---------- Home ---------- */

.intro {
  position: relative;
  padding-block: clamp(56px, 10vh, 104px) clamp(56px, 9vh, 96px);
}

/* Phones: no room beside the column, so the portrait sits above the greeting,
   its ear on the column edge. */
.portrait {
  display: block;
  width: 57px;
  height: auto;
  margin: 0 0 20px -6px;

  /* A sticker you can poke: grounded at the chin, springy on hover, one nod on load.
     The squish on click is in site.js. */
  transform-origin: 50% 92%;
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.55s cubic-bezier(0.34, 1.8, 0.5, 1);
  animation: portrait-nod 0.9s 0.8s ease-in-out;
}
@media (hover: hover) {
  .portrait:hover { transform: translateY(-3px) rotate(-2deg) scale(1.05); }
}

@keyframes portrait-nod {
  0%   { transform: none; }
  35%  { transform: rotate(-5deg) translateY(2px); }
  68%  { transform: rotate(2deg); }
  100% { transform: none; }
}

/* From 760px the portrait hangs in the left margin, so the greeting starts on the same
   edge as everything else. It grows with the margin up to 96px; about 16% of the image
   is whitespace right of the ear, hence the offset. */
@media (min-width: 760px) {
  .portrait {
    --pw: clamp(48px, calc(((100vw - var(--col)) / 2 - 60px) * 0.75), 96px);
    --gap: 40px;
    position: absolute;
    top: clamp(56px, 10vh, 104px);
    right: calc(100% + var(--gap) - 0.16 * var(--pw));
    width: var(--pw);
    margin: 0;
  }
}

.hello {
  margin: 0;
  font: 400 var(--fs-hello)/1.2 var(--serif);
  letter-spacing: -0.018em;
  color: var(--ink);
  text-wrap: balance;
}
.hello .soft { color: var(--muted); }

.posts {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--hair);
}
.posts li { border-bottom: 1px solid var(--hair); }

.post-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto 0fr;
  align-items: baseline;
  column-gap: 24px;
  padding-block: 20px 22px;
  color: var(--ink);
  text-decoration: none;
  transition: grid-template-rows 0.45s var(--ease);
}

.post-title {
  font: 400 var(--fs-item)/1.22 var(--serif);
  letter-spacing: -0.016em;
  text-wrap: balance;
  width: fit-content;
  transition: color 0.25s;
}

.post-date {
  font: 500 var(--fs-label)/1 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: lining-nums tabular-nums;
  white-space: nowrap;
}

.post-dek {
  grid-column: 1 / -1;
  min-height: 0;
  overflow: hidden;
}
.post-dek > span {
  display: block;
  max-width: 30em;
  padding-top: 8px;
  font: italic 400 1.0625rem/1.45 var(--serif);
  color: var(--text);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.35s var(--ease), transform 0.45s var(--ease);
}

@media (hover: hover) {
  .post-link:hover,
  .post-link:focus-visible { grid-template-rows: auto 1fr; }
  .post-link:hover .post-dek > span,
  .post-link:focus-visible .post-dek > span { opacity: 1; transform: none; }
  .post-link:hover .post-date,
  .post-link:focus-visible .post-date { color: var(--pencil); }
}
@media (hover: none) {
  .post-link { grid-template-rows: auto 1fr; }
  .post-dek > span { opacity: 1; transform: none; }
}

.post-link:focus-visible { outline-offset: 6px; }

.about a, .piece-body a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in srgb, var(--muted) 55%, transparent);
  transition: color 0.2s, text-decoration-color 0.2s;
}
.about a:hover, .piece-body a:hover { color: var(--pencil); text-decoration-color: currentColor; }

/* ---------- Article ---------- */

.piece-head { padding-block: clamp(56px, 10vh, 104px) 0; }

.kicker { margin: 0 0 18px; }

/* A mark beside the title, sized to the title's own type. */
.title-row { display: flex; align-items: baseline; gap: 0.2em; font-size: var(--fs-title); }
/* Sits on the text baseline; the small negative margin cancels the empty strip at the foot of the artwork. */
.title-row .logo { height: 0.74em; width: auto; flex: none; margin: 0 0 -0.04em -0.02em; }
.title-row .p-title { margin-left: 0; }

.p-title {
  margin: 0 0 0 -0.03em;
  font: 400 var(--fs-title)/1.04 var(--serif);
  letter-spacing: -0.032em;
  color: var(--ink);
  text-wrap: balance;
}

.deck {
  margin: 22px 0 0;
  max-width: 28em;
  font: italic 400 var(--fs-deck)/1.38 var(--serif);
  color: var(--text);
  text-wrap: balance;
}

.byline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 26px 0 0;
  font: 400 var(--fs-small)/1.4 var(--sans);
  color: var(--muted);
  font-variant-numeric: lining-nums;
}
.byline img {
  width: 40px;
  height: auto;
  margin: -6px 2px -6px -6px;
}
.byline strong { font-weight: 500; color: var(--ink); }

.facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 20px;
  margin: 40px 0 0;
  padding-block: 16px 18px;
  border-block: 1px solid var(--hair);
}
.facts div { min-width: 0; }
.facts dt { margin: 0; }
.facts dd {
  margin: 6px 0 0;
  font: 400 0.9375rem/1.4 var(--sans);
  color: var(--ink);
  font-variant-numeric: lining-nums proportional-nums;
}
.facts .asof {
  display: block;
  margin-top: 2px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.piece-body { margin-top: 80px; }

.sec { position: relative; }
.sec + .sec { margin-top: 56px; }

.piece-body p {
  margin: 0 0 1em;
  text-wrap: pretty;
  hanging-punctuation: first allow-end;
}
.piece-body p:last-child { margin-bottom: 0; }
.piece-body strong { font-weight: 600; color: var(--ink); }

/* Definition labels written in content files share the label style. */
.bet-meta dt, .measures dt {
  font: 600 var(--fs-label)/1.35 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Bets */
.sec p + .bets { margin-top: 36px; }
.bets {
  list-style: none;
  counter-reset: bet;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 48px;
}
.bet { counter-increment: bet; position: relative; }
.bet::before {
  content: counter(bet);
  display: block;
  margin-bottom: 6px;
  font: italic 400 2.25rem/1 var(--serif);
  color: var(--pencil);
  font-variant-numeric: lining-nums;
}
.bet h3 {
  margin: 0 0 12px;
  font: 500 var(--fs-h3)/1.25 var(--serif);
  letter-spacing: -0.014em;
  color: var(--ink);
  text-wrap: balance;
}

.bet-meta {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--hair);
  font: 400 0.9375rem/1.5 var(--sans);
}
.bet-meta div {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 12px;
}
.bet-meta dt { padding-top: 0.2em; }
.bet-meta dd { margin: 0; color: var(--text); }

/* Measures */
.measures {
  margin: 0;
  border-top: 1px solid var(--hair);
}
.measures div {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr);
  gap: 16px;
  padding-block: 14px;
  border-bottom: 1px solid var(--hair);
}
.measures dt { padding-top: 0.45em; }
.measures dd { margin: 0; }
.measures .ns dt { color: var(--pencil); }
.measures .ns dd { color: var(--ink); }

/* Margin notes */
.mn-ref {
  appearance: none;
  border: 0;
  margin: 0 0 0 0.08em;
  padding: 0 0.2em;
  background: none;
  font: 600 0.6875rem/1 var(--sans);
  color: var(--pencil);
  vertical-align: super;
  font-variant-numeric: lining-nums;
  cursor: pointer;
  border-radius: 3px;
  transition: background-color 0.2s;
}
.mn-body {
  display: none;
  font: italic 400 1rem/1.5 var(--serif);
  color: var(--pencil);
  text-wrap: pretty;
}
.mn-n {
  margin-right: 0.45em;
  font: 600 0.6875rem/1 var(--sans);
  font-style: normal;
  vertical-align: 0.15em;
}
.mn.is-open .mn-body {
  display: block;
  margin: 0.7em 0 0.9em;
  padding-left: 1em;
  border-left: 2px solid var(--pencil);
}
.mn.is-open .mn-ref, .mn-ref:hover { background: var(--pencil-wash); }

/* Pencil underline: a two-stroke mark that draws itself once it scrolls into view. */
.pencil {
  color: var(--ink);
  padding: 0 0.08em 0.24em;
  margin: 0 -0.08em;
  background-image: linear-gradient(var(--paper), var(--paper)), var(--pencil-line);
  background-repeat: no-repeat;
  background-position: right bottom, left bottom;
  background-size: 0% 0.78em, 100% 0.78em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
html.js .pencil {
  background-size: 100% 0.78em, 100% 0.78em;
  transition: background-size 1.3s cubic-bezier(0.6, 0.05, 0.25, 1) 0.15s;
}
html.js .pencil.is-drawn { background-size: 0% 0.78em, 100% 0.78em; }

/* Article footer */
.piece-foot { margin-top: 80px; }

.disclaimer {
  margin: 0;
  padding-top: 18px;
  border-top: 1px solid var(--hair);
  font: italic 400 1rem/1.5 var(--serif);
  color: var(--muted);
}

.sources { margin-top: 28px; }
.sources ol {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  font: 400 var(--fs-small)/1.5 var(--sans);
}
.sources a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--hair);
  text-underline-offset: 3px;
}
.sources a:hover { color: var(--pencil); text-decoration-color: currentColor; }

.piece-next {
  display: grid;
  gap: 6px;
  margin-top: 56px;
  padding-block: 24px 26px;
  border-block: 1px solid var(--hair);
  color: var(--ink);
  text-decoration: none;
}
.pn-title {
  font: 400 var(--fs-item)/1.22 var(--serif);
  letter-spacing: -0.016em;
  text-wrap: balance;
  width: fit-content;
}
.pn-dek {
  font: italic 400 1.0625rem/1.45 var(--serif);
  color: var(--muted);
  max-width: 30em;
  transition: color 0.25s;
}
.piece-next:hover .pn-dek { color: var(--text); }
.piece-next:hover .label { color: var(--pencil); }

/* Figures: images sit in the reading column; screenshots that need room break out of it. */
.fig { margin: 2.25rem 0; }
.fig img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}
.fig figcaption {
  margin-top: 10px;
  font: 400 0.8125rem/1.45 var(--sans);
  color: var(--muted);
}
.fig-framed img { border: 1px solid var(--hair); }
.fig video {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1152 / 862;
  border-radius: 8px;
  background: var(--hair);
}
.fig video[data-playing] { cursor: pointer; }

/* Wider than the column: centered on it, capped at 62rem, never closer than the gutter. */
.fig-wide, .fig-mid {
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}
.fig-wide { width: min(62rem, calc(100vw - 2 * var(--gutter))); }
.fig-mid  { width: min(44rem, calc(100vw - 2 * var(--gutter))); }

.fig-narrow { max-width: 28rem; margin-inline: auto; }

/* Phone screenshots, side by side. */
.phones {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.phones img { border-radius: 14px; }

/* Strip of the mascot pattern that opens the article. */
.fig-banner { margin: 0 0 56px; }

@media (max-width: 760px) {
  /* The dashboard keeps its size and scrolls sideways inside its own box. */
  .fig-scroll { overflow-x: auto; border-radius: 8px; }
  .fig-scroll img { width: 720px; max-width: none; }
  /* Phones become a swipeable row. */
  .phones {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
  }
  .phones > * { flex: 0 0 56%; width: 56%; min-width: 0; scroll-snap-align: start; }
}

/* 404 */
.lost { padding-block: clamp(56px, 10vh, 104px) 0; }
.lost .hello { margin-bottom: 20px; }
.lost code {
  font: 400 0.95em/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink);
  word-break: break-all;
}

/* ---------- Narrow screens ---------- */

@media (max-width: 640px) {
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .measures div, .bet-meta div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .measures dt, .bet-meta dt { padding-top: 0; }
}

/* ---------- Wide screens: open the rail and the margin ---------- */

@media (min-width: 1160px) {
  .rail {
    position: absolute;
    top: 0.62rem;
    left: calc(-1 * (var(--rail) + var(--rail-gap)));
    width: var(--rail);
    margin: 0;
    text-align: right;
  }
  .writing .rail { top: 1.85rem; }

  /* With the rail open, the portrait's ear lines up with the rail labels. */
  .portrait { --pw: 96px; --gap: var(--rail-gap); }

  .bet::before {
    position: absolute;
    top: -0.1rem;
    right: calc(100% + var(--rail-gap));
    margin: 0;
    font-size: 2.75rem;
  }

  .mn-ref { cursor: default; }
  .mn-body {
    display: block;
    float: right;
    clear: right;
    position: relative;
    width: var(--margin);
    margin: 0.35em calc(-1 * (var(--margin) + var(--margin-gap))) 0 0;
    padding: 6px 8px;
    font-size: 0.9375rem;
    line-height: 1.45;
    border-radius: 4px;
    transition: background-color 0.25s;
  }
  .mn.is-open .mn-body { margin: 0.35em calc(-1 * (var(--margin) + var(--margin-gap))) 0 0; padding: 6px 8px; border-left: 0; }
  .mn.is-hot .mn-body, .mn.is-hot .mn-ref { background: var(--pencil-wash); }
}

/* ---------- Page transitions ---------- */

@view-transition { navigation: auto; }

::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.28s; }

::view-transition-group(*) {
  animation-duration: 0.55s;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
