:root {
  --bg: #f5f5f7;
  --bg-accent: #eceef4;
  --bg-mesh-a: rgba(71, 123, 239, 0.14);
  --bg-mesh-b: rgba(16, 180, 145, 0.12);

  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: #ffffff;
  --surface-muted: #f7f8fb;

  --ink: #0f1a2e;
  --ink-muted: #5b6a85;
  --ink-soft: #7d8ba5;

  --line: rgba(129, 151, 192, 0.28);
  --line-strong: rgba(111, 138, 184, 0.46);

  --brand: #0f8f8c;
  --accent: #2a64e2;
  --active: #de5f42;

  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;

  --shadow-sm: 0 20px 38px -32px rgba(10, 24, 52, 0.35);
  --shadow-md: 0 34px 54px -38px rgba(11, 26, 54, 0.38);

  --font-sans: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Consolas", monospace;

  --dur-fast: 150ms;
  --dur-med: 260ms;

  --chart-tile-stroke: #9fb3cf;
  --chart-padded-fill: #dce5f2;
  --chart-active: #de5f42;
  --chart-axis: #496588;
  --chart-order-0: #16ad83;
  --chart-order-1: #2f91df;
  --chart-order-2: #2a64e2;
  --chart-cluster-0: #0f9a9d;
  --chart-cluster-1: #2a87dd;
  --chart-cluster-2: #245fd8;
  --chart-panel-a-fill: rgba(243, 251, 248, 0.92);
  --chart-panel-a-stroke: rgba(22, 170, 129, 0.42);
  --chart-panel-b-fill: rgba(244, 248, 255, 0.92);
  --chart-panel-b-stroke: rgba(47, 127, 224, 0.42);
  --chart-panel-c-fill: rgba(255, 255, 255, 0.72);
  --chart-panel-c-stroke: rgba(148, 173, 209, 0.6);
  --chart-a-label: #177454;
  --chart-b-label: #275fae;
  --chart-c-label: #2a425e;
  --chart-a-focus: rgba(22, 170, 129, 0.18);
  --chart-b-focus: rgba(47, 127, 224, 0.18);
  --chart-c-row-focus: rgba(22, 170, 129, 0.1);
  --chart-c-col-focus: rgba(47, 127, 224, 0.1);
  --chart-a-pad: rgba(22, 170, 129, 0.05);
  --chart-a-active: rgba(22, 170, 129, 0.52);
  --chart-a-base: rgba(22, 170, 129, 0.18);
  --chart-a-stroke: rgba(22, 170, 129, 0.2);
  --chart-b-pad: rgba(47, 127, 224, 0.05);
  --chart-b-active: rgba(47, 127, 224, 0.52);
  --chart-b-base: rgba(47, 127, 224, 0.18);
  --chart-b-stroke: rgba(47, 127, 224, 0.2);
  --chart-path-a: #169872;
  --chart-path-b: #2a74cf;
  --chart-path-both: #4c6488;
  --chart-path-rest: #95a9c6;
  --chart-arrow-a: rgba(22, 170, 129, 0.74);
  --chart-arrow-b: rgba(47, 127, 224, 0.74);
  --chart-label-padded: rgba(95, 121, 158, 0.78);
  --chart-legend-text: #58739a;
  --chart-cluster-path: #6b8ec0;
}

