/* ==========================================================================
   PRISM — "See the science differently."
   Accessibility-first design system. White ground, very large type,
   one spectral gradient used sparingly (wordmark, focus rings, hero prism).
   Fonts: Sora (display) + Atkinson Hyperlegible (body).
   ========================================================================== */

:root {
  --scale: 1;
  --bg: #FFFFFF;
  --bg-2: #F5F6FA;
  --bg-3: #ECEEF5;
  --ink: #111318;          /* 17.6:1 on white */
  --ink-2: #2B2F3A;        /* 13:1 */
  --muted: #4A5060;        /* 7.6:1 */
  --line: #CDD1DC;
  --line-strong: #9AA0B0;
  --primary: #3B2AB8;      /* 8.5:1 on white; white text on it 8.5:1 */
  --primary-ink: #2A1E8A;
  --primary-soft: #EEEBFF;
  --ok: #176B45;           /* 6.5:1 */
  --ok-soft: #E4F5EC;
  --warn: #8A4B00;         /* 6.4:1 */
  --warn-soft: #FFF2DF;
  --err: #A11A2B;          /* 7:1 */
  --err-soft: #FDE8EB;
  --focus: #3B2AB8;
  --spectrum: linear-gradient(90deg, #E5322D 0%, #F59E0B 25%, #22A06B 50%, #2563EB 75%, #7C3AED 100%);
  --spectrum-soft: linear-gradient(90deg, #FDE2E1, #FEF0D6, #DDF3E8, #DCE7FD, #EBDFFD);

  --font-display: 'Sora', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --radius: 14px;
  --radius-sm: 8px;
  --wrap: 1180px;
  --gutter: clamp(18px, 4vw, 44px);
  --touch: 48px;
  --ease: cubic-bezier(.2,.7,.2,1);
  --dur: .25s;
  --shadow: 0 1px 2px rgba(17,19,24,.05), 0 10px 30px -18px rgba(17,19,24,.25);
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: calc(100% * var(--scale)); -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 1.2rem; line-height: 1.65;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body.dyslexia { letter-spacing: .04em; word-spacing: .16em; line-height: 1.9; }
body.dyslexia p, body.dyslexia li { margin-bottom: 1.2em; }
img, svg, video, canvas { max-width: 100%; height: auto; display: block; }
a { color: var(--primary-ink); text-decoration-thickness: .12em; text-underline-offset: .18em; }
a:hover { color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink); line-height: 1.12; letter-spacing: -.01em; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: clamp(2.4rem, 5.5vw, 4.4rem); font-weight: 800; }
h2 { font-size: clamp(1.8rem, 3.5vw, 2.6rem); }
h3 { font-size: clamp(1.35rem, 2.2vw, 1.7rem); }
h4 { font-size: 1.15rem; }
p { margin: 0 0 1em; max-width: 72ch; }
ul, ol { padding-left: 1.4em; }
code, pre, kbd { font-family: var(--font-mono); font-size: .92em; }
kbd { background: var(--bg-3); border: 1px solid var(--line-strong); border-radius: 6px; padding: .05em .45em; }
pre { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 1rem; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
hr { border: 0; border-top: 2px solid var(--line); margin: 2rem 0; }
::selection { background: var(--primary); color: #fff; }

/* Focus: a strong indigo ring everywhere, a spectral ring on bordered controls */
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
.btn:focus-visible, .card:focus-visible, .tab:focus-visible, .sample:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 4px solid transparent; outline-offset: 0;
  box-shadow: 0 0 0 3px #fff, 0 0 0 7px var(--focus);
}
.spectral-focus:focus-visible { box-shadow: 0 0 0 3px #fff; background-image: linear-gradient(var(--bg), var(--bg)), var(--spectrum); background-origin: border-box; background-clip: padding-box, border-box; border-color: transparent; }

.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; }
.skip-link { position: absolute; left: 12px; top: -80px; z-index: 1000; background: var(--ink); color: #fff; padding: 12px 20px; border-radius: var(--radius-sm); font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.skip-link:focus { top: 12px; }

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

/* ---------- Layout ---------- */
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 var(--gutter); }
.site-header { border-bottom: 2px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 50; }
.site-header .wrap { display: flex; align-items: center; gap: 1.2rem; min-height: 78px; flex-wrap: wrap; padding-top: .5rem; padding-bottom: .5rem; }
.wordmark { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; letter-spacing: .06em; }
.wordmark svg { width: 44px; height: 44px; }
.wordmark .name { background: var(--spectrum); -webkit-background-clip: text; background-clip: text; color: transparent; }
@media (forced-colors: active) { .wordmark .name { color: CanvasText; background: none; } }
.site-nav { display: flex; gap: .25rem; flex-wrap: wrap; margin-left: auto; }
.site-nav a { display: inline-flex; align-items: center; min-height: var(--touch); padding: 0 .9rem; border-radius: 999px; text-decoration: none; color: var(--ink-2); font-weight: 700; }
.site-nav a:hover { background: var(--bg-3); color: var(--ink); }
.site-nav a[aria-current="page"] { background: var(--ink); color: #fff; }
.back-link { font-size: 1rem; color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; min-height: var(--touch); padding: 0 .5rem; }
.back-link:hover { color: var(--ink); text-decoration: underline; }

.a11y-bar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.a11y-bar .lbl { font-size: 1rem; color: var(--muted); font-weight: 700; margin-right: .2rem; }

.site-footer { border-top: 2px solid var(--line); margin-top: 4rem; padding: 2.5rem 0 3rem; color: var(--muted); font-size: 1.05rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; align-items: center; justify-content: space-between; }
.site-footer p { margin: 0; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--ink); }

main { padding: 2.5rem 0 1rem; }
.section { padding: 2.5rem 0; }
.section + .section { border-top: 2px solid var(--line); }
.lead { font-size: 1.4rem; line-height: 1.55; color: var(--ink-2); max-width: 60ch; }
.eyebrow { font-family: var(--font-display); font-weight: 700; text-transform: uppercase; letter-spacing: .14em; font-size: .95rem; color: var(--primary-ink); margin-bottom: .8rem; display: block; }
.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.card { background: var(--bg); border: 2px solid var(--line); border-radius: var(--radius); padding: 1.4rem; }
.card h3 { margin-top: 0; }
.card.soft { background: var(--bg-2); border-color: transparent; }

/* ---------- Buttons & controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: var(--touch); padding: .55rem 1.3rem; border-radius: 999px; border: 2px solid var(--ink); background: var(--ink); color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; text-decoration: none; cursor: pointer; transition: transform var(--dur) var(--ease), background var(--dur) var(--ease); }
.btn:hover { background: var(--ink-2); color: #fff; transform: translateY(-1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-ink); border-color: var(--primary-ink); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--bg-3); color: var(--ink); }
.btn.sm { min-height: 40px; padding: .3rem .9rem; font-size: .95rem; }
.btn.xl { font-size: 1.3rem; padding: .8rem 1.8rem; }
.btn[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }
.icon-btn { width: var(--touch); height: var(--touch); padding: 0; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--line-strong); background: var(--bg); color: var(--ink); font-weight: 800; cursor: pointer; font-family: var(--font-display); }
.icon-btn:hover { background: var(--bg-3); }
.icon-btn[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

label, .label { font-weight: 700; display: block; margin-bottom: .35rem; }
input[type="text"], input[type="number"], select, textarea { width: 100%; min-height: var(--touch); padding: .5rem .8rem; border: 2px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg); color: var(--ink); }
input[type="range"] { width: 100%; accent-color: var(--primary); min-height: var(--touch); }
input[type="checkbox"] { width: 1.5rem; height: 1.5rem; accent-color: var(--primary); }
.check { display: flex; align-items: center; gap: .7rem; min-height: var(--touch); font-weight: 700; cursor: pointer; }
.field { margin-bottom: 1rem; }
.field .hint { font-size: 1rem; color: var(--muted); margin: .2rem 0 0; }

.notice { border-radius: var(--radius-sm); padding: .9rem 1.1rem; border: 2px solid var(--line); background: var(--bg-2); margin: 0 0 1rem; }
.notice.ok { background: var(--ok-soft); border-color: #9CD6B6; color: var(--ok); }
.notice.warn { background: var(--warn-soft); border-color: #F2C68A; color: var(--warn); }
.notice.err { background: var(--err-soft); border-color: #F0A7B1; color: var(--err); }
.notice p { margin: 0; max-width: none; color: inherit; }
.badge { display: inline-block; border-radius: 999px; padding: .15em .7em; font-size: .9rem; font-weight: 700; background: var(--bg-3); color: var(--ink-2); font-family: var(--font-display); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }

/* ---------- Hero ---------- */
.hero { padding: 3.5rem 0 3rem; display: grid; gap: 2.5rem; grid-template-columns: 1.1fr .9fr; align-items: center; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; } }
.hero h1 { margin-bottom: 1rem; }
.hero .spectral { background: var(--spectrum); -webkit-background-clip: text; background-clip: text; color: transparent; }
@media (forced-colors: active) { .hero .spectral { color: CanvasText; background: none; } }
.hero-prism { background: var(--bg-2); border-radius: 28px; padding: 1.5rem; }
.hero-prism svg { width: 100%; height: auto; }

/* ---------- Mini demo (landing) ---------- */
.mini-demo { display: grid; gap: 1.5rem; grid-template-columns: 1fr 1fr; align-items: start; }
@media (max-width: 760px) { .mini-demo { grid-template-columns: 1fr; } }
.mini-demo .visual { background: var(--bg-2); border-radius: var(--radius); padding: 1rem; }
.mini-demo .visual svg { width: 100%; height: auto; }
.desc-box { background: var(--bg); border: 2px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.4rem; font-size: 1.25rem; line-height: 1.6; }
.desc-box p { max-width: none; margin: 0; }

/* ---------- App layout ---------- */
.app-grid { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 2rem; align-items: start; }
@media (max-width: 960px) { .app-grid { grid-template-columns: 1fr; } }
.panel { border: 2px solid var(--line); border-radius: var(--radius); padding: 1.3rem; background: var(--bg); }
.panel h2 { font-size: 1.5rem; margin-top: 0; }
.panel h3 { font-size: 1.2rem; }
.dropzone { border: 3px dashed var(--line-strong); border-radius: var(--radius); padding: 1.5rem 1.2rem; text-align: center; background: var(--bg-2); transition: background var(--dur), border-color var(--dur); }
.dropzone.over { background: var(--primary-soft); border-color: var(--primary); }
.dropzone p { margin: 0 0 .8rem; max-width: none; }
.dropzone .small { font-size: 1rem; color: var(--muted); }
.samples { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .7rem; list-style: none; padding: 0; margin: 0; }
.sample { display: flex; flex-direction: column; align-items: stretch; gap: .4rem; width: 100%; min-height: var(--touch); padding: .6rem; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); cursor: pointer; text-align: left; font-size: .95rem; font-weight: 700; color: var(--ink); }
.sample:hover { border-color: var(--ink); }
.sample[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); }
.sample svg { width: 100%; height: auto; aspect-ratio: 4 / 3; background: var(--bg-2); border-radius: 6px; }
.sample .cat { font-weight: 400; color: var(--muted); font-size: .85rem; }

