:root {
  color-scheme: dark;
  --ink: #f7f1df;
  --muted: #bdb29c;
  --subtle: #7d7668;
  --line: rgba(247, 241, 223, 0.14);
  --panel: rgba(26, 25, 22, 0.74);
  --panel-strong: rgba(36, 34, 30, 0.92);
  --coal: #10100e;
  --charcoal: #171613;
  --bronze: #d8a657;
  --gold: #f1cf66;
  --teal: #58d6c5;
  --coral: #ed7a5f;
  --green: #a7d86e;
  --violet: #b69cff;
  --radius: 8px;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--coal);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(16, 16, 14, 0.96), rgba(28, 23, 18, 0.96) 54%, rgba(15, 25, 22, 0.96)),
    repeating-linear-gradient(90deg, rgba(247, 241, 223, 0.035) 0 1px, transparent 1px 74px);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid rgba(241, 207, 102, 0.5);
  border-radius: 50%;
  background:
    linear-gradient(145deg, rgba(241, 207, 102, 0.9), rgba(88, 214, 197, 0.7)),
    radial-gradient(circle at 34% 33%, rgba(255, 255, 255, 0.8), transparent 31%);
  box-shadow: 0 0 38px rgba(216, 166, 87, 0.22);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--bronze);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 4.2rem);
  line-height: 0.96;
  letter-spacing: 0;
  max-width: 820px;
}

.live-readout {
  min-width: 190px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(20, 19, 17, 0.72);
  display: grid;
  gap: 2px;
  text-align: right;
  box-shadow: var(--shadow);
}

.readout-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.readout-value {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 12px;
}

.exhibit,
.controls {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.exhibit {
  min-height: 690px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.view-tabs {
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 12, 10, 0.24);
}

.tab-button,
.text-button,
.icon-button,
.preset-button,
.term-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(247, 241, 223, 0.055);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.tab-button {
  min-height: 42px;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 750;
}

.tab-button:hover,
.text-button:hover,
.icon-button:hover,
.preset-button:hover,
.term-button:hover {
  border-color: rgba(241, 207, 102, 0.5);
  background: rgba(241, 207, 102, 0.1);
}

.tab-button.is-active {
  color: var(--coal);
  border-color: rgba(241, 207, 102, 0.72);
  background: linear-gradient(135deg, var(--gold), #e4b95a);
}

.view {
  min-height: 0;
  display: none;
  position: relative;
}

.view.is-active {
  display: block;
}

.stage-canvas,
.graph-canvas {
  width: 100%;
  height: 100%;
  min-height: 620px;
  display: block;
}

.object-caption {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 20px;
  padding: 14px 16px;
  border: 1px solid rgba(247, 241, 223, 0.16);
  border-radius: var(--radius);
  background: rgba(13, 13, 11, 0.78);
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 16px;
  align-items: center;
}

.caption-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--bronze);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.object-caption strong {
  font-size: clamp(1rem, 2vw, 1.28rem);
  letter-spacing: 0;
}

.object-caption p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.stage-control-dock {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  width: min(360px, calc(100% - 32px));
  padding: 13px;
  border: 1px solid rgba(247, 241, 223, 0.16);
  border-radius: var(--radius);
  background: rgba(13, 13, 11, 0.82);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(16px);
  display: grid;
  gap: 10px;
}

.dock-heading {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: end;
}

.dock-heading .caption-kicker {
  grid-column: 1 / -1;
}

.dock-heading strong {
  min-width: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.dock-heading span:last-child {
  color: var(--current-color, var(--gold));
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.term-pills {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.term-button {
  height: 30px;
  min-width: 0;
  padding: 0;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  font-weight: 850;
}

.term-button.is-active {
  color: var(--coal);
  border-color: var(--active-color, var(--gold));
  background: var(--active-color, var(--gold));
}

.stage-control-dock p {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.38;
}

.graph-note {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(13, 13, 11, 0.78);
  line-height: 1.45;
}

.math-grid,
.compare-grid {
  height: 100%;
  min-height: 620px;
  overflow: auto;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.math-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
}

.math-card,
.compare-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 17, 15, 0.68);
}

.math-card {
  padding: 16px;
  min-height: 178px;
  display: grid;
  gap: 12px;
  cursor: pointer;
}

.math-card.is-active {
  border-color: var(--active-color, var(--gold));
  background:
    linear-gradient(135deg, rgba(247, 241, 223, 0.08), rgba(247, 241, 223, 0.025)),
    rgba(18, 17, 15, 0.78);
}

.math-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.math-card h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.math-symbol {
  min-width: 44px;
  padding: 6px 8px;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  color: var(--active-color, var(--gold));
  text-align: center;
  font-weight: 850;
}

.formula {
  margin: 0;
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
  line-height: 1.45;
}

.plain-copy,
.math-meta,
.compare-card p,
.section-heading small,
.slider-card small {
  color: var(--muted);
  line-height: 1.42;
}

.plain-copy,
.math-meta {
  margin: 0;
}

.math-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-variant-numeric: tabular-nums;
  font-size: 0.86rem;
}

.compare-grid {
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 14px;
}

.compare-card {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(280px, 1.08fr) minmax(260px, 0.92fr);
  gap: 14px;
  align-items: stretch;
  cursor: pointer;
}

.compare-card.is-active {
  border-color: rgba(241, 207, 102, 0.72);
}

.compare-card canvas {
  width: 100%;
  height: 190px;
  display: block;
  border: 1px solid rgba(247, 241, 223, 0.12);
  border-radius: var(--radius);
  background: rgba(7, 7, 6, 0.32);
}

.compare-copy {
  display: grid;
  gap: 9px;
  align-content: start;
}

.compare-card h2 {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: 0;
}

.compare-card p {
  margin: 0;
}

.compare-badge {
  width: fit-content;
  padding: 5px 8px;
  border: 1px solid rgba(247, 241, 223, 0.14);
  border-radius: var(--radius);
  color: var(--gold);
  background: rgba(241, 207, 102, 0.08);
  font-size: 0.76rem;
  font-weight: 800;
}

.compare-bars {
  display: grid;
  gap: 6px;
}

.compare-bar {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) 46px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.bar-name {
  color: rgba(247, 241, 223, 0.72);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  position: relative;
  height: 8px;
  border: 1px solid rgba(247, 241, 223, 0.09);
  border-radius: 999px;
  background: rgba(247, 241, 223, 0.06);
  overflow: hidden;
}

.bar-track::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: rgba(247, 241, 223, 0.24);
}

.bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: var(--bar-width, 0%);
  border-radius: 999px;
  background: var(--bar-color, var(--gold));
  box-shadow: 0 0 14px var(--bar-color, var(--gold));
  transform-origin: left center;
}

.bar-fill.is-negative {
  left: auto;
  right: 50%;
}

.compare-value {
  text-align: right;
}

.controls {
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

.control-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.control-section:first-child {
  padding-top: 0;
}

.control-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--coal);
  background: linear-gradient(135deg, var(--gold), #dba753);
  border-color: rgba(241, 207, 102, 0.72);
  font-weight: 900;
}

.text-button {
  height: 44px;
  padding: 0 16px;
  color: var(--ink);
  font-weight: 760;
}

.toggle-row {
  height: 44px;
  margin-left: auto;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
}

.toggle-row input {
  accent-color: var(--gold);
}

.speed-control {
  margin-top: 14px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.section-heading {
  display: grid;
  gap: 5px;
  margin-bottom: 12px;
}

.section-heading span {
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0;
}

.preset-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset-button {
  min-height: 48px;
  padding: 10px 11px;
  color: var(--muted);
  text-align: left;
  font-size: 0.88rem;
  font-weight: 750;
}

.preset-button.is-active {
  color: var(--coal);
  border-color: rgba(241, 207, 102, 0.72);
  background: linear-gradient(135deg, var(--gold), #e4b95a);
}

.slider-list {
  display: grid;
  gap: 10px;
}

.slider-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(247, 241, 223, 0.04);
  display: grid;
  gap: 9px;
}

.slider-card.is-active {
  border-color: var(--active-color, var(--gold));
  background:
    linear-gradient(135deg, rgba(247, 241, 223, 0.075), rgba(247, 241, 223, 0.02)),
    rgba(247, 241, 223, 0.03);
}

.slider-title {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 9px;
  align-items: center;
}

.color-chip {
  width: 11px;
  height: 32px;
  border-radius: 999px;
  background: var(--active-color, var(--gold));
  box-shadow: 0 0 18px var(--active-color, var(--gold));
}

.slider-title strong {
  font-size: 0.92rem;
  letter-spacing: 0;
}

.slider-title span:last-child {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
}

.slider-card small {
  display: block;
}

.footer-line {
  padding: 10px 2px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--subtle);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
}

@media (max-width: 1080px) {
  .app-shell {
    padding: 18px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .controls {
    overflow: visible;
  }

  .exhibit {
    min-height: 610px;
  }

  .stage-canvas,
  .graph-canvas,
  .math-grid,
  .compare-grid {
    min-height: 540px;
  }

  .slider-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compare-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
    gap: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    min-height: 0;
    padding-bottom: 14px;
  }

  .live-readout {
    width: 100%;
    text-align: left;
  }

  .view-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .exhibit {
    min-height: 560px;
  }

  .stage-canvas,
  .graph-canvas,
  .math-grid,
  .compare-grid {
    min-height: 500px;
  }

  .object-caption {
    left: 12px;
    right: 12px;
    bottom: 12px;
    grid-template-columns: 1fr;
  }

  .stage-control-dock {
    top: 12px;
    left: 12px;
    right: 12px;
    width: auto;
  }

  .math-grid,
  .compare-grid,
  .slider-list {
    grid-template-columns: 1fr;
  }

  .compare-card canvas {
    height: 168px;
  }

  .preset-list {
    grid-template-columns: 1fr;
  }
}