:root[data-theme="dark"] {
  --bg: #06080e;
  --bg-accent: #0a0f1a;
  --bg-mesh-a: rgba(110, 142, 251, 0.14);
  --bg-mesh-b: rgba(0, 240, 212, 0.09);

  --surface: rgba(14, 20, 36, 0.82);
  --surface-strong: #111827;
  --surface-muted: #0d1220;

  --ink: #f0f4ff;
  --ink-muted: #94a3c0;
  --ink-soft: #6b7d9e;

  --line: rgba(110, 142, 251, 0.15);
  --line-strong: rgba(110, 142, 251, 0.28);

  --brand: #00f0d4;
  --accent: #6e8efb;
  --active: #ff6b6b;

  --shadow-sm: 0 8px 32px -8px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(110, 142, 251, 0.06);
  --shadow-md: 0 16px 48px -12px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(110, 142, 251, 0.08);

  --chart-tile-stroke: #2a3a5c;
  --chart-padded-fill: #131d32;
  --chart-active: #ff6b6b;
  --chart-axis: #8eaad4;
  --chart-order-0: #34d399;
  --chart-order-1: #60a5fa;
  --chart-order-2: #a78bfa;
  --chart-cluster-0: #2dd4bf;
  --chart-cluster-1: #60a5fa;
  --chart-cluster-2: #a78bfa;
  --chart-panel-a-fill: rgba(0, 240, 212, 0.06);
  --chart-panel-a-stroke: rgba(0, 240, 212, 0.3);
  --chart-panel-b-fill: rgba(110, 142, 251, 0.06);
  --chart-panel-b-stroke: rgba(110, 142, 251, 0.3);
  --chart-panel-c-fill: rgba(14, 20, 36, 0.72);
  --chart-panel-c-stroke: rgba(110, 142, 251, 0.2);
  --chart-a-label: #5eead4;
  --chart-b-label: #93c5fd;
  --chart-c-label: #e0e7ff;
  --chart-a-focus: rgba(0, 240, 212, 0.16);
  --chart-b-focus: rgba(110, 142, 251, 0.16);
  --chart-c-row-focus: rgba(0, 240, 212, 0.09);
  --chart-c-col-focus: rgba(110, 142, 251, 0.09);
  --chart-a-pad: rgba(0, 240, 212, 0.05);
  --chart-a-active: rgba(0, 240, 212, 0.55);
  --chart-a-base: rgba(0, 240, 212, 0.18);
  --chart-a-stroke: rgba(0, 240, 212, 0.2);
  --chart-b-pad: rgba(110, 142, 251, 0.05);
  --chart-b-active: rgba(110, 142, 251, 0.55);
  --chart-b-base: rgba(110, 142, 251, 0.18);
  --chart-b-stroke: rgba(110, 142, 251, 0.2);
  --chart-path-a: #2dd4bf;
  --chart-path-b: #818cf8;
  --chart-path-both: #e0e7ff;
  --chart-path-rest: #475569;
  --chart-arrow-a: rgba(0, 240, 212, 0.8);
  --chart-arrow-b: rgba(110, 142, 251, 0.8);
  --chart-label-padded: rgba(148, 163, 192, 0.7);
  --chart-legend-text: #c7d2fe;
  --chart-cluster-path: #818cf8;
}

/* ─── Reset ─── */

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background:
    radial-gradient(90vw 62vh at -10% -5%, var(--bg-mesh-a), transparent 66%),
    radial-gradient(56vw 44vh at 95% 5%, var(--bg-mesh-b), transparent 72%),
    linear-gradient(165deg, var(--bg), var(--bg-accent));
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--dur-med) ease, color var(--dur-med) ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(140, 162, 196, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(140, 162, 196, 0.06) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), transparent 88%);
}

/* ─── Page Shell ─── */

.page-shell {
  position: relative;
  z-index: 1;
  width: min(1440px, calc(100% - 2rem));
  margin: 1rem auto 1.4rem;
}

/* ─── Typography ─── */

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.8rem, 3.4vw, 2.9rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 800;
}

h2 {
  margin: 0;
  color: var(--ink);
  font-size: 0.72rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  font-weight: 700;
}

p {
  margin: 0;
  color: var(--ink-muted);
}

code {
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--ink);
  padding: 0.07rem 0.34rem;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* ─── Hero ─── */

.hero {
  position: relative;
  padding: 1.3rem 1.4rem 1.25rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(16px) saturate(1.06);
  box-shadow: var(--shadow-md);
  animation: rise-in 560ms cubic-bezier(0.2, 0.72, 0.24, 1) both;
}

.hero::after {
  content: "";
  position: absolute;
  left: 1.3rem;
  right: 1.3rem;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 52%, transparent), transparent);
}

.hero-kicker {
  margin-bottom: 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.65rem;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-muted);
}

.hero-kicker::before {
  content: "";
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

.hero-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.hero-copy {
  max-width: 760px;
}

.hero-copy p {
  margin-top: 0.42rem;
  font-size: 0.92rem;
  line-height: 1.55;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.42rem;
  max-width: 340px;
}

.theme-toggle {
  min-height: 1.85rem;
  padding: 0.34rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--surface-strong) 72%, transparent);
  color: var(--ink);
  box-shadow: none;
  font-size: 0.63rem;
  letter-spacing: 0.08em;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent) 46%, var(--line-strong));
  box-shadow: 0 11px 20px -18px rgba(13, 35, 71, 0.65);
}

.theme-toggle:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.badge {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-muted) 80%, transparent);
  color: var(--ink-muted);
  padding: 0.32rem 0.55rem;
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

