:root {
  --bg: #14161a;
  --panel: #1c1f26;
  --panel2: #23272f;
  --ink: #e7e9ee;
  --dim: #9aa0ab;
  --accent: #6ea8ff;
  --line: #333844;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}
#app { display: flex; height: 100vh; }

/* ---- panel ---- */
#panel {
  width: 300px;
  flex: 0 0 300px;
  height: 100%;
  overflow-y: auto;
  padding: 18px 16px 40px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
#panel h1 { margin: 0 0 2px; font-size: 20px; letter-spacing: .3px; }
#panel .sub { margin: 0 0 14px; color: var(--dim); font-size: 12.5px; }
#panel section { margin: 0 0 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
#panel section.actions { border: 0; }

/* On wide displays, flow the option groups into two columns so the whole
   panel fits without scrolling. Each section stays intact within a column. */
@media (min-width: 1500px) {
  #panel { width: 600px; flex-basis: 600px; }
  #controls { columns: 2; column-gap: 22px; }
  #controls > section { break-inside: avoid; }
  #controls > section:first-child { margin-top: 0; }
  #controls .chips { max-height: none; }
}
#panel h2 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--dim); font-weight: 700;
}
label { display: block; margin: 5px 0; cursor: pointer; }
label.stack { display: flex; flex-direction: column; gap: 5px; }
label.radio { font-size: 13px; }
input[type=text], select {
  width: 100%; padding: 6px 8px; color: var(--ink);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); margin-right: 6px; }
output { color: var(--accent); font-variant-numeric: tabular-nums; }
.hint { margin: 6px 0 0; font-size: 11.5px; color: var(--dim); }
code { background: var(--panel2); padding: 1px 4px; border-radius: 4px; font-size: 11.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; max-height: 168px; overflow-y: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 7px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel2); font-size: 11.5px; cursor: pointer; user-select: none;
}
.chip input { margin: 0; }
.chip .swatch { width: 11px; height: 11px; border-radius: 50%; border: 1px solid #0006; }
.chip.off { opacity: .4; }

input[type=file] { width: 100%; font-size: 12px; color: var(--dim); }
input[type=file]::file-selector-button {
  color: var(--ink); background: var(--panel2); cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; margin-right: 8px;
}
.actions { display: flex; gap: 8px; }
button {
  flex: 1; padding: 8px 10px; color: var(--ink); cursor: pointer;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 7px;
  font-size: 13px;
}
button:hover { border-color: var(--accent); }
button.active { background: var(--accent); color: #0b1017; border-color: var(--accent); }

.status { margin-top: 12px; font-size: 11.5px; color: var(--dim); min-height: 1em; }

/* ---- stage ---- */
#stage { position: relative; flex: 1 1 auto; height: 100%; }
#gl { display: block; width: 100%; height: 100%; }
.error {
  position: absolute; inset: 20px; padding: 20px; overflow: auto;
  background: #2a1414; color: #ffd7d7; border: 1px solid #703; border-radius: 10px;
  font: 13px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap;
}
.hidden { display: none; }

/* ---- mobile drawer toggle (hidden on desktop) ---- */
#panel-toggle {
  display: none;
  position: fixed; top: 10px; left: 10px; z-index: 30;
  width: 44px; height: 44px; padding: 0; flex: none;
  font-size: 20px; line-height: 1; text-align: center;
  background: var(--panel2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 2px 8px #0007;
}
#panel-backdrop { display: none; }

/* ---- phones / narrow screens: panel becomes a slide-in drawer ---- */
@media (max-width: 760px) {
  #app { height: 100vh; height: 100dvh; }

  /* The toggle is a thin, always-visible sliver down the left edge. Tapping it
     slides the full control drawer out; when open it rides the drawer's right
     edge and shows an ✕. Collapsed by default so the stage owns the screen. */
  #panel-toggle {
    display: flex; align-items: center; justify-content: center;
    top: 0; left: 0; width: 26px; height: 100%;
    padding: 0; font-size: 17px;
    border: 0; border-right: 1px solid var(--line);
    border-radius: 0; box-shadow: 2px 0 10px #0007;
    transition: left .22s ease;
  }
  body.panel-open #panel-toggle {
    left: min(86vw, 340px);
    border-right: 0; border-left: 1px solid var(--line);
    box-shadow: -2px 0 10px #0007;
  }

  #panel {
    position: fixed; top: 0; left: 0; z-index: 25;
    width: min(86vw, 340px); flex-basis: auto;
    height: 100%; height: 100dvh;
    padding-top: 20px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 2px 0 18px #000a;
    -webkit-overflow-scrolling: touch;
  }
  body.panel-open #panel { transform: translateX(0); }

  #panel-backdrop {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: #0007; opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
  }
  body.panel-open #panel-backdrop { opacity: 1; pointer-events: auto; }

  /* stage fills the viewport; drawer floats above it */
  #stage { position: absolute; inset: 0; }

  /* comfortable touch targets */
  #panel section { padding-bottom: 16px; }
  label { margin: 8px 0; }
  input[type=range] { height: 26px; }
  button { padding: 11px 10px; }
  .chip { padding: 6px 10px; }
}
