/* ==========================================================================
   Sameed Hussain: personal site
   Light "paper" and dark "deep water" themes. Instruments (the Bloch sphere,
   plots) always sit on dark plates, in both themes.
   No external fonts, no external requests.
   ========================================================================== */

@view-transition { navigation: auto; }

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Charter, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* page, light */
  --paper: #f3f5f8;
  --paper-raised: #ffffff;
  --ink: #0b2239;
  --ink-2: #3b5167;
  --ink-3: #56697d;
  --rule: rgba(11, 34, 57, 0.14);
  --accent: #9a4700;
  --focus: #1c63c4;
  --selection: rgba(255, 180, 84, 0.45);
  --shadow-plate: 0 40px 70px -40px rgba(8, 28, 52, 0.55);
  --ok: #1d7a52;
  --err: #b3261e;

  /* instrument plates: identical in both themes */
  --plate: #0f2438;
  --plate-2: #153049;
  --plate-ink: #eaf1f8;
  --plate-ink-2: #b9c8d8;
  --plate-ink-3: #8aa0b6;
  --plate-line: rgba(180, 210, 240, 0.16);
  --amber: #ffb454;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;

  --gutter: clamp(20px, 4vw, 48px);
  --radius-plate: 20px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #081523;
  --paper-raised: #0c1d30;
  --ink: #e8eff7;
  --ink-2: #b4c4d6;
  --ink-3: #8da3b9;
  --rule: rgba(160, 195, 230, 0.16);
  --accent: #ffb454;
  --focus: #ffb454;
  --selection: rgba(255, 180, 84, 0.32);
  --shadow-plate: none;
  --ok: #4fd1a0;
  --err: #ff9a8a;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    --paper: #081523;
    --paper-raised: #0c1d30;
    --ink: #e8eff7;
    --ink-2: #b4c4d6;
    --ink-3: #8da3b9;
    --rule: rgba(160, 195, 230, 0.16);
    --accent: #ffb454;
    --focus: #ffb454;
    --selection: rgba(255, 180, 84, 0.32);
    --shadow-plate: none;
    --ok: #4fd1a0;
    --err: #ff9a8a;
    color-scheme: dark;
  }
}

/* --- base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--selection); }

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

h1, h2, h3, h4 { font-weight: 400; margin: 0; text-wrap: balance; }
p { margin: 0 0 1.1em; }
p:last-child { margin-bottom: 0; }

a { color: inherit; }

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -64px;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font: 600 0.9rem var(--sans);
  border-radius: 8px;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

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

.wrap {
  width: min(1160px, calc(100% - 2 * var(--gutter)));
  margin-inline: auto;
}

/* --- header -------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--paper);
  border-bottom: 1px solid transparent;
  transition: border-color 0.25s;
}
@supports (background: color-mix(in srgb, red 50%, blue)) {
  .site-header {
    background: color-mix(in srgb, var(--paper) 88%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
  }
}
.site-header[data-scrolled] { border-bottom-color: var(--rule); }

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.brand svg { width: 28px; height: 28px; flex: none; }
.brand .dot { fill: var(--accent); }

.nav {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 2.6vw, 2rem);
  font: 0.9rem var(--sans);
}
.nav a {
  color: var(--ink-2);
  text-decoration: none;
  padding: 0.35rem 0.05rem;
  border-bottom: 1px solid transparent;
}
.nav a:hover { color: var(--ink); border-bottom-color: currentColor; }
.nav a[aria-current] { color: var(--ink); border-bottom-color: var(--accent); }

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--ink-3); }
.theme-toggle svg { width: 18px; height: 18px; }

@media (max-width: 520px) {
  .brand span { display: none; }
}
@media (max-width: 400px) {
  .nav { gap: 0.6rem; font-size: 0.82rem; }
  .theme-toggle { width: 36px; height: 36px; }
  .site-header .wrap { width: calc(100% - 2 * 16px); }
}

/* --- buttons and links --------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font: 600 0.95rem var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn--primary { background: var(--ink); color: var(--paper); }
.btn--primary:hover { background: transparent; color: var(--ink); }

.link {
  color: var(--accent);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
}
.link:hover { text-decoration-thickness: 2px; }

.prose-link {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: var(--ink-3);
}
.prose-link:hover { text-decoration-color: currentColor; }

/* --- hero ---------------------------------------------------------------- */

