:root {
  --bg: #F8F9FA;
  --surface: #FFFFFF;
  --border: #DADCE0;
  --border-soft: #E8EAED;
  --text: #202124;
  --text-2: #5F6368;
  --text-3: #80868B;
  --accent: #FF6D00;
  --accent-strong: #FF5722;
  --accent-soft: #FFF3E0;
  --accent-ring: rgba(255, 109, 0, 0.28);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, 0.12), 0 1px 3px 1px rgba(60, 64, 67, 0.08);
  --shadow-2: 0 2px 6px 2px rgba(60, 64, 67, 0.10), 0 1px 2px rgba(60, 64, 67, 0.16);
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --header-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h2 { margin: 0; letter-spacing: -0.02em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
.mono { font-family: var(--font-mono); }
svg { flex-shrink: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */

.topbar {
  flex: none;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 16px 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
}
.brand__mark { width: 24px; height: 24px; }
.brand__word { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; color: var(--text-2); }

.topbar__divider { width: 1px; height: 24px; background: var(--border); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #C43E00;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid rgba(255, 109, 0, 0.22);
}
.badge svg { width: 16px; height: 16px; color: var(--accent); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface);
  white-space: nowrap;
}
.status__dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.status__dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}
.is-paused .status__dot { background: var(--text-3); }
.is-paused .status__dot::after { animation: none; }

@keyframes ping {
  0% { transform: scale(0.6); opacity: 0.7; }
  80%, 100% { transform: scale(1.6); opacity: 0; }
}

.tabs { display: flex; gap: 2px; margin: 0 auto; height: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s;
}
.tab::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.2s ease;
}
.tab:hover, .tab.is-active { color: var(--accent); }
.tab.is-active::after { transform: scaleX(1); }

.topbar__actions { display: flex; align-items: center; gap: 4px; }
.topbar__actions .segmented { margin-right: 6px; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-strong); box-shadow: 0 2px 8px var(--accent-ring); }
.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn--ghost:hover { color: var(--accent); border-color: rgba(255, 109, 0, 0.45); background: var(--accent-soft); }
.btn--ghost[aria-pressed='true'] { color: #C43E00; border-color: rgba(255, 109, 0, 0.45); background: var(--accent-soft); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn svg { width: 16px; height: 16px; transition: transform 0.2s; }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn--lg { width: 36px; height: 36px; border-radius: 50%; }
.icon-btn--lg svg { width: 18px; height: 18px; }
.icon-btn[aria-pressed='true'] { color: var(--accent); background: var(--accent-soft); }
#btn-pause .i-play, #btn-pause[aria-pressed='true'] .i-pause { display: none; }
#btn-pause[aria-pressed='true'] .i-play { display: block; }

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  transition: background 0.2s;
}
.switch span {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch[aria-checked='true'] { background: var(--accent); }
.switch[aria-checked='true'] span { transform: translateX(14px); }

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
}
.segmented button {
  height: 28px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.segmented button:hover { color: var(--accent); }
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

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

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #FBFBFC;
  overflow: hidden;
}
.stage--void { background: #0B0D12; }

#fluid {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* glass panels shared by HUD & dock */
.hud, .dock {
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
}
.hud { border-radius: 14px; }

.hud { top: 16px; right: 16px; width: 288px; max-height: calc(100% - 32px); overflow: auto; }
.hud__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 10px 14px;
}
.hud__title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}
.hud__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.hud__head-actions { display: flex; gap: 2px; }
.hud__body { padding: 4px 14px 14px; border-top: 1px solid var(--border-soft); }
.hud.is-collapsed .hud__body { display: none; }
.hud.is-collapsed #hud-toggle svg { transform: rotate(-90deg); }

.hud__sliders { display: grid; gap: 14px; padding-top: 12px; }
.hud__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
  color: var(--text-2);
}

.control { display: grid; gap: 6px; cursor: pointer; }
.control__head { display: flex; justify-content: space-between; align-items: baseline; }
.control__label { font-size: 13px; font-weight: 500; color: var(--text); }
.control__value { font-size: 11px; color: var(--text-2); }
.control:hover .control__value { color: var(--accent); }

input[type='range'] {
  --p: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--border) var(--p));
}
input[type='range']::-moz-range-track { height: 4px; border-radius: 4px; background: var(--border); }
input[type='range']::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: box-shadow 0.15s;
}
input[type='range']::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
input[type='range']:hover::-webkit-slider-thumb,
input[type='range']:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 6px var(--accent-ring); }
input[type='range']:hover::-moz-range-thumb { box-shadow: 0 0 0 6px var(--accent-ring); }
input[type='range']:focus-visible { outline: none; }

.control.is-locked { cursor: default; }
.control.is-locked .control__value { color: var(--accent); }
input[type='range']:disabled { opacity: 0.4; cursor: default; }

/* colour dock */
.dock {
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  border-radius: 999px;
  max-width: calc(100% - 24px);
  white-space: nowrap;
}
.dock__sep { width: 1px; height: 24px; background: var(--border); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}

.palettes, .swatches { display: flex; gap: 6px; }
.palette {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.palette__swatch { width: 22px; height: 22px; border-radius: 50%; background: var(--grad); }
.palette__name {
  position: absolute;
  width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}
.palette:hover { border-color: var(--accent); }
.palette.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.swatch:hover { transform: translateY(-2px); }
.swatch.is-active { box-shadow: 0 0 0 2px var(--accent); }

.picker {
  --c: #FF6D00;
  position: relative;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: conic-gradient(#FF1744, #FFEA00, #00E676, #00B0FF, #D500F9, #FF1744);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.picker:hover { transform: translateY(-2px); }
.picker__ring { width: 12px; height: 12px; border-radius: 3px; border: 2px solid #fff; background: var(--c); }
.picker.is-active { box-shadow: 0 0 0 2px var(--accent); }
.picker input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 88px;
  transform: translate(-50%, 8px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.stage__fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
  background: var(--bg);
}
.stage__fallback[hidden] { display: none; }
.stage__fallback p { max-width: 520px; color: var(--text-2); }
.stage__fallback .mono { font-size: 12px; color: var(--text-3); }

/* ---------- responsive ---------- */

@media (max-width: 1000px) {
  .status, .topbar__divider { display: none; }
}

@media (max-width: 760px) {
  :root { --header-h: 52px; }
  .topbar { padding: 0 8px 0 12px; gap: 8px; }
  .brand__word, .badge { display: none; }
  .tab { padding: 0 10px; font-size: 13px; }
  .topbar__actions .segmented { display: none; }
  .hud { top: 10px; right: 10px; width: min(288px, calc(100% - 20px)); }
  .dock {
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    transform: none;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    border-radius: 18px;
    max-width: none;
  }
  .dock__sep { display: none; }
  .toast { bottom: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  .status__dot::after { animation: none; }
}
