/* Within Quantum
   Palette follows domain colouring of complex phase: each tool sits at
   its own angle on the phase wheel. */

:root {
  --paper: #F4F5F9;
  --surface: #FFFFFF;
  --ink: #161B33;
  --muted: #545B78;
  --rule: #D6D9E6;
  --grid: #C3C8DB;

  --cobalt: #2F5FD0;   /* α, Qoffee */
  --rose: #C92A63;     /* β, Qorq */
  --leaf: #3B7F1C;     /* Qlossary */

  --display: "IBM Plex Sans Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --math: "STIX Two Text", "Cambria Math", "Times New Roman", serif;
  --code: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius-lg: 18px;
  --wrap: 1160px;

  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #10142A;
    --surface: #171C36;
    --ink: #E8EAF5;
    --muted: #A2A9C6;
    --rule: #2B3155;
    --grid: #3A4170;
    --cobalt: #8AA4FF;
    --rose: #FF7AA5;
    --leaf: #8BD166;
  }
}
:root[data-theme="dark"] {
  --paper: #10142A;
  --surface: #171C36;
  --ink: #E8EAF5;
  --muted: #A2A9C6;
  --rule: #2B3155;
  --grid: #3A4170;
  --cobalt: #8AA4FF;
  --rose: #FF7AA5;
  --leaf: #8BD166;
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 80px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }

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

.math { font-family: var(--math); font-size: 1.08em; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 clamp(20px, 4vw, 40px); }

.skip {
  position: absolute; left: 12px; top: -60px;
  background: var(--ink); color: var(--paper);
  padding: 10px 14px; border-radius: var(--radius-sm); z-index: 20;
}
.skip:focus { top: calc(env(safe-area-inset-top, 0px) + 12px); }

/* Header */
.site-header {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; }

.wordmark {
  font-family: var(--display); font-weight: 600; font-size: 1.25rem;
  letter-spacing: 0.005em; text-decoration: none; white-space: nowrap;
  display: inline-flex; align-items: baseline; margin: 0;
}
.wordmark .ket-bar, .wordmark .ket-angle { font-family: var(--math); font-weight: 400; font-size: 1.35em; line-height: 1; }
.wordmark .ket-bar { color: var(--cobalt); margin-right: 0.08em; }
.wordmark .ket-angle { color: var(--rose); margin-left: 0.04em; }

.nav { list-style: none; display: flex; gap: clamp(14px, 3vw, 28px); margin: 0; padding: 0; }
.nav a { text-decoration: none; font-weight: 500; color: var(--muted); }
.nav a:hover { color: var(--ink); text-decoration: underline; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0 20px;
  border-radius: 999px; font-weight: 600; font-size: 0.975rem;
  text-decoration: none; border: 1.5px solid transparent; cursor: pointer;
  font-family: var(--body);
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--cobalt)); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn-quiet:hover { border-color: var(--ink); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 0.875rem; }

/* Hero */
.hero {
  display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.25fr);
  gap: clamp(32px, 5vw, 64px); align-items: center;
  padding-top: clamp(48px, 8vw, 104px); padding-bottom: clamp(56px, 8vw, 112px);
}
.hero h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(2.5rem, 4.8vw, 4.25rem);
  line-height: 1.02; letter-spacing: -0.015em;
  margin: 0 0 24px; max-width: 15ch; text-wrap: balance;
}
.lede { font-size: 1.1875rem; color: var(--muted); max-width: 46ch; margin: 0 0 32px; }
.hero-links { display: flex; flex-wrap: wrap; gap: 12px; margin: 0; }

/* The lab: interactive Argand plane */
.lab {
  margin: 0; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius-lg);
  padding: clamp(18px, 3vw, 28px);
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(16px, 3vw, 28px); align-items: center;
}
.lab-plane svg { display: block; width: 100%; height: auto; overflow: visible; }

.grid .unit { fill: none; stroke: var(--grid); stroke-width: 0.012; }
.grid .half { fill: none; stroke: var(--grid); stroke-width: 0.006; stroke-dasharray: 0.03 0.03; }
.grid .axis, .mini-plane .axis { stroke: var(--grid); stroke-width: 0.008; }
.mini-plane .unit { fill: none; stroke: var(--grid); stroke-width: 0.014; }
.axis-label { font-family: var(--math); font-style: italic; font-size: 0.11px; fill: var(--muted); }
.origin { fill: var(--ink); }

