/* ==========================================================================
   MAK Synth — monochrome design system
   Palette: black, white, grays only. No color, no shadows, no gradients.
   ========================================================================== */

/* ---- Fonts (self-hosted) ------------------------------------------------- */
@font-face {
  font-family: "Synthek";
  src: url("../fonts/synthekR.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/IBMPlexSans-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/IBMPlexSans-Medium.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/IBMPlexSans-Bold.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

/* ---- Tokens -------------------------------------------------------------- */
:root {
  --bg: #ffffff;
  --surface: #f5f5f5;
  --surface-2: #ececec;
  --ink: #111111;
  --ink-2: #3c3c3c;
  --ink-3: #6a6a6a;
  --line: #e2e2e2;
  --line-strong: #c9c9c9;
  --on-ink: #ffffff;

  --font-body: "IBM Plex Sans", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Synthek", "IBM Plex Sans", system-ui, sans-serif;

  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;

  --gutter: clamp(1rem, 4vw, 2.5rem);
  --maxw: 72rem;
  --maxw-narrow: 46rem;

  --step: 0;
  --t-fast: 120ms;
  --t-med: 200ms;
}

/* Explicit dark theme only (default stays light regardless of device). */
:root[data-theme="dark"] {
  --bg: #0d0d0d;
  --surface: #181818;
  --surface-2: #232323;
  --ink: #f3f3f3;
  --ink-2: #cfcfcf;
  --ink-3: #9a9a9a;
  --line: #2b2b2b;
  --line-strong: #3d3d3d;
  --on-ink: #0d0d0d;
}

/* High-contrast: automatic via prefers-contrast, and manual via data-contrast. */
@media (prefers-contrast: more) {
  :root:not([data-contrast="normal"]) {
    --surface: #ffffff; --surface-2: #ffffff;
    --ink: #000000; --ink-2: #000000; --ink-3: #333333;
    --line: #000000; --line-strong: #000000;
  }
  :root[data-theme="dark"]:not([data-contrast="normal"]) {
    --bg: #000000; --surface: #000000; --surface-2: #000000;
    --ink: #ffffff; --ink-2: #ffffff; --ink-3: #dddddd;
    --line: #ffffff; --line-strong: #ffffff; --on-ink:#000000;
  }
}
:root[data-contrast="high"] {
  --surface: #ffffff; --surface-2: #ffffff;
  --ink: #000000; --ink-2: #000000; --ink-3: #2a2a2a;
  --line: #000000; --line-strong: #000000;
}
:root[data-theme="dark"][data-contrast="high"] {
  --bg: #000000; --surface: #000000; --surface-2: #000000;
  --ink: #ffffff; --ink-2: #ffffff; --ink-3: #e6e6e6;
  --line: #ffffff; --line-strong: #ffffff; --on-ink:#000000;
}

/* ---- Reset / base -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  font-size: calc(100% + (var(--step) * 1px));
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1, h2, h3, h4 { color: var(--ink); line-height: 1.12; margin: 0 0 .5em; text-wrap: balance; }
h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(2.1rem, 1.3rem + 3.4vw, 3.4rem); letter-spacing: .01em; }
h2 { font-family: var(--font-display); font-weight: 400; font-size: clamp(1.6rem, 1.15rem + 2vw, 2.4rem); letter-spacing: .01em; }
h3 { font-weight: 600; font-size: clamp(1.15rem, 1.05rem + .5vw, 1.4rem); }
h4 { font-weight: 600; font-size: 1.0625rem; }
p { margin: 0 0 1rem; text-wrap: pretty; max-width: 68ch; }
a { color: var(--ink); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
strong { font-weight: 600; }
img { max-width: 100%; height: auto; display: block; }
ul, ol { margin: 0 0 1rem; padding-left: 1.25rem; }
li { margin: .3rem 0; }
code, kbd, samp { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
::selection { background: var(--ink); color: var(--on-ink); }

/* ---- Skip link ----------------------------------------------------------- */
.skip-link {
  position: absolute; left: .75rem; top: -4rem;
  background: var(--ink); color: var(--on-ink);
  padding: .6rem 1rem; border-radius: var(--r-sm); z-index: 100;
  transition: top var(--t-fast) ease;
}
.skip-link:focus { top: .75rem; }

/* ---- Layout -------------------------------------------------------------- */
.container { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }
.narrow { max-width: var(--maxw-narrow); }
.section { padding-block: clamp(2.75rem, 1.5rem + 5vw, 5rem); }
.section--tight { padding-block: clamp(2rem, 1.2rem + 3vw, 3.25rem); }
.section + .section { border-top: 1px solid var(--line); }
.stack > * + * { margin-top: 1rem; }
.lead { font-size: clamp(1.1rem, 1.02rem + .4vw, 1.3rem); color: var(--ink-2); }
.eyebrow-free { color: var(--ink-3); }
.center { text-align: center; }
.muted { color: var(--ink-3); }

/* ---- Icons --------------------------------------------------------------- */
.icon { width: 1.25em; height: 1.25em; fill: currentColor; flex: none; vertical-align: -.2em; }
.icon--sm { width: 1em; height: 1em; }
.icon--lg { width: 1.9em; height: 1.9em; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ext-icon { width: .85em; height: .85em; margin-left: .25em; vertical-align: baseline; }

/* ---- Header / nav -------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 1rem; min-height: 4rem; position: relative; }
.brand {
  display: inline-flex; align-items: center; gap: .55rem;
  text-decoration: none; font-family: var(--font-display);
  font-size: 1.4rem; letter-spacing: .02em; color: var(--ink);
  padding: .4rem 0;
}
.brand .brand-mark { width: 1.55rem; height: 1.55rem; }
.brand:hover { text-decoration: none; }
/* Tighten the header on very narrow screens so the controls fit. */
@media (max-width: 24rem) {
  .brand { font-size: 1.15rem; }
  .header-inner { gap: .5rem; }
  .header-tools { gap: .25rem; }
}

/* Hamburger: three lines only, no button chrome. */
.nav-toggle {
  align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; background: none; padding: 0;
  color: var(--ink); cursor: pointer;
}
.nav-toggle .icon-close { display: none; }
.nav-toggle[aria-expanded="true"] .icon-open { display: none; }
.nav-toggle[aria-expanded="true"] .icon-close { display: inline-flex; }

/* Default (no JS): links are a visible stacked list. */
.nav-list {
  list-style: none; margin: 0; padding: .4rem 0 0;
  display: flex; flex-direction: column; gap: .25rem;
}
/* With JS on small screens: collapse into a dropdown opened by the button. */
html.js .nav-list {
  display: none; position: absolute; right: 0; top: calc(100% + .55rem); z-index: 45;
  flex-direction: column; min-width: 13rem; padding: .5rem;
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--r-md);
}
html.js .nav-list.open { display: flex; }
.nav-list a {
  display: block; padding: .7rem .6rem; text-decoration: none;
  color: var(--ink-2); font-weight: 500; border-radius: var(--r-sm);
}
.nav-list a:hover { color: var(--ink); }
.nav-list a[aria-current="page"] { color: var(--ink); font-weight: 600; background: var(--surface); padding-inline: .6rem; }

.header-tools { display: flex; gap: .4rem; align-items: center; margin-left: auto; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--ink);
  cursor: pointer; transition: background var(--t-fast) ease;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn:active { transform: translateY(1px); }

/* Theme toggle (light/dark) */
.theme-toggle {
  align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--ink);
  cursor: pointer; transition: background var(--t-fast) ease, transform var(--t-fast) ease;
}
.theme-toggle:hover { background: var(--surface); }
.theme-toggle:active { transform: translateY(1px); }
.theme-toggle .icon-light { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: inline-flex; }

/* Display-settings popover */
.settings-wrap { position: relative; }
.settings-panel {
  position: absolute; right: 0; top: calc(100% + .5rem); z-index: 60;
  width: min(20rem, 85vw); background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  padding: 1rem;
}
.settings-panel[hidden] { display: none; }
.settings-row { padding: .6rem 0; border-top: 1px solid var(--line); }
.settings-row:first-of-type { border-top: 0; }
.settings-row h3 { font-size: .95rem; margin: 0 0 .5rem; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; }
.seg button {
  min-height: 44px; min-width: 48px; padding: 0 .7rem; border: 0;
  background: var(--bg); color: var(--ink-2); cursor: pointer; font: inherit;
  border-left: 1px solid var(--line-strong);
}
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); font-weight: 600; }
.seg button:hover:not([aria-pressed="true"]) { background: var(--surface); }

