@layer reset, base, chrome, components, work, utilities;

/* Cross-document view transitions: the name mark stays put while the rest
   crosses over, so moving through the site reads as one instrument. */
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root), ::view-transition-new(root) {
    animation-duration: var(--d-page);
    animation-timing-function: var(--ease-out);
  }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ══ reset ══════════════════════════════════════════════════════════ */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; }
  body { min-height: 100dvh; -webkit-font-smoothing: antialiased; }
  img, svg, video, canvas { display: block; max-width: 100%; }
  img, video { height: auto; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { background: none; border: 0; padding: 0; cursor: pointer; }
  p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
  ul, ol { list-style: none; padding: 0; }
  table { border-collapse: collapse; width: 100%; }
  dialog { color: inherit; }
  [hidden] { display: none !important; }
}

/* ══ base ═══════════════════════════════════════════════════════════ */
@layer base {
  html { scroll-behavior: smooth; }
  @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

  body {
    background: var(--ground);
    color: var(--ink);
    font-family: var(--ui);
    font-size: var(--t-body);
    line-height: var(--lh-body);
    font-variant-numeric: tabular-nums;
  }

  h1, h2, h3, h4 { font-weight: 600; line-height: var(--lh-snug);
    letter-spacing: -0.022em; text-wrap: balance; }
  p, figcaption, .work-line, .proof-row span, .card-line, .room-line, .row .sub { text-wrap: pretty; }

  a { color: var(--accent); text-decoration-line: underline;
      text-decoration-thickness: 1px; text-underline-offset: 3px;
      text-decoration-color: color-mix(in srgb, var(--accent) 34%, transparent);
      transition: text-decoration-color var(--d-hover) ease, color var(--d-hover) ease; }
  @media (hover: hover) and (pointer: fine) {
    a:hover { text-decoration-color: currentColor; color: var(--accent-2); }
  }

  :focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: var(--r-sm); }
  :focus:not(:focus-visible) { outline: none; }

  ::selection { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--ink); }

  [id] { scroll-margin-top: calc(var(--nav-h, 64px) + var(--s6)); }

  .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0.005em; }
  .hand { font-family: var(--hand); font-weight: 600; }
}

/* ══ chrome ═════════════════════════════════════════════════════════ */
@layer chrome {
  :root { --nav-h: 64px; }

  .skip {
    position: absolute; left: var(--s4); top: var(--s4); z-index: 100;
    padding: var(--s3) var(--s4); background: var(--paper); color: var(--ink);
    border: 1px solid var(--rule); border-radius: var(--r-md);
    box-shadow: var(--shadow-lift); transform: translateY(-200%);
  }
  .skip:focus { transform: none; }

  .wrap { width: 100%; max-width: var(--container); margin-inline: auto;
          padding-inline: max(var(--gutter), env(safe-area-inset-left)); }
  .wrap-wide { max-width: var(--wide); }

  /* ── masthead ─────────────────────────────────────────────────── */
  .masthead {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--ground) 88%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--rule-soft);
  }
  @supports not (backdrop-filter: blur(1px)) { .masthead { background: var(--ground); } }

  .masthead > .wrap { min-height: var(--nav-h); display: flex; align-items: center; gap: var(--s5); }

  .namemark {
    view-transition-name: namemark;
    display: inline-flex; align-items: center; gap: var(--s3);
    font-size: 1rem; font-weight: 600; letter-spacing: -0.018em;
    color: var(--ink); text-decoration: none; margin-right: auto;
    white-space: nowrap; padding-block: var(--s2);
  }
  .namemark:hover { text-decoration: none; color: var(--ink); }

  /* the mark: a rounded indigo square split into two halves — design and
     system — and the same device as the favicon */
  .glyph { width: 26px; height: 26px; flex: none; border-radius: 7px; }
  .glyph .bg { fill: var(--accent); }
  .glyph .half { fill: rgba(255 255 255 / 0.95); }
  .glyph .split { stroke: rgba(255 255 255 / 0.55); stroke-width: 1; }

  .nav { display: flex; align-items: center; gap: var(--s1); }
  .nav a, .nav button {
    display: inline-flex; align-items: center; gap: var(--s2);
    min-height: 38px; padding-inline: var(--s3);
    border-radius: var(--r-md); font-size: var(--t-small); font-weight: 500;
    color: var(--ink-2); text-decoration: none; position: relative;
    transition: color var(--d-hover) ease, background-color var(--d-hover) ease,
                transform var(--d-press) var(--ease-out);
  }
  @media (hover: hover) and (pointer: fine) {
    .nav a:hover, .nav button:hover { color: var(--ink); background: var(--paper-3); }
  }
  .nav a[aria-current] { color: var(--ink); font-weight: 600; }
  .nav a[aria-current]::after {
    content: ""; position: absolute; inset-inline: var(--s3); bottom: -1px;
    height: 2px; border-radius: 2px; background: var(--accent);
  }
  .nav .icon-btn { min-width: 38px; justify-content: center; padding-inline: var(--s2); }
  #theme-toggle .t-dark { display: none; }
  #theme-toggle .t-light { display: inline-flex; }
  [data-theme="dark"] #theme-toggle .t-dark { display: inline-flex; }
  [data-theme="dark"] #theme-toggle .t-light { display: none; }
  .nav svg { width: 16px; height: 16px; }

  @media (pointer: coarse) {
    .nav a, .nav button { min-height: 44px; }
    .nav .icon-btn { min-width: 44px; }
    .toc a { min-height: 44px; align-items: center; }
  }

  .kbd {
    font-family: var(--mono); font-size: 0.6875rem; color: var(--ink-2);
    border: 1px solid var(--rule); border-radius: var(--r-sm);
    background: var(--paper-2); padding: 1px 5px; line-height: 1.5;
  }
  @media (max-width: 760px) { .nav .kbd { display: none; } }

  /* ── footer ───────────────────────────────────────────────────── */
  .sitefoot { margin-top: var(--section-gap); border-top: 1px solid var(--rule-soft);
    padding-block: var(--s8); padding-bottom: max(var(--s8), env(safe-area-inset-bottom)); }
  .sitefoot .wrap { display: flex; align-items: center; gap: var(--s6); flex-wrap: wrap; }
  .sitefoot .who { display: flex; align-items: baseline; gap: var(--s3); margin-right: auto; }
  .sitefoot .who strong { font-weight: 600; font-size: var(--t-small); }
  .sitefoot .who span { color: var(--graphite); font-size: var(--t-caption); }
  .sitefoot .links { display: flex; flex-wrap: wrap; gap: var(--s5); font-size: var(--t-small); }
  .sitefoot .links a { color: var(--ink-2); text-decoration: none; }
  @media (hover: hover) and (pointer: fine) { .sitefoot .links a:hover { color: var(--accent); } }
  .sitefoot .stamp { flex-basis: 100%; font-family: var(--mono); font-size: var(--t-machine);
    color: var(--graphite); }
}

