/* Wavefield — obsidian glass, chrome hairlines, one accent. */

:root {
  --bg:        #07080a;
  --glass:     rgba(22, 25, 29, 0.72);
  --glass-hi:  rgba(255, 255, 255, 0.045);
  --hair:      rgba(255, 255, 255, 0.10);
  --hair-soft: rgba(255, 255, 255, 0.055);
  --ink:       #e8ecf0;
  --ink-dim:   #8b939c;
  --ink-faint: #5a6169;
  --accent:    #7fd4e8;
  --danger:    #d8756a;
  --panel-w:   332px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Roboto', 'Inter', system-ui, sans-serif;
  font-weight: 300;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100%;
}

/* ---------------------------------------------------------------- stage */

#stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 38%, #12151a 0%, #07080a 70%);
}

#frame {
  flex: 0 0 auto;
  position: relative;
  margin: auto;
  border-radius: 3px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px var(--hair),
    0 24px 60px -20px rgba(0, 0, 0, 0.9);
}

#frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#overlay { cursor: crosshair; }
#overlay.grabbing { cursor: grabbing; }
#overlay.grab { cursor: grab; }

#statusbar {
  flex: 0 0 auto;
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 0 26px 14px;
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#statusbar > span { white-space: nowrap; }
#statusbar .spacer { flex: 1; }
#st-hint {
  text-transform: none;
  letter-spacing: 0.02em;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ---------------------------------------------------------------- panel */

#panel {
  flex: 0 0 var(--panel-w);
  width: var(--panel-w);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--glass);
  backdrop-filter: blur(14px);
  border-left: 1px solid var(--hair);
  padding-bottom: 24px;
}

#panel::-webkit-scrollbar { width: 9px; }
#panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.10);
  border-radius: 9px;
  border: 3px solid transparent;
  background-clip: content-box;
}

#brand { padding: 24px 20px 18px; border-bottom: 1px solid var(--hair-soft); }

#brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 300;
  letter-spacing: 0.42em;
  background: linear-gradient(100deg, #ffffff 0%, #9aa3ac 45%, #ffffff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#brand p {
  margin: 5px 0 0;
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

.block { padding: 16px 20px; border-bottom: 1px solid var(--hair-soft); }
/* !important because this is a utility class and every other rule in the file
   is more specific than it is. `#vary-modal` sets `display: flex` to centre its
   panel, an id beats a class, and the modal silently stopped hiding — it sat
   over the whole app on load with an empty grid, because the contents are only
   built when it is genuinely opened. A class whose one job is to hide things
   must not be outrankable by whatever happens to style the thing it is hiding. */
.hidden { display: none !important; }

.block h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  user-select: none;
  transition: color 0.12s;
}

.block h2:hover { color: var(--ink-dim); }

/* A chevron drawn from two borders — down when open, right when folded. */
.block[data-fold] h2::before {
  content: '';
  flex: 0 0 auto;
  width: 4px;
  height: 4px;
  margin-bottom: 2px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.block.collapsed h2::before { transform: rotate(-45deg); }
.block.collapsed h2 { margin-bottom: 0; }
.block.collapsed > *:not(h2) { display: none; }

/* ---------------------------------------------------------------- layers */

#layers { list-style: none; margin: 12px 0 0; padding: 0; }

#layers li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
  color: var(--ink-dim);
  transition: background 0.12s, color 0.12s;
}

#layers li:hover { background: var(--glass-hi); color: var(--ink); }

#layers li.selected {
  background: rgba(127, 212, 232, 0.09);
  border-color: rgba(127, 212, 232, 0.30);
  color: var(--ink);
}

#layers li.off { opacity: 0.38; }

#layers .glyph {
  flex: 0 0 16px;
  height: 16px;
  opacity: 0.85;
}

#layers .name { flex: 1; font-size: 12px; letter-spacing: 0.03em; }
#layers .meta { font-size: 10px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

