/* Toolchain design principles. Shared tokens and component classes.
 * Source of truth: toolchain-website/brand/shared.css. Rules: brand/DESIGN_PRINCIPLES.md.
 * Each site sets --acc and --acc-text on :root (and .dark) for its own accent.
 * Loads Outfit and JetBrains Mono itself; this file only names them. */

/* Metric-matched fallbacks so text does not move when Outfit and JetBrains Mono arrive (Next sites: next/font generates
 * "Outfit Fallback" itself; these faces add the 600 and 700 widths it leaves out). */
@font-face { font-family: "Outfit Fallback"; src: local("Arial"); font-weight: 100 550; ascent-override: 100.18%; descent-override: 26.05%; line-gap-override: 0%; size-adjust: 99.82%; }
@font-face { font-family: "Outfit Fallback"; src: local("Arial"); font-weight: 551 650; ascent-override: 98.72%; descent-override: 25.67%; line-gap-override: 0%; size-adjust: 101.3%; }
@font-face { font-family: "Outfit Fallback"; src: local("Arial"); font-weight: 651 900; ascent-override: 96.62%; descent-override: 25.12%; line-gap-override: 0%; size-adjust: 103.5%; }
@font-face { font-family: "JetBrains Mono Fallback"; src: local("Arial"); ascent-override: 75.79%; descent-override: 22.29%; line-gap-override: 0%; size-adjust: 134.59%; }

:root {
  /* grid. 24 columns from the column switch (1352px, where 24 cells of 52px fit with a cell each side);
     12 columns below it, with the cell capped at 52px and shrinking only on phones. The cell never
     shrinks as the viewport grows: it is 52px on both sides of the switch. */
  --switch: 1352px;
  --cols: 24;
  --cell: min(52px, 100vw / 26);
  --section-pad: round(up, clamp(calc(2 * var(--cell)), 6vw, calc(3 * var(--cell))), var(--cell));
  --head-gap: clamp(var(--cell), 4vw, 80px);
  --card-min: 17rem;
  --card-min-short: 15rem;

  /* neutrals, light */
  --page: #F8FAFC;
  --card: #FFFFFF;
  --tint: #F1F5F9;
  --ink: #0F172A;
  --muted: #475569;
  --muted-min: #64748B;
  --line: #E2E8F0;
  --line2: #CBD5E1;
  --shadow: #0F172A;
  --gridline: rgba(15, 23, 42, 0.055);
  --lift: 0 1px 2px rgba(15, 23, 42, 0.05), 0 18px 40px -24px rgba(15, 23, 42, 0.25);

  /* shape */
  --r-surface: 20px;
  --r-card: 16px;
  --r-control: 12px;
  /* The shadows are written inline below (5px 5px 0 var(--shadow)) so a local --shadow override applies. */

  /* type */
  --font-sans: "Outfit", "Outfit Fallback", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "JetBrains Mono Fallback", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* accent: each site overrides these */
  --acc: #0F172A;
  --acc-text: #0F172A;
  /* focus ring: solid accent text colour, which passes 3:1 in both schemes on every site */
  --focus: var(--acc-text);
}

.dark {
  --page: #0F172A;
  --card: #16213A;
  --tint: #101A2F;
  --ink: #F1F5F9;
  --muted: #94A3B8;
  --muted-min: #94A3B8;
  --line: #1E293B;
  --line2: #475569;
  --shadow: #334155; /* lighter than the page so the hard shadow still reads in dark mode */
  --gridline: rgba(241, 245, 249, 0.06);
  --lift: 0 18px 40px -20px rgba(0, 0, 0, 0.6);
}

@media (max-width: 1351px) {
  :root { --cols: 12; --cell: min(52px, 100vw / 13); }
  /* Below the switch the surfaces are full width, so the grid starts at the viewport edge: content one cell in sits on a line. */
  .tc-grid { background-position: 0 0; }
}

/* The drawn grid: the page ground, registered to the board, fading toward the bottom.
 * Absolute inside a position: relative body, so the lines stay registered to the layout while scrolling. */
