/* ---------------------------------------------------------------
   Tokens
   --------------------------------------------------------------- */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6ea;
  --border-strong: #cfd4da;
  --text: #14181d;
  --text-muted: #5b636d;
  --accent: #0d7a75;
  --accent-soft: rgba(13, 122, 117, 0.10);
  --nn-act-neg: #c9524b;
  --nn-act-zero: #d3d8de;
  --nn-act-pos: #0d7a75;
  /* Data-viz series palette — validated categorical order (blue/orange/aqua/yellow),
     colorblind-safe in both modes. Used by every controls plot for a shared color
     language. Reference labels always accompany the color, so identity is never color-alone. */
  --viz-1: #2a78d6;  /* blue   */
  --viz-2: #eb6834;  /* orange */
  --viz-3: #1baf7a;  /* aqua   */
  --viz-4: #eda100;  /* yellow */
  --viz-7: #4a3aa7;  /* violet — reference-palette slot 7; slots 5–6 unused so far */
  --viz-total: #6b7280;  /* neutral gray — aggregate / total lines */
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-lift: 0 2px 4px rgba(16, 24, 40, .06), 0 16px 40px rgba(16, 24, 40, .12);
  --radius: 14px;
  --wrap: 1080px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: "STIX Two Text", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0f14;
    --bg-soft: #111721;
    --surface: #121821;
    --border: #232c38;
    --border-strong: #33404f;
    --text: #e7ecf3;
    --text-muted: #9aa6b4;
    --accent: #3ecfc4;
    --accent-soft: rgba(62, 207, 196, 0.14);
    --nn-act-neg: #e06a60;
    --nn-act-zero: #2a3441;
    --nn-act-pos: #3ecfc4;
    --viz-1: #3987e5;
    --viz-2: #d95926;
    --viz-3: #199e70;
    --viz-4: #c98500;
    --viz-7: #9085e9;
    --viz-total: #9aa6b4;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .45), 0 16px 40px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-soft: #111721;
  --surface: #121821;
  --border: #232c38;
  --border-strong: #33404f;
  --text: #e7ecf3;
  --text-muted: #9aa6b4;
  --accent: #3ecfc4;
  --accent-soft: rgba(62, 207, 196, 0.14);
  --nn-act-neg: #e06a60;
  --nn-act-zero: #2a3441;
  --nn-act-pos: #3ecfc4;
  --viz-1: #3987e5;
  --viz-2: #d95926;
  --viz-3: #199e70;
  --viz-4: #c98500;
  --viz-7: #9085e9;
  --viz-total: #9aa6b4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, .45), 0 16px 40px rgba(0, 0, 0, .5);
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  /* Short pages (the hero-only homepage) keep the footer at the bottom. */
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
}
body > main { flex: 1 0 auto; }

img { max-width: 100%; display: block; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 .5em; }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: 0; }
h1 { font-size: clamp(2.1rem, 5vw, 3.1rem); }
h2 { font-size: clamp(1.5rem, 3vw, 1.95rem); }
h3 { font-size: 1.15rem; font-weight: 600; }

code, pre { font-family: var(--mono); font-size: .9em; }
code { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 6px; padding: .1em .35em; }
pre { background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; overflow-x: auto; }
pre code { background: none; border: 0; padding: 0; }