#layers .eye {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  opacity: 0.5;
}
#layers .eye:hover { opacity: 1; }

/* ---------------------------------------------------------------- rows */

.row { margin-bottom: 11px; }
.row:last-child { margin-bottom: 0; }

.row.buttons { display: flex; gap: 7px; margin-top: 12px; }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.preset {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--hair-soft);
  border-radius: 2px;
  overflow: hidden;
  background: #000;
  cursor: pointer;
  transition: border-color 0.12s;
}

.preset canvas { width: 100%; height: 100%; display: block; }
.preset:hover { border-color: rgba(255, 255, 255, 0.45); }

.preset.current {
  border-color: rgba(127, 212, 232, 0.7);
  box-shadow: 0 0 0 1px rgba(127, 212, 232, 0.28);
}

.preset .tag {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 8px 5px 3px;
  font-size: 9px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.88) 55%);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset.current .tag { color: var(--accent); }

/* --------------------------------------------------------------- swatches */

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.swatch {
  height: 20px;
  padding: 0;
  border: 1px solid var(--hair);
  border-radius: 2px;
  overflow: hidden;
  background: none;
  cursor: pointer;
  transition: border-color 0.12s;
}

.swatch canvas { width: 100%; height: 100%; display: block; }
.swatch:hover { border-color: rgba(255, 255, 255, 0.45); }

.swatch.on {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(127, 212, 232, 0.32);
}

.ctl-head output { text-transform: capitalize; }

.ctl-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
}

.ctl-head label {
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
}

.ctl-head output {
  font-size: 11px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  background: none;
  cursor: ew-resize;
  display: block;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: linear-gradient(90deg, var(--hair) 0%, rgba(255,255,255,0.22) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 9px;
  height: 9px;
  margin-top: -4px;
  border-radius: 50%;
  background: linear-gradient(160deg, #ffffff, #8d959d);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 0 8px rgba(127, 212, 232, 0.35);
}

input[type="range"]::-moz-range-track { height: 1px; background: var(--hair); }
input[type="range"]::-moz-range-thumb {
  width: 9px; height: 9px; border: 0; border-radius: 50%;
  background: linear-gradient(160deg, #ffffff, #8d959d);
}

select {
  width: 100%;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  border: 1px solid var(--hair);
  border-radius: 2px;
  font-family: inherit;
  font-weight: 300;
  font-size: 12px;
  outline: none;
}
select:focus { border-color: rgba(127, 212, 232, 0.5); }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.05em;
  user-select: none;
}
.check input { accent-color: var(--accent); }

/* ---------------------------------------------------------------- buttons */

.btn {
  flex: 1;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  border: 1px solid var(--hair);
  border-radius: 2px;
  font-family: inherit;
  font-weight: 300;
  font-size: 11px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover { background: rgba(255, 255, 255, 0.10); border-color: rgba(255, 255, 255, 0.2); }
.btn:active { background: rgba(255, 255, 255, 0.03); }
.btn.ghost { background: none; color: var(--ink-dim); }
.btn.ghost:hover { color: var(--ink); }
.btn.danger:hover { color: var(--danger); border-color: rgba(216, 117, 106, 0.45); }

.btn.accent {
  border-color: rgba(127, 212, 232, 0.42);
  color: var(--accent);
  background: rgba(127, 212, 232, 0.10);
}
.btn.accent:hover { background: rgba(127, 212, 232, 0.18); }

/* --------------------------------------------------------------- variations */

#vary-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  /* No backdrop-filter. This machine has no hardware GL, so a blur over the
     full viewport is a software pass that recomposites every time any of the
     nine tiles under it finishes painting — precisely while the grid is trying
     to fill smoothly. At 88% black there was almost nothing to see through it
     anyway, so the blur was costing the one moment it was visible in. */
  background: rgba(4, 5, 7, 0.88);
}

#vary-panel {
  /* The grid below is nine squares three across, so its height is its own
     width: widening the panel makes it taller. Bounding by width alone put a
     scrollbar down the grid on anything less than a very tall screen and cut
     the bottom row in half — you were choosing between nine things while
     looking at seven. The last term is the height budget: everything above the
     grid, plus its padding, taken out of the panel's own cap. */
  width: min(88vw, 860px, calc(92vh - 190px));
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: rgba(18, 20, 24, 0.96);
  border: 1px solid var(--hair);
  border-radius: 4px;
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.95);
}