/* ─── Main Layout (single-column flow) ─── */

.layout {
  margin-top: 0.7rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

/* ─── Toolbar Row ─── */

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr) minmax(0, 1fr);
  gap: 0.6rem;
  animation: rise-in 540ms cubic-bezier(0.2, 0.72, 0.24, 1) both;
  animation-delay: 50ms;
}

.toolbar-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(15px) saturate(1.04);
  padding: 0.85rem 0.9rem 0.9rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-med);
}

.toolbar-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--line-strong) 78%, var(--accent));
  box-shadow: 0 22px 38px -30px rgba(8, 22, 48, 0.55);
}

/* ─── Section Internals ─── */

.section-head {
  display: grid;
  gap: 0.2rem;
}

.section-head p {
  font-size: 0.78rem;
}

.grid-controls {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.5rem;
}

.geometry-info {
  margin-top: 0.55rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-muted) 76%, transparent);
  padding: 0.55rem 0.65rem;
  color: var(--ink-muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

/* ─── Form Elements ─── */

label {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font-size: 0.63rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-muted);
}

input[type="number"],
select {
  font: inherit;
  color: var(--ink);
  min-height: 1.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  padding: 0.38rem 0.48rem;
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background-color var(--dur-fast);
}

input[type="number"]:focus,
select:focus {
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

select {
  appearance: none;
  padding-right: 1.9rem;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='7' viewBox='0 0 12 7' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23637289' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.54rem center;
}

button {
  font: inherit;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  min-height: 1.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 75%, #1f47a8));
  color: #f4f8ff;
  padding: 0.44rem 0.72rem;
  cursor: pointer;
  transition: transform var(--dur-fast), box-shadow var(--dur-fast), filter var(--dur-fast);
  box-shadow: 0 15px 24px -18px color-mix(in srgb, var(--accent) 75%, transparent);
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:active {
  transform: translateY(0);
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent);
}

#playPause {
  background: linear-gradient(145deg, var(--brand), color-mix(in srgb, var(--brand) 74%, #0a6f6c));
  box-shadow: 0 15px 24px -18px color-mix(in srgb, var(--brand) 72%, transparent);
}

.play-row {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: auto repeat(2, minmax(90px, 1fr));
  gap: 0.55rem;
  align-items: end;
}

.wide {
  margin-top: 0.55rem;
}

/* ─── Range Inputs ─── */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  padding: 0;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg,
      color-mix(in srgb, var(--accent) 26%, transparent),
      color-mix(in srgb, var(--brand) 34%, transparent));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-top: -4.5px;
  cursor: pointer;
  background: var(--accent);
  border: 2px solid color-mix(in srgb, var(--surface-strong) 88%, #ffffff);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg,
      color-mix(in srgb, var(--accent) 26%, transparent),
      color-mix(in srgb, var(--brand) 34%, transparent));
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--surface-strong) 88%, #ffffff);
  background: var(--accent);
  cursor: pointer;
}

/* ─── Decode Panel ─── */

.decode-info {
  margin-top: 0.5rem;
  min-height: 80px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-muted) 72%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  padding: 0.55rem 0.65rem;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.55;
  color: color-mix(in srgb, var(--ink) 84%, var(--accent));
  overflow-y: auto;
  max-height: 220px;
}

/* ─── Tabs ─── */

.tab-strip {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.tab-button {
  min-height: 2rem;
  padding: 0.42rem 0.72rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-strong) 78%, transparent);
  color: var(--ink-muted);
  box-shadow: none;
  letter-spacing: 0.07em;
}

.tab-button:hover {
  filter: none;
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line-strong));
}

.tab-button.active {
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line-strong));
  background: linear-gradient(145deg,
      color-mix(in srgb, var(--accent) 18%, var(--surface-strong)),
      color-mix(in srgb, var(--brand) 14%, var(--surface-strong)));
  color: var(--ink);
  box-shadow: 0 12px 24px -20px color-mix(in srgb, var(--accent) 55%, transparent);
}

/* ─── Tab Panels ─── */

.tab-panel {
  display: grid;
  gap: 0.6rem;
}

.tab-panel[hidden] {
  display: none;
}

/* ─── Visualization Cards ─── */

.viz-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(15px) saturate(1.04);
  padding: 0.85rem 0.9rem 0.9rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-med);
  animation: rise-in 540ms cubic-bezier(0.2, 0.72, 0.24, 1) both;
  animation-delay: 100ms;
}

