:root {
  color-scheme: dark;
  font: 13px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
  --chrome: #252628;
  --bar: #212224;
  --stage: #101112;
  --control: #3a3b3e;
  --selected: #3b3942;
  --text: #ebecee;
  --muted: #afb0b5;
  --accent: #c5b6ef;
  --panel: #19191b;
  --unit: 4px;
  --gutter: calc(3 * var(--unit));
  background: var(--chrome);
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}

h1, h2, p, dl, dd { margin: 0; }
h1, h2 { font: inherit; }

button, input, select, output, kbd {
  font: inherit;
  color: inherit;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 0;
  border-radius: 2px;
  padding: 0;
  cursor: pointer;
}

button:hover { background: var(--control); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar, footer, .dock-heading, .track, .parameter-row, .tempo-row,
.status-group, .brand, .dialog-heading {
  display: flex;
  align-items: center;
}

.toolbar {
  gap: var(--unit);
  min-height: 40px;
  padding-inline: var(--gutter);
  background: var(--bar);
}

.brand { gap: 8px; font-weight: 650; }
.brandmark { display: flex; align-items: center; gap: 2px; height: 20px; transform: skew(-14deg); }
.brandmark i { width: 4px; height: 7px; background: var(--accent); }
.brandmark i:nth-child(2) { height: 14px; }
.brandmark i:nth-child(3) { height: 19px; }
.brandmark i:nth-child(4) { height: 11px; }

.document-title {
  min-width: 0;
  margin-inline: var(--gutter) auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

#scenes-toggle { display: none; }
#expand { margin-left: auto; }
.icon-button { width: 30px; height: 28px; flex: none; color: var(--muted); }

.action, .command, .secondary {
  min-height: 26px;
  padding-inline: 8px;
  background: var(--control);
  white-space: nowrap;
}

.action { color: #f0eaff; background: #494350; }
.action:hover, .command:hover, .secondary:hover { background: #505055; }
.quiet { min-height: 26px; padding-inline: var(--unit); color: var(--muted); font-size: 12px; }
.quiet .icon { width: 14px; }

/* Scenes run down a sidebar beside the 2.44:1 program monitor; the
   controls dock spans the full width beneath both. */
main {
  display: grid;
  min-height: 0;
  position: relative;
  grid-template: "scenes monitor" minmax(0, 1fr)
                 "dock dock" auto / clamp(260px, 21vw, 340px) minmax(0, 1fr);
}

#scene-sidebar {
  grid-area: scenes;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 10px;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}
/* Sidebar and dock sections are separate rounded cards. */
.scene-card, #scene-sidebar > section, .dock > section {
  min-width: 0;
  overflow: hidden;
  border-radius: 10px;
  background: var(--chrome);
  /* A soft drop shadow plus a hairline top highlight lift each card. */
  box-shadow: 0 6px 18px rgb(0 0 0 / .7), 0 2px 4px rgb(0 0 0 / .55), inset 0 1px 0 rgb(255 255 255 / .05);
}
.scene-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}
#scenes-heading {
  display: flex;
  align-items: center;
  min-height: 32px;
  padding-inline: var(--gutter);
  font-weight: 600;
  background: var(--bar);
}
#scene-list, .scene-cues { margin: 0; list-style: none; }
#scene-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 10px var(--gutter);
}
[data-scene-group] {
  display: grid;
  gap: 6px;
  flex: none;
}
/* Scene titles are text only; the cues beneath carry the thumbnails. */
[data-scene-group] > .scene-row { grid-template-columns: minmax(0, 1fr); }
[data-scene-group] > .scene-row .scene-thumb { display: none; }
.scene-cues {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 0;
}
.scene-status {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  background: var(--bar);
}
.scene-row, .cue {
  display: grid;
  width: 100%;
  justify-content: stretch;
  text-align: left;
  row-gap: 3px;
}
.scene-row:hover, .cue:hover { background: transparent; }
.scene-row:focus-visible, .cue:focus-visible { outline-offset: 2px; }
.scene-thumb, .cue-thumb {
  grid-column: 1 / -1;
  display: block;
  width: 100%;
  aspect-ratio: 12 / 5;
  object-fit: cover;
  border-radius: 6px;
}
.scene-row:hover img, .cue:hover img { filter: brightness(1.12); }
.scene-name, .cue-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scene-name { font-weight: 600; }
.cue-name { font-size: 12px; }
.scene-row[aria-current=true] .scene-name, .cue[data-state=Active] .cue-name,
.cue[data-state=Taking] .cue-name, .cue-state { color: var(--accent); }
.cue kbd { display: none; text-align: right; }
[data-scene-group]:has(> [aria-current=true]) .cue kbd { display: inline; }
.cue-state, kbd, .cue-feedback { font-size: 12px; }
kbd, .cue-feedback { color: var(--muted); }
.cue-feedback {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  padding: 5px var(--gutter);
  min-height: 28px;
  background: var(--bar);
}
.cue-feedback span { flex: none; }
.cue-progress, .cue-progress i { height: 2px; flex: none; }
.cue-progress i { display: block; width: 0; background: var(--accent); }