/* Desktop nav: links always visible inline, toggle hidden. */
@media (min-width: 56rem) {
  .nav-toggle { display: none !important; }
  /* Three-part navbar: brand left, links centered, controls right. */
  .header-inner { display: grid; grid-template-columns: 1fr auto 1fr; }
  .brand { justify-self: start; }
  .header-tools { justify-self: end; margin-left: 0; }
  .nav-list, html.js .nav-list {
    display: flex; flex-direction: row; align-items: center; gap: .35rem;
    position: static; min-width: 0; padding: 0; background: none; border: 0;
    justify-self: center;
  }
  .nav-list a { padding: .55rem .7rem; }
  .nav-list a[aria-current="page"] { padding-inline: .7rem; }
}

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .7rem 1.25rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border-radius: var(--r-sm); border: 1.5px solid var(--ink);
  background: var(--ink); color: var(--on-ink);
  transition: background var(--t-fast) ease, color var(--t-fast) ease, transform var(--t-fast) ease;
}
.btn:hover { background: var(--ink-2); border-color: var(--ink-2); text-decoration: none; transform: scale(1.04); }
.btn:active { transform: scale(.99); }
.btn--secondary { background: var(--bg); color: var(--ink); border-color: var(--line-strong); }
.btn--secondary:hover { background: var(--surface); border-color: var(--ink); }
.btn[aria-disabled="true"], .btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: .75rem; }