.viz-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--line-strong) 78%, var(--accent));
  box-shadow: 0 22px 38px -30px rgba(8, 22, 48, 0.55);
}

.viz-card svg {
  margin-top: 0.5rem;
}

/* ─── Chart Common ─── */

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.hint {
  margin-top: 0.2rem;
  font-size: 0.74rem;
}

.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--ink-muted);
  font-size: 0.66rem;
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex-shrink: 0;
}

.swatch.order {
  background: linear-gradient(90deg, var(--chart-order-0), var(--chart-order-1), var(--chart-order-2));
}

.swatch.aslice {
  background: var(--chart-order-0);
}

.swatch.bslice {
  background: var(--chart-order-1);
}

.swatch.padded {
  background: var(--chart-padded-fill);
  border: 1px solid var(--line-strong);
}

.swatch.active {
  background: var(--chart-active);
}

.swatch.cluster {
  background: linear-gradient(90deg, var(--chart-cluster-0), var(--chart-cluster-2));
}

.swatch.slot {
  background: linear-gradient(90deg, #ef7f45, #d84d7a, #5a67ef, #1ea0b5);
}

.swatch.wave {
  background: color-mix(in srgb, var(--chart-axis) 18%, transparent);
  border: 1px dashed var(--chart-axis);
}

.swatch.idle {
  background: color-mix(in srgb, var(--surface-muted) 84%, var(--line));
  border: 1px solid var(--line-strong);
}

/* ─── SVGs ─── */

svg {
  display: block;
  width: 100%;
  max-width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line-strong);
  background:
    radial-gradient(84% 88% at 0% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 62%),
    linear-gradient(160deg, color-mix(in srgb, var(--surface-strong) 86%, transparent), var(--surface-muted));
}

#blockAssignmentMap,
#smOccupancyMap {
  overflow: visible;
}

.tile-label,
.cluster-label {
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  paint-order: stroke fill;
  stroke-linejoin: round;
}

.tile-current {
  stroke: var(--chart-active);
  stroke-width: 2.6;
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--chart-active) 65%, transparent));
}

/* ─── H100 Panel ─── */

.h100-panel {
  display: grid;
  gap: 0.6rem;
}

.h100-summary {
  display: grid;
  gap: 0.55rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
}

.summary-card {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-strong) 88%, transparent);
  padding: 0.55rem 0.65rem;
}

.summary-card .k {
  display: block;
  color: var(--ink-soft);
  font-size: 0.62rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-weight: 700;
}

.summary-card .v {
  display: block;
  margin-top: 0.14rem;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.3;
}

.summary-card .d {
  display: block;
  margin-top: 0.28rem;
  color: var(--ink-muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.formula-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem;
}

.formula-chip {
  border-radius: 14px;
  border: 1px dashed color-mix(in srgb, var(--line-strong) 84%, var(--accent));
  background: color-mix(in srgb, var(--surface-muted) 70%, transparent);
  padding: 0.55rem 0.65rem;
}

.formula-chip .label {
  display: block;
  margin-bottom: 0.24rem;
  color: var(--ink-soft);
  font-size: 0.6rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-weight: 700;
}

.formula-chip code {
  display: inline-block;
  line-height: 1.45;
}

/* ─── Stats Row (derived state, below viz) ─── */

.stats-row:empty::before {
  content: "Derived state loads after the first mapping build.";
  display: block;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(15px) saturate(1.04);
  padding: 0.75rem 0.9rem;
  color: var(--ink-muted);
  font-size: 0.78rem;
}

.stat-grid {
  margin-top: 0.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 0.45rem;
}

.stat {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-strong) 86%, transparent);
  padding: 0.5rem 0.55rem;
}

.stat .k {
  display: block;
  color: var(--ink-soft);
  font-size: 0.6rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  font-weight: 700;
}

.stat .v {
  display: block;
  margin-top: 0.14rem;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
}

/* ─── Tooltip ─── */

.tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  transition: opacity 100ms ease, transform 120ms ease;
  max-width: 280px;
  padding: 0.48rem 0.58rem;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--line-strong) 66%, var(--accent));
  background: color-mix(in srgb, var(--surface-strong) 25%, #0f1727);
  box-shadow: 0 18px 30px -18px rgba(7, 18, 34, 0.85);
  color: #edf3ff;
  font-size: 0.68rem;
  font-family: var(--font-mono);
  line-height: 1.48;
}

.tooltip.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ─── Footer ─── */

