/* ============================================================
   Charger — styles
   ------------------------------------------------------------
   A quiet editorial index in the manner of satoshiwatanabe.org
   and archivio-uno.com: small type, one shared column grid from
   the header down through every row, monochrome, and a lot of
   whitespace. No ornament — alignment and spacing do the work.

     1. TOKENS
     2. RESET
     3. THE GRID   — one column template shared by header,
                     column heads, and index rows.
     4. HEADER
     5. INDEX
     6. SECTIONS   — about, contact
     7. FOOTER
     8. MOTION / THEME / RESPONSIVE
   ============================================================ */

/* ============================================================
   0 — TYPE
   Space Grotesk (variable, OFL — see assets/fonts/OFL.txt),
   self-hosted so the strict CSP stays font-src 'self'.
   ============================================================ */
@font-face {
  font-family: "Space Grotesk";
  src: url("/assets/fonts/SpaceGrotesk-var.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   1 — TOKENS
   ============================================================ */
:root {
  --bg: #fbfbf9;
  --ink: #161613;
  --muted: #a4a29a;       /* secondary columns, idle nav */
  --muted-dark: #6e6c66;  /* prose-adjacent gray */
  --line: #e9e8e3;
  --acc: #161613;         /* accent — equals ink except in color mode */
  --grain-blend: multiply;
  --grain-opacity: 0.035;
  --shadow: rgba(15, 15, 12, 0.16);

  --font: "Space Grotesk", "Helvetica Neue", "Inter", "Arial", system-ui,
    sans-serif;

  --fs: 0.875rem;      /* 14px — the working size */
  --fs-title: 0.9375rem; /* 15px — index row titles */
  --fs-lede: 1.125rem; /* 18px — about lede */
  --fs-sm: 0.75rem;    /* 12px — colophon */

  /* The shared grid: number / title / role / year */
  --col-num: 3.5rem;
  --col-title: 21rem;
  --col-role: 13rem;
  --col-year: 4rem;
  --col-gap: 2rem;

  --pad-x: clamp(1.25rem, 4vw, 2.5rem);
  --pad-y: clamp(1.25rem, 3.5vh, 2rem);

  --ease: cubic-bezier(0.25, 0.6, 0.25, 1);
}

/* Dark tokens apply two ways: the system asks for dark and no theme
   is forced (auto), or the toggle forces data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="color"]) {
    --bg: #131312;
    --ink: #e9e8e4;
    --muted: #63625c;
    --muted-dark: #93918a;
    --line: #262623;
    --acc: #e9e8e4;
    --grain-blend: screen;
    --grain-opacity: 0.05;
    --shadow: rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  --bg: #131312;
  --ink: #e9e8e4;
  --muted: #63625c;
  --muted-dark: #93918a;
  --line: #262623;
  --acc: #e9e8e4;
  --grain-blend: screen;
  --grain-opacity: 0.05;
  --shadow: rgba(0, 0, 0, 0.5);
}
/* Color — the same quiet page on warm paper, with one copper accent
   carried by the selection chips, ::selection, and the lede italic. */
:root[data-theme="color"] {
  --bg: #f6f1e6;
  --ink: #211c11;
  --muted: #a89d83;
  --muted-dark: #6f6750;
  --line: #e8e0cb;
  --acc: #a4501c;
  --grain-blend: multiply;
  --grain-opacity: 0.045;
  --shadow: rgba(74, 50, 16, 0.18);
}

/* ============================================================
   2 — RESET
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
}
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-thumb {
  background: var(--muted);
}
::-webkit-scrollbar-track {
  background: transparent;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs);
  font-weight: 400;
  line-height: 1.5;
  padding: var(--pad-y) var(--pad-x) 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* A whisper of print grain over everything — material, not skeuomorph. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 190; /* above content, below the cursor (200) */
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='280' height='280'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
}

h1,
h2,
p,
ol,
ul {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

ol,
ul {
  list-style: none;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

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

/* Author display rules (.grid etc.) must never beat [hidden]. */
[hidden] {
  display: none !important;
}

::selection {
  background: var(--acc);
  color: var(--bg);
}

/* The "selection" hover — interactive text inverts like a text
   selection. Resting states stay quiet; the flourish is on touch. */
.top a:hover,
.filter:hover,
.theme-btn:hover,
.theme-opt:hover,
.contact-list a:hover,
.footer a:hover,
.footer button:hover,
.copy-btn:hover,
.section-body a:hover {
  background: var(--acc);
  color: var(--bg);
  box-shadow: 0 0 0 3px var(--acc);
  text-decoration: none;
}

/* Custom cursor — a dot with a trailing ring, blend-mode difference
   so it reads over paper, ink chips, and dark mode alike. Enabled by
   js/main.js only for fine pointers without reduced-motion. */
.cursor-dot,
.cursor-ring {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 200;
  border-radius: 50%;
  opacity: 0;
  will-change: transform;
  mix-blend-mode: difference;
}
.cursor-dot {
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  background: #fff;
}
.cursor-ring {
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  transition: opacity 0.25s var(--ease);
}
html.has-cursor,
html.has-cursor * {
  cursor: none !important;
}

/* Skip link — hidden until focused. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.35rem 0.8rem;
  background: var(--ink);
  color: var(--bg);
}
.skip-link:focus {
  left: var(--pad-x);
  top: var(--pad-y);
}

/* ============================================================
   3 — THE GRID
   Header, column heads, and rows all share this template, so
   the whole page reads as one aligned system.
   ============================================================ */
.grid {
  display: grid;
  grid-template-columns: var(--col-num) var(--col-title) var(--col-role) var(--col-year);
  column-gap: var(--col-gap);
  align-items: baseline;
}

/* ============================================================
   4 — HEADER
   C. | filters | About | Contact (far right)
   ============================================================ */
.top {
  grid-template-columns: var(--col-num) var(--col-title) var(--col-role) 1fr;
}
.wordmark {
  font-weight: 500;
}
.top a,
.top .filter {
  color: var(--muted);
  transition: color 0.15s var(--ease);
}
/* Reinforce the selection-chip hover (declared with the reset) — the
   chip background is --acc, so the text must flip to --bg, not ink. */
.top a:hover,
.top .filter:hover {
  color: var(--bg);
}
/* Right cluster: nav links and the theme picker. Placed explicitly in
   the last column so pages with or without filters line up the same. */
.top .filters {
  grid-column: 2;
}
.top-end {
  grid-column: 3 / -1; /* two columns — the full nav needs the room */
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.3rem 1.6rem;
  align-items: baseline;
}

/* Theme picker — closed it reads as one quiet word (the current
   theme); open it becomes a comma-separated word list, like the
   filters. Choosing a word sets the theme and closes it. */
.theme-picker {
  display: inline-flex;
  align-items: baseline;
}
.theme-btn,
.theme-opt {
  color: var(--muted);
  transition: color 0.15s var(--ease);
}
.theme-btn:hover,
.theme-opt:hover {
  color: var(--bg);
}
.theme-opt[aria-pressed="true"] {
  color: var(--ink);
}
.theme-opts {
  display: inline-flex;
  align-items: baseline;
}
.theme-opts .sep {
  color: var(--muted);
  margin-right: 0.45em;
}
/* The picker is a JS feature — hide the empty shell without it. */
html:not(.js) .theme-picker {
  display: none;
}
/* Scroll-spy: the header link darkens while its section is in view. */
.top a.active {
  color: var(--ink);
}

/* Filters — a comma-separated word list, Watanabe-style. The commas
   are separator spans (from JS) so hover chips wrap the word only. */
.filters {
  display: flex;
  flex-wrap: wrap;
}
.filter[aria-pressed="true"] {
  color: var(--ink);
}
.filters .sep {
  color: var(--muted);
  margin-right: 0.45em;
}

/* ============================================================
   5 — INDEX
   ============================================================ */
.colheads {
  margin-top: clamp(3.5rem, 10vh, 6rem);
  margin-bottom: 0;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.work + .work {
  margin-top: 0;
}
.work {
  border-bottom: 1px solid var(--line);
}
.row {
  padding-block: 0.75rem;
  transition: color 0.15s var(--ease);
}
.c-num,
.c-role,
.c-year {
  color: var(--muted);
  transition: color 0.15s var(--ease);
}
.c-num,
.c-year,
.colheads,
.footer-meta {
  font-variant-numeric: tabular-nums;
}
.c-title {
  color: var(--ink);
  font-size: var(--fs-title);
  font-weight: 500;
  transition: color 0.15s var(--ease);
}

/* Hover: the list recedes; the hovered title inverts like a selection. */
.work-list:hover .c-title {
  color: var(--muted);
}
.work-list .row:hover .c-title,
.work-list .row:focus-visible .c-title {
  background: var(--acc);
  color: var(--bg);
  box-shadow: 0 0 0 3px var(--acc);
}
.work-list a.row:hover .c-num,
.work-list a.row:hover .c-year,
.work-list a.row:hover .c-role {
  color: var(--muted-dark);
}
/* The ↗ hint sits outside the chip, so keep it legible on hover. */
.row.ext:hover .c-title::after {
  color: var(--bg);
}

.work[hidden] {
  display: none;
}

/* Floating preview — an image that trails the cursor over index
   rows (the Watanabe/Archivio move). Injected by js/main.js;
   entries without media get a generated number card. */
.preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 150; /* under the grain (190) and cursor (200) */
  width: min(21rem, 36vw);
  pointer-events: none;
  opacity: 0;
  will-change: transform;
}
.preview img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border: 1px solid var(--line);
  box-shadow: 0 18px 44px var(--shadow);
  transform: scale(0.97);
  transition: transform 0.22s var(--ease);
}
.preview.on {
  opacity: 1;
  transition: opacity 0.18s var(--ease);
}
.preview.on img {
  transform: none;
}

/* External rows hint at leaving the site on hover. */
.row.ext .c-title::after {
  content: " ↗";
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s var(--ease);
}
.row.ext:hover .c-title::after,
.row.ext:focus-within .c-title::after {
  opacity: 1;
}

.index-fallback {
  color: var(--muted-dark);
  max-width: 34rem;
}

/* ============================================================
   6 — SECTIONS (about, contact)
   Letter label in the number column, content in the title
   column and beyond — same grid, quieter register.
   ============================================================ */
.section {
  margin-top: clamp(6rem, 18vh, 11rem);
}
.section-label {
  color: var(--muted);
}
.section-body {
  grid-column: 2 / 4;
  max-width: 32rem;
}
.section-body p + p {
  margin-top: 0.9rem;
}
/* The about lede sits a register above the working size. */
.section-body .lede {
  font-size: var(--fs-lede);
  line-height: 1.45;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.section-body .lede em {
  font-style: normal; /* no cursive — emphasis carries via the accent */
  color: var(--acc); /* equals ink outside color mode */
}
.section-body,
.section-body a {
  color: var(--muted-dark);
}
.section-body strong {
  color: var(--ink);
  font-weight: 400;
}

/* Contact rows: label + value pairs. */
.contact-list li {
  display: flex;
  gap: var(--col-gap);
}
.contact-list li + li {
  margin-top: 0.2rem;
}
.contact-list .k {
  width: 5.5rem;
  flex: none;
  color: var(--muted);
}
.contact-list a {
  color: var(--ink);
}
.contact-list a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Copy affordance (injected by JS) — appears on row hover. */
.copy-btn {
  color: var(--muted);
  font-size: var(--fs-sm);
  margin-left: 1rem;
  opacity: 0;
  transition: opacity 0.15s var(--ease), color 0.15s var(--ease);
}
.contact-list li:hover .copy-btn,
.copy-btn:focus-visible,
.copy-btn.did {
  opacity: 1;
}
.copy-btn:hover {
  color: var(--bg); /* the chip hover paints --acc behind it */
}

/* ============================================================
   6.4 — HOME (index.html)
   A short, plain statement and a numbered directory of the
   site's pages — the index of the index. Same register as
   everything else: no hero, no ornament.
   ============================================================ */
.home-intro {
  margin-top: clamp(4.5rem, 15vh, 8.5rem);
}
.home-statement {
  font-size: var(--fs-lede);
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.home-intro .section-body p {
  margin-top: 0.9rem;
}
.home-intro .section-body p.home-statement {
  margin-top: 0;
}
.home-now {
  color: var(--muted);
}
.home-intro .section-body p.home-now {
  margin-top: 1.8rem;
}
.home-dir {
  margin-top: clamp(3.5rem, 11vh, 6rem);
}
.home-dir .work-list {
  border-top: 1px solid var(--line);
}

/* ============================================================
   6.5 — BLOG (blog/index.html + js/blog.js)
   The same grid and register as the index: rows are number /
   title / date; a post opens as quiet prose in the title column.
   ============================================================ */
.where {
  color: var(--muted);
}

.blog-intro {
  margin-top: clamp(3.5rem, 10vh, 6rem);
  color: var(--muted-dark);
  max-width: 32rem;
}
.blog-intro + .colheads,
.blog .colheads {
  margin-top: clamp(1.6rem, 5vh, 3rem);
}

/* Post view */
.post {
  margin-top: clamp(3.5rem, 10vh, 6rem);
  align-items: start;
}
.post-backline {
  margin-bottom: 2rem;
}
.post-back {
  color: var(--muted);
}
.post-head {
  margin-bottom: 2.2rem;
}
.post-title {
  font-size: var(--fs-lede);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.post-meta {
  margin-top: 0.3rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Prose — small headings, generous leading, no ornament. */
.post-body {
  color: var(--muted-dark);
  line-height: 1.65;
}
.post-body p + p,
.post-body p + ul,
.post-body p + ol,
.post-body ul + p,
.post-body ol + p {
  margin-top: 0.9rem;
}
.post-body h2,
.post-body h3 {
  margin: 2rem 0 0.6rem;
  color: var(--ink);
  font-weight: 500;
}
.post-body h3 {
  color: var(--muted-dark);
}
.post-body strong {
  color: var(--ink);
  font-weight: 500;
}
.post-body em {
  font-style: italic; /* synthesized oblique — no serif/cursive face */
}
.post-body a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--muted);
}
.post-body a:hover {
  background: var(--acc);
  color: var(--bg);
  box-shadow: 0 0 0 3px var(--acc);
  text-decoration: none;
}
.post-body ul,
.post-body ol {
  padding-left: 1.1rem;
}
.post-body ul {
  list-style: "—  ";
}
.post-body ol {
  list-style: decimal-leading-zero;
}
.post-body li + li {
  margin-top: 0.25rem;
}
.post-body li::marker {
  color: var(--muted);
}
.post-body blockquote {
  margin: 1.1rem 0;
  padding-left: 1.1rem;
  border-left: 1px solid var(--ink);
  color: var(--ink);
}
.post-body code {
  font-family: ui-monospace, "SF Mono", "Menlo", monospace;
  font-size: 0.8125rem;
  color: var(--ink);
}
.post-body pre {
  margin: 1.1rem 0;
  padding: 0.8rem 1rem;
  border: 1px solid var(--line);
  overflow-x: auto;
  line-height: 1.55;
}
.post-body pre code {
  color: var(--muted-dark);
}
.post-body hr {
  margin: 1.8rem 0;
  border: 0;
  border-top: 1px solid var(--line);
}
.post-body img {
  max-width: 100%;
  border: 1px solid var(--line);
}

.blog-empty {
  margin-top: clamp(3.5rem, 10vh, 6rem);
  color: var(--muted-dark);
}

/* ============================================================
   7 — FOOTER
   ============================================================ */
.footer {
  margin-top: clamp(6rem, 20vh, 12rem);
  padding-block: 1.1rem calc(var(--pad-y) + 0.2rem);
  display: flex;
  justify-content: space-between;
  gap: var(--col-gap);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-sm);
}
.footer a {
  color: var(--muted);
}
.footer a:hover {
  color: var(--bg); /* the chip hover paints --acc behind it */
}
.footer-meta {
  display: flex;
  gap: 1.6rem;
}

/* ============================================================
   8 — MOTION / THEME / RESPONSIVE
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {
  .work {
    animation: rise 0.45s var(--ease) both;
    /* per-row delay set from js/main.js */
  }
  .top,
  .colheads {
    animation: rise 0.6s var(--ease) both;
  }
  /* Sections reveal as they scroll into view (html.js is set by
     main.js, so everything stays visible without JavaScript). */
  html.js .section,
  html.js .footer {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
  }
  html.js .section.in,
  html.js .footer.in {
    opacity: 1;
    transform: none;
  }
  /* The footer clock's colon breathes. */
  .clock-colon {
    animation: blink 2.4s steps(1) infinite;
  }
  @keyframes blink {
    50% {
      opacity: 0.25;
    }
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

@media (max-width: 56rem) {
  :root {
    --col-title: minmax(0, 1fr);
    --col-role: 9rem;
  }
}

@media (max-width: 40rem) {
  .grid {
    grid-template-columns: 2.6rem minmax(0, 1fr) 3.2rem;
  }
  .top {
    grid-template-columns: 2.6rem minmax(0, 1fr) auto;
  }
  .top-end {
    grid-column: 3;
    gap: 1.1rem;
  }
  /* The full nav (Works / Blog / About / Contact / theme) is too wide
     for one mobile line — it takes its own row under the wordmark.
     Short clusters (blog's Index link, 404) stay inline. */
  .top-end.wide {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: start;
    flex-wrap: wrap;
    margin-top: 0.5rem;
  }
  /* Filters (works page) get the row after that. */
  .top .filters {
    grid-column: 1 / -1;
    grid-row: 3;
    margin-top: 0.5rem;
  }
  /* Grid spacers exist only to pad desktop columns. */
  .top .top-spacer {
    display: none;
  }
  .colheads .c-role,
  .row .c-role {
    grid-column: 2;
    grid-row: 2;
    font-size: var(--fs-sm);
  }
  .row {
    padding-block: 0.35rem;
  }
  .section-body {
    grid-column: 2 / -1;
  }
  .contact-list .k {
    width: 4.2rem;
  }
  .footer {
    flex-direction: column;
    gap: 0.4rem;
  }
}

@media print {
  body {
    background: #fff;
  }
  .skip-link,
  .filters {
    display: none;
  }
}