/* ══ components ═════════════════════════════════════════════════════ */
@layer components {

  /* ── eyebrow ──────────────────────────────────────────────────── */
  .eyebrow {
    display: block; font-size: var(--t-eyebrow); font-weight: 600;
    letter-spacing: 0.11em; text-transform: uppercase; color: var(--graphite);
    margin-bottom: var(--s4);
  }
  .eyebrow a { color: inherit; text-decoration: none; }
  @media (hover: hover) and (pointer: fine) { .eyebrow a:hover { color: var(--accent); } }

  /* ── page head ────────────────────────────────────────────────── */
  .pagehead { padding-block: var(--s11) var(--s8); }
  .pagehead h1 { font-size: var(--t-page); letter-spacing: -0.032em; max-width: 20ch; }
  .pagehead .lede { margin-top: var(--s5); color: var(--ink-2);
    font-size: var(--t-prose); line-height: var(--lh-prose); max-width: 62ch; }
  @media (max-width: 640px) { .pagehead { padding-block: var(--s8) var(--s6); } }

  /* ── section ──────────────────────────────────────────────────── */
  .section { padding-block: var(--s11); border-top: 1px solid var(--rule-soft); }
  .section:first-of-type { border-top: 0; }
  .section > h2,
  .section > .wrap > h2,
  .section > .wrap > .section-head h2 { font-size: var(--t-section); letter-spacing: -0.028em; }
  .section > .intro,
  .section > .wrap > .intro { margin-top: var(--s4); color: var(--ink-2); max-width: 62ch;
    font-size: var(--t-prose); line-height: var(--lh-prose); }
  .section-head { display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--s6); flex-wrap: wrap; }

  /* ── arrow link ───────────────────────────────────────────────── */
  .arrow {
    display: inline-flex; align-items: center; gap: var(--s2);
    font-size: var(--t-small); font-weight: 500; color: var(--accent);
    text-decoration: none;
  }
  .arrow svg { width: 14px; height: 14px; transition: transform var(--d-hover) var(--ease-out); }
  @media (hover: hover) and (pointer: fine) {
    .arrow:hover { color: var(--accent-2); }
    .arrow:hover svg { transform: translateX(3px); }
  }

  /* ── the label column pattern ─────────────────────────────────── */
  .split { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--s10); align-items: start; }
  .split > .label { font-size: var(--t-caption); color: var(--graphite);
    position: sticky; top: calc(var(--nav-h) + var(--s6)); }
  @media (max-width: 900px) {
    .split { grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
    .split > .label { position: static; }
  }

  /* ── prose ────────────────────────────────────────────────────── */
  .prose { max-width: 50ch; font-size: var(--t-prose); line-height: var(--lh-prose); color: var(--ink-2); }
  .prose > * + * { margin-top: var(--s5); }
  .prose strong { color: var(--ink); font-weight: 600; }
  .prose h3 { color: var(--ink); font-size: var(--t-heading); margin-top: var(--s8); }
  .prose-human { max-width: 62ch; font-size: var(--t-prose); line-height: var(--lh-prose); color: var(--ink); }

  /* ── handwritten margin note ──────────────────────────────────── */
  .note-hand {
    font-family: var(--hand); font-weight: 600; font-size: 1.5rem; line-height: 1.28;
    color: var(--ink-2); max-width: 22ch;
  }
  .note-hand svg { color: var(--rule-strong); overflow: visible; }

  /* ── buttons ──────────────────────────────────────────────────── */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
    min-height: 42px; padding-inline: var(--s5);
    border-radius: var(--r-md); font-size: var(--t-small); font-weight: 500;
    border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
    text-decoration: none; touch-action: manipulation;
    transition: transform var(--d-press) var(--ease-out),
                border-color var(--d-hover) ease, background-color var(--d-hover) ease;
  }
  .btn:active { transform: scale(0.97); }

  /* Press is the only acknowledgement a touch reader gets, so it belongs on
     every pressable surface, not only the three that had it. */
  .nav a:active, .nav button:active, .toc a:active, .pager a:active,
  .work-card a:active, .deck-filter button:active { transform: scale(0.985); }
  .row:active { background: var(--paper-3); }
  @media (hover: hover) and (pointer: fine) {
    .btn:hover { border-color: var(--rule-strong); background: var(--paper-2); }
  }
  .btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
  @media (hover: hover) and (pointer: fine) {
    .btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
  }

  /* ── chips ────────────────────────────────────────────────────── */
  .chip {
    display: inline-flex; align-items: center; gap: var(--s2);
    min-height: 24px; padding: 2px var(--s3);
    border: 1px solid var(--rule); border-radius: var(--r-pill);
    background: var(--paper); font-size: var(--t-machine); font-family: var(--mono);
    color: var(--ink-2); white-space: nowrap;
  }
  .chip .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; }
  .chip[data-status="In development"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
  .chip[data-status="Built foundation"] { color: var(--ink); }
  .chip[data-status="Prototype"] { color: var(--ink-2); }
  .chip[data-status="Concept"] { color: var(--graphite); }

  /* ── divided rows ─────────────────────────────────────────────── */
  .rows { border-top: 1px solid var(--rule-soft); }
  .row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s5);
    align-items: baseline; padding-block: var(--s5);
    border-bottom: 1px solid var(--rule-soft); position: relative;
    transition: background-color var(--d-hover) ease;
  }
  .row h3, .row .row-h { font-size: var(--t-heading); font-weight: 600; letter-spacing: -0.018em; }
  .row h3 a, .row .row-h a { text-decoration: none; color: var(--ink); }
  .row h3 a::after, .row .row-h a::after { content: ""; position: absolute; inset: 0; }
  .row .sub { color: var(--ink-2); font-size: var(--t-small); margin-top: 3px; max-width: 48ch; }
  .row .meta { display: flex; align-items: center; gap: var(--s3); }
  @media (hover: hover) and (pointer: fine) {
    .row:hover { background: var(--paper-2);
      box-shadow: -14px 0 0 var(--paper-2), 14px 0 0 var(--paper-2); }
    .row:hover h3 a, .row:hover .row-h a { color: var(--accent); }
  }
  .row:has(a:focus-visible) { background: var(--paper-2);
    box-shadow: -14px 0 0 var(--paper-2), 14px 0 0 var(--paper-2); }
  .row:has(a:focus-visible) h3 a,
  .row:has(a:focus-visible) .row-h a { color: var(--accent); }
  @media (max-width: 640px) { .row { grid-template-columns: minmax(0, 1fr); gap: var(--s2); } }

  /* ── card ─────────────────────────────────────────────────────── */
  .card {
    border: 1px solid var(--rule); border-radius: var(--r-2xl);
    background: var(--paper); overflow: hidden; position: relative;
  }
  .card-tint { background: linear-gradient(158deg, var(--paper-2) 0%, var(--paper) 62%); }

  /* ── frame: where the site meets the work ─────────────────────── */
  .frame { border: 1px solid var(--rule); border-radius: var(--r-lg);
           background: var(--paper); overflow: hidden; position: relative; }
  .frame-label, .frame-note {
    display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
    font-size: var(--t-caption); color: var(--graphite);
  }
  .frame-label { margin-bottom: var(--s3); }
  .frame-note { margin-top: var(--s3); font-family: var(--mono); font-size: var(--t-machine); }
  .frame-note code { font-family: inherit; }

  /* ── local table of contents ──────────────────────────────────── */
  .toc { display: grid; gap: 2px; font-size: var(--t-small); }
  .toc a { display: flex; gap: var(--s3); text-decoration: none; color: var(--graphite);
           padding: var(--s1) 0;
           transition: color var(--d-hover) ease, transform var(--d-press) var(--ease-out); }
  .toc a .n { font-family: var(--mono); font-size: var(--t-machine); opacity: 0.7; }
  @media (hover: hover) and (pointer: fine) { .toc a:hover { color: var(--ink); } }
  .toc a[aria-current="true"] { color: var(--accent); font-weight: 500; }

  /* ── palette ──────────────────────────────────────────────────── */
  #palette {
    padding: 0; border: 1px solid var(--rule); border-radius: var(--r-xl);
    background: var(--paper); color: var(--ink); width: min(560px, calc(100vw - 32px));
    box-shadow: var(--shadow-dialog); margin-top: 12vh; overscroll-behavior: contain;
  }
  #palette::backdrop { background: rgba(15 23 41 / 0.32); }
  [data-theme="dark"] #palette::backdrop { background: rgba(0 0 0 / 0.6); }
  #palette input {
    width: 100%; padding: var(--s5); font-size: 1rem; background: none; border: 0;
    border-bottom: 1px solid var(--rule-soft); outline: none;
  }
  @media (max-width: 640px) { #palette input { font-size: 16px; } }
  #palette input::placeholder { color: var(--graphite); }
  #palette ul { max-height: 46vh; overflow-y: auto; overscroll-behavior: contain; padding: var(--s2); }
  #palette li a {
    display: flex; align-items: baseline; gap: var(--s3); padding: var(--s3) var(--s4);
    border-radius: var(--r-md); text-decoration: none; color: var(--ink-2);
  }
  #palette li a strong { font-weight: 600; color: var(--ink); }
  #palette li a .kind { margin-left: auto; font-family: var(--mono); font-size: var(--t-machine); color: var(--graphite); }
  #palette li[aria-selected="true"] a { background: var(--accent-soft); color: var(--ink); }
  #palette .empty { padding: var(--s6); color: var(--graphite); font-size: var(--t-small); }
  #palette footer { display: flex; gap: var(--s5); padding: var(--s3) var(--s5);
    border-top: 1px solid var(--rule-soft); font-size: var(--t-machine); color: var(--graphite); }

  /* ── data table ───────────────────────────────────────────────── */
  .table-wrap { overflow-x: auto; }
  table.data { font-size: var(--t-small); }
  table.data th, table.data td { text-align: left; padding: var(--s3) var(--s4) var(--s3) 0;
    border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
  table.data th { font-weight: 500; color: var(--graphite); font-size: var(--t-caption); }
  table.data td { color: var(--ink-2); }
  table.data td:first-child { color: var(--ink); }
  table.data .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

  /* ── prev / next ──────────────────────────────────────────────── */
  .pager { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s5);
    border-top: 1px solid var(--rule-soft); padding-top: var(--s7); margin-top: var(--s10); }
  .pager a { text-decoration: none; display: grid; gap: var(--s1); padding: var(--s5);
    border: 1px solid var(--rule); border-radius: var(--r-lg); background: var(--paper);
    transition: border-color var(--d-hover) ease, background-color var(--d-hover) ease,
                transform var(--d-press) var(--ease-out); }
  @media (hover: hover) and (pointer: fine) {
    .pager a:hover { border-color: var(--accent-line); background: var(--paper-2); }
  }
  .pager .dir { font-size: var(--t-caption); color: var(--graphite); }
  .pager .to { font-size: var(--t-heading); font-weight: 600; color: var(--ink); letter-spacing: -0.018em; }
  .pager .next { text-align: right; }
  @media (max-width: 560px) { .pager { grid-template-columns: 1fr; } }
}

/* ══ utilities ══════════════════════════════════════════════════════ */
@layer utilities {
  .vh { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
        overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
  .muted { color: var(--ink-2); }
  .faint { color: var(--graphite); }
  .stack > * + * { margin-top: var(--s4); }
  .stack-lg > * + * { margin-top: var(--s7); }
  .flow { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
  .measure { max-width: 62ch; }
  .nowrap { white-space: nowrap; }
}

/* Reduced motion is no MOVEMENT, not no motion — the promise /design/motion
   makes to the reader. An allowlist drops every property that travels and
   leaves colour and opacity on their own declared timing. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-property: color, background-color, border-color, outline-color,
      text-decoration-color, fill, stroke, opacity, box-shadow !important;
  }
}