.hero { padding-block: clamp(24px, 3.4vw, 48px) clamp(48px, 7vw, 96px); }

.hero__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(0, 0.98fr);
  gap: clamp(32px, 5vw, 76px);
  align-items: center;
}

.nowrap { white-space: nowrap; }

.hero h1 {
  font-size: clamp(2.6rem, 6vw, 4.9rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
  margin-bottom: 1.5rem;
}

.lead {
  font-size: clamp(1.15rem, 1.5vw, 1.32rem);
  line-height: 1.6;
  color: var(--ink-2);
  max-width: 33em;
}

.actions { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-top: 2.2rem; }

@media (max-width: 960px) {
  .hero__grid { grid-template-columns: minmax(0, 1fr); }
}

/* Laptop-height screens: size the hero to the window so the whole qubit
   instrument is visible without scrolling. The sphere shrinks with the window
   height, and the controls and readout get tighter. */
@media (min-width: 961px) and (max-height: 1000px) {
  .hero { padding-top: clamp(12px, 2.4vh, 24px); padding-bottom: 48px; }
  .hero .plate__bar { padding-top: 0.75rem; }
  .hero .instrument { padding-bottom: 0.9rem; }
  .hero .instrument__stage {
    max-width: clamp(220px, calc(100vh - 385px), 480px);
    max-width: clamp(220px, calc(100svh - 385px), 480px);
    margin-top: 0.2rem;
  }
  .hero .gate, .hero .plate-btn { min-height: 38px; }
  .hero .instrument__row { margin-top: 6px; }
  .hero .readout { margin-top: 0.65rem; padding: 0.55rem 0.8rem; gap: 0.35rem; }
  .hero .readout__bars { grid-template-columns: 1fr 1fr; gap: 1.6rem; }
  .hero .hint { margin-top: 0.55rem; font-size: 0.78rem; }
}

/* --- plates (instruments) ------------------------------------------------ */

.plate {
  margin: 0;
  background: var(--plate);
  color: var(--plate-ink);
  border: 1px solid var(--plate-line);
  border-radius: var(--radius-plate);
  box-shadow: var(--shadow-plate);
  font-family: var(--sans);
  font-size: 0.9rem;
  line-height: 1.45;
}
.plate :focus-visible { outline-color: var(--amber); }

.plate__bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem 0;
  color: var(--plate-ink-2);
}
.plate__title { margin: 0; font: 600 0.95rem var(--sans); color: var(--plate-ink); }
.plate__note { font-size: 0.82rem; color: var(--plate-ink-3); }

.instrument { padding-bottom: 1.2rem; }

.instrument__stage {
  position: relative;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  margin: 0.4rem auto 0;
  touch-action: pan-y;
  cursor: grab;
}
.instrument__stage:active { cursor: grabbing; }
.instrument__stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.instrument__controls { padding: 0 1.2rem; }

.gates {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}
.gate, .plate-btn {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--plate-line);
  background: rgba(255, 255, 255, 0.035);
  color: var(--plate-ink);
  font: 600 0.95rem var(--sans);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.gate:hover, .plate-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(180, 210, 240, 0.4); }
.gate:active, .plate-btn:active { background: rgba(255, 180, 84, 0.16); border-color: var(--amber); }

.instrument__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.plate-btn--measure { border-color: rgba(255, 180, 84, 0.55); color: var(--amber); }

.readout {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0 0;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  font-variant-numeric: tabular-nums;
}
.readout__ket { color: var(--plate-ink); font-size: 0.95rem; overflow-wrap: anywhere; }
.readout__bars { display: grid; gap: 0.4rem; }
.pbar {
  display: grid;
  grid-template-columns: 2.4rem 1fr 3.2rem;
  align-items: center;
  gap: 0.6rem;
  color: var(--plate-ink-2);
  font-size: 0.82rem;
}
.pbar__track { height: 6px; border-radius: 3px; background: rgba(180, 210, 240, 0.16); overflow: hidden; }
.pbar__fill { display: block; height: 100%; border-radius: 3px; width: 0; }
.pbar--0 .pbar__fill { background: var(--series-1); }
.pbar--1 .pbar__fill { background: var(--series-2); }
.pbar output { text-align: right; color: var(--plate-ink); }
.readout__log { color: var(--plate-ink-3); font-size: 0.82rem; min-height: 1.3em; }

