:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --surface: #fffaf0;
  --surface-strong: #ffffff;
  --ink: #20201d;
  --muted: #68645c;
  --hairline: #ddd4c2;
  --teal: #157a72;
  --teal-soft: #d9f0ec;
  --berry: #b53b5d;
  --amber: #c5872e;
  --violet: #5b5aa6;
  --shadow: 0 18px 60px rgba(37, 31, 18, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(21, 122, 114, 0.06), transparent 26%),
    linear-gradient(180deg, #fbf7ee, var(--paper));
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(33, 118, 210, 0.82);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 320px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.inspector {
  padding: 24px;
  border-color: var(--hairline);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 32px;
  border-right: 1px solid var(--hairline);
  min-height: 0;
  overflow: hidden;
}

.inspector {
  border-left: 1px solid var(--hairline);
  background: var(--surface);
  overflow-y: auto;
  min-height: 0;
}

.brand-block h1 {
  margin: 4px 0 0;
  max-width: 100%;
  font-size: 24px;
  line-height: 1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.scene-tabs {
  display: grid;
  gap: 8px;
}

.scene-tab,
.mode-button,
.icon-button,
.primary-button,
.preset-button,
.feature-toggle,
.small-button {
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.scene-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 700;
}

.scene-tab span {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: rgba(32, 32, 29, 0.07);
  color: var(--muted);
  font-size: 12px;
}

.scene-tab:hover,
.mode-button:hover,
.icon-button:hover,
.primary-button:hover,
.preset-button:hover,
.feature-toggle:hover,
.small-button:hover {
  transform: translateY(-1px);
}

.scene-tab.active {
  background: var(--surface-strong);
  border-color: var(--hairline);
  box-shadow: 0 10px 28px rgba(37, 31, 18, 0.07);
}

.scene-tab.active span {
  background: var(--teal);
  color: white;
}

.sidebar-note {
  margin-top: auto;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  padding: 24px;
  gap: 18px;
  overflow: hidden;
}

.workspace-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.workspace-header h2 {
  margin: 4px 0 0;
  font-size: clamp(30px, 4vw, 54px);
  line-height: 0.94;
  letter-spacing: 0;
}

.mode-switch {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
}

.mode-switch.hidden {
  display: none;
}

.mode-button {
  min-width: 92px;
  padding: 8px 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 760;
}

.mode-button.active {
  background: var(--ink);
  color: white;
}

.visual-stage {
  position: relative;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background:
    linear-gradient(rgba(32, 32, 29, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 32, 29, 0.035) 1px, transparent 1px),
    var(--surface-strong);
  background-size: 28px 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#demoCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

#demoCanvas.hidden {
  display: none;
}

.playground-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    linear-gradient(rgba(32, 32, 29, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 32, 29, 0.035) 1px, transparent 1px),
    rgba(255, 250, 240, 0.96);
  background-size: 28px 28px;
}

.playground-panel.hidden {
  display: none;
}

.playground-content {
  display: grid;
  gap: 14px;
  min-height: 100%;
  padding: 20px;
}

.playground-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.playground-header h3 {
  margin: 4px 0 8px;
  font-size: clamp(22px, 2.4vw, 34px);
  line-height: 1;
  letter-spacing: 0;
}

.playground-header p:last-child {
  margin: 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.45;
}

.accuracy-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 8px;
  width: min(100%, 360px);
}

.accuracy-pill {
  display: grid;
  gap: 3px;
  padding: 8px 12px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.accuracy-pill span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.accuracy-pill strong {
  font-size: 21px;
  line-height: 1;
}

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

.preset-button,
.small-button,
.feature-toggle {
  border-color: var(--hairline);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  font-weight: 760;
  touch-action: manipulation;
}

.preset-button {
  display: grid;
  min-height: 48px;
  padding: 8px;
  text-align: left;
  align-content: center;
  gap: 4px;
}

.preset-button span {
  color: var(--muted);
  font-size: 11px;
}

.preset-button.active {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--ink);
}

.playground-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.feature-board,
.model-result {
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 10px 28px rgba(37, 31, 18, 0.06);
}

.feature-board {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 14px;
}

.board-heading,
.model-result-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.board-heading h4,
.model-result-head h4 {
  margin: 4px 0 0;
  font-size: 20px;
  line-height: 1.05;
  letter-spacing: 0;
}

.small-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--muted);
}

.feature-toggle-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.feature-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px;
  text-align: left;
}

