:root {
  --bg: #08090c;
  --bg2: #10131a;
  --line: #232833;
  --fg: #e6e9ef;
  --dim: #8b93a3;
  --accent: #4fd1c5;
  --accent2: #f6ad55;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The browser ships `[hidden] { display: none }`, but any of our own rules that set
   `display` beat it on order. `.slider { display: grid }` was leaving controls marked
   `hidden` fully visible. This settles it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--line);
}

#btn-mode {
  flex: 0 0 auto;
  padding: 8px 14px;
}

/* The physics controls only exist in expert mode. The default leaves four decisions:
   what plays, what is shown, how much detail, and fullscreen.
   The switch lives in a data attribute rather than a class: if <body> carried the
   class `expert` it would match the `.expert` rule itself and hide the whole page. */
.expert { display: none; }
body[data-mode="expert"] .expert { display: block; }

header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

header .sub {
  margin: 4px 0 0;
  color: var(--dim);
  font-size: 13px;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  padding: 16px 24px 40px;
  align-items: start;
}

/* Panels and spectrum stack in their own column. If instead the controls column
   spanned two grid rows, its height would be distributed across them and open a large
   gap between the panels and the spectrum. */
#left {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

#stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  min-width: 0;
}

#stage.only-chladni { grid-template-columns: 1fr; }
#stage.only-chladni #panel-faraday { display: none; }
#stage.only-faraday { grid-template-columns: 1fr; }
#stage.only-faraday #panel-chladni { display: none; }

.panel {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.tag {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: var(--accent);
  color: #062320;
  font-size: 11px;
  font-weight: 800;
}

#panel-faraday .tag { background: var(--accent2); color: #2a1704; }

.hint {
  color: var(--dim);
  font-size: 12px;
}

.expand {
  flex: 0 0 auto;
  margin-left: auto;
  width: 28px;
  padding: 4px 0;
  font-size: 13px;
  line-height: 1;
}

button.demo {
  background: #1d2733;
  border-color: #2c3a4a;
}

button.demo.on {
  background: var(--accent);
  color: #062320;
  border-color: var(--accent);
  font-weight: 600;
}

/* In fullscreen the panel is just the canvas: no header, no readout, which is what
   screen recording needs. */
.panel:fullscreen {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #000;
}

.panel:fullscreen .panel-head,
.panel:fullscreen .readout { display: none; }

.panel:fullscreen canvas {
  width: auto;
  height: 100vh;
  max-width: 100vw;
  border-radius: 0;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #000;
}

#cv-spectrum {
  aspect-ratio: auto;
  height: 90px;
}

.readout {
  margin-top: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  color: var(--dim);
  line-height: 1.5;
  min-height: 2.4em;
  white-space: pre-wrap;
}

#spectrum-wrap {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  min-width: 0;
}

#controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding-right: 4px;
}

.group {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.group h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--dim);
}

.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row + .row { margin-top: 6px; }

button {
  flex: 1 1 auto;
  min-width: 0;
  padding: 7px 10px;
  background: #1a1f29;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

button:hover:not(:disabled) { background: #232a37; border-color: #39424f; }
button:disabled { opacity: .38; cursor: not-allowed; }

button.primary { background: var(--accent); color: #062320; border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #6ee0d5; border-color: #6ee0d5; }

.seg button.on { background: var(--accent); color: #062320; border-color: var(--accent); font-weight: 600; }

.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--dim);
}

.slider span { grid-column: 1; }

.slider output {
  grid-column: 2;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--fg);
}

.slider input[type=range] {
  grid-column: 1 / -1;
  width: 100%;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.status {
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--dim);
  line-height: 1.45;
}

.note p {
  margin: 0 0 8px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--dim);
}

.note p:last-child { margin-bottom: 0; }
.note b { color: var(--fg); font-weight: 600; }

.error {
  color: #fc8181;
}

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  #controls { position: static; max-height: none; }
  #stage { grid-template-columns: 1fr; }
}