/* ---- Cards & grids ------------------------------------------------------- */
.grid { display: grid; gap: clamp(1rem, 2.5vw, 1.5rem); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: clamp(1.25rem, 1rem + 1vw, 1.75rem);
}
.card h3 { margin-top: 0; }
.card .card-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.75rem; height: 2.75rem; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); margin-bottom: .9rem; color: var(--ink);
}
.card--plain { background: var(--bg); }

/* Numbered marker (pillars / disciplines) */
.num {
  display: block; margin-bottom: .4rem;
  font-family: var(--font-display); color: var(--ink-3);
  font-size: .95rem; letter-spacing: .08em;
}
.card .card-icon { display: flex; }

/* ---- Hero ---------------------------------------------------------------- */
.hero { padding-block: clamp(2.5rem, 1.5rem + 5vw, 5rem); }
.hero-grid { display: grid; gap: clamp(1.5rem, 1rem + 4vw, 3rem); align-items: center; }
@media (min-width: 56rem) { .hero-grid { grid-template-columns: 1.05fr 1fr; } }
.hero h1 { margin-bottom: .75rem; }
.hero .lead { margin-bottom: 1.5rem; }
.hero figure { margin: 0; }
.figure {
  margin: 0; border: 1px solid var(--line); border-radius: var(--r-md);
  overflow: hidden; background: var(--surface);
}
.figure img { width: 100%; height: auto; }
.figure figcaption { padding: .7rem 1rem; font-size: .9rem; color: var(--ink-3); border-top: 1px solid var(--line); }

/* One-line page title helper */
.h1--tight { font-size: clamp(1.7rem, 1rem + 2.6vw, 2.5rem); }
@media (min-width: 56rem) { .h1--tight { white-space: nowrap; } }

/* Feature cards with media */
.card--feature { display: flex; flex-direction: column; }
.card-media {
  margin: 0 0 1.1rem; border: 1px solid var(--line); border-radius: var(--r-sm);
  overflow: hidden; aspect-ratio: 16 / 10; background: var(--surface-2);
}
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card--feature .card-icon { margin-bottom: .75rem; }

/* Image + text split (setup, downloads) */
.feature-split { display: grid; gap: clamp(1.25rem, 1rem + 2vw, 2rem); align-items: center; }
@media (min-width: 52rem) { .feature-split { grid-template-columns: 1.3fr .9fr; } }

/* ---- Signal chain / steps ------------------------------------------------ */
.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; display: grid; gap: 1rem; }
.steps > li {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 1.25rem 1.25rem 1.25rem 4.25rem; margin: 0;
}
.steps > li::before {
  counter-increment: step; content: counter(step, decimal-leading-zero);
  position: absolute; left: 1.1rem; top: 1.1rem;
  font-family: var(--font-display); font-size: 1.25rem; color: var(--ink);
  width: 2.3rem; height: 2.3rem; border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center;
}
.steps h3 { margin-top: .1rem; }
.steps p:last-child { margin-bottom: 0; }

.chain { display: grid; gap: .85rem; }
.chain-item {
  display: flex; gap: 1rem; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 1.1rem 1.25rem;
}
.chain-item .card-icon { margin: 0; flex: none; }
.chain-arrow { display: flex; justify-content: center; color: var(--ink-3); }
.chain-arrow .icon { transform: rotate(90deg); }

