/**
 * Obsidian Studio — Darkroom Cinema Instrument Design System (v2)
 * Matches the ObsidianLoop / ObsidianStage Darkroom Cinema visual spec:
 * - Pure obsidian canvas (#060709) with floating 14px rounded darkroom cards
 * - Monochrome warm ivory (#F2EFE9) & crisp white (#FFFFFF) controls + custom sliders
 * - Signal Vermilion (#EF4444) reserved strictly for Export pill, active playhead, and record/live cues
 * - Precision interaction & animation curves (emil-design-eng standards)
 */

:root,
[data-theme="dark"] {
  /* Darkroom Cinema Core Palette */
  --suite-bg-app: #060709;
  --suite-bg-surface: #101114;
  --suite-bg-elevated: #16181d;
  --suite-bg-card: #191b21;
  --suite-bg-card-hover: #22252d;
  --suite-bg-stage-well: #030304;
  --suite-border: rgba(255, 255, 255, 0.085);
  --suite-border-strong: rgba(255, 255, 255, 0.16);
  --suite-text-primary: #f2efe9;
  --suite-text-secondary: #a1a6b3;
  --suite-text-muted: #6c7280;

  /* Monochrome Instrument Active + Signal Vermilion Action */
  --suite-accent: #f2efe9;
  --suite-accent-strong: #ffffff;
  --suite-accent-soft: rgba(255, 255, 255, 0.1);
  --suite-accent-ink: #09090b;
  --suite-signal: #ef4444;
  --suite-signal-hover: #dc2626;
  --suite-signal-soft: rgba(239, 68, 68, 0.16);

  /* Precision Easing Curves (emil-design-eng) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  /* Map onto ObsidianStage Studio variables */
  --bg-app: var(--suite-bg-app);
  --bg-surface: var(--suite-bg-surface);
  --bg-elevated: var(--suite-bg-elevated);
  --bg-card: var(--suite-bg-card);
  --bg-card-hover: var(--suite-bg-card-hover);
  --bg-stage-well: var(--suite-bg-stage-well);
  --border: var(--suite-border);
  --border-strong: var(--suite-border-strong);
  --text-primary: var(--suite-text-primary);
  --text-secondary: var(--suite-text-secondary);
  --text-muted: var(--suite-text-muted);
  --accent: var(--suite-accent);
  --accent-strong: var(--suite-accent-strong);
  --accent-soft: var(--suite-accent-soft);
  --accent-rose: var(--suite-signal);
  --rose-soft: var(--suite-signal-soft);
  --alpha-a: #0f1014;
  --alpha-b: rgba(255, 255, 255, 0.05);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.75);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.42);
}

/* Light Theme Parity */
[data-theme="light"] {
  --suite-bg-app: #eceae4;
  --suite-bg-surface: #ffffff;
  --suite-bg-elevated: #f3f2ee;
  --suite-bg-card: #f8f7f4;
  --suite-bg-card-hover: #eae7df;
  --suite-bg-stage-well: #dfdcd4;
  --suite-border: rgba(15, 17, 21, 0.1);
  --suite-border-strong: rgba(15, 17, 21, 0.2);
  --suite-text-primary: #111215;
  --suite-text-secondary: #4e5360;
  --suite-text-muted: #767c8a;
  --suite-accent: #111215;
  --suite-accent-strong: #000000;
  --suite-accent-soft: rgba(17, 18, 21, 0.08);
  --suite-accent-ink: #ffffff;
  --suite-signal: #dc2626;
  --suite-signal-hover: #b91c1c;
  --suite-signal-soft: rgba(220, 38, 38, 0.12);

  --bg-app: var(--suite-bg-app);
  --bg-surface: var(--suite-bg-surface);
  --bg-elevated: var(--suite-bg-elevated);
  --bg-card: var(--suite-bg-card);
  --bg-card-hover: var(--suite-bg-card-hover);
  --bg-stage-well: var(--suite-bg-stage-well);
  --border: var(--suite-border);
  --border-strong: var(--suite-border-strong);
  --text-primary: var(--suite-text-primary);
  --text-secondary: var(--suite-text-secondary);
  --text-muted: var(--suite-text-muted);
  --accent: var(--suite-accent);
  --accent-strong: var(--suite-accent-strong);
  --accent-soft: var(--suite-accent-soft);
  --accent-rose: var(--suite-signal);
  --rose-soft: var(--suite-signal-soft);
}