.tc-grid {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-color: var(--page);
  background-image:
    linear-gradient(to right, var(--gridline) 1px, transparent 1px),
    linear-gradient(to bottom, var(--gridline) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-position: calc(50% - var(--cell) / 2) 0;
}
.tc-grid-fade {
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 30%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 30%, transparent 100%);
}

/* The board: the 24-column grid every container snaps to. */
.board {
  width: calc(var(--cols) * var(--cell));
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  position: relative;
}

/* Surfaces */
.surface {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-surface);
  box-shadow: var(--lift);
}
.band-tint { background: var(--tint); }

/* Cards. The hard shadow means "you can click this": only a card that is
   one link as a whole carries it. */
.card {
  background: var(--card);
  border: 1.5px solid var(--line2);
  border-radius: var(--r-card);
  padding: 32px;
}
a.card, .card-link {
  box-shadow: 5px 5px 0 var(--shadow);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
a.card:hover, .card-link:hover { transform: translate(-1px, -1px); box-shadow: 6px 6px 0 var(--shadow); }
a.card:active, .card-link:active { transform: translate(0, 0); box-shadow: 5px 5px 0 var(--shadow); }

/* Type */
.h1 { font: 700 clamp(40px, 2.4rem + 2.2vw, 64px) / 1.02 var(--font-sans); letter-spacing: -0.04em; color: var(--ink); }
.h1 em, .h-close em { font-style: normal; color: var(--acc-text); }
.h2 { font: 600 clamp(30px, 1.6rem + 0.6vw, 36px) / 1.1 var(--font-sans); letter-spacing: -0.03em; color: var(--ink); }
.h3 { font: 600 clamp(20px, 1.1rem + 0.4vw, 24px) / 1.3 var(--font-sans); letter-spacing: -0.01em; color: var(--ink); }
.lead { font: 400 clamp(18px, 1rem + 0.3vw, 20px) / 1.6 var(--font-sans); color: var(--muted); max-width: 34em; }
.body { font: 400 16px / 1.6 var(--font-sans); color: var(--muted); max-width: 36em; }
/* Measure caps are in em, not ch: Outfit's zero is wide, so 65ch runs to about 100 characters. 29em is about 70. */
.prose { max-width: 29em; }
.fine { max-width: 30em; font-size: 14px; line-height: 1.5; }
.small { font-size: 14px; line-height: 1.5; }
.label {
  font: 600 11px / 1.4 var(--font-mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--acc-text);
}
.data { font: 400 14px / 1.5 var(--font-mono); }

/* Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 32px;
  border: 1.5px solid var(--line2);
  border-radius: var(--r-control);
  background: var(--card);
  color: var(--ink);
  font: 600 15px / 1 var(--font-sans);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--shadow);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--shadow); }
.btn:active { transform: translate(1px, 1px); box-shadow: 3px 3px 0 var(--shadow); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* Colour scheme selector (DESIGN_PRINCIPLES.md section 6): three 44px icon buttons, no visible label. */
.tc-scheme { display: flex; gap: 4px; }
.tc-scheme button {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  border: 1px solid transparent; border-radius: var(--r-control); background: none; color: var(--ink); cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.tc-scheme button:hover { background: var(--tint); }
.tc-scheme button[aria-pressed="true"] { background: var(--tint); border-color: var(--line2); }
.tc-scheme svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Visually hidden, for assistive technology. */
.tc-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Text selection takes the site's accent. */
::selection { background: var(--acc); color: #FFFFFF; }
.dark ::selection { background: var(--acc); color: #FFFFFF; }
/* Primary text must reach 4.5:1 on its fill. A site whose --acc is too light for white text sets --acc-fill (and
 * --acc-fill-hover, a shade darker); Made to Fit AI and Toolchain use teal 700 #0F766E. */
.btn-primary { background: var(--acc-fill, var(--acc)); border-color: var(--acc-fill, var(--acc)); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--acc-fill-hover, var(--acc-fill, var(--acc))); border-color: var(--acc-fill-hover, var(--acc-fill, var(--acc))); }
.btn-sm { height: 44px; padding: 0 18px; }

.link {
  display: inline-block;
  padding-block: 4px;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--acc);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  transition: text-decoration-thickness 120ms ease;
}
.link:hover { text-decoration-thickness: 3px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font: 600 11px / 1.4 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

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

/* Colour scheme selector (DESIGN_PRINCIPLES.md section 6): three 44px icon buttons, no visible label. */
.tc-scheme { display: flex; gap: 4px; }
.tc-scheme button {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  border: 1px solid transparent; border-radius: var(--r-control); background: none; color: var(--ink); cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.tc-scheme button:hover { background: var(--tint); }
.tc-scheme button[aria-pressed="true"] { background: var(--tint); border-color: var(--line2); }
.tc-scheme svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Visually hidden, for assistive technology. */
.tc-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Text selection takes the site's accent. */
::selection { background: var(--acc); color: #FFFFFF; }
.dark ::selection { background: var(--acc); color: #FFFFFF; }

/* Fixed header: two cells tall, the full viewport wide, on the grid at the top. A frosted-glass surface fades in behind
 * it as the page scrolls, its opacity tied to scroll position over the first two cells (the header height) so it never
 * pops. Height never changes. Fixed, not sticky: a sticky header inside the page grid jumps on phones as the address
 * bar collapses, and a popup anchored to it is re-placed on every scroll. The header is out of the flow, so each page
 * keeps its two rows open with a placeholder (`.tc-header-space`, or a site's own rule). */
.tc-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  height: calc(2 * var(--cell));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tc-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background-color: var(--page);
  box-shadow: 0 1px 0 var(--line);
  opacity: 0;
  transition: opacity 240ms cubic-bezier(.2, 0, 0, 1);
  pointer-events: none;
}
.tc-header.is-scrolled::before { opacity: 1; }
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .tc-header::before {
    background-color: color-mix(in srgb, var(--page) 86%, transparent);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
}
/* Where supported, scroll position drives the opacity directly: no threshold, no timed animation. */
@keyframes tc-header-glass { from { opacity: 0; } to { opacity: 1; } }
@supports (animation-timeline: scroll()) {
  .tc-header::before {
    transition: none;
    animation: tc-header-glass linear both;
    animation-timeline: scroll(root block);
    animation-range: 0 calc(2 * var(--cell));
  }
}
/* Keeps the header's two rows open in the flow. */
.tc-header-space { height: calc(2 * var(--cell)); }
:target { scroll-margin-top: calc(2 * var(--cell)); }
/* keeps a keyboard-focused element clear of the sticky header (two cells tall) */
html { scroll-padding-top: calc(2 * var(--cell)); }
/* Smooth scrolling for in-page links and, in Next.js, back to the top on page changes (never set
 * data-scroll-behavior="smooth" on <html>: Next 16 reads it as "turn smooth scrolling off during navigation"). */
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

/* Card sets: columns come from the container, never from the viewport. A set of four goes 1, 2, 4;
 * a set of three goes 1, 3. The band holding a set must be a container (.band sets that). */
.band { container-type: inline-size; }
.card-set { display: grid; gap: 24px; grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--card-min)), 1fr)); }
.card-set-short { --card-min: var(--card-min-short); }
/* Four across from 58rem: four cards of about 13.5rem plus gaps, which the 65rem main surface content width allows. */
@container (min-width: 30rem) and (max-width: 57.9rem) { .card-set-4 { grid-template-columns: repeat(2, 1fr); } }
@container (min-width: 58rem) { .card-set-4 { grid-template-columns: repeat(4, 1fr); } }
@container (max-width: 53.9rem) { .card-set-3 { grid-template-columns: 1fr; } }
@container (min-width: 54rem) { .card-set-3 { grid-template-columns: repeat(3, 1fr); } }

/* Below the column switch the main and closing surfaces span the viewport: one container, not a container in a container. */
@media (max-width: 1351px) {
  .surface { border-radius: 0; border-left: 0; border-right: 0; }
}
@media (max-width: 599px) {
  .card { padding: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, a.card, .card-link, .link, .tc-header::before, .tc-scheme button { transition: none; }
  @supports not (animation-timeline: scroll()) { .tc-header::before { opacity: 1; } }
  .btn:hover, a.card:hover, .card-link:hover { transform: none; }
}