.feature-toggle span {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border-radius: 50%;
  background: rgba(32, 32, 29, 0.08);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.feature-toggle.active {
  border-color: rgba(21, 122, 114, 0.5);
  background: rgba(217, 240, 236, 0.82);
}

.feature-toggle.active span {
  background: var(--teal);
  color: white;
}

.vector-readout {
  padding: 12px;
  border-radius: 8px;
  background: rgba(32, 32, 29, 0.05);
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.model-comparison {
  display: grid;
  order: -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.model-result {
  display: grid;
  align-content: start;
  gap: 11px;
  padding: 14px;
}

.model-result.hebbian {
  border-top: 4px solid var(--teal);
}

.model-result.backprop {
  border-top: 4px solid var(--berry);
}

.prediction-badge {
  min-width: 82px;
  padding: 7px 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(32, 32, 29, 0.06);
  font-weight: 800;
  text-align: center;
}

.prediction-badge.correct {
  border-color: rgba(21, 122, 114, 0.35);
  background: var(--teal-soft);
  color: var(--teal);
}

.prediction-badge.mismatch {
  border-color: rgba(181, 59, 93, 0.34);
  background: rgba(181, 59, 93, 0.1);
  color: var(--berry);
}

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

.score-row {
  display: grid;
  grid-template-columns: minmax(66px, 0.85fr) minmax(82px, 1.35fr) 44px;
  gap: 8px;
  align-items: center;
}

.score-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

.score-label span {
  font-weight: 760;
  white-space: nowrap;
}

.score-label small {
  display: none;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 10px;
}

.score-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(32, 32, 29, 0.08);
  overflow: hidden;
}

.score-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transform-origin: left center;
  background: var(--teal);
  transition: transform 180ms ease;
}

.backprop .score-fill {
  background: var(--berry);
}

.score-row.predicted .score-label span {
  color: var(--ink);
}

.score-row.expected .score-label span::after {
  content: " *";
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.score-row strong {
  text-align: right;
  font-size: 12px;
}

.model-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.32;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 250, 240, 0.86);
  color: var(--muted);
  font-weight: 760;
}

.loading-overlay.hidden {
  display: none;
}

.control-strip {
  display: grid;
  grid-template-columns: auto auto auto auto minmax(160px, 1fr) 88px;
  align-items: center;
  gap: 10px;
}

.control-strip.hidden {
  visibility: hidden;
  pointer-events: none;
}

.icon-button,
.primary-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  border-color: var(--hairline);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-weight: 760;
}

.primary-button {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
  min-width: 88px;
}

#stepSlider {
  width: 100%;
  accent-color: var(--teal);
}

.step-readout {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  text-align: right;
}

.inspector-section {
  padding: 0 0 22px;
  margin: 0 0 22px;
  border-bottom: 1px solid var(--hairline);
}

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

.inspector h3 {
  margin: 6px 0 8px;
  font-size: 24px;
  line-height: 1.05;
  letter-spacing: 0;
}

#stepNarrative {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.formula-box {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.formula-line {
  padding: 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  overflow-wrap: anywhere;
}

.value-grid {
  display: grid;
  gap: 8px;
}

.value-row {
  display: grid;
  grid-template-columns: minmax(96px, 0.82fr) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 9px 0;
  border-bottom: 1px solid rgba(221, 212, 194, 0.72);
  font-size: 13px;
}

.value-row:last-child {
  border-bottom: 0;
}

.value-label {
  color: var(--muted);
  font-weight: 760;
}

.value-number {
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}

@media (max-width: 1080px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar,
  .inspector {
    border: 0;
  }

  .sidebar {
    padding-bottom: 0;
    overflow: visible;
  }

  .workspace {
    overflow: visible;
  }

  .visual-stage {
    min-height: 460px;
    height: auto;
  }

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

  .scene-tab {
    justify-content: center;
  }

  .playground-grid,
  .model-comparison {
    grid-template-columns: 1fr;
  }

  .preset-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sidebar-note {
    margin-top: 0;
  }

}

@media (max-width: 720px) {
  .workspace,
  .sidebar,
  .inspector {
    padding: 18px;
  }

  .workspace-header {
    align-items: stretch;
    flex-direction: column;
  }

  .scene-tabs {
    grid-template-columns: 1fr;
  }

  .playground-content {
    padding: 16px;
  }

  .playground-header {
    grid-template-columns: 1fr;
  }

  .accuracy-summary,
  .preset-row,
  .feature-toggle-grid {
    grid-template-columns: 1fr;
  }

  .control-strip {
    grid-template-columns: repeat(4, 1fr);
  }

  .visual-stage {
    min-height: 700px;
  }

  #stepSlider,
  .step-readout {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scene-tab,
  .mode-button,
  .icon-button,
  .primary-button,
  .preset-button,
  .feature-toggle,
  .small-button,
  .score-fill {
    transition: none;
  }
}
