/* ============================================================================
   WebJam — visual design
   "lab instrument meets VJ booth": near-black canvas, hairline panels, a
   monospace data layer, and four signal colours that recur everywhere
   (lead = lime, bass = magenta, face = cyan, pose = orange).
   ========================================================================== */

:root {
  --bg: #08090c;
  --bg-soft: #0d0f14;
  --panel: #101218;
  --panel-2: #0b0d12;
  --line: #1d212b;
  --line-soft: #15181f;
  --text: #e7eaf1;
  --muted: #828b9e;
  --muted-2: #59617240;

  --lead: #b6ff3c;
  --bass: #ff4fd8;
  --face: #33e1ed;
  --pose: #ff9d3c;
  --accent: var(--lead);

  --font: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --r: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 800px at 80% -10%, #12161f 0%, transparent 55%),
    radial-gradient(900px 700px at -10% 110%, #14101a 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; min-height: 0; }

/* ---- top bar ------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0c0e13 0%, #090a0e 100%);
}
.brand { display: flex; align-items: baseline; gap: 14px; }
.logo, .start-logo {
  font-weight: 700; letter-spacing: 1.5px; font-size: 20px;
}
.logo-accent { color: var(--accent); text-shadow: 0 0 18px color-mix(in srgb, var(--accent) 55%, transparent); }
.tagline { color: var(--muted); font-size: 12.5px; letter-spacing: .2px; }
@media (max-width: 640px) { .tagline { display: none; } }

.status {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 100px; padding: 5px 12px;
  background: var(--panel-2); text-transform: lowercase; white-space: nowrap;
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 0 transparent; }
.status[data-state="loading"] .dot { background: var(--pose); animation: pulse 1s infinite; }
.status[data-state="live"]    .dot { background: var(--lead); box-shadow: 0 0 10px var(--lead); }
.status[data-state="error"]   .dot { background: var(--bass); box-shadow: 0 0 10px var(--bass); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* ---- layout -------------------------------------------------------------- */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px; padding: 14px;
}
.stage { display: flex; flex-direction: column; gap: 14px; min-height: 0; min-width: 0; }

.viewport {
  position: relative; flex: 1 1 58%; min-height: 0;
  border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
  background: #05060a;
}
.scene {
  position: relative; flex: 1 1 42%; min-height: 170px;
  border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
  background: #05060a;
}
#overlay, .scene canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }

.scene-label {
  position: absolute; left: 10px; bottom: 9px; z-index: 2;
  font-family: var(--mono); font-size: 10.5px; color: var(--muted);
  letter-spacing: .3px; pointer-events: none;
  background: #06070bcc; padding: 3px 7px; border-radius: 6px; border: 1px solid var(--line-soft);
}

/* ---- heads-up display ---------------------------------------------------- */
.hud {
  position: absolute; left: 10px; top: 10px; z-index: 2;
  display: flex; flex-direction: column; gap: 4px;
  font-family: var(--mono); font-size: 11.5px;
  background: #06070bcc; backdrop-filter: blur(4px);
  border: 1px solid var(--line-soft); border-radius: 8px; padding: 8px 10px;
  pointer-events: none; min-width: 132px;
}
.hud-row { display: flex; justify-content: space-between; gap: 14px; }
.hud .k { color: var(--muted); letter-spacing: .5px; }
.hud .v { color: var(--text); font-weight: 500; }
.k-lead { color: var(--lead) !important; }
.k-bass { color: var(--bass) !important; }
.k-face { color: var(--face) !important; }
.hud .k-pose { color: var(--pose) !important; }

/* ---- control panel ------------------------------------------------------- */
.panel {
  border: 1px solid var(--line); border-radius: var(--r);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  padding: 6px 0; overflow-y: auto; min-height: 0;
  scrollbar-width: thin; scrollbar-color: #2a2f3a transparent;
}
.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb { background: #232834; border-radius: 8px; }

.group { border-top: 1px solid var(--line-soft); }
.group:first-child { border-top: 0; }
.group > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px;
  padding: 11px 16px; font-size: 12px; font-weight: 600;
  letter-spacing: .6px; text-transform: uppercase; color: var(--muted);
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent); flex: none;
}
.group[data-accent="bass"] > summary::before { background: var(--bass); box-shadow: 0 0 8px var(--bass); }
.group[data-accent="face"] > summary::before { background: var(--face); box-shadow: 0 0 8px var(--face); }
.group[data-accent="pose"] > summary::before { background: var(--pose); box-shadow: 0 0 8px var(--pose); }
.group[data-accent="sys"]  > summary::before { background: var(--muted); box-shadow: none; }
.group > summary .chev { margin-left: auto; transition: transform .15s ease; color: var(--muted); }
.group[open] > summary .chev { transform: rotate(90deg); }
.group-body { padding: 4px 16px 14px; display: flex; flex-direction: column; gap: 12px; }

