/* Morphogen — studio chrome. Near-black stage, restrained warm/cool accents,
   a typographic UI that stays out of the artwork's way. */

:root {
  --bg: #07080c;
  --bg-elev: #0d0f16;
  --bg-elev-2: #141722;
  --line: #20242f;
  --line-soft: #181b24;
  --text: #e7e9ef;
  --text-dim: #9aa0b0;
  --text-faint: #626878;
  --accent: #52c5c9;
  --accent-warm: #e98f86;
  --accent-press: #2a2f3c;
  --danger: #ff5d5d;
  --radius: 9px;
  --radius-sm: 6px;
  --panel-w: 312px;
  --toolbar-h: 56px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  grid-template-rows: var(--toolbar-h) 1fr;
  grid-template-areas:
    "toolbar toolbar"
    "stage   panel";
  height: 100vh;
}

body.panel-collapsed {
  grid-template-columns: 1fr 0;
}
body.panel-collapsed .panel { transform: translateX(100%); opacity: 0; pointer-events: none; }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  background: linear-gradient(180deg, var(--bg-elev) 0%, #0a0c12 100%);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.toolbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.toolbar-right { display: flex; align-items: center; gap: 7px; }

.btn-systems {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 12px;
  font-weight: 600; font-size: 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
}
.btn-systems:hover { border-color: #2d3340; }
.logo-dot {
  width: 13px; height: 13px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--accent), #185f6e 70%);
  box-shadow: 0 0 12px rgba(82, 197, 201, 0.5);
}
.brand { letter-spacing: 0.2px; }
.chev { color: var(--text-faint); font-size: 11px; }

.system-meta { display: flex; flex-direction: column; min-width: 0; }
.system-name { font-size: 13px; font-weight: 600; color: var(--text); }
.system-blurb {
  font-size: 11.5px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 42ch;
}

.divider { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }

/* buttons */
.btn {
  appearance: none;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
  user-select: none;
}
.btn:hover { background: #1a1e29; }
.btn:active { transform: translateY(1px); background: var(--accent-press); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; font-size: 15px; line-height: 1;
}
#btn-record.recording {
  color: var(--danger); border-color: var(--danger);
  box-shadow: 0 0 0 1px rgba(255, 93, 93, 0.25);
  animation: pulse 1.3s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 14px rgba(255, 93, 93, 0.45); } }

/* seed field */
.seed-field {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 4px 3px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.seed-field label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.6px; }
.seed-field input {
  width: 124px;
  background: transparent; border: 0; outline: none;
  color: var(--text); font-family: var(--mono); font-size: 12.5px;
}
.seed-field .icon-btn { width: 26px; height: 26px; font-size: 13px; }

/* ------------------------------------------------------------------ stage */
.stage-wrap { grid-area: stage; position: relative; overflow: hidden; background: var(--bg); }
#stage { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.status-bar {
  position: absolute; left: 12px; bottom: 10px;
  display: flex; align-items: center; gap: 14px;
  font-size: 11.5px; color: var(--text-faint);
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.status-fps { font-family: var(--mono); color: var(--text-dim); }
.status-hint { opacity: 0.7; }

.toast {
  position: absolute; left: 50%; bottom: 26px; transform: translate(-50%, 12px);
  padding: 9px 16px; border-radius: 999px;
  background: rgba(20, 23, 34, 0.92); border: 1px solid var(--line);
  color: var(--text); font-size: 12.5px; backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity 200ms ease, transform 200ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------------ panel */
.panel {
  grid-area: panel;
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1), opacity 180ms ease;
  z-index: 10;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 14px; border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.7px; text-transform: uppercase; color: var(--text-dim); }
.panel-body { flex: 1; overflow-y: auto; padding: 6px 14px 16px; }
.panel-foot { padding: 10px 14px; border-top: 1px solid var(--line-soft); }
.kbd-legend { font-size: 10.5px; color: var(--text-faint); line-height: 1.7; }
kbd {
  font-family: var(--mono); font-size: 10px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; color: var(--text-dim);
}