.wrap { max-width: var(--wrap); margin-inline: auto; padding-inline: 1.25rem; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

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

/* ---------------------------------------------------------------
   Header / nav
   --------------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav {
  max-width: var(--wrap); margin-inline: auto; padding: .7rem 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}

.nav-brand {
  display: flex; align-items: center; gap: .6rem;
  color: var(--text); font-weight: 600; letter-spacing: -0.01em;
  margin-right: auto;
  flex-shrink: 0;
}
.nav-brand:hover { text-decoration: none; color: var(--accent); }
.nav-brand img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }

.nav-links {
  display: flex; gap: .25rem; list-style: none; margin: 0; padding: 0;
  min-width: 0; overflow-x: auto; scrollbar-width: none;
}
.nav-links::-webkit-scrollbar { display: none; }
.nav-links li { flex-shrink: 0; }
.nav-links a {
  display: block; padding: .4rem .7rem; border-radius: 8px;
  color: var(--text-muted); font-size: .95rem; font-weight: 500;
}
.nav-links a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.nav-links a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.theme-toggle {
  position: relative;
  width: 42px; height: 24px; padding: 0;
  border: none; border-radius: 12px;
  background: var(--border-strong);
  cursor: pointer; flex-shrink: 0;
  transition: background .25s;
}
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff;
  display: grid; place-items: center;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  color: #f59e0b;
}
.toggle-thumb svg { grid-area: 1 / 1; }
.icon-moon { display: none; }

:root[data-theme="dark"] .theme-toggle { background: var(--accent); }
:root[data-theme="dark"] .toggle-thumb { transform: translateX(18px); color: var(--accent); }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle { background: var(--accent); }
  :root:not([data-theme="light"]) .toggle-thumb { transform: translateX(18px); color: var(--accent); }
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

@media (max-width: 620px) {
  .nav-brand span { display: none; }
  .nav-home { display: none; }
  .nav-links a { padding: .4rem .5rem; font-size: .9rem; }
}

/* ---------------------------------------------------------------
   Hero
   --------------------------------------------------------------- */
/* The hero grows to fill <main>, so the symbol field reaches the footer. */
main:has(> .hero) { display: flex; flex-direction: column; }
.hero { flex: 1 0 auto; padding: clamp(4.5rem, 14vw, 9rem) 0 4.5rem; position: relative; overflow: hidden; }
/* The symbol field is a band wider than the text column (.hero-inner is wrapped)
   but not full-bleed; its sides fade out so it has no hard edge. */
.hero-field {
  position: absolute; top: 0; bottom: 0; left: 50%; z-index: 0;
  width: min(100%, 1400px); height: 100%;
  transform: translateX(-50%);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(to right, transparent, #000 12%, #000 88%, transparent);
  pointer-events: none;
  contain: paint;
}
.hero-inner {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 1fr auto; gap: clamp(1.5rem, 5vw, 3.5rem);
  align-items: center;
}
.hero-eyebrow {
  display: block;
  font-family: var(--mono); font-size: .8rem; letter-spacing: .03em;
  color: var(--accent); margin-bottom: 1rem;
}
.hero h1 { margin-bottom: .6rem; }
.hero h1 .accent { color: var(--accent); }
.hero-lede { font-size: 1.12rem; color: var(--text-muted); max-width: 56ch; margin: 0 0 1.6rem; }
.hero-photo {
  width: clamp(150px, 22vw, 220px); aspect-ratio: 1; border-radius: 50%;
  object-fit: cover; box-shadow: var(--shadow-lift); border: 3px solid var(--surface);
}
@media (max-width: 760px) {
  .hero-inner { grid-template-columns: 1fr; }
  .hero-photo { order: -1; width: 130px; }
}

.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; }
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .6rem 1.1rem; border-radius: 10px; font-size: .95rem; font-weight: 550;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-icon { padding: .6rem; }
.btn-icon .social-icon { width: 20px; height: 20px; display: block; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #0b0f14; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary { color: #0b0f14; }
}

/* Page body block (projects, photos). */
.section { padding-block: 3rem; }   /* block only: `.wrap.section` keeps the wrap's side gutters */

.page-head { padding: clamp(2.5rem, 6vw, 4rem) 1.25rem 1.5rem; }
.page-title { margin-bottom: .35rem; }
.page-sub { color: var(--text-muted); font-size: 1.08rem; margin: 0; max-width: 60ch; }
/* No single word stranded on the last line of a blurb or caption. */
.card p, .page-sub, .about-caption { text-wrap: pretty; }

/* ---------------------------------------------------------------
   Project cards
   --------------------------------------------------------------- */
.card-grid {
  display: grid; gap: 1.1rem;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.card {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.35rem;
  transition: border-color .16s ease, background .16s ease;
}
.card:hover { border-color: var(--accent); background: var(--bg-soft); }
.card-media { margin: -1.35rem -1.35rem 1.1rem; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.card-media img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.card h3 { margin: 0 0 .5rem; }
.card h3 a { color: var(--text); }
.card h3 a:hover { color: var(--accent); text-decoration: none; }
.card-year { font-size: .8rem; color: var(--text-muted); font-family: var(--mono); white-space: nowrap; }
.card p { margin: 0 0 1rem; color: var(--text-muted); font-size: .96rem; }
.card-foot { margin-top: auto; display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: center; }

.tags { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1rem; padding: 0; list-style: none; }
.tag {
  font-size: .74rem; font-weight: 500; letter-spacing: .01em;
  padding: .18rem .55rem; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-muted);
}

.card-links { display: flex; flex-wrap: wrap; gap: .9rem; list-style: none; margin: 0; padding: 0; }
.card-links a { font-size: .9rem; font-weight: 550; display: inline-flex; align-items: center; gap: .3rem; }
.card-links a::after { content: "→"; font-size: .9em; transition: transform .14s ease; }
.card-links a:hover { text-decoration: none; }
.card-links a:hover::after { transform: translateX(3px); }

.cv-flag {
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--accent); background: var(--accent-soft);
  padding: .15rem .5rem; border-radius: 6px;
}

/* ---------------------------------------------------------------
   Photo gallery
   --------------------------------------------------------------- */
.gallery {
  display: grid; gap: .9rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  grid-auto-rows: 240px;
}
.shot {
  position: relative; overflow: hidden; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-soft);
  cursor: zoom-in; padding: 0;
}
.shot.tall { grid-row: span 2; }
.shot img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s ease; }
.shot:hover img { transform: scale(1.05); }
.shot figcaption {
  position: absolute; inset: auto 0 0 0; padding: 2.5rem .9rem .8rem;
  background: linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,0));
  color: #fff; text-align: left;
  opacity: 0; transform: translateY(6px); transition: opacity .25s ease, transform .25s ease;
}
.shot:hover figcaption, .shot:focus-visible figcaption { opacity: 1; transform: none; }
.shot .shot-title { display: block; font-weight: 600; font-size: .98rem; }
.shot .shot-meta { display: block; font-size: .82rem; opacity: .8; }
@media (max-width: 560px) {
  .gallery { grid-auto-rows: 200px; }
  .shot figcaption { opacity: 1; transform: none; }
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  display: none; place-items: center;
  background: rgba(4, 7, 11, .93); padding: 1.5rem;
}
.lightbox[open] { display: grid; }
.lightbox img { max-width: min(1200px, 94vw); max-height: 82vh; object-fit: contain; border-radius: 10px; }
.lightbox-cap { color: #e7ecf3; text-align: center; margin-top: 1rem; font-size: .95rem; }
.lightbox-cap strong { display: block; font-size: 1.05rem; }
.lightbox-cap span { color: #9aa6b4; }
.lightbox-close {
  position: absolute; top: 1rem; right: 1rem;
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2);
  color: #fff; font-size: 1.3rem; line-height: 1;
}
.lightbox-close:hover { background: rgba(255,255,255,.2); }

/* ---------------------------------------------------------------
   Timeline / about
   --------------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative; padding: 0 0 1.6rem 1.6rem;
  border-left: 2px solid var(--border);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: .45rem;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px var(--bg);
}
.timeline .t-when { font-family: var(--mono); font-size: .8rem; color: var(--text-muted); }
.timeline .t-what { font-weight: 600; margin: .1rem 0 .1rem; }
.timeline .t-where { color: var(--text-muted); font-size: .95rem; }

.prose { padding-bottom: 4rem; }
.prose > * + * { margin-top: 1rem; }
.prose h2 { margin-top: 2.5rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li + li { margin-top: .35rem; }
.prose blockquote {
  margin: 1.5rem 0; padding: .25rem 0 .25rem 1.2rem;
  border-left: 3px solid var(--accent); color: var(--text-muted);
}
.about-photos { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.about-photos img { border-radius: var(--radius); aspect-ratio: 4 / 3; object-fit: cover; }
.about-photos-3x2 img { aspect-ratio: 3 / 2; }
.photo-row { display: flex; flex-wrap: nowrap; gap: .75rem; margin-top: 1.25rem; align-items: flex-start; }
/* Width follows each photo's aspect ratio (--r), so all three share one height and fill the row. */
.photo-row img { flex: var(--r) 1 0; min-width: 0; width: 100%; height: auto; aspect-ratio: var(--r); object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); }
.about-caption { margin-top: 1rem; }
@media (max-width: 560px) {
  .about-photos { grid-template-columns: 1fr; }
}

