:root {
  color-scheme: light;
  --ink: #1f2024;
  --muted: #6b6d75;
  --paper: #f3f1ec;
  --panel: #fbfaf7;
  --line: #d6d2c8;
  --accent: #2a9d8f;
  --accent-ink: #ffffff;
  --field: #ffffff;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--paper); color: var(--ink); font: 14px/1.45 var(--sans); }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 28px 0 36px; }
.masthead { margin-bottom: 16px; }
h1 { margin: 0; font-size: clamp(22px, 3vw, 30px); font-weight: 600; letter-spacing: -0.02em; }
.sim-shell { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 16px; align-items: start; }
.stage {
  width: min(100%, 640px);
  aspect-ratio: 1;
  justify-self: center;
  display: grid;
  place-items: center;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #15161a;
}
#lattice { display: block; max-width: 100%; max-height: 100%; background: #15161a; image-rendering: pixelated; touch-action: manipulation; cursor: crosshair; }
#lattice:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

.controls { display: grid; gap: 16px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.control { display: grid; gap: 7px; min-width: 0; }
.control-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 600; }
.control-label em { font: italic 14px Georgia, "Times New Roman", serif; }
output { color: var(--muted); font: 11px var(--mono); font-weight: 400; white-space: nowrap; }
input[type="range"] { display: block; width: 100%; margin: 0; accent-color: var(--accent); }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
button { min-height: 38px; padding: 7px 10px; border: 1px solid var(--ink); border-radius: 4px; background: var(--field); cursor: pointer; font-size: 12px; font-weight: 600; }
button:hover:not(:disabled) { filter: brightness(.94); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
button:disabled { opacity: .5; cursor: default; }
.status { min-height: 1.5em; margin: 0; color: var(--muted); font: 11px/1.5 var(--mono); }

html[data-view="geometry"] .dynamics-controls,
html[data-view="dynamics"] .geometry-controls { display: none; }
.dynamics-controls { display: grid; gap: 16px; }
.geometry-controls { display: grid; gap: 16px; }

@media (max-width: 760px) {
  .app { width: min(100% - 28px, 640px); padding: 20px 0 24px; }
  .sim-shell { grid-template-columns: 1fr; gap: 12px; }
  .stage, .controls { width: 100%; }
}

/* Embedded mode uses the same chalkboard variables as the main CCA simulation. */
html[data-embed] {
  color-scheme: dark;
  --ink: #f2efe6;
  --muted: #8c9690;
  --paper: transparent;
  --panel: #25322f;
  --line: #3a4a45;
  --field: #1f2a2e;
  --accent: #8fd3c4;
  --accent-ink: #1f2a2e;
}
html[data-embed] body { background: transparent; }
html[data-embed] .app { width: 100%; padding: 0; }
html[data-embed] .masthead { display: none; }
html[data-embed] .sim-shell { grid-template-columns: 1fr; gap: 12px; }
html[data-embed] .stage { width: min(100%, 620px); border-color: var(--line); }
html[data-embed] .controls { width: min(100%, 620px); justify-self: center; border-color: var(--line); }
html[data-embed] #lattice { background: #15161a; }
html[data-embed] button { border-color: var(--line); }
html[data-embed] button.primary { color: var(--accent-ink); }

@media (max-width: 520px) {
  .controls { padding: 13px; }
  .dynamics-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
  .dynamics-controls .button-row { grid-column: 1 / -1; }
  .control-label { font-size: 12px; }
}
