/* Advance Intelligence — daily deck for X.
   Direction: editorial wire desk. Warm paper canvas, serif headlines (our voice),
   X-look posts (the proof). X blue is reserved for links, progress and focus. */

@layer tokens, base, layout, components, motion;

@layer tokens {
  /* Dark is the default, whatever the device prefers. The toggle at the bottom of the page sets
     data-theme="light" on <html>; every colour below is a light-dark() pair, so they all follow. */
  :root {
    color-scheme: dark;

    --bg: light-dark(#f7f6f2, #0e0f10);
    --surface: light-dark(#ffffff, #16181a);
    --surface-2: light-dark(#efede7, #1d2023);
    --text: light-dark(#000000, #e7e9ea);
    --text-2: light-dark(#2b3640, #b9bec2);
    --muted: light-dark(#536471, #8b949b);
    --line: light-dark(#e1ded5, #2a2e32);
    --blue: #1d9bf0;                                   /* progress, accents */
    --link: light-dark(#0a6fae, #4fb3f5);              /* text links (4.5:1) */
    --adds: light-dark(#0b6b4a, #5fd3a6);
    --disputes: light-dark(#a8420a, #f0a46b);

    /* X's own palette for the post component */
    --x-bg: light-dark(#ffffff, #000000);
    --x-line: light-dark(#cfd9de, #2f3336);
    --x-text: light-dark(#0f1419, #e7e9ea);
    --x-grey: light-dark(#536471, #71767b);
    --x-blue: #1d9bf0;

    --font-display: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
    --font-text: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-x: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

    --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px; --s9: 96px;
    --r-sm: 6px; --r-md: 14px; --r-lg: 22px; --r-pill: 999px;

    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --spring: cubic-bezier(0.34, 1.35, 0.5, 1);
    --card-h: min(78dvh, 760px);
  }
  @supports (transition-timing-function: linear(0, 1)) {
    :root {
      --spring: linear(0, 0.18 4%, 0.55 9%, 0.9 15%, 1.06 21%, 1.07 25%, 1.02 32%, 0.995 40%, 1.003 52%, 1);
    }
  }
}

@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 400 1.0625rem/1.6 var(--font-text);
    -webkit-font-smoothing: antialiased;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }
  h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 400; line-height: 1.08; letter-spacing: -0.01em; text-wrap: balance; }
  p { margin: 0; text-wrap: pretty; }
  a { color: var(--link); text-underline-offset: 3px; text-decoration-thickness: 1px; }
  a:hover { text-decoration-thickness: 2px; }
  img, svg { display: block; max-width: 100%; }
  button, input { font: inherit; color: inherit; }
  :focus-visible { outline: 2px solid var(--link); outline-offset: 3px; border-radius: 4px; }
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .skip { position: absolute; left: var(--s4); top: -100px; background: var(--text); color: var(--bg); padding: var(--s2) var(--s4); border-radius: var(--r-sm); z-index: 50; }
  .skip:focus { top: var(--s2); }
  ::selection { background: color-mix(in oklab, var(--blue) 30%, transparent); }
}

@layer layout {
  .wrap { width: min(100% - 2 * var(--s4), 1120px); margin-inline: auto; }
  main { flex: 1; padding-block: var(--s6) var(--s8); }
  .head-left { display: flex; align-items: center; gap: var(--s3); min-width: 0; }

  .site-head { border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 20; }
  .site-head .wrap { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); min-height: 56px; }
  .brand { display: flex; align-items: baseline; gap: var(--s2); color: var(--text); text-decoration: none; font-family: var(--font-display); font-size: 1.5rem; line-height: 1; white-space: nowrap; }
  .nav { display: flex; gap: var(--s1); align-items: center; }
  .nav a { color: var(--text-2); text-decoration: none; font-size: 0.9375rem; font-weight: 500; padding: var(--s2) var(--s3); border-radius: var(--r-pill); min-height: 40px; display: inline-flex; align-items: center; }
  .nav a:hover { background: var(--surface-2); }
  .nav a[aria-current='page'] { color: var(--text); background: var(--surface-2); }
  .nav .nav-cta { background: var(--text); color: var(--bg); }
  .nav .nav-cta:hover { background: var(--text-2); }
  @media (max-width: 560px) {
    .brand { font-size: 1.3125rem; }
    .nav a { padding-inline: var(--s2); font-size: 0.875rem; }
    .nav .hide-sm { display: none; }
    main { padding-top: var(--s5); }
  }

  .site-foot { border-top: 1px solid var(--line); padding-block: var(--s6); color: var(--muted); font-size: 0.875rem; }
  .site-foot .wrap { display: grid; gap: var(--s3); }
  .site-foot a { color: var(--text-2); }
  .foot-links { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); }

  .page { max-width: 44rem; }
  .page h1 { font-size: clamp(2.25rem, 1.4rem + 3.5vw, 3.75rem); margin-bottom: var(--s4); }
  .page .lede { color: var(--text-2); font-size: 1.1875rem; max-width: 36rem; }

  /* Today: asymmetric. Rail on the left, deck on the right. */
  .today { display: grid; gap: var(--s5); }
  @media (min-width: 960px) {
    .today { grid-template-columns: 17rem minmax(0, 40rem); gap: var(--s8); align-items: start; }
    .rail { position: sticky; top: calc(56px + var(--s5)); }
  }
}

@layer components {
  .eyebrow { font: 600 0.75rem/1 var(--font-text); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

  /* ---------- Rail ---------- */
  .rail-date { font-family: var(--font-display); font-size: clamp(2.25rem, 1.5rem + 3vw, 3.5rem); line-height: 1; margin-block: var(--s3); }
  .rail-date .dow { color: var(--muted); font-style: italic; }
  .rail-meta { color: var(--text-2); font-size: 0.9375rem; display: grid; gap: var(--s1); }
  .scan { display: flex; gap: var(--s2); align-items: center; color: var(--muted); font-size: 0.8125rem; margin-top: var(--s4); }
  .scan::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); flex: none; }
  .jump { list-style: none; padding: 0; margin: var(--s5) 0 0; display: none; gap: 2px; counter-reset: j; }
  .jump button { all: unset; box-sizing: border-box; cursor: pointer; width: 100%; display: grid; grid-template-columns: 1.75rem 1fr; gap: var(--s2); padding: 6px var(--s2); border-radius: var(--r-sm); font-size: 0.875rem; line-height: 1.35; color: var(--muted); min-height: 32px; }
  .jump button::before { counter-increment: j; content: counter(j, decimal-leading-zero); font-variant-numeric: tabular-nums; color: var(--muted); }
  .jump button span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .jump button:hover { background: var(--surface-2); color: var(--text); }
  .jump button[aria-current='true'] { color: var(--text); background: var(--surface-2); }
  .jump button[aria-current='true']::before { color: var(--link); }
  .jump button:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
  .js .jump { display: grid; }
  .keys { margin-top: var(--s5); font-size: 0.8125rem; color: var(--muted); display: none; }
  .js .keys { display: block; }
  @media (max-width: 959px) { .js .jump, .js .keys { display: none; } }
  kbd { font: 500 0.75rem/1 var(--font-text); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 2px 6px; background: var(--surface); color: var(--text-2); }

  .sample-note { border: 1px dashed var(--muted); border-radius: var(--r-md); padding: var(--s3) var(--s4); font-size: 0.875rem; color: var(--text-2); margin-bottom: var(--s5); }
  .sample-note strong { color: var(--text); }
  .stale { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-md); padding: var(--s3) var(--s4); font-size: 0.875rem; color: var(--text-2); margin-bottom: var(--s4); }
  .stale[hidden] { display: none; }

  /* ---------- Progress ---------- */
  .progress { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
  .progress-bar { flex: 1; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
  .progress-fill { height: 100%; width: 100%; background: var(--blue); transform-origin: left; transform: scaleX(var(--p, 1)); transition: transform 0.5s var(--ease-out); }
  .mini-date { display: none; color: var(--text); }
  .mini-date b { font-weight: 700; }

  /* ---------- Deck (desktop: one card at a time) ---------- */
  .deck { position: relative; }
  .deck-stack { position: relative; z-index: 1; display: grid; gap: var(--s5); }
  .js .deck-stack { display: block; }
  @media (min-width: 768px) {
    .js .deck::before, .js .deck::after { content: ''; position: absolute; inset: 0 0 auto 0; height: var(--card-h); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); z-index: 0; }
    .js .deck::before { transform: translateY(10px) scale(0.965); opacity: 0.7; }
    .js .deck::after { transform: translateY(20px) scale(0.93); opacity: 0.4; }
    .js .deck.last::before, .js .deck.last::after { opacity: 0; }
    .js .card:not(.is-active) { display: none; }
  }
  .card { display: block; }
  html:not(.js) .card { margin-bottom: var(--s5); }

  /* ---------- The card: a real two-sided card ---------- */
  .card-scene { position: relative; height: var(--card-h); min-height: 30rem; perspective: 1800px; }
  html:not(.js) .card-scene { height: auto; min-height: 0; }
  .card-flip { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 0.8s cubic-bezier(0.3, 0.9, 0.3, 1); }
  html:not(.js) .card-flip { position: static; }
  .story-card.is-flipped .card-flip { transform: rotateY(180deg); }
  .story-card.no-anim .card-flip, .story-card.no-anim * { transition: none !important; animation: none !important; }
  .card-face {
    position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; min-width: 0;
    padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    box-shadow: 0 18px 44px rgb(0 0 0 / 0.08);
    backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden;
  }
  html:not(.js) .card-face { position: static; margin-bottom: var(--s4); }
  .card-back { transform: rotateY(180deg); }
  html:not(.js) .card-back { transform: none; }

  /* front: tag, headline (a link to the post), the post, details */
  .card-top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); font-size: 0.8125rem; color: var(--muted); }
  .rank { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
  .tag { border: 1px solid var(--line); border-radius: var(--r-pill); padding: 2px 10px; font-weight: 500; color: var(--text-2); background: var(--bg); }
  .sample-pill { font-size: 0.6875rem; letter-spacing: 0.06em; text-transform: uppercase; border: 1px solid var(--muted); border-radius: var(--r-pill); padding: 1px 8px; color: var(--muted); }
  .signal { color: var(--muted); font-size: 0.8125rem; }
  .headline { font-size: clamp(1.55rem, 1.05rem + 1.6vw, 2.1rem); flex: none; overflow-wrap: anywhere; }
  .headline a { color: var(--text); text-decoration: none; }
  .headline a:hover, .headline a:focus-visible { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 5px; }
  .headline .ext { display: inline-block; width: 0.5em; height: 0.5em; margin-left: 0.28em; vertical-align: 0.38em; color: var(--muted); }

  .tweet-area { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; border-radius: 16px; scrollbar-width: thin; }
  .front-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
  .details-btn { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 14px 0 18px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--bg); font-weight: 600; font-size: 0.9375rem; margin-left: auto; transition: background 0.15s, transform 0.15s, border-color 0.15s; }
  .share-btn { all: unset; box-sizing: border-box; cursor: pointer; flex: none; display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); transition: background 0.15s, transform 0.15s, border-color 0.15s; }
  .share-btn:hover { background: var(--surface-2); border-color: var(--muted); }
  .share-btn:active { transform: scale(0.94); }
  .share-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
  .share-btn svg { grid-area: 1 / 1; width: 20px; height: 20px; }
  .share-btn .share-done, .share-btn.is-done .share-icon { display: none; }
  .share-btn.is-done .share-done { display: block; color: var(--link); }
  .share-btn { position: relative; }
  .share-btn.is-done::after { content: 'Link copied'; position: absolute; left: 0; bottom: calc(100% + 10px); padding: 7px 12px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 0.8125rem; font-weight: 600; white-space: nowrap; pointer-events: none; animation: share-pop 0.18s ease-out; }
  @keyframes share-pop { from { opacity: 0; transform: translateY(4px); } }
  .details-btn:hover { background: var(--surface-2); border-color: var(--muted); }
  .details-btn:active { transform: scale(0.96); }
  .details-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
  .flip-icon { width: 24px; height: 24px; flex: none; transition: transform 0.5s var(--spring); transform-origin: 40% 50%; }
  .details-btn:hover .flip-icon { transform: perspective(60px) rotateY(-22deg); }

  /* ---------- Post: laid out like X's own post view ---------- */
  .post {
    margin: 0; display: grid; gap: 12px; min-width: 0; max-width: 100%;
    padding: 14px 16px 6px; border: 1px solid var(--x-line); border-radius: 16px;
    background: var(--x-bg); color: var(--x-text); font-family: var(--font-x);
  }
  .post-head { display: flex; align-items: center; gap: 12px; }
  .avatar-link { display: block; flex: none; text-decoration: none; }
  .avatar { width: 44px; height: 44px; border-radius: 50%; background: light-dark(#cfd9de, #333639); color: var(--x-text); display: grid; place-items: center; font: 700 0.9375rem/1 var(--font-x); overflow: hidden; flex: none; }
  .avatar img { width: 100%; height: 100%; max-width: none; object-fit: cover; }
  .who { display: grid; min-width: 0; flex: 1; line-height: 1.25; }
  .who .name { font-weight: 700; font-size: 1rem; color: var(--x-text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .who .handle { font-size: 0.9375rem; color: var(--x-grey); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .who a.name:hover { text-decoration: underline; }
  .x-logo { width: 22px; height: 22px; fill: var(--x-text); flex: none; align-self: flex-start; }
  .post-text { font-size: 1.0625rem; line-height: 1.4; color: var(--x-text); white-space: pre-line; overflow-wrap: anywhere; word-break: break-word; }
  .post-text a { color: var(--x-blue); text-decoration: none; }
  .post-text a:hover { text-decoration: underline; }
  .post-media { border-radius: 16px; overflow: hidden; border: 1px solid var(--x-line); background: light-dark(#eff3f4, #16181c); aspect-ratio: 16 / 9; display: grid; place-items: center; color: var(--x-grey); font-size: 0.8125rem; padding: var(--s4); text-align: center; }
  .post-media img { width: 100%; height: 100%; object-fit: cover; }
  .post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; color: var(--x-grey); font-size: 0.9375rem; padding-bottom: 12px; border-bottom: 1px solid var(--x-line); }
  .post-meta a, .post-meta .when { color: var(--x-grey); text-decoration: none; }
  .post-meta a:hover { text-decoration: underline; }
  .post-meta b { color: var(--x-text); font-weight: 700; }
  .actions { display: flex; align-items: center; gap: 4px 20px; flex-wrap: wrap; color: var(--x-grey); font-size: 0.875rem; font-variant-numeric: tabular-nums; margin: 0 -8px; }
  .actions .act:last-child:not(:first-child) { margin-left: auto; }
  .act { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 8px; color: inherit; text-decoration: none; border-radius: var(--r-pill); }
  .act svg { width: 19px; height: 19px; fill: currentColor; flex: none; }
  a.act:hover { color: var(--x-blue); background: color-mix(in oklab, var(--x-blue) 12%, transparent); }

  /* ---------- Back of the card: three parts, then the text ---------- */
  .card-back { gap: 10px; }
  .back-top { flex: none; display: flex; align-items: center; justify-content: space-between; }
  .back-btn { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding-right: 12px; font-weight: 600; color: var(--link); }
  .back-btn svg { width: 16px; height: 16px; }
  .back-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
  .back-count { font-size: 0.8125rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
  .back-panel { flex: 1; min-height: 0; min-width: 0; display: none; flex-direction: column; gap: 12px; }
  .back-panel.is-current { display: flex; }
  html:not(.js) .back-panel { display: flex; margin-bottom: var(--s4); }
  html:not(.js) .back-panel[data-panel='menu'], html:not(.js) .back-btn { display: none; }
  .back-title { font-family: var(--font-display); font-size: 1.45rem; line-height: 1.15; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
  .menu { list-style: none; margin: auto 0 0; padding: 0; display: grid; gap: 10px; }
  .menu button { all: unset; box-sizing: border-box; cursor: pointer; width: 100%; min-height: 64px; padding: 0 18px; border: 1px solid var(--line); border-radius: 16px; display: flex; align-items: center; justify-content: space-between; gap: var(--s3); font-weight: 600; font-size: 1.0625rem; background: var(--bg); transition: background 0.15s, border-color 0.15s, transform 0.15s; }
  .menu button:hover { background: var(--surface-2); border-color: var(--muted); }
  .menu button:active { transform: scale(0.98); }
  .menu button:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
  .menu svg { width: 18px; height: 18px; color: var(--muted); }
  .back-panel h3 { font-size: clamp(1.7rem, 1.3rem + 1.4vw, 2.1rem); flex: none; }
  .section-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 2px 8px 36px 0; display: grid; align-content: start; gap: 1em; color: var(--text-2); font-size: 1.0625rem; line-height: 1.65; overflow-wrap: anywhere; word-break: break-word; scrollbar-width: thin; -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 34px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 34px), transparent); }
  html:not(.js) .section-scroll { overflow: visible; -webkit-mask-image: none; mask-image: none; }
  .section-scroll p { color: var(--text-2); }
  .ctx-label { display: block; font: 600 0.75rem/1 var(--font-text); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: var(--s2); }
  .why { padding: 14px 16px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
  .why p { color: var(--text); font-weight: 500; }
  .sources ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
  .sources a { display: inline-flex; align-items: baseline; gap: 6px; font-size: 0.9375rem; }
  .sources .ext { width: 0.8em; height: 0.8em; flex: none; }

  .text-btn { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s3); font-weight: 600; color: var(--muted); border-radius: var(--r-pill); }
  .text-btn:hover { color: var(--text); }
  .text-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }

  .card-foot { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); align-items: center; padding-top: var(--s3); border-top: 1px solid var(--line); font-size: 0.875rem; }
  .card-foot a { color: var(--text-2); display: inline-flex; align-items: center; min-height: 32px; }

  /* ---------- Deck controls (desktop) ---------- */
  .controls { display: none; align-items: center; justify-content: space-between; gap: var(--s3); margin-top: var(--s6); }
  .js .controls { display: flex; }
  .btn { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 48px; padding: 0 var(--s5); border-radius: var(--r-pill); font-weight: 600; background: var(--text); color: var(--bg); transition: transform 0.15s, background 0.15s; text-decoration: none; }
  .btn:hover { background: var(--text-2); }
  .btn:active { transform: scale(0.97); }
  .btn:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
  .btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
  .btn.ghost:hover { background: var(--surface-2); }
  .btn[disabled] { opacity: 0.35; cursor: default; pointer-events: none; }
  .btn svg { width: 16px; height: 16px; flex: none; }

  /* ---------- End screen ---------- */
  .end-face { min-height: 22rem; display: flex; flex-direction: column; justify-content: center; gap: var(--s4); padding: var(--s6) var(--s5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: 0 18px 44px rgb(0 0 0 / 0.08); position: relative; overflow: hidden; }
  @media (min-width: 768px) { .end-face { height: var(--card-h); min-height: 30rem; } }
  .end h2 { font-size: clamp(2.25rem, 1.5rem + 3vw, 3.5rem); }
  .end p { color: var(--text-2); }
  .burst { position: relative; width: 64px; height: 64px; margin-bottom: var(--s2); }
  .burst svg { width: 64px; height: 64px; }
  .burst .ring { fill: none; stroke: var(--blue); stroke-width: 3; stroke-dasharray: 176; stroke-dashoffset: 176; }
  .burst .tick { fill: none; stroke: var(--text); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; }
  .burst i { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: var(--blue); opacity: 0; }
  .burst i:nth-of-type(3n) { background: var(--text); }
  .end.celebrate .ring { animation: draw 0.6s var(--ease-out) forwards; }
  .end.celebrate .tick { animation: draw 0.4s var(--ease-out) 0.4s forwards; }
  .end.celebrate .burst i { animation: pop 0.9s var(--ease-out) 0.45s forwards; }
  .end-links { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); font-size: 0.9375rem; }

  /* ---------- Archive ---------- */
  .day-list { list-style: none; padding: 0; margin: var(--s6) 0 0; display: grid; }
  .day-list > li { border-top: 1px solid var(--line); padding-block: var(--s5); display: grid; gap: var(--s3); justify-items: start; }
  .day-list > li:last-child { border-bottom: 1px solid var(--line); }
  .day-list > li[hidden] { display: none; }
  .day-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--s2) var(--s4); }
  .day-head h2 { font-size: 2.1rem; }
  .day-head h2 .dow { color: var(--muted); font-style: italic; }
  .day-head h2 small { font: 500 0.875rem var(--font-text); color: var(--muted); margin-left: 10px; }
  .day-head .count { font-size: 0.8125rem; color: var(--muted); }
  .bullets { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; color: var(--text-2); font-size: 1rem; line-height: 1.45; }
  .bullets li::marker { color: var(--blue); }
  .empty { padding-block: var(--s7) var(--s6); }
  .empty-links { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); margin-top: var(--s5); }
  .empty-note { margin-top: var(--s6); padding: var(--s5); border: 1px dashed var(--muted); border-radius: var(--r-md); color: var(--text-2); }
  .empty-note[hidden] { display: none; }

  /* ---------- Sources ---------- */
  .src-group { border-top: 1px solid var(--line); padding-block: var(--s5); display: grid; gap: var(--s3); }
  .src-group h2 { font-size: 1.75rem; }
  .src-group > p { color: var(--text-2); }
  .src-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s2); }
  .src-list li { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: var(--s3); align-items: center; }
  .src-list .avatar { width: 40px; height: 40px; font-size: 0.875rem; }
  .src-list .note { color: var(--muted); font-size: 0.875rem; }
  .src-list a, .src-list .name { font-weight: 600; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
  .src-list .handle { font-weight: 400; color: var(--muted); }

  /* ---------- Story page ---------- */
  .story { max-width: 42rem; display: grid; gap: var(--s5); }
  .story h1 { font-size: clamp(2.25rem, 1.4rem + 3.5vw, 3.5rem); }
  .story .back { font-size: 0.9375rem; }
  .story-section { display: grid; gap: var(--s3); color: var(--text-2); line-height: 1.65; }
  .story-section h2 { font-size: 1.6rem; color: var(--text); }
  .story .why { margin: 0; }

  /* ---------- Email (only when switched on in data/site.json) ---------- */
  /* The quiet subscribe ask: a small card in the left rail on wide screens, a one-line strip on phones. */
  .soft-ask { display: none; }
  .soft-ask .dismiss { all: unset; box-sizing: border-box; cursor: pointer; flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--muted); transition: background 0.15s, color 0.15s; }
  .soft-ask .dismiss:hover { background: var(--surface-2); color: var(--text); }
  .soft-ask .dismiss:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
  .soft-ask .dismiss svg { width: 16px; height: 16px; }
  .ask-rail { position: relative; margin-top: var(--s4); padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); gap: var(--s3); }
  .ask-rail.show { display: grid; animation: rise 0.5s var(--ease-out); }
  .ask-rail p { font-size: 0.9375rem; line-height: 1.4; color: var(--text-2); padding-right: 28px; }
  .ask-rail p b { display: block; color: var(--text); }
  .ask-rail .dismiss { position: absolute; top: 6px; right: 6px; }
  .ask-rail .email-form { gap: 0; }
  .ask-rail .email-form .row { flex-direction: column; flex-wrap: nowrap; }
  .ask-rail .email-form input[type='email'] { flex: none; width: 100%; min-height: 44px; }
  .ask-rail .email-form .btn { min-height: 44px; }
  .ask-rail .email-form .fine { display: none; }
  .ask-rail .email-form .status:empty { display: none; }
  .ask-rail .email-form .status { min-height: 0; margin-top: var(--s2); }
  .soft-ask .email-form input[type='email'], .end .email-form input[type='email'] { background: var(--bg); border-color: var(--line); }
  .soft-ask .email-form label, .end .email-form label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .end .email-form { max-width: 30rem; }
  .email-form.is-done > :not(.status) { display: none; }
  .email-form.is-done .status { font-size: 1rem; }
  .sub-points { list-style: none; padding: 0; margin: var(--s5) 0 0; display: grid; gap: var(--s2); max-width: 36rem; color: var(--text-2); }
  .sub-points li { position: relative; padding-left: var(--s5); }
  .sub-points li::before { content: ''; position: absolute; left: 4px; top: 0.6em; width: 7px; height: 7px; border-radius: 50%; background: var(--link); }
  .email-form { display: grid; gap: var(--s2); }
  .email-form .row { display: flex; gap: var(--s2); flex-wrap: wrap; }
  .email-form label { font-size: 0.875rem; font-weight: 600; }
  .email-form input[type='email'] { flex: 1 1 14rem; min-height: 48px; padding: 0 var(--s4); border-radius: var(--r-pill); border: 1px solid var(--muted); background: var(--surface); }
  .email-form input[type='email']:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
  .email-form .status { font-size: 0.875rem; min-height: 1.25em; color: var(--muted); }
  .email-form .status[data-state='error'] { color: var(--disputes); }
  .email-form .status[data-state='ok'] { color: var(--adds); font-weight: 600; }
  .email-form .fine { font-size: 0.8125rem; color: var(--muted); }
  .email-form button[disabled] { opacity: 0.6; }
  .vote { border: 0; padding: 0; margin: var(--s4) 0 0; display: grid; gap: var(--s2); }
  .vote legend { font-size: 0.875rem; font-weight: 600; padding: 0; margin-bottom: var(--s2); }
  .vote label { display: flex; align-items: center; gap: var(--s3); min-height: 44px; padding: 0 var(--s4); border: 1px solid var(--line); border-radius: var(--r-md); font-weight: 400; font-size: 1rem; cursor: pointer; background: var(--surface); }
  .vote label:has(input:checked) { border-color: var(--text); }
  .vote label.is-soon { color: var(--muted); cursor: not-allowed; background: transparent; }
  .vote label small { margin-left: auto; font-size: 0.75rem; color: var(--muted); }
  .vote input { accent-color: var(--text); width: 18px; height: 18px; }

  /* ---------- Niche picker (shown only with two or more niches) ---------- */
  .niche { position: relative; }
  .niche summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 var(--s3); border: 1px solid var(--line); border-radius: var(--r-pill); font-size: 0.875rem; font-weight: 600; background: var(--surface); }
  .niche summary::-webkit-details-marker { display: none; }
  .niche summary svg { width: 12px; height: 12px; }
  .niche-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); }
  .niche-pop { position: absolute; left: 0; top: calc(100% + 8px); width: min(22rem, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s3); box-shadow: 0 12px 40px rgb(0 0 0 / 0.14); z-index: 40; }
  .niche-pop ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
  .niche-pop li a, .niche-soon { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s2); border-radius: var(--r-sm); color: var(--text); text-decoration: none; min-height: 48px; }
  .niche-pop li span { display: grid; line-height: 1.3; }
  .niche-pop li small { color: var(--muted); font-size: 0.8125rem; }
  .niche-pop li em { font-style: normal; font-size: 0.75rem; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 2px 10px; flex: none; }
  .niche-foot { display: block; margin-top: var(--s2); padding: var(--s3) var(--s2) var(--s2); font-size: 0.875rem; border-top: 1px solid var(--line); }
}

