:root {
  --ink: #f6edd9;
  --muted: #cbbfa6;
  --bg: #1c1410;
  --panel: #2a1d16;
  --line: #4a3426;
  --gold: #e2b657;
  --red: #c4313a;
  --green: #1f7a3a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(196, 49, 58, 0.18), transparent 32%),
    radial-gradient(circle at top right, rgba(31, 122, 58, 0.16), transparent 28%),
    var(--bg);
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

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

button, .check, .slider { touch-action: manipulation; }

.top, .workspace, .now-playing { width: min(1080px, calc(100% - 32px)); margin: 0 auto; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  padding: 28px 0 8px;
}

.eyebrow {
  margin: 0 0 4px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--gold);
}

h1, h2 { font-weight: 600; margin: 0; }

h1 { font-size: 40px; line-height: 1; }

h2 { font-size: 22px; }

.top-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.status {
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: #3a241c;
  color: var(--muted);
  font-size: 14px;
  max-width: 100%;
}

.status.is-on { background: #1d3a24; color: #d7f5d4; }
.status.is-off { background: #4a2020; color: #ffd0d0; }

.now-playing {
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--gold);
  border-radius: 16px;
  background: #2a1d16;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.now-kicker {
  margin: 0;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
}

.now-name { margin: 0; font-size: 28px; line-height: 1.1; }

.now-detail { margin: 0; color: var(--muted); font-size: 16px; }

.now-scenes, .now-frames {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.now-scene, .now-frame {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #140e0b;
}

.now-scene {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 10px 6px 6px;
  cursor: pointer;
}

.now-scene canvas, .now-frame canvas {
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
  background: #000;
  border-radius: 6px;
  display: block;
}

.now-frame { padding: 4px; }

.now-frame.is-on, .now-scene.is-on {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  grid-template-areas:
    "stage tools"
    "scenes scenes";
  gap: 22px 28px;
  align-items: start;
  padding-top: 18px;
}

.stage-wrap { grid-area: stage; }
.tools { grid-area: tools; }
.presets { grid-area: scenes; }

.stage-wrap { display: flex; flex-direction: column; gap: 10px; }

.update-lights {
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: #6e1c24;
  color: #fff8ee;
  font-weight: 650;
  cursor: pointer;
}

.update-lights:disabled { opacity: 0.7; cursor: wait; }

.grid {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  aspect-ratio: 1;
  gap: 4px;
  padding: 12px;
  border-radius: 18px;
  background: #090807;
  border: 1px solid #3a2a22;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  border: 0;
  padding: 0;
  border-radius: 3px;
  background: #000;
  min-width: 0;
  min-height: 0;
}

.mode-label { margin: 0; color: var(--ink); font-size: 20px; font-weight: 700; }

.preset.is-on span::before { content: "Now · "; color: var(--gold); }

.preset.is-in { outline: 2px solid var(--green); outline-offset: 2px; }

.tools {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

fieldset {
  margin: 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(42, 29, 22, 0.88);
}

legend {
  padding: 0 6px;
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.color-row { display: flex; gap: 10px; align-items: center; }

#color {
  width: 54px;
  height: 54px;
  padding: 0;
  border: 2px solid var(--gold);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }

.swatches button, .tool-row button, .text-actions button, .presets-head button, .preset {
  border: 1px solid var(--line);
  background: #3a271e;
  border-radius: 10px;
  cursor: pointer;
}

.swatches button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 0;
}

.swatches button.is-on, .tool-row button.is-on, .preset.is-on {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.ask { display: flex; flex-direction: column; gap: 8px; }

.ask input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #140e0b;
}

.tool-row, .text-actions { display: flex; gap: 8px; }

.tool-row { margin-bottom: 8px; }

.tool-row button, .text-actions button, .presets-head button {
  min-height: 44px;
  padding: 10px 12px;
}

.tool-row button { flex: 1; }

.slider, .check { display: flex; align-items: center; gap: 8px; margin: 8px 0; }

.slider input[type="range"] { flex: 1; height: 32px; accent-color: var(--gold); }

.check input { width: 22px; height: 22px; }

input, select { font-size: 16px; }

.slider span { width: 3.4em; text-align: right; color: var(--muted); }

.presets { padding: 0 0 48px; }

.presets-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.scene-nav { display: flex; flex-wrap: wrap; gap: 8px; }

.flip-box { margin-bottom: 16px; }

.flip-help { margin: 6px 0 12px; color: var(--muted); }

.flip-sets, .flip-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.flip-sets { margin-bottom: 10px; }

.flip-set, #play-flip, #clear-checks {
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #3a271e;
  cursor: pointer;
}

#play-flip, #save-drawing, #save-series { background: #1d3a24; border-color: var(--green); }

.save-row { display: flex; gap: 8px; margin-top: 10px; }

.save-row input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #140e0b;
}

.save-row button, .saved-series button {
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #3a271e;
  cursor: pointer;
}

.saved-series { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.saved-drop { min-height: 44px; }

.preset-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.preset-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 72px;
}

.flip-check {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
}

.preset {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 8px;
  text-align: left;
  flex: 1;
  min-width: 0;
  min-height: 64px;
}

.preset canvas {
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  image-rendering: pixelated;
  background: #000;
  border-radius: 8px;
}

.preset span { font-size: 16px; }

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "stage"
      "scenes"
      "tools";
  }
  h1 { font-size: 32px; }
  .top { flex-direction: column; align-items: start; }
  .top-side { align-items: flex-start; }
  .workspace {
    grid-template-areas:
      "scenes"
      "stage"
      "tools";
  }
  .preset-list { grid-template-columns: 1fr; }
  .grid { gap: 3px; padding: 8px; }
}

@media (max-width: 700px) {
  .top, .workspace, .now-playing { width: min(1080px, calc(100% - 20px)); }
  h1 { font-size: 28px; }
}

@media (min-width: 981px) and (max-height: 820px) {
  .preset-list { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
