:root {
  --bg-deep: #050814;
  --glass-bg: rgba(11, 18, 36, 0.72);
  --glass-border: rgba(148, 163, 184, 0.18);
  --glass-hover: rgba(30, 41, 59, 0.85);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-cyan: #38bdf8;
  --accent-purple: #a855f7;
  --accent-pink: #f43f5e;
  --accent-green: #34d399;
  --radius-lg: 16px;
  --radius-md: 11px;
  --shadow-glow: 0 12px 40px rgba(2, 6, 23, 0.65);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#stageCanvas {
  position: absolute;
  inset: 0;
  display: block;
  cursor: crosshair;
}

.hud-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-glow);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.app-shell.stage-mode .hud-panel {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
}

.exit-stage-btn {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 40;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.4);
  background: rgba(11, 18, 36, 0.78);
  color: var(--text-main);
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.exit-stage-btn:hover {
  background: rgba(56, 189, 248, 0.22);
}

/* Audio Unlock Banner */
.audio-banner {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 16px 11px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.92), rgba(30, 27, 75, 0.9));
  border: 1px solid rgba(56, 189, 248, 0.45);
  box-shadow: 0 10px 35px rgba(56, 189, 248, 0.22);
  cursor: pointer;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.audio-banner.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
}

.audio-banner-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 12px var(--accent-cyan);
  animation: pulseDot 1.6s infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.45; }
}

.audio-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.audio-banner-text strong {
  font-size: 13px;
  letter-spacing: 0.2px;
}

.audio-banner-text span {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Top Bar */
.top-bar {
  position: fixed;
  top: 12px;
  left: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-radius: var(--radius-lg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-size: 17px;
  background: linear-gradient(135deg, #38bdf8, #a855f7);
  color: #fff;
  box-shadow: 0 0 18px rgba(168, 85, 247, 0.45);
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.3px;
}

.brand-sub {
  font-size: 10.5px;
  color: var(--text-muted);
}

.live-stats {
  display: flex;
  gap: 6px;
  margin-left: 6px;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.stat-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
}

/* Preset Bar */
.preset-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.preset-bar::-webkit-scrollbar {
  display: none;
}

.preset-buttons {
  display: flex;
  gap: 5px;
}

.preset-chip {
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.55);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
}

.preset-chip:hover {
  border-color: rgba(56, 189, 248, 0.5);
  color: #fff;
}

.preset-chip.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.28), rgba(168, 85, 247, 0.28));
  border-color: rgba(56, 189, 248, 0.7);
  color: #fff;
}

/* Buttons */
.action-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn {
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 9px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  background: rgba(15, 23, 42, 0.65);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
}

.btn:hover {
  background: var(--glass-hover);
  border-color: rgba(148, 163, 184, 0.45);
}

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #8b5cf6);
  border-color: transparent;
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-accent {
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.28), rgba(168, 85, 247, 0.34));
  border-color: rgba(244, 63, 94, 0.5);
}

.btn-accent:hover {
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.42), rgba(168, 85, 247, 0.48));
}

.btn-icon {
  min-width: 34px;
  text-align: center;
}

.btn.recording {
  background: rgba(239, 68, 68, 0.3);
  border-color: #ef4444;
  color: #fecaca;
  animation: recPulse 1.2s infinite;
}

@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50% { box-shadow: 0 0 14px 2px rgba(239, 68, 68, 0.45); }
}

/* Left Tool Dock */
.tool-dock {
  position: fixed;
  top: 76px;
  left: 14px;
  z-index: 20;
  width: 148px;
  padding: 10px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.dock-section-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding-left: 3px;
}

.tool-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: #cbd5e1;
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
  transition: all 0.14s ease;
}

.tool-btn:hover {
  background: rgba(30, 41, 59, 0.65);
  color: #fff;
}

.tool-btn.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.24), rgba(168, 85, 247, 0.22));
  border-color: rgba(56, 189, 248, 0.62);
  color: #fff;
}

.tool-ico {
  width: 18px;
  text-align: center;
  font-size: 14px;
}

.tool-lbl {
  flex: 1;
}

.tool-btn kbd {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
}

.dock-divider {
  height: 1px;
  background: rgba(148, 163, 184, 0.14);
}

.inst-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inst-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #cbd5e1;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.inst-btn:hover {
  background: rgba(30, 41, 59, 0.65);
}

.inst-btn.active {
  background: rgba(30, 41, 59, 0.9);
  border-color: var(--inst-color, #38bdf8);
  color: #fff;
}

.inst-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--inst-color, #38bdf8);
  box-shadow: 0 0 8px var(--inst-color, #38bdf8);
}

.dock-quick-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mini-btn {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.55);
  color: #cbd5e1;
  font-size: 11.5px;
  cursor: pointer;
}

.mini-btn:hover {
  background: rgba(30, 41, 59, 0.85);
  color: #fff;
}

.mini-btn.danger:hover {
  border-color: rgba(244, 63, 94, 0.6);
  color: #fda4af;
}

/* Right-Bottom Control Rack */
.control-rack {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 20;
  width: 288px;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.rack-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 13px;
  font-size: 12.5px;
  font-weight: 600;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.mini-icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.6);
  color: #cbd5e1;
  cursor: pointer;
}

.rack-body {
  padding: 11px 13px 13px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rack-body.collapsed {
  display: none;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-row.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.field-label {
  font-size: 11px;
  color: var(--text-muted);
}

.field select {
  width: 100%;
  padding: 5px 7px;
  border-radius: 7px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(15, 23, 42, 0.88);
  color: #f8fafc;
  font-size: 11.5px;
  outline: none;
}

.slider-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
}

.slider-head strong {
  color: #e2e8f0;
  font-family: ui-monospace, monospace;
}

input[type="range"] {
  width: 100%;
  accent-color: #38bdf8;
  cursor: pointer;
}

.gravity-pills {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.pill-btn {
  padding: 5px 4px;
  border-radius: 7px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.6);
  color: #cbd5e1;
  font-size: 11px;
  cursor: pointer;
}

.pill-btn.active {
  background: rgba(56, 189, 248, 0.25);
  border-color: #38bdf8;
  color: #fff;
}

.volume-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.volume-row strong {
  font-size: 11px;
  font-family: ui-monospace, monospace;
  min-width: 34px;
  text-align: right;
}

/* Bottom Hint Bar */
.hint-bar {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 11.5px;
  color: #cbd5e1;
  pointer-events: none;
  white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(56, 189, 248, 0.55);
  color: #f8fafc;
  font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.hidden {
  display: none !important;
}

/* Gallery Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  width: min(560px, 100%);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: 18px;
  background: #0b1224;
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 16px;
}

.save-form {
  display: grid;
  grid-template-columns: 1.5fr 1fr auto;
  gap: 8px;
}

.save-form input {
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.9);
  color: #f8fafc;
  font-size: 12.5px;
  outline: none;
}

.save-form input:focus {
  border-color: var(--accent-cyan);
}

.gallery-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 48vh;
  padding-right: 4px;
}

.gallery-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.gallery-meta strong {
  display: block;
  font-size: 13px;
}

.gallery-meta span {
  font-size: 11px;
  color: var(--text-muted);
}

.gallery-actions {
  display: flex;
  gap: 6px;
}

.gallery-empty {
  text-align: center;
  padding: 28px 12px;
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  .live-stats, .hint-bar {
    display: none;
  }
  .brand-sub {
    display: none;
  }
  .save-form {
    grid-template-columns: 1fr;
  }
}