/* ---------- First-visit tour. Opaque on purpose: nothing behind it competes. ---------- */
@layer components {
  .tour { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: grid; grid-template-rows: 1fr auto; padding: max(var(--s5), env(safe-area-inset-top)) var(--s5) max(var(--s5), env(safe-area-inset-bottom)); animation: fade-in 0.3s var(--ease-out); }
  .tour[hidden] { display: none; }
  .tour-body { display: grid; place-items: center; min-height: 0; }
  .tour-step { display: grid; justify-items: center; gap: var(--s4); text-align: center; max-width: 24rem; animation: rise 0.45s var(--ease-out); }
  .tour-step[hidden] { display: none; }
  .tour-step h2 { font-size: clamp(1.9rem, 1.4rem + 2vw, 2.4rem); }
  .tour-step p { color: var(--text-2); }
  .tour-nav { display: grid; gap: var(--s4); justify-items: center; width: min(100%, 24rem); margin-inline: auto; }
  .tour-btns { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); width: 100%; }
  .tour-btns .btn { min-width: 8rem; }
  .dots { display: flex; gap: 8px; }
  .dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background 0.2s, transform 0.2s; }
  .dots i.on { background: var(--blue); transform: scale(1.3); }
  @media (min-width: 768px) { .t-phone { display: none !important; } }
  @media (max-width: 767px) { .t-desk { display: none !important; } }

  .demo { position: relative; width: 190px; height: 230px; display: grid; place-items: center; margin-bottom: var(--s2); }
  .mock i, .dm i, .dm u, .mf i { display: block; height: 10px; border-radius: 5px; background: var(--line); text-decoration: none; }
  /* 1: swipe */
  .demo-swipe { width: 150px; height: 220px; overflow: hidden; border-radius: 24px; border: 2px solid var(--text); background: var(--surface); }
  .demo-swipe .mock { position: absolute; inset: 10px; border-radius: 16px; background: var(--bg); border: 1px solid var(--line); display: grid; align-content: start; gap: 10px; padding: 14px; }
  .demo-swipe .mock i:first-child { width: 40%; background: var(--blue); }
  .demo-swipe .mock i:nth-child(2) { height: 22px; }
  .demo-swipe .mock-a { animation: demo-out 2.4s var(--ease-out) infinite; }
  .demo-swipe .mock-b { animation: demo-in 2.4s var(--ease-out) infinite; }
  .demo-swipe .finger { position: absolute; left: 50%; bottom: 36px; width: 38px; height: 38px; margin-left: -19px; border-radius: 50%; background: var(--text); opacity: 0.85; animation: demo-finger 2.4s var(--ease-out) infinite; }
  .demo-keys { display: flex; gap: 14px; height: auto; }
  .demo-keys kbd { font-size: 1.6rem; padding: 14px 22px; border-bottom-width: 4px; animation: key-press 2.2s ease-in-out infinite; }
  .demo-keys kbd + kbd { animation-delay: 1.1s; }
  /* 2: flip */
  .demo-flip { perspective: 800px; }
  .mock-card { position: relative; width: 140px; height: 190px; transform-style: preserve-3d; animation: demo-flip 4.2s ease-in-out infinite; }
  .mf { position: absolute; inset: 0; border-radius: 16px; border: 2px solid var(--text); background: var(--surface); padding: 14px; display: grid; align-content: start; gap: 10px; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
  .mf-front i:first-child { height: 20px; }
  .mf-front b { position: absolute; right: 10px; bottom: 10px; font: 600 0.75rem var(--font-text); border: 1px solid var(--muted); border-radius: 999px; padding: 4px 10px; animation: pulse 1.4s ease-in-out infinite; }
  .mf-back { transform: rotateY(180deg); }
  .mf-back i { height: 22px; border-radius: 8px; border: 1px solid var(--muted); background: var(--bg); }
  /* 3: parts → text */
  .demo-menu { width: 190px; height: 210px; border-radius: 16px; border: 2px solid var(--text); background: var(--surface); overflow: hidden; }
  .dm { position: absolute; inset: 40px 14px 14px; display: grid; align-content: start; gap: 8px; }
  .dm-list i { height: 30px; border-radius: 8px; border: 1px solid var(--muted); background: var(--bg); font: 600 0.7rem/28px var(--font-text); font-style: normal; padding: 0 10px; text-align: left; color: var(--text); }
  .dm-list { animation: dm-list 6s ease-in-out infinite; }
  .dm-text { opacity: 0; animation: dm-text 6s ease-in-out infinite; }
  .dm-text u { height: 8px; }
  .dm-text u:nth-child(3n) { width: 70%; }
  .dm-back { position: absolute; left: 12px; top: 10px; font: 700 0.75rem var(--font-text); color: var(--link); animation: pulse 3s ease-in-out infinite; }
  /* 4: headline link */
  .demo-link { display: flex; align-items: center; justify-content: center; gap: 18px; height: auto; }
  .dl-title { white-space: nowrap; font-family: var(--font-display); font-size: 1.7rem; line-height: 1.1; text-decoration: underline; text-underline-offset: 5px; }
  .dl-title span { color: var(--muted); display: inline-block; animation: nudge 1.6s ease-in-out infinite; }
  .dl-x { width: 54px; height: 54px; border-radius: 14px; background: var(--x-bg); border: 1px solid var(--x-line); display: grid; place-items: center; }
  .dl-x svg { width: 26px; height: 26px; fill: var(--x-text); }
}