.phasor line { stroke-width: 0.035; stroke-linecap: round; }
.phasor-a line { stroke: var(--cobalt); }
.phasor-a polygon { fill: var(--cobalt); }
.phasor-b line { stroke: var(--rose); }
.phasor-b polygon { fill: var(--rose); }

.state { margin: 0 0 14px; font-size: 1.2rem; line-height: 1.35; min-height: 2.8em; }

.probs { margin: 0 0 18px; display: grid; gap: 10px; }
.prob dt { font-size: 0.875rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.prob dd { margin: 4px 0 0; display: flex; align-items: center; gap: 10px; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.prob-a .swatch, .prob-a .fill { background: var(--cobalt); }
.prob-b .swatch, .prob-b .fill { background: var(--rose); }
.bar { flex: 1; height: 6px; background: var(--rule); border-radius: 999px; overflow: hidden; }
.fill { display: block; height: 100%; width: 0; border-radius: 999px; transition: width 280ms ease; }

.gates { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.gate {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink);
  font-family: var(--math); font-size: 1.25rem; font-style: italic; cursor: pointer;
}
.gate:hover { background: var(--ink); color: var(--paper); }
.gate:active { transform: translateY(1px); }
.reset {
  height: 44px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1.5px dashed var(--rule); background: transparent; color: var(--muted);
  font-family: var(--body); font-size: 0.875rem; cursor: pointer;
}
.reset:hover { border-color: var(--muted); color: var(--ink); }

.circuit {
  margin: 0; font-size: 0.95rem; color: var(--muted);
  white-space: nowrap; overflow-x: auto; min-height: 1.6em;
}
.circuit .g { font-family: var(--math); font-style: italic; color: var(--ink); }

.lab figcaption {
  grid-column: 1 / -1; font-size: 0.9375rem; color: var(--muted);
  border-top: 1px solid var(--rule); padding-top: 14px;
}

/* Section titles */
.section-title {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(2rem, 3.6vw, 2.75rem); line-height: 1.1;
  letter-spacing: -0.01em; margin: 0 0 clamp(28px, 4vw, 48px);
}

/* Tools */
.tools { border-top: 1px solid var(--rule); padding: clamp(56px, 8vw, 104px) 0; }

.tool { --hue: var(--cobalt); padding: clamp(36px, 5vw, 56px) 0; border-top: 1px solid var(--rule); }
.tool:first-of-type { border-top: 0; padding-top: 0; }
.tool:last-of-type { padding-bottom: 0; }
.tool-qoffee { --hue: var(--cobalt); }
.tool-qorq { --hue: var(--rose); }
.tool-qlossary { --hue: var(--leaf); }

.tool-head { display: flex; align-items: center; gap: 18px; margin-bottom: 24px; }
.tool-glyph { width: 56px; height: 56px; flex: none; }
.tool-glyph circle { fill: none; stroke: var(--hue); stroke-width: 0.1; }
.tool-glyph line { stroke: var(--hue); stroke-width: 0.16; stroke-linecap: round; }

.tool h3 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(2.25rem, 4.4vw, 3.25rem); line-height: 1; margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.tagline { margin: 0; font-size: 1.125rem; color: var(--hue); font-weight: 500; }

.tool-body {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(28px, 5vw, 64px); align-items: start;
}
.tool-qorq .tool-body { grid-template-columns: minmax(0, 1fr) minmax(0, 0.8fr); }
.tool-text p { max-width: 60ch; margin: 0 0 16px; }

.facts {
  margin: 24px 0 28px; display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px 24px;
  border-left: 3px solid var(--hue); padding-left: 18px;
}
.facts dt { font-size: 0.8125rem; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; }

.tool-links { display: flex; flex-wrap: wrap; gap: 12px; }

.tool-demo {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-lg); padding: clamp(18px, 3vw, 28px);
}

/* Qoffee demo */
.steps {
  list-style: none; margin: 0 0 20px; padding: 0;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px;
  counter-reset: step;
}
.steps li { counter-increment: step; border-top: 3px solid var(--hue); padding-top: 10px; }
.steps li:nth-child(2) { border-top-color: color-mix(in srgb, var(--hue) 60%, var(--rule)); }
.steps li:nth-child(3) { border-top-color: color-mix(in srgb, var(--hue) 30%, var(--rule)); }
.step-name { display: block; font-family: var(--display); font-weight: 700; font-size: 1.25rem; }
.step-name::before { content: counter(step) ". "; color: var(--muted); font-weight: 500; }
.step-note { display: block; font-size: 0.875rem; color: var(--muted); line-height: 1.4; }

.code {
  margin: 0 0 16px; padding: 16px 18px; overflow-x: auto;
  background: var(--paper); border-radius: var(--radius-sm); border: 1px solid var(--rule);
  font-family: var(--code); font-size: 0.8125rem; line-height: 1.7;
}
.c-var { color: var(--muted); }
.c-str { color: var(--hue); font-weight: 500; }

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--hue) 9%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--hue) 30%, var(--rule));
}
.notice-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--hue); margin-top: 7px; flex: none; }
.notice p { margin: 0; }
.notice-title { font-weight: 600; }
.notice-body { font-size: 0.875rem; color: var(--muted); }