#vary-panel header {
  position: relative;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--hair-soft);
}

#vary-panel header h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

#vary-panel header p {
  margin: 6px 44px 0 0;               /* clears the close button */
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-faint);
}

#vary-panel header p .keys { white-space: nowrap; margin-left: 4px; }

#vary-panel header p kbd {
  font: inherit;
  color: var(--ink-dim);
  border: 1px solid var(--hair);
  border-radius: 2px;
  padding: 0 4px;
  margin: 0 1px;
}

#vary-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 26px;
  height: 26px;
  border: 0;
  background: none;
  color: var(--ink-faint);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}
#vary-close:hover { color: var(--ink); }

#vary-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--hair-soft);
}

#vary-locks { display: flex; gap: 6px; }

.lock {
  padding: 5px 11px;
  border: 1px solid var(--hair);
  border-radius: 2px;
  background: none;
  color: var(--ink-faint);
  font-family: inherit;
  font-weight: 300;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.lock:hover { color: var(--ink); }
.lock.on {
  border-color: rgba(127, 212, 232, 0.45);
  color: var(--accent);
  background: rgba(127, 212, 232, 0.10);
}

#vary-strength { flex: 1; min-width: 120px; }
#vary-strength .row { margin: 0; }
#vary-bar .btn { flex: 0 0 auto; padding: 6px 16px; }

#vary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px;
  overflow-y: auto;
}

.vary-tile {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--hair-soft);
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
  background: #000;
  padding: 0;
}

.vary-tile canvas {
  width: 100%;
  height: 100%;
  display: block;
  /* Fades in as each tile lands, and again as the coarse pass is replaced by
     the supersampled one, so the grid resolves instead of snapping. */
  opacity: 1;
  transition: opacity 0.22s ease-out;
}

/* An unrendered tile and a legitimately near-black variation looked identical.
   Now an empty slot is visibly an empty slot. */
.vary-tile.pending { border-color: rgba(255, 255, 255, 0.05); }
.vary-tile.pending canvas { opacity: 0; }

.vary-tile:hover { border-color: rgba(255, 255, 255, 0.42); }

.vary-tile:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.vary-tile.parent {
  border-color: rgba(127, 212, 232, 0.55);
  cursor: default;
}

.vary-tile .tag {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 4px 7px;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
  text-align: left;
  pointer-events: none;
}

.vary-tile.parent .tag { color: var(--accent); }

/* ---------------------------------------------------------------- recording */

.rec-bar {
  margin-top: 10px;
  height: 2px;
  background: rgba(255, 255, 255, 0.09);
  border-radius: 2px;
  overflow: hidden;
}

.rec-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, rgba(127, 212, 232, 0.5), var(--accent));
  transition: width 0.12s linear;
}

.btn.recording {
  border-color: rgba(216, 117, 106, 0.55);
  color: var(--danger);
  background: rgba(216, 117, 106, 0.12);
}

/* ---------------------------------------------------------------- ramp preview */

#ramp-strip {
  width: 100%;
  height: 12px;
  border-radius: 2px;
  border: 1px solid var(--hair);
  display: block;
}

/* ---------------------------------------------------------------- footer */

#keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 16px 20px 0;
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

kbd {
  font-family: inherit;
  border: 1px solid var(--hair);
  border-radius: 2px;
  padding: 1px 5px;
  margin-right: 3px;
  color: var(--ink-dim);
}