@layer motion {
  @keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes draw { to { stroke-dashoffset: 0; } }
  @keyframes pop {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.4); }
  }
  @keyframes slide-next { from { opacity: 0; transform: translateY(28px) scale(0.97); } to { opacity: 1; transform: none; } }
  @keyframes slide-prev { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
  .card.enter-next { animation: slide-next 0.5s var(--ease-out); }
  .card.enter-prev { animation: slide-prev 0.4s var(--ease-out); }

  /* Back of the card: the parts vanish, then the text appears (and the reverse). */
  @keyframes vanish { to { opacity: 0; filter: blur(5px); transform: translateY(-8px) scale(0.98); } }
  @keyframes appear { from { opacity: 0; filter: blur(6px); transform: translateY(10px) scale(0.985); } to { opacity: 1; filter: none; transform: none; } }
  .back-panel.is-leaving .anim-item, .back-panel.is-leaving .menu li { animation: vanish 0.24s ease-in both; animation-delay: calc(var(--i, 0) * 35ms); }
  .back-panel.is-entering .anim-item, .back-panel.is-entering .menu li { animation: appear 0.5s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms + 40ms); }
  .back-panel.is-entering .section-scroll > * { animation: appear 0.55s var(--ease-out) both; animation-delay: calc(var(--n, 0) * 70ms + 180ms); }

  /* Tour demos */
  @keyframes demo-out { 0%, 20% { transform: none; opacity: 1; } 55%, 100% { transform: translateY(-110%); opacity: 0; } }
  @keyframes demo-in { 0%, 20% { transform: translateY(110%); } 55%, 100% { transform: none; } }
  @keyframes demo-finger { 0%, 12% { transform: translateY(40px) scale(1); opacity: 0; } 22% { transform: translateY(30px) scale(0.9); opacity: 0.85; } 55% { transform: translateY(-110px) scale(0.9); opacity: 0.85; } 70%, 100% { transform: translateY(-120px) scale(1); opacity: 0; } }
  @keyframes key-press { 0%, 70%, 100% { transform: none; border-bottom-width: 4px; } 80% { transform: translateY(3px); border-bottom-width: 1px; background: var(--surface-2); } }
  @keyframes demo-flip { 0%, 18% { transform: rotateY(0); } 36%, 82% { transform: rotateY(180deg); } 100% { transform: rotateY(360deg); } }
  @keyframes pulse { 0%, 100% { background: transparent; } 50% { background: color-mix(in oklab, var(--blue) 26%, transparent); } }
  @keyframes dm-list { 0%, 30% { opacity: 1; transform: none; filter: none; } 40%, 80% { opacity: 0; transform: translateY(-8px); filter: blur(4px); } 90%, 100% { opacity: 1; transform: none; filter: none; } }
  @keyframes dm-text { 0%, 38% { opacity: 0; transform: translateY(8px); filter: blur(4px); } 50%, 76% { opacity: 1; transform: none; filter: none; } 86%, 100% { opacity: 0; } }
  @keyframes nudge { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(4px, -4px); } }

  /* On phones, each card eases in as it scrolls into view (where the browser supports it). */
  @supports (animation-timeline: view()) {
    @media (max-width: 767px) {
      .js .story-card .card-scene { animation: card-enter linear both; animation-timeline: view(block); animation-range: entry 0% entry 90%; }
      @keyframes card-enter { from { opacity: 0.35; transform: scale(0.94); } to { opacity: 1; transform: none; } }
    }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; transition-delay: 0s !important; }
    .burst .ring, .burst .tick { stroke-dashoffset: 0; }
    .burst i { display: none; }
    .demo-swipe .mock-a { opacity: 0; }
    .demo-swipe .finger { opacity: 0.85; transform: translateY(-60px); }
    .dm-text { opacity: 1; }
    .dm-list { display: none; }
  }
}