/* Qorq demo */
.qorq-preview { display: grid; gap: 18px; }
.wire { display: flex; align-items: center; font-size: 1.1rem; }
.wire .math { margin-right: 6px; }
.wire-line { flex: 1; height: 1.5px; background: var(--ink); min-width: 16px; }
.wire-gate {
  width: 40px; height: 40px; border: 1.5px solid var(--ink); border-radius: var(--radius-sm);
  display: grid; place-items: center; background: var(--paper);
  font-family: var(--math); font-style: italic; font-size: 1.15rem;
}
.mini-plane { width: 100%; max-width: 280px; margin: 0 auto; display: block; }
.mini-plane .phasor line { stroke-width: 0.04; }

/* Qlossary demo */
.puzzle-hint { margin: 0 0 12px; font-size: 0.875rem; color: var(--muted); }
.tiles { display: flex; flex-wrap: wrap; gap: 10px 22px; margin: 0 0 16px; min-height: 48px; }
.word { display: inline-flex; gap: 4px; max-width: 100%; }
.tile {
  flex: 0 1 28px; min-width: 14px; height: 44px; display: grid; place-items: center;
  border-bottom: 3px solid var(--hue);
  font-family: var(--display); font-weight: 700; font-size: 1.4rem;
}
.tile.missed { color: var(--rose); }
.puzzle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.misses { margin: 0; font-size: 0.875rem; color: var(--muted); }
.keys { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 5px; }
.key {
  height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--rule);
  background: var(--paper); color: var(--ink); font-family: var(--display);
  font-weight: 600; font-size: 1rem; cursor: pointer; padding: 0;
}
.key:hover:not(:disabled) { border-color: var(--ink); }
.key.hit { background: var(--hue); border-color: var(--hue); color: var(--surface); }
.key.miss { opacity: 0.35; text-decoration: line-through; }
.key:disabled { cursor: default; }

/* About */
.about { padding: clamp(56px, 8vw, 104px) 0; border-top: 1px solid var(--rule); }
.about-body { max-width: 62ch; }
.about-body p { margin: 0 0 16px; font-size: 1.125rem; }
.about-body p:last-child { margin-top: 24px; }

/* Footer */
.site-footer { border-top: 1px solid var(--rule); padding: 28px 0; }
.footer-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.wordmark-small { font-size: 1.05rem; }
.footer-links { list-style: none; display: flex; gap: 20px; margin: 0; padding: 0; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--ink); text-decoration: underline; }
.copyright { margin: 0; font-size: 0.875rem; color: var(--muted); }

/* Responsive */
@media (max-width: 980px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero h1 { max-width: 16ch; }
  .tool-body, .tool-qorq .tool-body { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .lab { grid-template-columns: minmax(0, 1fr); }
  .lab-plane { max-width: 300px; margin: 0 auto; width: 100%; }
  .nav li:nth-child(2) { display: none; }
  .steps { grid-template-columns: 1fr; }
  .keys { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .footer-row { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .fill { transition: none; }
}

/* 404 */
.notfound { min-height: 60vh; display: grid; align-content: center; padding-top: 64px; padding-bottom: 64px; }
.notfound h1 { font-family: var(--display); font-size: clamp(2.5rem, 6vw, 4rem); line-height: 1.05; margin: 0 0 16px; }
.notfound p { color: var(--muted); max-width: 48ch; margin: 0 0 28px; }