.hint { margin: 0.9rem 1.2rem 0; color: var(--plate-ink-3); font-size: 0.82rem; }

@media (max-width: 420px) {
  .gates { gap: 6px; }
}

/* --- sections ------------------------------------------------------------ */

.section { padding-block: clamp(56px, 7.5vw, 104px); }
.section--tight { padding-top: 0; }

.section__head {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: clamp(24px, 4vw, 64px);
  align-items: end;
  margin-bottom: clamp(32px, 5vw, 56px);
}
.section__head h2 { font-size: clamp(2rem, 4.2vw, 3.1rem); line-height: 1.08; letter-spacing: -0.02em; }
.section__head p { color: var(--ink-2); max-width: 34em; }
@media (max-width: 800px) {
  .section__head { grid-template-columns: minmax(0, 1fr); align-items: start; }
}

/* work rows */

.work {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: clamp(28px, 4.5vw, 72px);
  align-items: center;
  padding-block: clamp(32px, 5vw, 60px);
  border-top: 1px solid var(--rule);
}
.work--flip { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
.work--flip .work__text { order: 2; }
.work h3 { font-size: clamp(1.55rem, 2.6vw, 2.1rem); line-height: 1.15; letter-spacing: -0.015em; margin-bottom: 0.9rem; }
.work__text p { color: var(--ink-2); }
.work__text .link { display: inline-block; margin-top: 0.8rem; }
.plate__img { display: block; width: calc(100% - 2.4rem); height: auto; margin: 0.6rem 1.2rem 0; border-radius: 10px; background: #fff; }
.work__visual figcaption { padding: 0.7rem 1.2rem 1.1rem; color: var(--plate-ink-3); font-size: 0.82rem; }
.work__visual .plate__bar { padding-bottom: 0.4rem; }
@media (max-width: 860px) {
  .work, .work--flip { grid-template-columns: minmax(0, 1fr); }
  .work--flip .work__text { order: 0; }
}

/* about */

.about {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 7fr);
  gap: clamp(32px, 6vw, 96px);
  align-items: start;
}
.portrait {
  position: sticky;
  top: 104px;
  margin: 0;
}
.portrait img {
  width: 100%;
  max-width: 380px;
  height: auto;
}
.portrait figcaption { margin-top: 0.9rem; font: 0.85rem var(--sans); color: var(--ink-3); }
@media (max-width: 860px) {
  .about { grid-template-columns: minmax(0, 1fr); }
  .portrait { position: static; }
  .portrait img { max-width: 300px; }
}

.about__text h2 { font-size: clamp(2rem, 4.2vw, 3.1rem); line-height: 1.08; letter-spacing: -0.02em; margin-bottom: 1.4rem; }
.about__text p { color: var(--ink-2); max-width: 36em; }
.about__text h3 { font-size: 1.4rem; margin: 3rem 0 1.2rem; letter-spacing: -0.01em; }

.path { list-style: none; margin: 0; padding: 0; max-width: 40em; }
.path li {
  position: relative;
  padding: 0 0 1.9rem 1.8rem;
  border-left: 1px solid var(--rule);
}
.path li:last-child { padding-bottom: 0; border-left-color: transparent; }
.path li::before {
  content: "";
  position: absolute;
  left: -5px; top: 0.62em;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.5px solid var(--ink-3);
}
.path li[data-now]::before { background: var(--accent); border-color: var(--accent); }
.path h4 { font-size: 1.12rem; line-height: 1.35; margin-bottom: 0.25rem; }
.path p { color: var(--ink-2); font-size: 1rem; line-height: 1.6; }

/* contact */

.contact { border-top: 1px solid var(--rule); }
.contact__grid {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: clamp(32px, 6vw, 96px);
  align-items: start;
}
.contact h2 { font-size: clamp(2.2rem, 5vw, 3.6rem); line-height: 1.05; letter-spacing: -0.025em; margin-bottom: 1.4rem; }
.contact__intro p { color: var(--ink-2); max-width: 30em; }
@media (max-width: 900px) { .contact__grid { grid-template-columns: minmax(0, 1fr); } }

.form {
  display: grid;
  gap: 1.15rem;
  padding: clamp(20px, 3vw, 34px);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 20px;
  font-family: var(--sans);
}
.form label { display: block; margin-bottom: 0.4rem; font-size: 0.88rem; font-weight: 600; color: var(--ink); }
.form input[type="text"], .form input[type="email"], .form textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 0.9rem;
  font: 1rem/1.5 var(--sans);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 12px;
}
.form textarea { min-height: 160px; resize: vertical; }
.form input:hover, .form textarea:hover { border-color: var(--ink-3); }
.form input:focus-visible, .form textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
.form input:read-only, .form textarea:read-only { opacity: 0.75; }
.form__hint, .form__note { margin: 0.4rem 0 0; font-size: 0.82rem; line-height: 1.5; color: var(--ink-3); }
.form__note { margin: 0; }
.form__trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.form__send { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem 1.2rem; }
.form__status { margin: 0; flex: 1 1 16rem; font-size: 0.92rem; font-weight: 600; line-height: 1.45; color: var(--ink-2); }
.form__status[data-state="ok"] { color: var(--ok); }
.form__status[data-state="error"] { color: var(--err); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn:disabled:hover { background: var(--ink); color: var(--paper); }

.toast {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translate(-50%, 24px);
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font: 600 0.88rem var(--sans);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 80;
}
.toast[data-show] { opacity: 1; transform: translate(-50%, 0); }

/* footer */

.site-footer { border-top: 1px solid var(--rule); padding-block: 2rem 2.6rem; font: 0.85rem var(--sans); color: var(--ink-3); }
.site-footer__inner { display: flex; flex-wrap: wrap; gap: 0.8rem 2rem; justify-content: space-between; }
.site-footer a { color: var(--ink-2); }
.site-footer ul { list-style: none; display: flex; gap: 1.4rem; margin: 0; padding: 0; }

/* --- project pages ------------------------------------------------------- */

.page-head { padding-block: clamp(36px, 6vw, 80px) clamp(28px, 4vw, 48px); }
.page-head .crumb { font: 0.9rem var(--sans); color: var(--ink-3); margin-bottom: 1.6rem; }
.page-head .crumb a { color: var(--ink-2); }
.page-head h1 { font-size: clamp(2.3rem, 5.6vw, 4.2rem); line-height: 1.04; letter-spacing: -0.028em; max-width: 14em; margin-bottom: 1.3rem; }
.page-head .lead { max-width: 38em; }
.page-head .credit { margin-top: 1.4rem; font: 0.92rem var(--sans); color: var(--ink-3); }

.article { padding-block: clamp(40px, 6vw, 80px); border-top: 1px solid var(--rule); }
.article__grid {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 7fr);
  gap: clamp(24px, 5vw, 80px);
  align-items: start;
}
.article h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.12; letter-spacing: -0.018em; }
.article__body > * { max-width: 38em; }
.article__body p { color: var(--ink-2); }
.article__body h3 { font-size: 1.25rem; margin: 2rem 0 0.6rem; }
@media (max-width: 860px) {
  .article__grid { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
}

.note {
  padding: 1rem 1.2rem;
  border-left: 2px solid var(--accent);
  background: var(--paper-raised);
  color: var(--ink-2);
  font: 0.95rem/1.55 var(--sans);
  border-radius: 0 10px 10px 0;
}

/* equation block */

.equation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 0.9rem;
  margin: 1.6rem 0;
  padding: 1.4rem 1.4rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 16px;
  font-size: 1.15rem;
  overflow-x: auto;
}
.equation i, .equation var { font-style: italic; }
.equation sub, .equation sup { font-size: 0.7em; line-height: 0; }
.frac { display: inline-grid; justify-items: center; line-height: 1.25; }
.frac > span:first-child { padding: 0 0.3em 0.08em; border-bottom: 1px solid currentColor; }
.frac > span:last-child { padding-top: 0.08em; }
.controls__pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.controls__pair .seg label { padding: 0 0.3rem; font-size: 0.8rem; }
.matrix {
  display: inline-grid;
  grid-template-columns: repeat(3, auto);
  gap: 0.35rem 1.1rem;
  padding: 0.2rem 0.9rem;
  border-left: 1.5px solid var(--ink-2);
  border-right: 1.5px solid var(--ink-2);
  border-radius: 8px;
  text-align: center;
  font-size: 1.02rem;
}