/* ---------- Phone: one story per screen. Swipe up for the next, down for the one before. ---------- */
@layer components {
  @media (max-width: 767px) {
    .js .is-deck { height: 100dvh; overflow: hidden; }
    .is-deck main { padding: 0; }
    .is-deck main > .wrap { width: 100%; max-width: none; }
    .is-deck .site-foot { display: none; }
    .js .today { display: block; }
    .js .rail, .js .sample-note, .js .controls { display: none; }
    /* "No new deck yet today": one slim line under the header. The deck gives up exactly its height. */
    .js .stale { display: flex; align-items: center; gap: var(--s2); height: 32px; margin: 0; padding: 0 var(--s4); border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: var(--surface); font-size: 0.8125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .js .stale::before { content: ''; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
    .js .stale[hidden] { display: none; }
    .js .progress { height: 44px; margin: 0; padding: 0 var(--s4); border-bottom: 1px solid var(--line); background: var(--bg); }
    .js .mini-date { display: inline; }
    .js .deck { --deck-h: calc(100dvh - 104px); height: var(--deck-h); overflow-y: auto; overscroll-behavior-y: contain; scroll-snap-type: y mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .js.has-stale .deck { --deck-h: calc(100dvh - 137px); }
    .js .deck::-webkit-scrollbar { display: none; }
    .js .deck-stack { display: block; }
    .js .card { height: var(--deck-h); padding: 10px 12px 14px; scroll-snap-align: start; scroll-snap-stop: always; }
    .js .card-scene { height: 100%; min-height: 0; }
    .js .card-face { padding: 16px; box-shadow: 0 10px 28px rgb(0 0 0 / 0.1); }
    .js .headline { font-size: 1.55rem; }
    .js .post { padding: 12px 14px 4px; }
    .js .post-text { font-size: 1rem; }
    .js .end .end-face { height: 100%; min-height: 0; overflow: auto; }
    .js .card.enter-next, .js .card.enter-prev { animation: none; }
    .js.has-ask .deck { --deck-h: calc(100dvh - 149px); }
    .js.has-ask.has-stale .deck { --deck-h: calc(100dvh - 182px); }
    .js .ask-strip.show { display: flex; align-items: center; gap: var(--s2); height: 44px; padding: 0 var(--s1) 0 var(--s4); border-bottom: 1px solid var(--line); background: var(--surface); font-size: 0.8125rem; color: var(--text-2); }
    .ask-strip span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .ask-strip .ask-go { flex: none; display: inline-flex; align-items: center; height: 30px; padding: 0 var(--s3); border-radius: var(--r-pill); background: var(--text); color: var(--bg); font-weight: 600; text-decoration: none; }
    .niche-pop { position: fixed; left: var(--s4); right: var(--s4); top: 60px; width: auto; }
  }
}

@layer components {
  /* The X logo in the corner of a post opens that post on X. 40px target, 22px logo. */
  .x-link { flex: none; display: grid; place-items: center; width: 40px; height: 40px; margin: -9px -9px 0 0; align-self: flex-start; border-radius: 50%; text-decoration: none; transition: background 0.15s; }
  .x-link:hover { background: color-mix(in oklab, var(--x-blue) 14%, transparent); }
  .x-link:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
  .x-link .x-logo { align-self: auto; }
}

/* ---------- Theme: dark by default, light on request ---------- */
@layer tokens {
  :root[data-theme='light'] { color-scheme: light; }
}
@layer components {
  .theme-toggle { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: var(--s2); min-height: 40px; padding: 0 var(--s4) 0 var(--s3); border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); color: var(--text-2); font-size: 0.875rem; font-weight: 500; transition: background 0.15s, border-color 0.15s, color 0.15s; }
  .theme-toggle:hover { background: var(--surface-2); border-color: var(--muted); color: var(--text); }
  .theme-toggle:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
  .theme-toggle svg { width: 18px; height: 18px; flex: none; }
  .theme-toggle .icon-sun { display: none; }
  [data-theme='light'] .theme-toggle .icon-moon { display: none; }
  [data-theme='light'] .theme-toggle .icon-sun { display: block; }
  .end-theme { display: flex; }
}