.prose table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.prose th, .prose td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* ---------------------------------------------------------------
   Footer
   --------------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--border); background: var(--bg-soft); margin-top: 2rem; }
.footer-inner {
  display: flex; flex-wrap: wrap; gap: .75rem 1.5rem;
  align-items: center; justify-content: space-between;
  padding-block: .55rem; color: var(--text-muted); font-size: .9rem;
}
.footer-inner p { margin: 0; }
.footer-links { display: flex; align-items: center; gap: 1.1rem; list-style: none; margin: 0; padding: 0; }
.footer-links a { display: inline-flex; align-items: center; color: var(--text-muted); }
.footer-links a:hover { color: var(--text); }
.footer-links .social-icon { width: 20px; height: 20px; display: block; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------------------------------------------------------------
   Controls page
   --------------------------------------------------------------- */
.sim-tabs {
  display: flex; gap: .4rem; flex-wrap: wrap;
  margin-bottom: 1.75rem;
}
.sim-tab {
  padding: .45rem 1.1rem; border-radius: 10px; font-size: .92rem; font-weight: 550;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  cursor: pointer; transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.sim-tab:hover { color: var(--text); border-color: var(--border-strong); }
.sim-tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.sim-tabs-row { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.sim-tabs-row .sim-tabs { margin-bottom: 0; }
.sim-tab-link {
  padding: .45rem 1.1rem; border-radius: 10px; font-size: .92rem; font-weight: 550;
  border: 1px solid var(--border); color: var(--text-muted); background: var(--surface);
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.sim-tab-link:hover { color: var(--text); border-color: var(--border-strong); }

.sim-section { display: none; }
.sim-section.active { display: block; }

.sim-layout {
  display: flex; gap: 1.25rem; align-items: stretch; flex-wrap: wrap;
}
.sim-canvas-wrap { flex: 1 1 480px; min-width: 0; }
.sim-canvas {
  display: block; width: 100%; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-soft);
}

/* Sim on top, its plots below, each exactly half the column. The bottom half
   is split again: state plot over the PID (control-input) plot. The column
   stretches to the control panel's height, so the pair lines up with the
   panel top and bottom. On /controls/ every tab shares one minimum (just over
   the tallest panel), so all the sims come out the same size. Canvases sit
   absolutely inside their cells: the JS sizes their pixel buffers from the
   CSS box, and that buffer must never feed back into the layout. */
.sim-stack {
  display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: .6rem;
}
.sim-section .sim-stack { min-height: 646px; }
.sim-cell { position: relative; min-height: 0; }
.sim-cell-pair {
  display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: .6rem; min-height: 0;
}
.sim-cell > canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; box-sizing: border-box;
}
.sim-states {
  display: block; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg);
}
/* Once the panel wraps below, nothing sets the height: give the sim 300px,
   and on /controls/ give each of the two plots under it about 190px. */
@media (max-width: 760px) {
  .sim-stack { min-height: calc(600px + .6rem); }
  .sim-section .sim-stack { min-height: calc(760px + .6rem); }
}

.sim-panel {
  flex: 0 0 220px; display: flex; flex-direction: column; gap: 1rem;
  padding: 1.1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.sim-panel h3 { margin: 0 0 .25rem; font-size: 1rem; }
/* /controls/ panels: tighter rhythm so sim + panel fit on a laptop screen. */
.sim-section .sim-panel { gap: .6rem; padding: .95rem 1rem; }
.sim-section .sim-panel h3 { margin: .2rem 0 0; }
.sim-section .sim-panel h3:first-child { margin-top: 0; }
.sim-section .score-block { padding: .1rem 0; }
.sim-section .score-value { font-size: 1.6rem; }

/* Full-width neural-network activation diagram */
.nn-netviz {
  margin-top: 1.25rem; padding: 1rem 1.1rem 1.1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.nn-netviz-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem;
}
.nn-netviz-head h3 { margin: 0; font-size: 1rem; }
.nn-netviz canvas {
  display: block; width: 100%;
  border-radius: var(--radius); background: var(--bg-soft);
}
.nn-legend { display: flex; align-items: center; gap: .4rem; }
.nn-legend-bar {
  width: 120px; height: 12px; border-radius: 6px;
  border: 1px solid var(--border);
  background: linear-gradient(90deg,
    var(--nn-act-neg, #c85050) 0%,
    var(--nn-act-zero, #cfd4da) 50%,
    var(--nn-act-pos, var(--accent)) 100%);
}
.nn-legend-cap {
  font-family: var(--mono); font-size: .85rem; color: var(--text-muted);
  line-height: 1; width: 1ch; text-align: center;
}
.nn-legend-txt {
  font-size: .78rem; color: var(--text-muted); margin-left: .1rem;
}

/* Slider group: name + value on top; slider with its ± range box on one line. */
.pid-group {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  column-gap: .5rem; row-gap: .15rem; align-items: center;
}
.pid-group > label {
  grid-column: 1 / -1; display: flex; align-items: baseline;
  font-size: .85rem; font-weight: 550; color: var(--text-muted);
}
/* The value is pushed right; "K" and its <sub> stay together on the left. */
.pid-group > label span {
  margin-left: auto;
  font-family: var(--mono); font-size: .82rem; color: var(--accent); font-weight: 400;
}
.pid-group input[type="range"] {
  width: 100%; accent-color: var(--accent); cursor: pointer;
}
.pid-group > input[type="range"]:last-child { grid-column: 1 / -1; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.score-block { text-align: center; padding: .5rem 0; }
.score-value {
  display: block; font-size: 2rem; font-weight: 700; font-family: var(--mono);
  color: var(--accent); line-height: 1;
}
.score-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.score-best { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }

.mode-toggle {
  display: flex; gap: .4rem;
}
.mode-btn {
  flex: 1; padding: .35rem .5rem; font-size: .85rem; font-weight: 550;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text-muted); cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.mode-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.telemetry {
  font-family: var(--mono); font-size: .78rem; color: var(--text-muted);
  display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px;
  padding: .55rem .7rem;
}
.telemetry .t-key { color: var(--text-muted); }
.telemetry .t-val { color: var(--accent); text-align: right; }
.telemetry .t-head { grid-column: 1 / -1; }

.elev-indicator {
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
}
.elev-track {
  width: 10px; height: 80px; background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 5px; position: relative;
}
.elev-thumb {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: 18px; height: 6px; border-radius: 3px;
  background: var(--accent); top: 50%;
}

.matrix-section { display: flex; flex-direction: column; gap: .75rem; }
.matrix-label { font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: .2rem; }
.matrix-display {
  font-family: var(--mono); font-size: .75rem; line-height: 1.55;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 8px; padding: .6rem .8rem; margin: 0;
  overflow-x: auto; white-space: pre;
}

.sysid-progress { display: flex; flex-direction: column; gap: .35rem; }
.sysid-bar-wrap {
  height: 6px; background: var(--bg-soft); border-radius: 3px;
  border: 1px solid var(--border); overflow: hidden;
}
.sysid-bar {
  height: 100%; background: var(--accent); border-radius: 3px;
  width: 0%; transition: width .3s ease;
}
.sysid-count { font-size: .78rem; color: var(--text-muted); font-family: var(--mono); }

.sim-btn {
  width: 100%; padding: .5rem .75rem; border-radius: 9px; font-size: .88rem; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: background .12s ease, border-color .12s ease;
}
.sim-btn:hover { background: var(--bg-soft); border-color: var(--border-strong); }
.sim-btn.recording { background: rgba(220,50,50,.12); border-color: #dc3232; color: #dc3232; }
.sim-btn:disabled { opacity: .45; cursor: not-allowed; }

.score-compare {
  font-size: .78rem; color: var(--text-muted); font-family: var(--mono);
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .7rem;
}

.controls-intro {
  max-width: none; color: var(--text-muted); font-size: 1rem; margin-bottom: 2rem;
}
.controls-intro + * { }

.demo-heading {
  font-size: 1.05rem; font-weight: 600; margin: 0 0 .3rem;
  font-family: var(--font);
}
.demo-sub { font-size: .88rem; color: var(--text-muted); margin: 0 0 1.25rem; max-width: 65ch; }

/* Demo notes + hints — shared by /controls/ and /controls/swingup/ */
.demo-note{margin:.55rem 0 .85rem;border:1px solid var(--border);border-radius:8px;padding:.65rem .85rem;background:var(--bg-soft)}
.demo-note-title{margin:0 0 .35rem;font-size:.8rem;font-weight:600;color:var(--text);letter-spacing:.01em}
.demo-note>p{margin:.15rem 0;font-size:.82rem;line-height:1.55}
.demo-note>p+p{margin-top:.5rem}
.panel-hint{font-size:.75rem;line-height:1.45;color:var(--text-muted);margin:.1rem 0 .5rem}
.mx { display: inline-grid; vertical-align: middle; gap: .15rem .6rem; padding: .1rem .5rem; margin: 0 .25rem;
  border-left: 2px solid currentColor; border-right: 2px solid currentColor; border-radius: 4px;
  font-family: var(--mono); text-align: center; line-height: 1.35; }
.mx-row { grid-auto-flow: column; }
.mx-grid { grid-auto-flow: row; }
.mx-col { grid-auto-flow: row; }
.mx-line { display: flex; flex-wrap: nowrap; align-items: center; gap: .2rem; margin: .1rem 0 .6rem;
  font-size: .72rem; color: var(--text-muted); }
.mx-f { white-space: nowrap; }
.mx-line .mx { margin: 0 .1rem; gap: .1rem .45rem; padding: .1rem .35rem; }
.mx-line .mx-row { color: var(--accent); }
.mx-line .mx-state { color: var(--text-muted); }
/* Matrix equations never wrap mid-expression; a row scrolls sideways if it is wider than the screen. */
.eqn-row:has(.mx) { overflow-x: auto; padding-bottom: .2rem; }
.eqn-rhs:has(.mx) { display: flex; align-items: center; white-space: nowrap; }
/* Phones: the CAD render goes full width on top, the two bike photos share the row below. */
@media (max-width: 560px) {
  .photo-row { display: grid; grid-template-columns: 1fr 1fr; }
  .photo-row img { width: 100%; aspect-ratio: 3 / 4; }
  .photo-row img:first-child { grid-column: 1 / -1; aspect-ratio: var(--r); }
}
@media (max-width: 720px) {
  .sim-section .sim-panel { flex-basis: 100%; }
  .mx { font-size: .74rem; padding: .1rem .35rem; margin: 0 .15rem; gap: .1rem .4rem; }
}
.eqn-note{margin:.5rem 0 0;font-size:.74rem;color:var(--text-muted);font-family:var(--font);font-style:italic}

/* Swing-up page */
.su-crumb { margin: 0 0 .9rem; font-size: .88rem; }
.su-layout .sim-stack { min-height: 646px; }   /* same sim size as the /controls/ tabs */
.su-canvas { touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.su-canvas:active { cursor: grabbing; }
.su-model-status:empty { display: none; }
.sim-panel .panel-hint { margin: 0; }
.su-targets { display: flex; flex-direction: column; gap: .4rem; }
.su-targets[hidden] { display: none; }
.goal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; }
.goal-btn {
  display: flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .1rem .4rem; font: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.goal-btn:hover { background: var(--bg-soft); border-color: var(--border-strong); }
.goal-btn.active { background: var(--accent-soft); border-color: var(--accent); }
.goal-btn.active .goal-label { color: var(--accent); }
.goal-btn-random { grid-column: 1 / -1; padding: .3rem .4rem; }
.goal-icon {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 700; font-size: .95rem; color: var(--text-muted);
}
.goal-icon svg { display: block; width: 28px; height: 46px; }
.goal-label { font-family: var(--mono); font-weight: 700; font-size: .88rem; }
.su-reset-row { display: flex; gap: .4rem; }
.su-reset-row .sim-btn { padding: .45rem .3rem; font-size: .8rem; white-space: nowrap; }
.su-layout .sim-panel { gap: .8rem; }
.su-layout .score-block { padding: .2rem 0; }
.su-layout .mode-btn { white-space: nowrap; padding-inline: .3rem; }
/* The label changes with the pose ("UD → UU time"); keep it one line so the panel height never moves. */
.su-layout .score-label { white-space: nowrap; }
.gi-rail { stroke: var(--border-strong); stroke-width: 1.5; }
.gi-cart { fill: var(--accent); }
.gi-rod { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.gi-bob-0 { fill: var(--viz-1); }
.gi-bob-1 { fill: var(--viz-2); }
@media (max-width: 720px) { .su-layout .sim-panel { flex-basis: 100%; } }

/* ---------------------------------------------------------------
   Touch polish: 44px hit areas, no iOS focus-zoom, no double-tap zoom.
   Desktop (fine pointer) is untouched.
   --------------------------------------------------------------- */
@media (pointer: coarse) {
  a, button, input, select, summary, [role="tab"] { touch-action: manipulation; }
  button, .btn, [role="tab"] { -webkit-tap-highlight-color: transparent; }
  .nav-links a { padding-top: .6rem; padding-bottom: .6rem; }
  .theme-toggle::after { content: ""; position: absolute; inset: -10px -6px; }
  .footer-links a { padding: .75rem .4rem; margin: -.75rem -.4rem; }
  .mode-btn, .sim-btn, .goal-btn, .btn { min-height: 44px; }
  input[type="number"], input[type="text"], select, .range-input { font-size: 16px; min-height: 40px; }
  input[type="range"] { min-height: 32px; }
  .card-links a { padding: .6rem 0; }
}

/* Hint box: a recommended solution, shown until the visitor has tried things themselves. */
.hint-box {
  border: 1px solid var(--accent); border-radius: 8px; background: var(--accent-soft);
  padding: .55rem .7rem; font-size: .8rem; line-height: 1.5; color: var(--text);
}
.hint-box[hidden] { display: none; }
.hint-text { margin: 0 0 .45rem; }
.hint-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.hint-row .sim-btn { padding: .25rem .7rem; }
