/* ── Fonts ──────────────────────────────────────────────────────────────── */

/* OpenMono is the OpenCode interface face (SIL OFL, see fonts/OFL-OpenMono.txt).
   This is its Latin subset, which includes the block and box characters. */
@font-face {
  font-family: "OpenMono";
  src: url("../fonts/openmono-regular-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* JetBrains Mono 2.304 (SIL OFL, see fonts/OFL-JetBrains-Mono.txt). */
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ── Tokens ─────────────────────────────────────────────────────────────── */

:root {
  color-scheme: light dark;

  /* Headings, navigation and labels. */
  --font-ui: "OpenMono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  /* Running text and ASCII art. */
  --font-text: "JetBrains Mono", "OpenMono", ui-monospace, Menlo, Consolas, monospace;

  --bg: light-dark(#fbfbfb, #0c0c0c);
  --bg-weak: light-dark(#efefef, #1c1c1c);
  --bg-weak-hover: light-dark(#e4e4e4, #262626);
  --bg-strong: light-dark(#161616, #fafafa);
  --text: light-dark(#161616, #fafafa);
  --text-weak: light-dark(#6b6b6b, #8f8f8f);
  --text-faint: light-dark(#a3a3a3, #5c5c5c);
  --border: light-dark(#e3e3e3, #242424);
  --accent: light-dark(#3b5cf6, #6b8fff);
  --on-accent: #fff;

  /* Art surfaces stay dark in both themes. */
  --stage: #161616;
  --stage-band: #1a1a1a;
  --stage-ink: #8f8f8f;
  --stage-ink-hover: #c4c4c4;
  --stage-ink-dim: #4b4b4b;
  --stage-text: #fafafa;
  --stage-muted: #aeaeae;

  --edge: 1.5rem;
  --sidebar: 13.5rem;
  --gutter: 2rem;
  --block-space: 4.5rem;
  --topbar-height: 4rem;

  --fs-body: 15px;
  --fs-lead: 18px;
  --fs-entry: 24px;
  --fs-nav: 15px;
  --fs-meta: 13px;
  --fs-button: 14px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

@media (max-width: 640px) {
  :root {
    --fs-body: 14px;
    --fs-lead: 16px;
    --fs-entry: 21px;
    --block-space: 3rem;
    --gutter: 1rem;
  }
}

/* ── Base ───────────────────────────────────────────────────────────────── */

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

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: var(--fs-body);
  line-height: 1.6;
  /* JetBrains Mono ligatures would merge art characters such as "==" or "!=".
     Children set font longhands only, so this is never reset. */
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

h1, h2, h3 {
  margin: 0;
  font-family: var(--font-ui);
  font-weight: 400;
}

p { margin: 0; }

a { color: inherit; }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  top: var(--edge);
  left: var(--edge);
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--bg-strong);
  color: var(--bg);
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.ascii {
  margin: 0;
  overflow: hidden;
  font-family: var(--font-text);
  font-size: 11px;
  line-height: 1.15em;
  white-space: pre;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Chrome: logo, sidebar, corner link ─────────────────────────────────── */

.logo {
  display: inline-flex;
  color: var(--text);
}
.logo svg { fill: currentColor; }
.logo:hover { color: var(--accent); }

.corner-link {
  position: fixed;
  top: var(--edge);
  right: var(--edge);
  z-index: 20;
  display: inline-flex;
  padding: 0.25rem;
  color: var(--text);
}
.corner-link:hover { color: var(--accent); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  width: calc(var(--sidebar) + var(--edge));
  padding: var(--edge);
  overflow-y: auto;
}

.nav {
  display: flex;
  flex-direction: column;
  margin-top: 2.25rem;
}

.nav-secondary { margin-top: 4rem; }

.nav a {
  display: flex;
  align-items: baseline;
  gap: 0.75ch;
  padding: 0.35rem 0;
  color: var(--text-weak);
  font-family: var(--font-ui);
  font-size: var(--fs-nav);
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  transition: color 160ms var(--ease-out);
}

.nav a:hover,
.nav a:focus-visible,
.nav a[aria-current] { color: var(--text); }

.nav .index { color: var(--text-faint); }
.nav a:hover .index,
.nav a[aria-current] .index { color: var(--accent); }

.nav a[aria-current] [data-label]::after {
  content: "▍" / "";
  margin-left: 0.15ch;
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}

.nav .external {
  font-size: 0.75em;
  color: var(--text-faint);
}

@keyframes blink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .nav a[aria-current] [data-label]::after { animation: none; }
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: auto;
  padding-top: 3rem;
}

.theme-switch {
  display: inline-flex;
  align-self: flex-start;
  border: 1px solid var(--border);
}

.theme-switch button {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-weak);
  cursor: pointer;
}
.theme-switch button + button { border-left: 1px solid var(--border); }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] {
  background: var(--bg-weak);
  color: var(--text);
}

.progress {
  color: var(--text-weak);
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
  white-space: pre;
}
.progress-filled { color: var(--text); }
.progress-empty { color: var(--text-faint); }
.progress-percent { margin-left: 1ch; }

.copyright {
  color: var(--text-weak);
  font-family: var(--font-ui);
  font-size: var(--fs-meta);
}

/* Mobile top bar, hidden on wide screens. */
.topbar { display: none; }

.menu-toggle {
  display: grid;
  gap: 6px;
  align-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0 0.5rem;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.menu-toggle span {
  display: block;
  height: 1.5px;
  background: var(--text);
  transition: transform 200ms var(--ease-out);
}
.menu-toggle[aria-expanded="true"] span:first-child { transform: translateY(3.75px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] span:last-child { transform: translateY(-3.75px) rotate(-45deg); }

/* ── Content ────────────────────────────────────────────────────────────── */

.content {
  margin-left: calc(var(--sidebar) + var(--edge));
  padding: 4.25rem calc(var(--edge) + 2.5rem) 0 var(--edge);
  outline: none;
}

.content > section { scroll-margin-top: 2rem; }

.hero h1 {
  font-size: clamp(2rem, 1rem + 3.6vw, 4.25rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

/* Letters are swapped while they scramble; keep each one a fixed cell. */
.hero h1 [data-char] { display: inline-block; white-space: pre; }

.lead {
  max-width: 50rem;
  margin-top: 1.75rem;
  color: var(--text-weak);
  font-size: var(--fs-lead);
  line-height: 1.5;
}

.lead a,
.band-copy a:not(.button) {
  color: var(--text);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
.lead a:hover { color: var(--accent); }

/* ── Cards ──────────────────────────────────────────────────────────────── */

.cards {
  --visible: 1.15;
  --gaps: 1;
  margin-top: 3.5rem;
  container-type: inline-size;
}

@media (min-width: 640px) { .cards { --visible: 2.4; --gaps: 2; } }
@media (min-width: 1280px) { .cards { --visible: 3; --gaps: 2; } }

.track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: calc((100cqw - var(--gaps) * var(--gutter)) / var(--visible));
  gap: var(--gutter);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.track::-webkit-scrollbar { display: none; }

.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  scroll-snap-align: start;
}

.card-media {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: var(--stage);
  cursor: crosshair;
  touch-action: pan-y;
}

.card-media .ascii {
  position: absolute;
  inset: 0;
  color: var(--stage-ink);
  transition: color 300ms var(--ease-out);
}
.card-media:hover .ascii { color: var(--stage-ink-hover); }

.card-hint {
  position: absolute;
  left: 1rem;
  bottom: 0.875rem;
  padding: 0.25rem 0.5rem;
  background: var(--stage);
  color: var(--stage-ink);
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.card-hint b { color: var(--stage-text); font-weight: 400; }
.card-hint span { color: var(--stage-ink-dim); }
.card-media:hover .card-hint { opacity: 1; transform: none; }

@media (hover: none) {
  .card-hint { opacity: 1; transform: none; }
}

.card h3 {
  margin-top: 1.5rem;
  font-size: var(--fs-entry);
  letter-spacing: -0.01em;
}

.card p {
  margin-top: 0.5rem;
  color: var(--text-weak);
}

.card .button { margin-top: 1.25rem; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.button {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  height: 2.5rem;
  padding: 0 1.1rem;
  font-family: var(--font-ui);
  font-size: var(--fs-button);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out);
}
.button:active { scale: 0.98; }

.button.primary { background: var(--bg-strong); color: var(--bg); }
.button.secondary { background: var(--bg-weak); color: var(--text); }
.button.secondary span { color: var(--text-weak); }
.button.inverse { background: var(--stage-text); color: var(--stage); }

.button:hover { background: var(--accent); color: var(--on-accent); }
.button:hover span { color: inherit; }

/* ── Sections ───────────────────────────────────────────────────────────── */

.section {
  position: relative;
  margin-top: var(--block-space);
  padding-top: var(--block-space);
}

/* The rule above each section; drawn left to right when it scrolls in. */
.section::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: var(--border);
  transform-origin: left;
}

.cards + .section::before { content: none; }

.section h2,
.band h2 {
  font-size: var(--fs-entry);
  letter-spacing: -0.01em;
}

.section h2 + .lead { margin-top: 1rem; }

.steps {
  display: grid;
  gap: 2.75rem;
  margin: 3.5rem 0 0;
  padding: 0;
  list-style: none;
}

.steps li {
  display: grid;
  grid-template-columns: 4.5rem 1fr auto;
  align-items: start;
  gap: 0 1rem;
}

.step-number {
  padding-top: 0.2rem;
  color: var(--text-weak);
  font-family: var(--font-ui);
  font-size: var(--fs-nav);
}

.steps h3 { font-size: var(--fs-entry); letter-spacing: -0.01em; }

.steps p {
  margin-top: 0.5rem;
  color: var(--text-weak);
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .steps li { grid-template-columns: 2.75rem 1fr; }
  .steps .button { grid-column: 2; margin-top: 1rem; justify-self: start; }
}

/* ── Contact band ───────────────────────────────────────────────────────── */

.band {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 26rem;
  margin-top: var(--block-space);
  overflow: hidden;
  background: var(--stage-band);
  color: var(--stage-text);
  cursor: crosshair;
}

.band .ascii {
  position: absolute;
  inset: 0;
  color: var(--stage-ink-dim);
}

.band-copy {
  position: relative;
  grid-column: 2;
  align-self: center;
  padding: 3rem var(--gutter) 3rem 0;
  pointer-events: none;
}
.band-copy .button { pointer-events: auto; }

.band-copy p {
  margin-top: 1rem;
  color: var(--stage-muted);
  font-size: var(--fs-lead);
}

.band-copy .button { margin-top: 2rem; }

@media (max-width: 760px) {
  .band { grid-template-columns: 1fr; min-height: 24rem; }
  .band-copy { grid-column: 1; align-self: end; padding: 3rem var(--gutter) 2rem; }
}

/* ── Wordmark ───────────────────────────────────────────────────────────── */

.wordmark {
  margin-top: var(--block-space);
  padding-bottom: var(--edge);
  cursor: crosshair;
}

.wordmark .ascii {
  color: var(--text);
  line-height: 1.12em;
}

/* ── Reveal on scroll (driven by js/ui/reveal.js) ───────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  :root[data-js] :is([data-reveal], [data-reveal-scramble], [data-reveal-stagger] > *) {
    opacity: 0;
    translate: 0 0.75rem;
    /* Colour transitions are listed so hover effects keep working. */
    transition:
      opacity 600ms var(--ease-out),
      translate 800ms var(--ease-out),
      color 160ms var(--ease-out),
      background-color 160ms var(--ease-out);
    transition-delay: calc(var(--stagger, 0) * 70ms), calc(var(--stagger, 0) * 70ms), 0s, 0s;
  }

  :root[data-js] :is(
    [data-reveal][data-revealed],
    [data-reveal-scramble][data-revealed],
    [data-reveal-stagger][data-revealed] > *
  ) {
    opacity: 1;
    translate: none;
  }

  .section::before { transition: transform 1400ms var(--ease-out); }
  :root[data-js] .section[data-reveal-line]:not([data-revealed])::before { transform: scaleX(0); }
}

/* ── Small screens: top bar plus a sheet for the sidebar ────────────────── */

@media (max-width: 960px) {
  .topbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 calc(var(--edge) - 0.5rem) 0 var(--edge);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
  }

  .corner-link { display: none; }

  .sidebar {
    z-index: 25;
    width: 100%;
    padding-top: calc(var(--topbar-height) + 0.5rem);
    background: var(--bg);
    visibility: hidden;
    opacity: 0;
    transition: opacity 200ms var(--ease-out), visibility 0s 200ms;
  }
  .sidebar > .logo { display: none; }
  .sidebar .nav { margin-top: 1rem; }
  .sidebar .nav a { font-size: 18px; padding: 0.5rem 0; }

  body[data-menu-open] { overflow: hidden; }
  body[data-menu-open] .sidebar {
    visibility: visible;
    opacity: 1;
    transition: opacity 200ms var(--ease-out);
  }

  .content {
    margin-left: 0;
    padding: calc(var(--topbar-height) + 2rem) var(--edge) 0;
  }

  .content > section { scroll-margin-top: calc(var(--topbar-height) + 1rem); }
}


@media (hover: hover) and (pointer: fine) and (forced-colors: none) {
  html, body, a[href], button:not(:disabled), summary,
  .card-media, .band, .wordmark {
    cursor: url("../assets/pixel-dot.png") 6 6, auto;
  }

  input:not([type]), input[type="text"], input[type="search"],
  input[type="email"], input[type="password"], textarea, [contenteditable="true"] {
    cursor: text;
  }
}

.pixel-click {
  position: fixed;
  z-index: 9999;
  width: 4px;
  height: 4px;
  pointer-events: none;
  background: var(--accent);
  box-shadow: -8px 0 var(--accent), 8px 0 var(--accent),
    0 -8px var(--accent), 0 8px var(--accent);
  translate: -50% -50%;
  animation: pixel-click 360ms steps(4, end) forwards;
}

@keyframes pixel-click {
  from { opacity: 1; scale: 0.5; }
  to { opacity: 0; scale: 2; }
}