/* param rows */
.param-row { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.param-row:last-child { border-bottom: 0; }
.param-label {
  display: block; font-size: 12px; color: var(--text-dim);
  margin-bottom: 7px; font-weight: 500;
}
.param-control { display: flex; align-items: center; gap: 10px; }
.param-value {
  min-width: 46px; text-align: right;
  font-family: var(--mono); font-size: 11.5px; color: var(--accent);
}
.param-hint { margin-top: 6px; font-size: 10.5px; color: var(--text-faint); line-height: 1.4; }

/* range input */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 3px; border-radius: 3px;
  background: var(--line); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-elev);
  box-shadow: 0 0 0 1px var(--accent); cursor: pointer;
  transition: transform 80ms ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.18); }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-elev); cursor: pointer;
}

/* toggle */
.param-toggle {
  min-width: 58px; padding: 6px 12px; font-size: 12px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 999px; color: var(--text-dim); cursor: pointer;
}
.param-toggle.on { color: var(--bg); background: var(--accent); border-color: var(--accent); font-weight: 600; }

/* select */
.param-select {
  flex: 1; padding: 7px 9px; font-family: inherit; font-size: 12.5px;
  color: var(--text); background: var(--bg-elev-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer;
}
.param-color {
  width: 44px; height: 28px; padding: 0; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--bg-elev-2); cursor: pointer;
}

/* ---------------------------------------------------------------- gallery */
.gallery-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 5, 9, 0.66); backdrop-filter: blur(7px);
  display: none; align-items: flex-start; justify-content: center;
  padding: 64px 20px; overflow-y: auto;
}
.gallery-overlay.open { display: flex; animation: fade 160ms ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.gallery-panel {
  width: min(960px, 100%);
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: 22px 24px 28px;
}
.gallery-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.gallery-header h2 { margin: 0; font-size: 18px; font-weight: 650; }
.gallery-close {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  color: var(--text-dim); cursor: pointer; font-size: 14px;
}
.gallery-close:hover { color: var(--text); }
.gallery-group { margin-top: 18px; }
.gallery-group h3 {
  margin: 0 0 10px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.8px; text-transform: uppercase; color: var(--text-faint);
}
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 11px; }
.gallery-card {
  display: flex; flex-direction: column; gap: 5px; text-align: left;
  padding: 14px; border-radius: 11px; cursor: pointer;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}
.gallery-card:hover { transform: translateY(-2px); border-color: #333a49; background: #181c27; }
.gallery-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.gallery-card-name { font-size: 14px; font-weight: 600; color: var(--text); }
.gallery-card-blurb { font-size: 11.5px; color: var(--text-dim); line-height: 1.45; }

/* scrollbars */
.panel-body::-webkit-scrollbar, .gallery-overlay::-webkit-scrollbar { width: 10px; }
.panel-body::-webkit-scrollbar-thumb, .gallery-overlay::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 6px; border: 3px solid var(--bg-elev);
}

/* responsive: collapse the panel into a bottom sheet on narrow screens */
@media (max-width: 760px) {
  body { grid-template-columns: 1fr; grid-template-rows: var(--toolbar-h) 1fr auto;
    grid-template-areas: "toolbar" "stage" "panel"; }
  .panel { max-height: 42vh; border-left: 0; border-top: 1px solid var(--line); }
  .system-blurb { display: none; }
}

/* Touch / coarse-pointer devices: drop keyboard-only chrome, grow tap targets
   to ~44px, make sliders thumb-friendly. Scoped so desktop is untouched. */
@media (hover: none) and (pointer: coarse) {
  .panel-foot { display: none; }            /* keyboard legend is useless on touch */
  .icon-btn { width: 40px; height: 40px; font-size: 16px; }
  .seed-field .icon-btn { width: 30px; height: 30px; }
  .param-row { padding: 13px 0; }
  input[type="range"] { height: 5px; }
  input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; }
  input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }
  .param-toggle { min-width: 64px; padding: 9px 15px; }
  .param-select { padding: 10px 11px; }
  .gallery-overlay { padding: 24px 12px; }
  .gallery-grid { grid-template-columns: 1fr 1fr; }
}