.row { display: flex; flex-direction: column; gap: 6px; }
.row label { font-size: 11.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.row label .val { font-family: var(--mono); color: var(--text); }

select, input[type="number"], textarea, button.btn {
  font-family: var(--font); font-size: 13px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; width: 100%; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
textarea { font-family: var(--mono); font-size: 12px; line-height: 1.5; resize: vertical; min-height: 120px; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* range sliders */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px; background: #232834; outline: none; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid #0a0b0e;
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
}
input[type="range"]::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid #0a0b0e; }

/* toggles */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; font-size: 12.5px; color: var(--text); }
.toggle input { display: none; }
.switch { width: 38px; height: 21px; border-radius: 100px; background: #232834; position: relative; transition: background .15s; flex: none; border: 1px solid var(--line); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.toggle input:checked + .switch { background: color-mix(in srgb, var(--accent) 30%, #232834); }
.toggle input:checked + .switch::after { transform: translateX(17px); background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.toggle[data-accent="bass"] input:checked + .switch::after { background: var(--bass); box-shadow: 0 0 8px var(--bass); }
.toggle[data-accent="bass"] input:checked + .switch { background: color-mix(in srgb, var(--bass) 30%, #232834); }
.toggle[data-accent="pose"] input:checked + .switch::after { background: var(--pose); box-shadow: 0 0 8px var(--pose); }
.toggle[data-accent="pose"] input:checked + .switch { background: color-mix(in srgb, var(--pose) 30%, #232834); }

button.btn { cursor: pointer; font-weight: 600; transition: border-color .15s, background .15s; }
button.btn:hover { border-color: var(--accent); }
button.btn.primary { background: color-mix(in srgb, var(--accent) 16%, var(--panel-2)); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }

.hint { font-size: 11px; color: var(--muted); line-height: 1.5; }
.hint code, .start-note code { font-family: var(--mono); color: var(--text); background: #ffffff10; padding: 1px 5px; border-radius: 5px; }
.msg { font-family: var(--mono); font-size: 11px; min-height: 14px; }
.msg.ok { color: var(--lead); }
.msg.err { color: var(--bass); }

/* off-screen webcam source */
#webcam { position: fixed; width: 2px; height: 2px; opacity: 0; pointer-events: none; top: -10px; left: -10px; }

/* ---- start overlay ------------------------------------------------------- */
#start-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 600px at 50% 30%, #14171f 0%, #06070a 70%);
}
#start-overlay.hidden { display: none; }
.start-card {
  max-width: 520px; width: 100%; text-align: center;
  border: 1px solid var(--line); border-radius: 16px; padding: 36px 32px;
  background: linear-gradient(180deg, #0e1117 0%, #0a0c11 100%);
  box-shadow: 0 30px 80px #000a, 0 0 0 1px #ffffff06 inset;
}
.start-logo { font-size: 34px; letter-spacing: 2px; margin-bottom: 14px; }
.start-lede { color: var(--text); font-size: 15px; line-height: 1.6; margin: 0 auto 20px; max-width: 42ch; }
.start-points { list-style: none; padding: 0; margin: 0 auto 26px; max-width: 40ch; text-align: left; display: flex; flex-direction: column; gap: 9px; }
.start-points li { font-size: 13px; color: var(--muted); line-height: 1.5; padding-left: 16px; position: relative; }
.start-points li::before { content: "›"; position: absolute; left: 0; color: var(--accent); }
.start-points b { color: var(--text); }
.start-btn {
  font-family: var(--font); font-size: 16px; font-weight: 600; color: #07090c;
  background: var(--accent); border: 0; border-radius: 100px; padding: 14px 30px; cursor: pointer;
  box-shadow: 0 0 30px color-mix(in srgb, var(--accent) 45%, transparent); transition: transform .12s, box-shadow .2s;
}
.start-btn:hover { transform: translateY(-1px); box-shadow: 0 0 44px color-mix(in srgb, var(--accent) 65%, transparent); }
.start-btn:disabled { opacity: .6; cursor: progress; }
.start-note { color: var(--muted); font-size: 11.5px; line-height: 1.6; margin: 22px auto 0; max-width: 42ch; }
.start-error { color: var(--bass); font-family: var(--mono); font-size: 12px; margin-top: 16px; line-height: 1.5; }

.k-lead { color: var(--lead); } .k-bass { color: var(--bass); } .k-face { color: var(--face); }

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  .layout { grid-template-columns: 1fr; }
  .viewport { height: 56vh; flex: none; }
  .scene { height: 40vh; flex: none; }
  .panel { max-height: none; overflow: visible; }
}