/* parameter table */

.params { width: 100%; border-collapse: collapse; font: 0.95rem var(--sans); }
.params th, .params td { text-align: left; padding: 0.6rem 0.9rem 0.6rem 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.params th { font-weight: 600; color: var(--ink); width: 45%; }
.params td { color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* --- the explorer (plots) ------------------------------------------------ */

.lab { display: grid; grid-template-columns: minmax(0, 1fr) 344px; gap: 20px; align-items: start; }
@media (max-width: 1020px) { .lab { grid-template-columns: minmax(0, 1fr); } }

.lab__plot { padding: 0 0 1.1rem; }
.lab__metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 1rem 1.2rem 0.2rem;
  border-radius: 12px;
  overflow: hidden;
  background: var(--plate-line);
}
.metric { padding: 0.8rem 1rem; background: var(--plate); }
.metric dt { color: var(--plate-ink-3); font-size: 0.78rem; margin-bottom: 0.15rem; }
.metric dd { margin: 0; font: 600 1.45rem/1.15 var(--sans); color: var(--plate-ink); font-variant-numeric: tabular-nums; }
.metric dd small { font-size: 0.8rem; font-weight: 400; color: var(--plate-ink-3); margin-left: 0.2rem; }
@media (max-width: 520px) {
  .lab__metrics { grid-template-columns: 1fr; }
  .metric { display: flex; justify-content: space-between; align-items: baseline; }
  .metric dt { margin: 0; }
}

.chart-box { position: relative; margin: 0.6rem 0.6rem 0; }
.chart-box canvas { width: 100%; height: 400px; touch-action: pan-y; }
.chart-box canvas:focus-visible { outline: 2px solid var(--amber); outline-offset: -2px; border-radius: 12px; }
@media (max-width: 600px) { .chart-box canvas { height: 330px; } }
.chart-box--short canvas { height: 300px; }

.tip {
  position: absolute;
  top: 0; left: 0;
  z-index: 5;
  min-width: 168px;
  padding: 0.6rem 0.75rem;
  background: #0a1a2b;
  border: 1px solid var(--plate-line);
  border-radius: 10px;
  color: var(--plate-ink-2);
  font-size: 0.8rem;
  line-height: 1.4;
  pointer-events: none;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.6);
  font-variant-numeric: tabular-nums;
}
.tip[hidden] { display: none; }
.tip__head { color: var(--plate-ink); font-weight: 600; margin-bottom: 0.35rem; }
.tip__row { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 0.5rem; }
.tip__key { width: 14px; height: 0; border-top: 2px solid; }
.tip__val { color: var(--plate-ink); font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; margin: 0.5rem 1.2rem 0; padding: 0; list-style: none; color: var(--plate-ink-2); font-size: 0.82rem; }
.legend li { display: inline-flex; align-items: center; gap: 0.45rem; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid; }
.legend i.legend__dash { border-top-style: dashed; }
.legend i.legend__band { height: 10px; border-top: 0; border-radius: 2px; background: rgba(185, 200, 216, 0.22); }
.legend i.legend__dot { width: 9px; height: 9px; border: 0; border-radius: 50%; }

