:root {
  --bg-shell: #0a0c10;
  --panel-bg: rgba(16, 19, 26, 0.94);
  --panel-border: rgba(216, 166, 52, 0.18);
  --card-bg: rgba(255, 255, 255, 0.035);
  --card-hover: rgba(255, 255, 255, 0.07);
  --gold: #d8a634;
  --gold-bright: #f2c864;
  --gold-dim: rgba(216, 166, 52, 0.18);
  --silver: #d6dce4;
  --text-main: #f3f5f8;
  --text-muted: #9aa3b2;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

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

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

.app-shell {
  display: flex;
  flex-direction: row;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ====== STAGE AREA ====== */
.stage-area {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  background: radial-gradient(circle at 50% 45%, #171c26 0%, #090b0f 100%);
}

.viewport-frame {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.72),
    0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: width 0.25s ease, height 0.25s ease, background 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewport-frame.bg-bright {
  background:
    radial-gradient(circle at 50% 46%, rgba(255, 232, 178, 0.24) 0%, rgba(255, 232, 178, 0.0) 42%),
    radial-gradient(circle at 50% 48%, #f7f9fc 0%, #e1e6f0 56%, #c2cbd9 100%);
}

.viewport-frame.bg-pure_white {
  background: radial-gradient(circle at 50% 48%, #ffffff 0%, #f0f3f7 100%);
}

.viewport-frame.bg-dark {
  background: radial-gradient(circle at 50% 46%, #1e2430 0%, #0c0f15 62%, #06070a 100%);
}

.viewport-frame.bg-transparent {
  background-color: #1a1d24;
  background-image:
    linear-gradient(45deg, #252932 25%, transparent 25%),
    linear-gradient(-45deg, #252932 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #252932 75%),
    linear-gradient(-45deg, transparent 75%, #252932 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
}

#glCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ====== FLOATING HUD OVERLAYS ====== */
.hud-top-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(12, 14, 20, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 600;
  color: var(--silver);
  pointer-events: none;
  z-index: 10;
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold);
}

.transport-bar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 700px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(12, 14, 20, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 12;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.25);
}

.icon-btn.primary {
  background: linear-gradient(135deg, var(--gold) 0%, #b5831d 100%);
  color: #0f1116;
  border-color: var(--gold-bright);
  font-weight: 800;
}

.fullscreen-pill-btn {
  width: auto;
  padding: 0 10px;
  gap: 5px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
}

.scrubber-wrap {
  position: relative;
  flex: 1;
  height: 24px;
  display: flex;
  align-items: center;
  min-width: 60px;
}

.scrubber-wrap input[type="range"] {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
  cursor: pointer;
  position: relative;
  z-index: 2;
  touch-action: manipulation;
}

.scrubber-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid #12151c;
  box-shadow: 0 0 8px rgba(216, 166, 52, 0.7);
  cursor: pointer;
}

.scrubber-progress {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold) 0%, var(--gold-bright) 100%);
  pointer-events: none;
  width: 0%;
  z-index: 1;
}

.time-readout {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--silver);
  white-space: nowrap;
  flex-shrink: 0;
}

.time-sep {
  color: var(--text-muted);
  margin: 0 2px;
}

.floating-show-ui {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  right: 18px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(16, 19, 26, 0.9);
  border: 1px solid var(--panel-border);
  color: var(--gold-bright);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  z-index: 40;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* Clean view / fullscreen mode */
.app-shell.ui-hidden .control-panel {
  display: none;
}

.app-shell.ui-hidden .hud-top-badge,
.app-shell.ui-hidden .transport-bar {
  opacity: 0;
  pointer-events: none;
}

/* ====== CONTROL PANEL (RTL RIGHT SIDEBAR) ====== */
.control-panel {
  width: 375px;
  flex-shrink: 0;
  height: 100%;
  background: var(--panel-bg);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 20;
}

.panel-header {
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

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

.brand-titles {
  flex: 1;
  min-width: 0;
}

.reset-all-btn {
  flex-shrink: 0;
}

.brand-crest {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(216, 166, 52, 0.22), rgba(214, 220, 228, 0.08));
  border: 1px solid rgba(216, 166, 52, 0.45);
  color: var(--gold-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.panel-header h1 {
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: -0.2px;
  color: var(--text-main);
}

.panel-header p {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-scroll::-webkit-scrollbar {
  width: 6px;
}

.panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
}

.ctrl-section {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.section-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 13px;
  font-size: 13px;
  font-weight: 800;
  color: var(--gold-bright);
  background: rgba(216, 166, 52, 0.07);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease;
}

.section-summary::-webkit-details-marker {
  display: none;
}

.section-summary:hover {
  background: rgba(216, 166, 52, 0.13);
}

.summary-chevron {
  font-size: 12px;
  transition: transform 0.2s ease;
}

.ctrl-section:not([open]) .summary-chevron {
  transform: rotate(90deg);
}

.section-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ctrl-group {
  background: var(--card-bg);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
}

.ctrl-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--silver);
  margin-bottom: 8px;
}

.val-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gold-dim);
  color: var(--gold-bright);
  border: 1px solid rgba(216, 166, 52, 0.28);
}

.mini-action {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.mini-action:hover {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: var(--gold-bright);
}

.segmented {
  display: grid;
  gap: 6px;
}

.segmented.cols-2 { grid-template-columns: repeat(2, 1fr); }
.segmented.cols-3 { grid-template-columns: repeat(3, 1fr); }
.segmented.cols-4 { grid-template-columns: repeat(4, 1fr); }

.seg-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 9px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  touch-action: manipulation;
  transition: all 0.15s ease;
  line-height: 1.25;
}

.seg-btn:hover {
  background: var(--card-hover);
  color: var(--text-main);
}

.seg-btn.active {
  background: linear-gradient(135deg, rgba(216, 166, 52, 0.24), rgba(216, 166, 52, 0.09));
  border-color: rgba(216, 166, 52, 0.72);
  color: var(--gold-bright);
  box-shadow: inset 0 0 12px rgba(216, 166, 52, 0.12);
}

.sliders-group {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.slider-row input[type="range"] {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  outline: none;
  cursor: pointer;
  touch-action: manipulation;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid #14171f;
  cursor: pointer;
}

/* ====== PANEL FOOTER ====== */
.panel-footer {
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 12, 16, 0.72);
}

.footer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.export-preset-btn {
  flex: 1.15;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(242, 200, 100, 0.5);
  background: linear-gradient(135deg, #d8a634 0%, #b07f1a 100%);
  color: #101216;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.export-preset-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.export-preset-btn:disabled {
  opacity: 0.72;
  cursor: wait;
}

.copy-preset-btn {
  flex: 0.9;
  padding: 11px 10px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--silver);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
}

.copy-preset-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

.cancel-export-btn {
  width: 38px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(240, 90, 90, 0.45);
  background: rgba(220, 60, 60, 0.2);
  color: #ff9c9c;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}

.recording-overlay {
  position: absolute;
  top: 14px;
  left: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(20, 14, 14, 0.85);
  border: 1px solid rgba(255, 100, 100, 0.45);
  color: #ffd5d5;
  font-size: 12px;
  font-weight: 700;
  z-index: 15;
  pointer-events: none;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff4f4f;
  box-shadow: 0 0 8px #ff4f4f;
}

.footer-note {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-muted);
  text-align: center;
}

/* ====== TOAST ====== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: rgba(20, 24, 32, 0.96);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ====== MOBILE-FIRST RESPONSIVE LAYOUT (<= 900px) ====== */
@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .stage-area {
    flex: 0 0 46dvh;
    height: 46dvh;
    min-height: 250px;
    width: 100%;
    padding: 8px;
  }

  .app-shell.ui-hidden .stage-area {
    flex: 1 1 100dvh;
    height: 100dvh;
    padding: 8px;
  }

  .viewport-frame {
    border-radius: 12px;
  }

  .hud-top-badge {
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    font-size: 11px;
  }

  .transport-bar {
    bottom: 8px;
    width: 96%;
    padding: 6px 8px;
    gap: 6px;
    border-radius: 12px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    font-size: 14px;
  }

  .fullscreen-pill-btn {
    padding: 0 8px;
  }

  .fullscreen-label {
    display: none;
  }

  .time-readout {
    font-size: 11px;
  }

  .control-panel {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: auto;
    border-right: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .panel-header {
    padding: 10px 14px;
  }

  .brand-crest {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .panel-header h1 {
    font-size: 14.5px;
  }

  .panel-header p {
    font-size: 11px;
  }

  .panel-scroll {
    padding: 10px 12px;
    gap: 8px;
  }

  .slider-row input[type="range"]::-webkit-slider-thumb {
    width: 21px;
    height: 21px;
  }

  .panel-footer {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .footer-note {
    display: none;
  }
}