/* ==========================================================================
   1. Floating Darkroom Card Shell (Matches Mockup Silhouette)
   ========================================================================== */

.app-shell {
  grid-template-rows: 56px minmax(0, 1fr) var(--timeline-height, 210px);
  gap: 10px;
  padding: 0 10px 10px;
  background: var(--bg-app);
}

/* Clean Transparent Cinema Top Bar */
.top-bar {
  padding: 0 6px;
  background: transparent;
  border-bottom: none;
}

.brand-name {
  font-family: "Inter", "Space Grotesk", sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.title-input,
.top-select {
  height: 32px;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.pill-group {
  padding: 3px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  gap: 2px;
}

.pill-btn {
  height: 26px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.pill-btn.is-active {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.icon-btn,
.secondary-btn {
  height: 32px;
  padding: 0 13px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 500;
}

.icon-btn:hover:not(:disabled),
.secondary-btn:hover:not(:disabled) {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.new-scene-btn {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.new-scene-btn:hover:not(:disabled) {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--bg-app);
}

/* Signature Signal Vermilion Pill Export CTA (Matches Mockup) */
.primary-btn {
  height: 34px;
  padding: 0 18px;
  border-radius: 999px;
  border: none;
  background: var(--suite-signal);
  color: #ffffff;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.28);
}

.primary-btn:hover:not(:disabled) {
  background: var(--suite-signal-hover);
  filter: none;
}

.obs-switcher-trigger {
  height: 32px !important;
  padding: 0 12px !important;
  border-radius: 999px !important;
  background: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
}

/* ==========================================================================
   2. Floating 3-Column Workspace Cards (Library | Darkroom Stage | Inspector)
   ========================================================================== */

.workspace {
  gap: 10px;
}

.panel {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  overflow: hidden;
}

.library-panel,
.properties-panel {
  border: 1px solid var(--border);
}

/* Precision Underline Tabs (Matches 'Scene & Morph | Audio & Sync | Title & Export') */
.panel-tabs {
  gap: 2px;
  padding: 6px 10px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.tab-btn {
  height: 36px;
  border-radius: 0;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
  transition: color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}

.tab-btn:hover {
  background: transparent;
  color: var(--text-primary);
}

.tab-btn.is-active {
  background: transparent;
  border-color: transparent;
  border-bottom-color: var(--text-primary);
  color: var(--text-primary);
  font-weight: 600;
}

.panel-header {
  padding: 10px 14px;
  min-height: 44px;
  border-bottom: 1px solid var(--border);
}

.panel-scroll {
  padding: 14px;
}

/* Darkroom Stage Viewport Card */
.stage-area {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-stage-well);
  padding: 20px;
}

.stage-frame {
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.stage-hud-chip {
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(16, 17, 20, 0.86);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
}

.stage-hud-chip.is-active,
.stage-hud-chip.is-accent-chip {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

.stage-status-badge {
  background: rgba(16, 17, 20, 0.86);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ==========================================================================
   3. Custom Minimalist White Sliders & Inspector Rows (Matches Mockup)
   ========================================================================== */

.prop-section {
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.prop-label,
.lib-audio-slider-head {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.prop-val,
.lib-audio-slider-val,
.time-readout,
.ruler-tick,
.sfx-cue-time {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* Custom Slim Track + Crisp White Circular Thumb */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  outline: none;
  margin: 6px 0;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ffffff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.65);
  transition: transform 140ms var(--ease-out);
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.18);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ffffff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.65);
}

[data-theme="light"] input[type="range"] {
  background: rgba(15, 17, 21, 0.16);
}

[data-theme="light"] input[type="range"]::-webkit-slider-thumb,
[data-theme="light"] input[type="range"]::-moz-range-thumb {
  background: #111215;
}

/* Monochrome Active Library & Segmented Controls */
.lib-card {
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.lib-card.is-active {
  border-color: var(--text-primary);
  box-shadow: inset 0 0 0 1px var(--text-primary);
}

.lib-icon {
  color: var(--text-primary);
}

.seg-btn.is-active,
.mini-btn.is-active,
.toggle-pill.is-on {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--bg-app);
}

/* ==========================================================================
   4. Floating Darkroom Timeline Deck + Vermilion Playhead (Matches Mockup)
   ========================================================================== */

.timeline-panel {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
}

.timeline-resize-handle {
  height: 6px;
  background: transparent;
}

.timeline-transport {
  padding: 8px 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.play-btn {
  height: 28px;
  min-width: 68px;
  border-radius: 999px;
  background: var(--text-primary);
  color: var(--bg-app);
  font-weight: 700;
}

.play-btn.is-playing {
  background: var(--suite-signal);
  color: #ffffff;
}

.timeline-ruler-row {
  background: #0b0c0f;
  border-bottom: 1px solid var(--border);
}

[data-theme="light"] .timeline-ruler-row {
  background: var(--bg-elevated);
}

.playhead-head {
  width: 10px;
  height: 11px;
  background: var(--suite-signal);
  border-radius: 3px 3px 5px 5px;
}

.playhead-line {
  width: 1.5px;
  background: var(--suite-signal);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.55);
}

/* Sleek Monochrome Clip Blocks (Replacing Loud Rainbow Bars) */
.clip-pill,
.clip-pill.kind-hologram,
.clip-pill.kind-text,
.clip-pill.kind-fx-scene,
.clip-pill.kind-fx-point {
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #1a1c22;
  color: var(--text-primary);
}

[data-theme="light"] .clip-pill,
[data-theme="light"] .clip-pill.kind-hologram,
[data-theme="light"] .clip-pill.kind-text,
[data-theme="light"] .clip-pill.kind-fx-scene,
[data-theme="light"] .clip-pill.kind-fx-point {
  background: #efede7;
  border-color: rgba(15, 17, 21, 0.15);
  color: #111215;
}

.clip-pill.is-selected {
  border-color: var(--text-primary);
  background: #23262f;
  box-shadow: inset 0 0 0 1px var(--text-primary);
}

.clip-pill.kind-hologram .clip-badge {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.12);
}

.clip-pill.kind-text .clip-badge {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.16);
}

.clip-pill.kind-fx-scene .clip-badge,
.clip-pill.kind-fx-point .clip-badge {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.16);
}

.audio-bgm-pill {
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #16181e;
}

.export-progress-bar {
  background: var(--suite-signal);
}

/* ==========================================================================
   5. emil-design-eng Precision Interactions & Motion Standards
   ========================================================================== */

.icon-btn,
.mini-btn,
.secondary-btn,
.primary-btn,
.pill-btn,
.seg-btn,
.stage-hud-chip,
.play-btn,
.format-option,
.new-scene-cat-btn,
.gallery-filter-btn,
.qc-format-btn,
.qc-palette-btn,
.obs-switcher-trigger {
  transition:
    transform 160ms var(--ease-out),
    background-color 160ms var(--ease-out),
    border-color 160ms var(--ease-out),
    color 160ms var(--ease-out),
    opacity 160ms var(--ease-out);
}

.icon-btn:active:not(:disabled),
.mini-btn:active:not(:disabled),
.secondary-btn:active:not(:disabled),
.primary-btn:active:not(:disabled),
.pill-btn:active:not(:disabled),
.seg-btn:active:not(:disabled),
.stage-hud-chip:active:not(:disabled),
.play-btn:active:not(:disabled),
.format-option:active:not(:disabled),
.gallery-filter-btn:active:not(:disabled),
.obs-switcher-trigger:active:not(:disabled) {
  transform: scale(0.97);
}

.lib-card,
.scene-tpl-card,
.gallery-card {
  transition:
    transform 160ms var(--ease-out),
    border-color 160ms var(--ease-out),
    background-color 160ms var(--ease-out);
}

.lib-card:active,
.scene-tpl-card:active {
  transform: scale(0.98);
}

@media (hover: none), (pointer: coarse) {
  .lib-card:hover,
  .scene-tpl-card:hover,
  .gallery-card:hover {
    transform: none;
  }
}

/* Natural Modal & Drawer Entries via @starting-style (never scale(0)) */
.modal-backdrop {
  background: rgba(3, 3, 5, 0.8);
  backdrop-filter: blur(10px);
  opacity: 1;
  transition: opacity 180ms var(--ease-out);
}

.modal-card {
  border-radius: 16px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  opacity: 1;
  transform: scale(1) translateY(0);
  transform-origin: center;
  transition:
    opacity 200ms var(--ease-out),
    transform 220ms var(--ease-out);
}

@starting-style {
  .modal-backdrop {
    opacity: 0;
  }
  .modal-card {
    opacity: 0;
    transform: scale(0.96) translateY(6px);
  }
}

.quick-customize-drawer {
  border-radius: 14px;
  background: rgba(16, 17, 20, 0.92);
  border: 1px solid var(--border-strong);
  transform-origin: top right;
  opacity: 1;
  transform: scale(1) translateY(0);
  transition:
    opacity 180ms var(--ease-out),
    transform 220ms var(--ease-drawer);
}

@starting-style {
  .quick-customize-drawer {
    opacity: 0;
    transform: scale(0.96) translateY(-6px);
  }
}

.obs-switcher-menu {
  transform-origin: top left;
  background: #101114 !important;
  border-color: var(--border-strong) !important;
  color: var(--text-primary) !important;
  opacity: 1;
  transform: scale(1) translateY(0);
  transition:
    opacity 160ms var(--ease-out),
    transform 180ms var(--ease-out);
}

@starting-style {
  .obs-switcher-menu {
    opacity: 0;
    transform: scale(0.96) translateY(-4px);
  }
}

@media (max-width: 960px) {
  .app-shell {
    gap: 0;
    padding: 0;
  }

  .panel,
  .stage-area,
  .timeline-panel {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
}

/* ==========================================================================
   6. Collapsible 2-Column Cinema Layout, Project Popover & Centered Transport
   ========================================================================== */

.top-bar {
  overflow: visible !important;
  position: relative;
  z-index: 40;
}

.library-toggle-btn.is-active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--bg-app);
}

/* Default 2-Column Cinema Silhouette (Matches Mockup) on Desktop */
@media (min-width: 961px) {
  .app-shell[data-library-open="false"] .workspace,
  .app-shell[data-library-open="false"][data-studio-mode] .workspace {
    grid-template-columns: minmax(0, 1fr) 316px !important;
  }

  .app-shell[data-library-open="false"] .library-panel {
    display: none;
  }

  .app-shell[data-library-open="true"] .workspace {
    grid-template-columns: 276px minmax(0, 1fr) 304px !important;
  }
}

/* Compact Project Popover Menu (origin-aware top-right per emil-design-eng) */
.top-project-menu {
  position: relative;
}

.top-project-menu > summary {
  list-style: none;
  cursor: pointer;
}

.top-project-menu > summary::-webkit-details-marker {
  display: none;
}

.top-project-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 264px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 90;
  transform-origin: top right;
  opacity: 1;
  transform: scale(1) translateY(0);
  transition: opacity 160ms var(--ease-out), transform 180ms var(--ease-out);
}

@starting-style {
  .top-project-popover {
    opacity: 0;
    transform: scale(0.96) translateY(-4px);
  }
}

.top-menu-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.top-menu-field > span {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.top-project-popover .title-input,
.top-project-popover .top-select {
  width: 100%;
  border-radius: 8px;
  background: var(--bg-elevated);
}

.top-menu-row {
  display: flex;
  gap: 6px;
}

.top-menu-row > * {
  flex: 1;
  border-radius: 8px;
}

/* 3-Column Centered Timeline Transport (Matches Mockup) */
.timeline-transport {
  display: grid !important;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.transport-left {
  justify-self: start;
}

.transport-center {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

.transport-right {
  justify-self: end;
}

.live-signal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--suite-signal);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.55);
  flex-shrink: 0;
}

@media (max-width: 960px) {
  .library-toggle-btn {
    display: none;
  }

  .timeline-transport {
    display: flex !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .icon-btn:active,
  .mini-btn:active,
  .secondary-btn:active,
  .primary-btn:active,
  .pill-btn:active,
  .lib-card:active,
  .scene-tpl-card:active {
    transform: none !important;
  }
}