.lab__tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem; margin: 0.8rem 1.2rem 0; }
.plate-link {
  background: none; border: 0; padding: 0.4rem 0;
  color: var(--plate-ink-2); font: 0.82rem var(--sans);
  text-decoration: underline; text-underline-offset: 0.2em; cursor: pointer;
}
.plate-link:hover { color: var(--plate-ink); }

.table-wrap { margin: 0.6rem 1.2rem 0; overflow-x: auto; }
.table-wrap[hidden] { display: none; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.data-table caption { text-align: left; color: var(--plate-ink-3); padding-bottom: 0.4rem; }
.data-table th, .data-table td { padding: 0.35rem 0.6rem 0.35rem 0; text-align: right; border-bottom: 1px solid var(--plate-line); white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--plate-ink-2); font-weight: 600; }

/* controls panel */

.controls { padding: 1.1rem 1.2rem 1.3rem; display: grid; gap: 1.2rem; }
.controls fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.controls legend, .field__label { display: block; padding: 0; margin-bottom: 0.45rem; color: var(--plate-ink-2); font-size: 0.82rem; }

.seg {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  width: 100%;
  padding: 3px;
  border: 1px solid var(--plate-line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.03);
}
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg label {
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 0 0.6rem;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--plate-ink-2);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.seg label:hover { color: var(--plate-ink); }
.seg input:checked + label { background: var(--plate-ink); color: var(--plate); font-weight: 600; }
.seg input:focus-visible + label { outline: 2px solid var(--amber); outline-offset: 2px; }