footer {
  margin-top: 0.6rem;
  padding: 0.7rem 1rem;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(12px) saturate(1.02);
  color: var(--ink-muted);
  font-size: 0.72rem;
}

/* ─── Animations ─── */

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Dark-mode polish ─── */

:root[data-theme="dark"] body::before {
  background-image:
    linear-gradient(rgba(110, 142, 251, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(110, 142, 251, 0.045) 1px, transparent 1px);
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent 80%);
}

:root[data-theme="dark"] .hero {
  background: rgba(14, 20, 36, 0.85);
  border-color: rgba(110, 142, 251, 0.18);
  backdrop-filter: blur(24px) saturate(1.2);
  box-shadow:
    0 16px 48px -12px rgba(0, 0, 0, 0.7),
    inset 0 1px 0 rgba(110, 142, 251, 0.08);
}

:root[data-theme="dark"] .hero::after {
  background: linear-gradient(90deg,
      transparent,
      rgba(110, 142, 251, 0.4),
      rgba(0, 240, 212, 0.3),
      transparent);
  height: 1px;
}

:root[data-theme="dark"] .hero-kicker::before {
  background: linear-gradient(90deg, #00f0d4, #6e8efb);
}

:root[data-theme="dark"] .toolbar-card,
:root[data-theme="dark"] .viz-card {
  background: rgba(14, 20, 36, 0.78);
  border-color: rgba(110, 142, 251, 0.13);
  backdrop-filter: blur(20px) saturate(1.15);
  box-shadow:
    0 8px 32px -8px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

:root[data-theme="dark"] .toolbar-card:hover,
:root[data-theme="dark"] .viz-card:hover {
  border-color: rgba(110, 142, 251, 0.3);
  box-shadow:
    0 12px 40px -10px rgba(0, 0, 0, 0.7),
    0 0 20px -4px rgba(110, 142, 251, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

:root[data-theme="dark"] input[type="number"],
:root[data-theme="dark"] select {
  background: rgba(10, 15, 26, 0.9);
  border-color: rgba(110, 142, 251, 0.18);
  color: #f0f4ff;
}

:root[data-theme="dark"] input[type="number"]:focus,
:root[data-theme="dark"] select:focus {
  border-color: rgba(110, 142, 251, 0.5);
  box-shadow: 0 0 0 3px rgba(110, 142, 251, 0.15),
    0 0 12px -2px rgba(110, 142, 251, 0.1);
}

:root[data-theme="dark"] button {
  background: linear-gradient(135deg, #6e8efb, #5a75e0);
  box-shadow: 0 8px 24px -6px rgba(110, 142, 251, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

:root[data-theme="dark"] button:hover {
  box-shadow: 0 12px 28px -6px rgba(110, 142, 251, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

:root[data-theme="dark"] #playPause {
  background: linear-gradient(135deg, #00f0d4, #00c4aa);
  color: #06080e;
  font-weight: 800;
  box-shadow: 0 8px 24px -6px rgba(0, 240, 212, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

:root[data-theme="dark"] #playPause:hover {
  box-shadow: 0 12px 28px -6px rgba(0, 240, 212, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

:root[data-theme="dark"] .tab-button {
  background: rgba(14, 20, 36, 0.6);
  border-color: rgba(110, 142, 251, 0.15);
  color: #94a3c0;
}

:root[data-theme="dark"] .tab-button:hover {
  border-color: rgba(110, 142, 251, 0.35);
  color: #c7d2fe;
}

:root[data-theme="dark"] .tab-button.active {
  background: linear-gradient(135deg,
      rgba(110, 142, 251, 0.18),
      rgba(0, 240, 212, 0.1));
  border-color: rgba(110, 142, 251, 0.4);
  color: #f0f4ff;
  box-shadow: 0 8px 20px -10px rgba(110, 142, 251, 0.35);
}

:root[data-theme="dark"] .theme-toggle {
  background: rgba(14, 20, 36, 0.7);
  border-color: rgba(110, 142, 251, 0.22);
  color: #c7d2fe;
}

:root[data-theme="dark"] .theme-toggle:hover {
  border-color: rgba(110, 142, 251, 0.45);
  box-shadow: 0 4px 16px -4px rgba(110, 142, 251, 0.2);
}

:root[data-theme="dark"] .badge {
  background: rgba(110, 142, 251, 0.1);
  border-color: rgba(110, 142, 251, 0.2);
  color: #c7d2fe;
}

:root[data-theme="dark"] code {
  background: rgba(110, 142, 251, 0.08);
  border-color: rgba(110, 142, 251, 0.18);
  color: #c7d2fe;
}

:root[data-theme="dark"] .geometry-info {
  background: rgba(10, 15, 26, 0.7);
  border-color: rgba(110, 142, 251, 0.12);
}

:root[data-theme="dark"] .decode-info {
  background: rgba(10, 15, 26, 0.75);
  border-color: rgba(110, 142, 251, 0.12);
  box-shadow: inset 0 1px 0 rgba(110, 142, 251, 0.06);
  color: #c7d2fe;
}

:root[data-theme="dark"] .summary-card,
:root[data-theme="dark"] .stat {
  background: rgba(14, 20, 36, 0.8);
  border-color: rgba(110, 142, 251, 0.12);
}

:root[data-theme="dark"] .formula-chip {
  border-color: rgba(110, 142, 251, 0.2);
  background: rgba(110, 142, 251, 0.05);
}

:root[data-theme="dark"] svg {
  background:
    radial-gradient(84% 88% at 0% 0%, rgba(110, 142, 251, 0.08), transparent 62%),
    linear-gradient(160deg, rgba(14, 20, 36, 0.9), rgba(10, 15, 26, 0.95));
  border-color: rgba(110, 142, 251, 0.15);
}

:root[data-theme="dark"] .tooltip {
  background: rgba(10, 15, 26, 0.95);
  border-color: rgba(110, 142, 251, 0.35);
  box-shadow:
    0 16px 40px -10px rgba(0, 0, 0, 0.8),
    0 0 16px -4px rgba(110, 142, 251, 0.15);
  color: #e0e7ff;
}

:root[data-theme="dark"] footer {
  background: rgba(14, 20, 36, 0.7);
  border-color: rgba(110, 142, 251, 0.1);
  backdrop-filter: blur(12px) saturate(1.1);
}

:root[data-theme="dark"] .stats-row:empty::before {
  background: rgba(14, 20, 36, 0.7);
  border-color: rgba(110, 142, 251, 0.12);
}

:root[data-theme="dark"] input[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(90deg,
      rgba(110, 142, 251, 0.3),
      rgba(0, 240, 212, 0.25));
}

:root[data-theme="dark"] input[type="range"]::-webkit-slider-thumb {
  background: #6e8efb;
  border-color: rgba(14, 20, 36, 0.9);
  box-shadow: 0 0 8px rgba(110, 142, 251, 0.4);
}

:root[data-theme="dark"] input[type="range"]::-moz-range-track {
  background: linear-gradient(90deg,
      rgba(110, 142, 251, 0.3),
      rgba(0, 240, 212, 0.25));
}

:root[data-theme="dark"] input[type="range"]::-moz-range-thumb {
  background: #6e8efb;
  border-color: rgba(14, 20, 36, 0.9);
  box-shadow: 0 0 8px rgba(110, 142, 251, 0.4);
}

:root[data-theme="dark"] .swatch.padded {
  background: #131d32;
  border-color: rgba(110, 142, 251, 0.25);
}

:root[data-theme="dark"] .swatch.idle {
  background: rgba(14, 20, 36, 0.6);
  border-color: rgba(110, 142, 251, 0.2);
}

:root[data-theme="dark"] .swatch.wave {
  background: rgba(110, 142, 251, 0.08);
  border-color: rgba(110, 142, 251, 0.35);
}

:root[data-theme="dark"] ::-webkit-scrollbar-track {
  background: rgba(10, 15, 26, 0.5);
}

:root[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: rgba(110, 142, 251, 0.3);
}

:root[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(110, 142, 251, 0.5);
}

/* ─── Responsive ─── */

@media (max-width: 1080px) {
  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar-card:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .page-shell {
    width: min(1440px, calc(100% - 1rem));
    margin-top: 0.6rem;
  }

  .hero {
    padding: 1rem 0.9rem;
  }

  .hero-main {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-meta {
    justify-content: flex-start;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar-card:last-child {
    grid-column: auto;
  }

  .play-row {
    grid-template-columns: 1fr;
  }

  .grid-controls {
    grid-template-columns: repeat(2, minmax(100px, 1fr));
  }

  .legend {
    gap: 0.35rem 0.5rem;
  }

  .legend span {
    font-size: 0.62rem;
  }
}

/* ─── Scrollbar ─── */

::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: color-mix(in srgb, var(--line) 65%, transparent);
}

::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 44%, var(--line-strong));
}

::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--accent) 62%, var(--line-strong));
}