/* ---- Definition / spec lists --------------------------------------------- */
.spec { display: grid; grid-template-columns: 1fr; gap: 0; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.spec div { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: .85rem 1.1rem; border-top: 1px solid var(--line); }
.spec div:first-child { border-top: 0; }
.spec dt { color: var(--ink-3); margin: 0; }
.spec dd { margin: 0; font-weight: 500; }

/* ---- Tables (responsive to cards) ---------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; border: 1px solid var(--line); border-radius: var(--r-md); }
table.data caption { text-align: left; color: var(--ink-3); font-size: .9rem; padding: .5rem 0; }
table.data th, table.data td { text-align: left; padding: .7rem .9rem; border-top: 1px solid var(--line); vertical-align: top; }
table.data thead th { border-top: 0; background: var(--surface); font-weight: 600; }
table.data tbody tr:nth-child(even) { background: var(--surface); }
@media (max-width: 44rem) {
  table.data, table.data thead, table.data tbody, table.data tr, table.data th, table.data td { display: block; }
  table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data tr { border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: .75rem; }
  table.data td { border-top: 1px solid var(--line); padding-left: 42%; position: relative; }
  table.data td:first-child { border-top: 0; }
  table.data td::before {
    content: attr(data-label); position: absolute; left: .9rem; top: .7rem;
    width: 36%; color: var(--ink-3); font-weight: 500;
  }
}

/* ---- Download list ------------------------------------------------------- */
.dl-card { display: grid; gap: 1rem; }
.dl-card .dl-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.dl-card code.fname { font-size: 1rem; background: var(--surface-2); padding: .15rem .45rem; border-radius: var(--r-sm); }
.dl-meta { display: flex; flex-wrap: wrap; gap: .3rem 1.25rem; color: var(--ink-3); font-size: .9rem; list-style: none; padding: 0; margin: 0; }
.dl-meta li { margin: 0; }

/* ---- Process / prototypes ------------------------------------------------ */
.proto { display: grid; gap: clamp(1.25rem, 1rem + 2vw, 2rem); }
.proto-item { display: grid; gap: 1.25rem; align-items: center; }
@media (min-width: 52rem) {
  .proto-item { grid-template-columns: 1fr 1fr; }
  .proto-item:nth-child(even) .proto-media { order: 2; }
}
.badge-step { font-family: var(--font-display); color: var(--ink-3); letter-spacing: .08em; font-size: .9rem; display: block; margin-bottom: .4rem; }

/* ---- Footer -------------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); margin-top: 2rem; }
.footer-grid { display: grid; gap: 1.5rem 2rem; padding-block: 2.5rem 1.5rem; grid-template-columns: 1fr; }
@media (min-width: 40rem) { .footer-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 60rem) { .footer-grid { grid-template-columns: 1.5fr 1fr 1fr; } }
.footer-grid h2 { font-family: var(--font-body); font-weight: 600; font-size: .95rem; letter-spacing: .02em; color: var(--ink-3); margin-bottom: .75rem; }
.footer-grid ul { list-style: none; padding: 0; margin: 0; }
.footer-grid li { margin: .4rem 0; }
.footer-grid a { color: var(--ink-2); text-decoration: none; }
.footer-grid a:hover { color: var(--ink); text-decoration: underline; }
.footer-bottom { border-top: 1px solid var(--line); padding-block: 1.25rem; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; justify-content: space-between; color: var(--ink-3); font-size: .9rem; }
/* Footer brand matches the navbar brand styling. */
.footer-brand { text-decoration: none; }
.footer-brand:hover { text-decoration: none; }
/* Footer display controls (full-width row, wraps freely) */
.footer-grid > * { min-width: 0; }
.footer-display { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 2rem; padding-block: 1.25rem; border-top: 1px solid var(--line); }
.footer-display h2 { margin: 0; }
.footer-display .disp-row { display: flex; flex-direction: row; align-items: center; gap: .6rem; margin: 0; }
.footer-display .disp-label { color: var(--ink-2); font-size: .9rem; }

/* ---- Breadcrumbs --------------------------------------------------------- */
.breadcrumb { font-size: .9rem; color: var(--ink-3); padding-block: 1rem 0; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; padding: 0; margin: 0; }
.breadcrumb li::after { content: "/"; margin-left: .4rem; color: var(--line-strong); }
.breadcrumb li:last-child::after { content: ""; }
.breadcrumb a { color: var(--ink-2); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---- Error pages --------------------------------------------------------- */
.error-wrap { min-height: 60vh; display: grid; place-content: center; text-align: center; gap: 1rem; }
.error-code { font-family: var(--font-display); font-size: clamp(3.5rem, 2rem + 8vw, 7rem); line-height: 1; }

/* ---- JS-only controls (hidden until boot.js confirms JS) ----------------- */
.js-only { display: none; }
html.js .js-only { display: inline-flex; }

/* ---- Motion -------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---- Forced colors ------------------------------------------------------- */
@media (forced-colors: active) {
  .btn, .icon-btn, .nav-toggle, .card, .figure, .steps > li, .chain-item { border: 1px solid ButtonText; }
  .icon { fill: currentColor; }
}

/* ---- Print --------------------------------------------------------------- */
@media print {
  :root { --bg:#fff; --ink:#000; --ink-2:#000; --ink-3:#333; --surface:#fff; --surface-2:#fff; --line:#999; --line-strong:#000; }
  .site-header, .site-footer, .skip-link, .header-tools, .nav, .btn, .btn-row, .breadcrumb { display: none !important; }
  body { color:#000; background:#fff; }
  a { color:#000; text-decoration: underline; }
  main a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .85em; color:#333; }
  .ext-icon { display: none; }
  .card, .figure, .steps > li, .chain-item, .proto-item, table.data tr { break-inside: avoid; }
  thead { display: table-header-group; }
  @page { margin: 16mm; }
}