.preview { background: var(--bg-2); border-radius: var(--radius); padding: .8rem; margin-top: 1rem; }
.preview img, .preview svg { max-height: 240px; width: auto; margin: 0 auto; }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; border-bottom: 2px solid var(--line); margin-bottom: 1.2rem; padding-bottom: .5rem; }
.tab { position: relative; min-height: var(--touch); padding: .4rem 1rem; border: 2px solid transparent; border-radius: 999px; background: transparent; color: var(--ink-2); font-family: var(--font-display); font-weight: 700; cursor: pointer; }
.tab:hover { background: var(--bg-3); }
.tab[aria-selected="true"] { color: var(--ink); background: var(--bg-3); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 1rem; right: 1rem; bottom: -.6rem; height: 5px; border-radius: 3px; background: var(--spectrum); }
.tabpanel[hidden] { display: none; }
.tabpanel { padding-top: .5rem; }
.show-all .tabpanel { display: block !important; border-top: 2px solid var(--line); padding-top: 1.5rem; margin-top: 1.5rem; }
.show-all .tabpanel > h3:first-child { margin-top: 0; }
.tabpanel > h3.panel-title { display: none; }
.show-all .tabpanel > h3.panel-title { display: block; }

.levels { display: inline-flex; gap: .3rem; border: 2px solid var(--line); border-radius: 999px; padding: .2rem; margin-bottom: 1rem; }
.levels .btn { border: 0; background: transparent; color: var(--ink-2); min-height: 40px; }
.levels .btn[aria-pressed="true"] { background: var(--ink); color: #fff; }
.description { font-size: 1.3rem; line-height: 1.65; }
.description p { max-width: none; }
.description .sent { display: inline; }

/* Tree */
[role="tree"] { list-style: none; padding: 0; margin: 0; }
[role="tree"] ul { list-style: none; padding-left: 1.4rem; margin: 0; border-left: 2px solid var(--line); }
[role="treeitem"] { margin: .15rem 0; }
[role="treeitem"] > .ti { display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: .2rem .5rem; border-radius: var(--radius-sm); cursor: default; }
[role="treeitem"]:focus { outline: none; }
[role="treeitem"]:focus > .ti { outline: 4px solid var(--focus); outline-offset: -2px; background: var(--primary-soft); }
.ti .tw { width: 1.4rem; display: inline-block; text-align: center; font-weight: 800; color: var(--muted); }
.ti .tk { font-weight: 700; }
.ti .tv { color: var(--muted); }
[role="treeitem"][aria-expanded="false"] > ul { display: none; }

/* Accessible SVG */
.asvg-wrap { background: var(--bg); border: 2px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.asvg-wrap svg { width: 100%; height: auto; max-height: 520px; }
.asvg-wrap svg g[tabindex]:focus { outline: none; }
.asvg-wrap svg g[tabindex]:focus > .hl, .asvg-wrap svg g.current > .hl { stroke: var(--primary); stroke-width: 4; fill: rgba(59,42,184,.10); opacity: 1; }
.asvg-wrap svg .hl { fill: none; stroke: transparent; opacity: 0; pointer-events: none; }
.asvg-wrap svg text { font-family: var(--font-body); }
.asvg-wrap.hc svg { filter: contrast(1.35); }
.asvg-wrap.hc svg .stroke { stroke-width: 4; }
.asvg-wrap.large svg text { font-size: 150%; font-weight: 700; }
.focus-desc { margin-top: 1rem; border-left: 6px solid var(--primary); padding: .8rem 1rem; background: var(--primary-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 1.15rem; }
.focus-desc p { margin: 0; max-width: none; }

/* Data */
table.data { border-collapse: collapse; width: 100%; font-size: 1.05rem; }
table.data th, table.data td { border: 2px solid var(--line); padding: .5rem .7rem; text-align: left; }
table.data th { background: var(--bg-2); font-family: var(--font-display); }
table.data td[contenteditable] { background: #FFFDF5; }
table.data td[contenteditable]:focus { outline: 4px solid var(--focus); outline-offset: -3px; }
.table-scroll { overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin: 1rem 0; }
.stat { background: var(--bg-2); border-radius: var(--radius-sm); padding: .8rem 1rem; }
.stat .k { font-size: .95rem; color: var(--muted); font-weight: 700; }
.stat .v { font-family: var(--font-display); font-size: 1.35rem; font-weight: 700; }

/* Params / refine */
.params { display: grid; gap: .8rem; }
.param { background: var(--bg-2); border-radius: var(--radius-sm); padding: .8rem 1rem; }
.param output { font-weight: 800; font-family: var(--font-display); }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.history li { display: flex; gap: .6rem; align-items: center; }
.history button { flex: 1; text-align: left; min-height: var(--touch); padding: .4rem .8rem; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); cursor: pointer; }
.history button:hover { border-color: var(--ink); }
.history img { width: 40px; height: 30px; object-fit: contain; background: var(--bg-2); border-radius: 4px; }
.history .meta { font-size: .9rem; color: var(--muted); display: block; }
details { border: 2px solid var(--line); border-radius: var(--radius-sm); padding: .6rem 1rem; margin-bottom: 1rem; }
details summary { cursor: pointer; font-weight: 700; min-height: 36px; display: flex; align-items: center; }
.speech-controls { display: grid; gap: 1rem; }
.speech-controls .row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: end; }
.speech-controls .row > * { flex: 1 1 160px; }
.component-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.component-list li { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.component-list .name { flex: 1 1 160px; }
.sonify-bar { display: flex; gap: .7rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.feature-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; }
.feature-list li { display: grid; grid-template-columns: 56px 1fr; gap: 1rem; align-items: start; }
.feature-list .n { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; background: var(--bg-3); color: var(--ink); }
.feature-list h3 { margin-bottom: .2rem; }
.feature-list p { margin: 0; }
.spectral-rule { height: 6px; border-radius: 3px; background: var(--spectrum); margin: 1.5rem 0; max-width: 240px; }
.toc { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.toc a { display: inline-flex; min-height: 44px; align-items: center; padding: 0 .9rem; border: 2px solid var(--line); border-radius: 999px; text-decoration: none; font-weight: 700; }
.toc a:hover { border-color: var(--ink); }
.status-line { min-height: 1.6em; color: var(--muted); font-size: 1.05rem; }
.two-col { columns: 2; column-gap: 2.5rem; }
@media (max-width: 720px) { .two-col { columns: 1; } }
.cap-table th, .cap-table td { vertical-align: top; }
@media (max-width: 560px) {
  .site-header .wrap { gap: .6rem; }
  .wordmark { font-size: 1.25rem; }
  .btn.xl { font-size: 1.15rem; width: 100%; }
  .hero { padding-top: 2rem; }
  .panel { padding: 1rem; }
  .samples { grid-template-columns: repeat(2, 1fr); }
}
