:root {
  --bg: #f7f8f9;
  --surface: #ffffff;
  --line: #e6e9ee;
  --line-strong: #d5dae1;
  --ink: #16202e;
  --muted: #4a5568;
  --faint: #77828f;
  --accent: #0e7490;       /* single restrained accent */
  --accent-soft: #e3f0f3;
  --slate: #64748b;        /* classical series */
  --rust: #c2410c;         /* corrupted cells */
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap { max-width: 980px; margin: 0 auto; padding: 0 26px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
em { font-style: italic; color: var(--ink); }
strong { font-weight: 640; color: var(--ink); }

/* ---- header ---- */
.site { padding: 74px 0 30px; }
.eyebrow {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--faint); margin: 0 0 16px;
}
.site h1 {
  margin: 0; font-family: var(--serif); font-weight: 600;
  font-size: clamp(2.3rem, 5.5vw, 3.3rem); line-height: 1.05; letter-spacing: -0.01em;
}
.lede { max-width: 62ch; color: var(--muted); font-size: 1.05rem; margin: 18px 0 22px; }
.links { display: flex; flex-wrap: wrap; gap: 22px; font-family: var(--mono); font-size: 0.82rem; }
.links a { color: var(--muted); }
.links a:hover { color: var(--accent); }

/* ---- panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px 30px 34px;
  margin: 26px 0;
}
.panel-head { display: flex; gap: 16px; align-items: baseline; margin-bottom: 24px; }
.panel-head .num { font-family: var(--mono); font-size: 0.8rem; color: var(--faint); flex: none; }
.panel-head h2 { margin: 0 0 8px; font-family: var(--serif); font-weight: 600; font-size: 1.5rem; letter-spacing: -0.005em; }
.panel-head p { margin: 0; color: var(--muted); max-width: 68ch; font-size: 0.97rem; }

/* ---- panel 1: recall ---- */
.recall-grid { display: grid; grid-template-columns: minmax(0, 420px) 1fr; gap: 34px; align-items: start; }
.stage { min-width: 0; }
#grid { width: 100%; max-width: 420px; height: auto; aspect-ratio: 1; border-radius: 8px; display: block;
  background: #fff; border: 1px solid var(--line-strong); cursor: crosshair; }
.stage-meta { margin-top: 12px; }
#grid-caption { color: var(--faint); font-size: 0.83rem; font-family: var(--mono); }

.side { min-width: 0; }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 16px 0 8px; }
.label { font-size: 0.72rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--faint); font-family: var(--mono); }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; padding: 2px; }
.seg-btn { font: inherit; font-size: 0.82rem; color: var(--muted); background: none; border: 0; padding: 5px 11px; border-radius: 6px; cursor: pointer; }
.seg-btn.is-on { background: var(--accent-soft); color: var(--accent); }

.mem-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 0; }
.mem-thumb { width: 44px; height: 44px; border-radius: 7px; border: 1px solid var(--line-strong);
  background: #fff; padding: 0; cursor: pointer; transition: border-color .12s, transform .1s; }
.mem-thumb canvas { width: 100%; height: 100%; display: block; border-radius: 6px; }
.mem-thumb.is-stored { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mem-thumb:hover { transform: translateY(-1px); }
.hint { font-size: 0.82rem; color: var(--faint); margin: 10px 0 4px; }
#stored-count { color: var(--accent); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 3px; border-radius: 3px; background: var(--line-strong); outline: none; margin: 0; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); }
input[type="range"]::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid #fff; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 4px; }
.btn { font: inherit; font-size: 0.87rem; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  background: #fff; color: var(--ink); border: 1px solid var(--line-strong); transition: border-color .12s, background .12s; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 550; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: none; }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn:disabled { opacity: 0.5; cursor: default; }

.readouts { display: flex; gap: 26px; margin: 22px 0 14px; }
.readouts > div { display: flex; flex-direction: column; }
.ro-k { font-size: 0.68rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--faint); font-family: var(--mono); }
.ro-v { font-size: 1.3rem; font-family: var(--serif); color: var(--ink); }
#energy { width: 100%; max-width: 360px; height: auto; aspect-ratio: 360/150; display: block; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.cap { font-size: 0.79rem; color: var(--faint); margin: 8px 0 0; max-width: 64ch; }

/* ---- panel 2: capacity ---- */
.cap-grid { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 34px; align-items: start; }
#capacity { width: 100%; height: auto; aspect-ratio: 560/360; display: block; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.legend { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-direction: column; gap: 9px; font-size: 0.86rem; color: var(--muted); font-family: var(--mono); }
.legend .dot { display: inline-block; width: 22px; height: 2px; border-radius: 2px; margin-right: 10px; vertical-align: middle; }
.dot-c { background: var(--slate); }
.dot-m { background: var(--accent); }

/* ---- panel 3: modern ---- */
.modern-grid { display: grid; grid-template-columns: auto 1fr auto; gap: 28px; align-items: start; }
.modern-col { display: flex; flex-direction: column; gap: 10px; }
.modern-col canvas { border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; display: block; }
#m-query, #m-out { width: 170px; height: 170px; }
.modern-weights { min-width: 0; }
#m-weights { width: 100%; }
#beta { margin-top: 6px; }

/* ---- footer ---- */
.site-foot { border-top: 1px solid var(--line); margin: 42px 0; padding: 24px 0 66px; }
.site-foot p { color: var(--faint); font-size: 0.83rem; max-width: 72ch; margin: 0; }
.site-foot a { color: var(--muted); }

@media (max-width: 860px) {
  .recall-grid, .cap-grid, .modern-grid { grid-template-columns: 1fr; }
  #m-query, #m-out { width: 150px; height: 150px; }
}
