:root {
  --bg: #0b0e12;
  --panel: #151a21;
  --ink: #d7dee6;
  --dim: #8a97a3;
  --accent: #4db2ff;
  --line: #262e38;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  display: grid;
  grid-template-columns: 1fr 320px;
  height: 100%;
}

#stage {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
}

/* The canvas is fluid; winit sets inline width/height styles, so the
   overrides must win. The backing store stays at simulation size and
   object-fit letterboxes it, aspect preserved. */
canvas#bouncy {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  background: #000;
  outline: none;
  touch-action: none;
}

/* Armed placement tool: an invisible layer over the stage catches the
   next click before winit's canvas handlers can turn it into a burst. */
#tool-overlay {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  z-index: 4;
}

#hint {
  position: absolute;
  left: 0; right: 0; bottom: 8px;
  text-align: center;
  color: var(--dim);
  font-size: 11.5px;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

#panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 14px 16px 24px;
  overflow-y: auto;
  /* Own compositor layer + paint containment: panel scrolling must
     stay off the main thread and never share raster damage with the
     canvas repainting underneath at frame rate. */
  will-change: transform;
  contain: layout paint;
}

#panel h1 {
  font-size: 18px;
  margin: 0 0 8px;
}
#panel h1 span { color: var(--dim); font-size: 12px; font-weight: normal; }

/* Status chips: one pill per live state, shown/hidden from the
   per-frame snapshot so they can never disagree with the simulation. */
#chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}
.chip {
  font-size: 11px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip.run  { background: #17301c; color: #8fdd9a; }
.chip.pause{ background: #33270f; color: #f0c060; }
.chip.stop { background: #3a1518; color: #f09595; }
.chip.info { background: #12283a; color: #6cc3ff; }
.chip.warn { background: #33270f; color: #f0c060; }
.chip.boom { background: #2b1a33; color: #cf9df2; }
.chip.tool { background: #0f3038; color: #6fe0d0; }

#readouts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
#readouts div {
  background: #0f1319;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 4px;
  text-align: center;
}
#readouts span { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
#readouts label { color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }

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

button {
  flex: 1;
  min-width: 64px;
  background: #1d242e;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
/* "Fullscreen" is the longest one-word label in the four-button row:
   trim its side padding so the text never overflows the button. */
#btn-fullscreen { padding-left: 2px; padding-right: 2px; }

button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }

/* A placement tool is armed: the button stays lit until the canvas
   click lands (or Esc cancels). */
button.armed {
  border-color: var(--accent);
  background: #14344d;
  color: #cfeaff;
}

/* Cycle buttons show where in their cycle they are: a dim caption
   (with the matching hotkey) over the current value. */
button.cycle small {
  display: block;
  color: var(--dim);
  font-size: 10px;
  letter-spacing: .03em;
  margin-bottom: 1px;
}
button.cycle span { display: block; }

.slider {
  display: block;
  margin: 10px 0 2px;
  font-size: 12.5px;
  color: var(--dim);
}
.slider output { float: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.slider input {
  width: 100%;
  margin-top: 2px;
  accent-color: var(--accent);
}

#toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  margin: 10px 0;
  font-size: 13px;
}
/* Checkboxes drawn as switches: on-state is unmistakable at a glance,
   and the label brightens with it. The input stays a real checkbox
   (keyboard and screen-reader behavior come free). */
#toggles label {
  display: flex;
  /* The input precedes the text in the markup; visually the switch
     belongs on the right, label on the left. */
  flex-direction: row-reverse;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--dim);
  cursor: pointer;
}
#toggles label:has(input:checked) { color: var(--ink); }
#toggles input {
  appearance: none;
  flex: none;
  width: 30px;
  height: 17px;
  margin: 0;
  border-radius: 999px;
  background: #2a333f;
  position: relative;
  cursor: pointer;
  transition: background .12s ease-out;
}
#toggles input::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #7c8794;
  transition: transform .12s ease-out, background .12s ease-out;
}
#toggles input:checked { background: var(--accent); }
#toggles input:checked::after {
  transform: translateX(13px);
  background: #0b0e12;
}
#toggles input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Inspector for the selected emitter/wall stroke: amber accent to
   match the canvas selection highlight. */
#inspector {
  margin: 10px 0;
  border: 1px solid #8a6d2f;
  border-radius: 6px;
  padding: 6px 10px 8px;
}
.insp-title {
  margin: 2px 0 4px;
  font-size: 12.5px;
  color: #ffd25a;
}

#launch {
  margin: 12px 0 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
}
#launch summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
}
#launch[open] summary { margin-bottom: 4px; }
.launch-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  font-size: 12.5px;
  color: var(--dim);
}
.launch-field select,
.launch-field input {
  width: 120px;
  background: #0f1319;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 6px;
  font: inherit;
  font-size: 12.5px;
}

/* MIDI port dropdown: its own full-width row once connected, so long
   port names ("IAC Driver Bus 1") never truncate. */
#midi-port {
  display: block;
  width: 100%;
  margin: 6px 0;
  background: #0f1319;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 5px 6px;
  font: inherit;
  font-size: 12.5px;
}

.fine { color: var(--dim); font-size: 11.5px; }
.fine a { color: var(--accent); text-decoration: none; }
#threads-note { color: var(--dim); font-size: 11.5px; margin: 8px 0 0; }

#panel-toggle { display: none; }

#error {
  position: fixed;
  inset: auto 12px 12px 12px;
  background: #3a1518;
  border: 1px solid #a33;
  border-radius: 8px;
  padding: 10px 14px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  z-index: 10;
}

/* Narrow screens: the panel becomes a slide-over drawer. */
@media (max-width: 760px) {
  main { grid-template-columns: 1fr; }
  #panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(320px, 88vw);
    transform: translateX(100%);
    transition: transform .18s ease-out;
    z-index: 5;
  }
  #panel.open { transform: none; }
  #panel-toggle {
    display: block;
    position: fixed;
    top: 10px; right: 10px;
    z-index: 6;
    flex: none;
  }
}