.field { display: grid; gap: 0.1rem; }
.field__head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.field__head .field__label { margin: 0; }
.field__head output { color: var(--plate-ink); font-weight: 600; font-variant-numeric: tabular-nums; font-size: 0.85rem; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 0.5rem; }
.chip {
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--plate-line);
  background: transparent;
  color: var(--plate-ink-2);
  font: 0.78rem var(--sans);
  cursor: pointer;
}
.chip:hover { color: var(--plate-ink); border-color: rgba(180, 210, 240, 0.4); }
.chip[aria-pressed="true"] { background: rgba(255, 180, 84, 0.16); border-color: var(--amber); color: var(--plate-ink); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(180, 210, 240, 0.26); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; margin-top: -7px;
  border-radius: 50%;
  background: var(--amber);
  border: 3px solid var(--plate);
  box-shadow: 0 0 0 1px var(--amber);
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(180, 210, 240, 0.26); }
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--amber);
  border: 3px solid var(--plate);
  box-shadow: 0 0 0 1px var(--amber);
}
input[type="range"]:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 6px; }

.controls details { border-top: 1px solid var(--plate-line); padding-top: 0.9rem; }
.controls summary { cursor: pointer; color: var(--plate-ink); font-weight: 600; font-size: 0.88rem; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.controls summary::-webkit-details-marker { display: none; }
.controls summary::after { content: "+"; font-size: 1.2rem; font-weight: 400; color: var(--plate-ink-3); }
.controls details[open] summary::after { content: "\2212"; }
.controls details > .controls__group { display: grid; gap: 0.9rem; margin-top: 1rem; }
.controls details p { color: var(--plate-ink-3); font-size: 0.8rem; margin: 0; }

.reset-row { display: flex; justify-content: flex-end; }

/* --- pipeline explorer (JWST) -------------------------------------------- */

.stages { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; position: relative; }
.stage-tab {
  position: relative;
  display: grid;
  gap: 0.15rem;
  width: 100%;
  padding: 1.1rem 1rem 1rem 0;
  text-align: left;
  background: none;
  border: 0;
  border-top: 2px solid var(--rule);
  color: var(--ink-3);
  font: 0.9rem var(--sans);
  cursor: pointer;
}
.stage-tab strong { font: 400 1.25rem var(--serif); color: var(--ink-2); }
.stage-tab:hover { color: var(--ink); }
.stage-tab[aria-selected="true"] { border-top-color: var(--accent); color: var(--ink-2); }
.stage-tab[aria-selected="true"] strong { color: var(--ink); }
.stage-tab:focus-visible { outline-offset: -2px; }

.stage-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(20px, 3vw, 40px); padding-top: 1.6rem; }
.stage-panel[hidden] { display: none; }
.stage-panel h3 { font: 600 0.85rem var(--sans); color: var(--ink-3); margin: 0 0 0.45rem; }
.stage-panel p { font-size: 1rem; line-height: 1.6; color: var(--ink-2); }
.stage-panel code { font: 0.88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--ink); background: var(--paper-raised); border: 1px solid var(--rule); padding: 0.05em 0.35em; border-radius: 5px; }
@media (max-width: 860px) {
  .stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-panel { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
}

.figures { display: grid; grid-template-columns: minmax(0, 1fr); gap: clamp(28px, 4vw, 48px); align-items: start; }
.figure { margin: 0; }
.figure img { width: 100%; height: auto; border-radius: 14px; border: 1px solid var(--rule); background: #fff; }
.figure figcaption { margin-top: 0.7rem; font: 0.9rem/1.5 var(--sans); color: var(--ink-3); }

/* --- 404 ----------------------------------------------------------------- */

.lost { min-height: 62vh; display: grid; align-content: center; padding-block: 64px; }
.lost h1 { font-size: clamp(2.4rem, 6vw, 4.4rem); line-height: 1.04; letter-spacing: -0.028em; margin-bottom: 1.2rem; max-width: 12em; }
.lost p { color: var(--ink-2); max-width: 30em; }

/* --- motion preferences -------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

@media print {
  .site-header, .toast, .skip-link { display: none; }
  body { background: #fff; color: #000; }
}