.stage {
  grid-area: monitor;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
  background: var(--stage);
}

.viewport {
  cursor: grab;
  touch-action: none;
  width: min(100cqw, calc(100cqh * 2.44));
  aspect-ratio: 2.44;
  position: relative;
  overflow: hidden;
}

.viewport:active { cursor: grabbing; }
.stage:fullscreen { background: #000; }
#wall { width: 100%; height: 100%; display: block; }

.dock {
  grid-area: dock;
  display: grid;
  /* Twice the original control height; room is left for future controls. */
  min-height: 278px;
  align-items: start;
  /* The lighting card takes the left half; the right half is left free. */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  background: var(--panel);
}
.parameter-row[hidden] { display: none; }
/* The lighting card spans the dock and shows every feature of the scene at
   once, side by side: a colour field, the hex code and a brightness slider. */
.dock > .material-controls {
  grid-column: 1;
  align-self: stretch;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding-bottom: 0;
}
.light-panels {
  display: grid;
  /* One column per feature, always on one row so the dock keeps its height. */
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  padding: 10px var(--gutter) 12px;
}
.light-panel {
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}
.light-heading { display: flex; align-items: center; justify-content: space-between; min-height: 22px; }
.light-name { font: inherit; font-weight: 550; margin: 0; }
.light-row { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.light-row input[type=range] { flex: 1; }
.light-level { min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }
.light-level-label { white-space: nowrap; }
.color-field {
  display: block;
  width: 100%;
  /* Fixed: the canvas sizes its bitmap from its box, so it must not size the box. */
  height: 124px;
  border-radius: 6px;
  touch-action: none;
  box-shadow: 0 0 0 1px rgb(255 255 255 / .08);
}
.color-field:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#view-auto[aria-pressed=true], #beam-auto[aria-pressed=true] { color: var(--accent); }
.dock > section { min-width: 0; }
/* Overlay effects take the dock's right half: launch tiles, the settings of
   the effect last launched (also applied live), and what is on air. */
.dock > .overlay-controls { grid-column: 2; align-self: stretch; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.overlay-body {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.2fr) minmax(0, .9fr);
  gap: 14px;
  min-height: 0;
  padding: 10px var(--gutter) 12px;
}
.overlay-tiles { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; gap: 6px; min-height: 0; }
.overlay-tile {
  position: relative;
  display: block;
  min-height: 40px;
  padding: 0;
  overflow: hidden;
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgb(255 255 255 / .08);
}
.overlay-tile canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.overlay-tile-name {
  position: absolute; left: 8px; bottom: 5px;
  font-size: 12px; font-weight: 550; color: #fff; text-shadow: 0 1px 3px #000;
}
.overlay-tile:hover { box-shadow: 0 0 0 1px rgb(255 255 255 / .3); }
.overlay-tile[aria-current=true] { box-shadow: 0 0 0 2px var(--accent); }
.overlay-tile:active { transform: scale(.98); }
.overlay-settings { display: grid; align-content: start; gap: 6px; min-width: 0; }
.overlay-settings .color-field { height: 64px; }
.overlay-settings .light-row label, .overlay-settings .light-row > span { white-space: nowrap; min-width: 4.5em; }
.overlay-settings output { min-width: 4.5ch; text-align: right; font-variant-numeric: tabular-nums; }
.segmented { display: flex; flex: 1; gap: 2px; padding: 2px; border-radius: 6px; background: var(--control); }
.segmented button { flex: 1; min-height: 22px; padding: 0 2px; border-radius: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
/* When the panel is narrow the beat choices drop below their label rather than squeeze. */
.light-row:has(> .segmented) { flex-wrap: wrap; row-gap: 4px; }
.light-row > .segmented { min-width: 168px; }
.segmented button[aria-checked=true] { color: #28242d; background: var(--accent); }
.overlay-running { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 6px; min-width: 0; min-height: 0; }
#overlay-active { display: grid; align-content: start; gap: 6px; margin: 0; padding: 0; list-style: none; overflow: auto; min-height: 0; }
.overlay-empty { color: var(--muted); font-size: 12px; }
.overlay-item { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: center; gap: 6px; font-size: 12px; }
.overlay-item .swatch { width: 10px; height: 10px; border-radius: 50%; }
.overlay-item .remaining { color: var(--muted); font-variant-numeric: tabular-nums; }
.overlay-item .bar { grid-column: 2 / -1; height: 2px; background: #515256; }
.overlay-item .bar i { display: block; height: 100%; background: var(--accent); }
.overlay-item[data-ending] { opacity: .5; }
/* Audio and beat effects live in the sidebar under the scenes. */
#scene-sidebar > .sound, #scene-sidebar > .effects, .dock > section { padding-bottom: 8px; }
#scene-sidebar .track { min-height: 48px; }
#scene-sidebar #waveform { height: 40px; }
#scene-sidebar #signal-scope { height: 36px; }


.dock-heading {
  justify-content: space-between;
  min-height: 32px;
  padding-inline: var(--gutter);
  background: var(--bar);
}

.dock-heading h2, .dialog-heading h2 { font-weight: 600; }
.track-info strong { font-weight: 500; }

.track { min-height: 52px; gap: 8px; padding-inline: var(--gutter); }
.play { width: 30px; height: 28px; flex: none; color: #28242d; background: var(--accent); }
.play:hover { background: #d7cafa; }
.track-info { min-width: 0; flex: 1; }
.track-info strong, .track-info span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-info span, .track-time { font-size: 12px; color: var(--muted); }
.track-time { white-space: nowrap; }
.track-time b { font-weight: 500; color: var(--text); }

#waveform {
  display: block;
  width: calc(100% - 2 * var(--gutter));
  height: 48px;
  margin-inline: var(--gutter);
}

time, .track-time, .tempo, output { font-variant-numeric: tabular-nums; }
.parameter-row, .tempo-row { gap: 8px; padding-inline: var(--gutter); min-height: 31px; }
.parameter-row label, .parameter-row .quiet { flex: none; white-space: nowrap; }
.parameter-row input[type=range] { flex: 1; }
.parameter-row output { min-width: 4ch; text-align: right; }

input[type=range] {
  appearance: none;
  accent-color: var(--accent);
  width: 100%;
  min-width: 0;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type=range]::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill,70%), #515256 var(--fill,70%));
}
input[type=range]::-moz-range-track { height: 3px; background: #515256; }
input[type=range]::-moz-range-progress { height: 3px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 10px;
  height: 13px;
  margin-top: -5px;
  border-radius: 1px;
  background: #dddbe1;
}
input[type=range]::-moz-range-thumb {
  width: 10px;
  height: 13px;
  border: 0;
  border-radius: 1px;
  background: #dddbe1;
}

.switch { width: 34px; height: 28px; position: relative; }
.groove-row .groove-scene { flex: 1; font-size: 12px; color: var(--muted); }
.switch::before { content: ""; width: 28px; height: 14px; border-radius: 8px; background: #58595e; }
.switch span { position: absolute; left: 5px; width: 10px; height: 10px; border-radius: 50%; background: #ddd; }
.switch[aria-checked=true]::before { background: var(--accent); }
.switch[aria-checked=true] span { left: 19px; background: #302936; }

.tempo { font-size: 12px; color: var(--muted); }
.tempo strong { font-size: 15px; font-weight: 550; color: var(--text); }
.tempo-row { min-height: 32px; }
.tempo-row .command { margin-left: auto; font-size: 12px; }
#beats { display: inline-flex; gap: 3px; }
#beats i { width: 6px; height: 8px; background: #525358; }
#beats i.on { background: var(--accent); }

.meter { display: flex; align-items: center; gap: 8px; padding-inline: var(--gutter); }
.legend { display: grid; gap: 2px; font-size: 11px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend span::before { content: ""; width: 7px; height: 2px; background: var(--accent); }
.legend span:last-child::before { background: #81cfaa; }
#signal-scope { display: block; flex: 1; min-width: 0; width: 0; height: 44px; }

footer {
  min-height: 27px;
  gap: var(--gutter);
  padding-inline: var(--gutter);
  background: var(--bar);
  color: var(--muted);
  font-size: 11px;
}

.status-group { gap: 8px; margin-right: auto; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #81cfaa; }
.dot.dim { background: #838489; }
footer .quiet { font-size: inherit; }

dialog {
  width: min(345px, calc(100vw - 24px));
  max-height: 90dvh;
  padding: var(--gutter);
  border: 0;
  background: var(--chrome);
  color: var(--text);
  box-shadow: 0 6px 28px #0008;
}
dialog::backdrop { background: #0008; }
.dialog-heading { justify-content: space-between; margin-bottom: 8px; }
.source-option { width: 100%; justify-content: flex-start; gap: 10px; min-height: 42px; text-align: left; }
.source-option span { display: grid; }
.source-option strong { font-weight: 500; }
.source-option small, .dialog-detail { color: var(--muted); font-size: 12px; }
.input-select { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: var(--unit); margin-block: var(--gutter); }
.input-select label { grid-column: 1 / -1; }
.input-select select { min-width: 0; min-height: 28px; padding-inline: 4px; border: 0; background: var(--control); }
.offset-label { display: flex; justify-content: space-between; }
.key-list { display: grid; grid-template-columns: 1fr auto; align-items: center; row-gap: 8px; }
.key-list dd { text-align: right; }
#notice {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px var(--gutter);
  background: #424147;
  box-shadow: 0 3px 12px #0005;
}

@media (max-height: 520px) and (min-width: 761px) {
  body { height: auto; min-height: 100dvh; }
  main { grid-template: "scenes monitor" auto "dock dock" auto / clamp(260px, 21vw, 340px) minmax(0, 1fr); }
  #scene-list { max-height: calc((100vw - clamp(260px, 21vw, 340px)) / 2.44 - 70px); }
  .stage { container-type: normal; }
  .viewport { width: 100%; }
}

@media (max-width: 760px) {
  body { height: auto; min-height: 100dvh; grid-template-rows: auto 1fr auto; }
  main { display: block; }
  /* The scene bar scrolls sideways; the status sits beneath it. */
  #scene-sidebar { grid-template-rows: none; }
  #scenes-heading { display: none; }
  #scene-list { flex-direction: row; gap: 18px; overflow: auto hidden; padding: 8px var(--gutter); }
  [data-scene-group] { width: clamp(220px, 60vw, 300px); }
  .scene-status { min-width: 0; }
  .stage { container-type: normal; }
  .viewport { width: 100%; }
  .dock { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .color-field { height: 110px; }
  .dock > .overlay-controls { grid-column: 1; }
  .overlay-body { grid-template-columns: minmax(0, 1fr); }
  #waveform { height: 32px; margin-bottom: 8px; }
  footer { flex-wrap: wrap; gap: 4px 8px; }
}

@media (max-width: 520px) {
  .dock { display: flex; flex-direction: column; }
  .toolbar, footer { padding-inline: 8px; }
  .brand { font-size: 12px; }
  .document-title { display: none; }
  .action { font-size: 12px; }
  .dock-heading { min-height: 36px; }
  .effects { padding-bottom: 4px; }
  .quiet, .icon-button, .action, .play { min-height: 32px; }
  .status-group { flex-basis: 100%; }
  #system-status { margin-right: auto; }
}

/* In the narrow sidebar the cue state rides on the thumbnail as a badge. */
.cue { position: relative; grid-template-columns: minmax(0, 1fr) auto; }
.cue-state { position: absolute; }
.cue-state:empty { display: none; }
.cue-state {
  top: 3px;
  left: 3px;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 10px;
  line-height: 15px;
  background: #121316d0;
}

/* The cue on program is outlined in the theme colour. */
.cue-thumb { box-sizing: border-box; border: 2px solid transparent; }
.cue[aria-pressed=true] .cue-thumb { border-color: var(--accent); }
