:root {
  --bg: #05070d;
  --panel: rgba(10, 14, 28, 0.78);
  --border: rgba(120, 180, 255, 0.18);
  --text: #d8e6ff;
  --accent: #6fb4ff;
  --muted: #8aa0c6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

#gl {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  /* dvh follows the mobile browser's collapsing toolbar; resize() sizes the
     drawing buffer from window.innerHeight, so with plain vh the canvas would
     be stretched by the toolbar's height on a phone. */
  height: 100dvh;
  display: block;
  cursor: grab;
  /* the canvas handles drag and pinch itself: keep the browser from
     scrolling / page-zooming on touch */
  touch-action: none;
}
#gl:active { cursor: grabbing; }

#notice {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  z-index: 20;
}
#notice.fatal {
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  border-color: rgba(255, 140, 120, 0.45);
}
#notice pre {
  margin: 8px 0 0;
  max-height: 40vh;
  overflow: auto;
  white-space: pre-wrap;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  color: #ffb9a8;
}
#notice code { color: var(--accent); }

#panel {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 260px;
  max-height: calc(100vh - 32px);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 10;
}
#panel.collapsed #controls { display: none; }
#panel.collapsed { width: auto; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
header h1 {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0;
  color: var(--accent);
  font-weight: 600;
}
#panel.collapsed header { margin-bottom: 0; }
#panel.collapsed header h1 { display: none; }

button, select {
  background: rgba(30, 50, 90, 0.55);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
button:hover, select:hover { background: rgba(60, 100, 170, 0.55); }

#controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

/* One control: the head line (name, readout, padlock) over the input. */
.ctl {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.head {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* The readout is the accent-coloured monospace half of the head line — and it
   is contenteditable, so it needs to look typeable once you are in it. */
[data-out] {
  color: var(--accent);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  cursor: text;
  border-radius: 3px;
  padding: 0 2px;
}
[data-out]:hover  { background: rgba(120, 180, 255, 0.12); }
[data-out]:focus  { outline: 1px solid var(--accent); background: rgba(120, 180, 255, 0.14); }

/* The padlock keeps a control out of Random and Varia. Off it is nearly
   invisible: it must not compete with the value for attention. */
.lock {
  flex: 0 0 auto;
  padding: 0 2px;
  border: 0;
  background: none;
  font-size: 10px;
  line-height: 1;
  opacity: 0.28;
  filter: grayscale(1);
}
.lock:hover { background: none; opacity: 0.7; }
.ctl.locked .lock { opacity: 1; filter: none; }
.ctl.locked .name { color: var(--accent); }

/* A mode that never reads a uniform gets its slider dimmed and disabled rather
   than removed: the panel keeps the same shape (nothing jumps when the mode
   changes) and the value keeps living in the permalink — it just stops
   pretending the knob does something. */
.ctl.inert { opacity: 0.4; }
.ctl.inert input[type="range"] {
  filter: grayscale(1);
  cursor: not-allowed;
}
.ctl.inert input[type="range"]::-webkit-slider-thumb { background: #7f8aa0; box-shadow: none; }
.ctl.inert input[type="range"]::-moz-range-thumb     { background: #7f8aa0; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, #1a3a70, #4a90e2);
  outline: none;
}

/* The band each mode is tuned for, painted on the track. It suggests without
   forbidding: min and max stay put, because narrowing them per mode would clamp
   the values of a permalink arriving from another mode. The two stops are set
   by tuning.js, which knows the (possibly exponential) scale of the track. */
input[type="range"].zoned {
  background-image:
    linear-gradient(90deg,
      transparent 0 var(--zone-a),
      rgba(255, 210, 122, 0.30) var(--zone-a) var(--zone-b),
      transparent var(--zone-b) 100%),
    linear-gradient(90deg, #1a3a70, #4a90e2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffd27a;
  border: 2px solid #0a1428;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(255, 210, 122, 0.6);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffd27a;
  border: 2px solid #0a1428;
  cursor: pointer;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.row button {
  flex: 1 1 auto;
  min-width: 54px;
  padding: 6px 6px;
}
/* History and A/B: gestures you repeat while comparing two views, so they get
   their own narrower row instead of competing with Random and PNG. */
.row.mini { margin-top: 0; }
.row.mini button {
  min-width: 0;
  padding: 4px 6px;
  font-size: 13px;
  line-height: 1.1;
}
.row.mini button:disabled { opacity: 0.35; cursor: default; }
.row.mini button:disabled:hover { background: rgba(30, 50, 90, 0.55); }
#ab.armed { border-color: rgba(255, 210, 122, 0.6); color: #ffd27a; }

.hint {
  font-size: 10px;
  color: var(--muted);
  margin: 6px 0 0;
  line-height: 1.5;
  opacity: 0.8;
}

select {
  width: 100%;
}

/* Two selects that belong to one control: size and sampling of the export. */
.pair {
  display: flex;
  gap: 6px;
}
.pair select:first-child { flex: 1 1 auto; min-width: 0; }
.pair select:last-child  { flex: 0 0 auto; width: auto; }

/* ---- Narrow screens ----------------------------------------------------
   The 260px panel pinned to the top right eats a phone's whole viewport, so
   below this breakpoint it becomes a bottom sheet: full width, capped height,
   sliders in two columns. main.js starts it collapsed at the same width — the
   breakpoint is written in both files, change one and you must change the
   other. Collapsed it drops `left`, so the ☰ shrinks back to a button in the
   bottom-right corner, where a thumb can reach it. */
@media (max-width: 620px) {
  #panel {
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
    width: auto;
    max-height: min(68vh, calc(100vh - 24px));
    border-radius: 16px;
  }
  #panel.collapsed { left: auto; }

  /* clear of the collapsed panel's button, which is now bottom-right */
  #notice { bottom: 76px; }
  #notice.fatal { bottom: auto; }

  #controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px 12px;
  }
  /* The selects hold long option text and the button rows need their width:
     everything except the sliders spans the pair of columns. */
  #controls > .ctl.wide,
  #controls > .row,
  #controls > .hint { grid-column: 1 / -1; }
}

/* ---- Touch ----
   A 4px track with a 14px thumb is a mouse target. Widen both where the
   pointer is a finger, whatever the screen width. */
@media (pointer: coarse) {
  input[type="range"] { height: 6px; border-radius: 3px; }
  input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; }
  input[type="range"]::-moz-range-thumb     { width: 22px; height: 22px; }
  button, select { padding: 9px 12px; }
  #toggle { min-width: 40px; min-height: 40px; }
  /* The padlock is a 10px glyph on a mouse: a finger needs something to hit. */
  .lock { padding: 4px 6px; font-size: 13px; }
}
