:root {
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Theme Defaults (Dark) */
  --bg-app: #0a0b10;
  --bg-surface: #12141c;
  --bg-elevated: #1a1d28;
  --bg-inset: #0e1017;
  --timeline-bg: #11131a;
  --border-subtle: #242836;
  --border-focus: #38bdf8;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-glow: rgba(56, 189, 248, 0.15);
  --danger: #ef4444;
  --success: #10b981;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
}

/* Light Theme Overrides */
body.theme-light {
  --bg-app: #f4f5f8;
  --bg-surface: #ffffff;
  --bg-elevated: #e8ecf2;
  --bg-inset: #e2e6ee;
  --timeline-bg: #eaedf3;
  --border-subtle: #d2d7e2;
  --border-focus: #0284c7;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-glow: rgba(2, 132, 199, 0.12);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.08);
}

/* System Theme prefers-color-scheme */
@media (prefers-color-scheme: light) {
  body.theme-system {
    --bg-app: #f4f5f8;
    --bg-surface: #ffffff;
    --bg-elevated: #e8ecf2;
    --bg-inset: #e2e6ee;
    --timeline-bg: #eaedf3;
    --border-subtle: #d2d7e2;
    --border-focus: #0284c7;
    --text-main: #0f172a;
    --text-muted: #475569;
    --text-dim: #94a3b8;
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --primary-glow: rgba(2, 132, 199, 0.12);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.08);
  }
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
  transition: all 0.15s ease;
}

input, select, textarea {
  font-family: inherit;
  background-color: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
}

/* Range Inputs */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  background: var(--border-subtle);
  border-radius: 4px;
  border: none;
  padding: 0;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 6px var(--primary-glow);
  transition: transform 0.1s;
}

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

/* Color Inputs */
input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  height: 32px;
  width: 44px;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}

/* Minimalist Circular Button */
.btn-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.btn-circle:hover {
  background: var(--bg-elevated);
  border-color: var(--primary);
  color: var(--primary);
}

/* Action Icon Buttons */
.btn-action-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-action-icon:hover {
  background: var(--bg-elevated);
  border-color: var(--text-dim);
}

.btn-action-icon.btn-action-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.btn-action-icon.btn-action-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

/* Home Page */
.home-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  position: relative;
  overflow: hidden;
}

.home-top-controls {
  position: absolute;
  top: 24px;
  right: 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.hero-box {
  text-align: center;
  max-width: 640px;
  margin-bottom: 32px;
}

.hero-title {
  font-size: 38px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
  color: var(--text-main);
}

.hero-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
}

.upload-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-surface);
  border: 1.5px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.upload-card:hover, .upload-card.drag-over {
  border-color: var(--primary);
  background: var(--bg-elevated);
}

.upload-icon-circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  margin-bottom: 16px;
  transition: transform 0.2s;
}

.upload-card:hover .upload-icon-circle {
  transform: scale(1.06);
}

/* Secondary Button */
.btn-secondary-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s ease;
}

.btn-secondary-action:hover {
  background: var(--bg-elevated);
}

.btn-secondary-action.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--bg-elevated);
}

/* Render Page Layout */
.render-layout {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.render-top-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  background-color: var(--bg-app);
}

.render-bottom-area {
  flex: none;
  height: 114px;
  min-height: 110px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Left Section of Top Area */
.top-left-section {
  width: 360px;
  min-width: 310px;
  max-width: 420px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  overflow: hidden;
}

.vertical-sidebar {
  width: 60px;
  min-width: 60px;
  background-color: var(--bg-inset);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 6px;
}

.sidebar-tab-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.sidebar-tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-tab-btn.active {
  color: var(--primary);
  background: var(--bg-surface);
  font-weight: 600;
}

.sidebar-panel-content {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
}

/* Middle Section: Preview Canvas Stage */
.top-middle-section {
  flex: 1;
  background: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.canvas-stage-wrapper {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: #000000;
}

.canvas-stage-wrapper canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Right Section: Properties Inspector */
.top-right-section {
  width: 300px;
  min-width: 270px;
  max-width: 340px;
  background-color: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  overflow-y: auto;
  padding: 18px;
}

/* Form & Panel Controls */
.panel-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-group {
  margin-bottom: 16px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.control-val-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--primary);
  background: var(--bg-inset);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Effect Cards with Live Visual Preview */
.effects-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.effect-card {
  position: relative;
  width: 100%;
  height: 84px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-subtle);
  background: #000000;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  transition: border-color 0.18s ease, transform 0.15s ease, box-shadow 0.18s ease;
  display: block;
  text-align: left;
  user-select: none;
  box-sizing: border-box;
}

.effect-card:hover {
  border-color: rgba(255, 255, 255, 0.45);
  transform: translateY(-1px);
}

.effect-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1.5px var(--primary), 0 4px 14px rgba(0, 0, 0, 0.6);
}

.effect-card-preview {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.effect-card-bg-black {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000000;
}

.effect-card-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.28) 60%, rgba(0, 0, 0, 0) 100%);
  display: flex;
  align-items: center;
  z-index: 2;
  pointer-events: none;
}

.effect-card-name {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff !important;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 8px rgba(0, 0, 0, 0.9);
}

/* Color Pickers Grid */
.color-swatches-grid {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-block-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

/* 9-grid position picker */
.grid-position-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  max-width: 150px;
}

.grid-pos-btn {
  height: 30px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-inset);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.grid-pos-btn .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
}

.grid-pos-btn.active {
  border-color: var(--primary);
  background: var(--bg-elevated);
}

.grid-pos-btn.active .dot {
  background: var(--primary);
}

/* Collapsible Section */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  border-top: 1px solid var(--border-subtle);
  margin-top: 12px;
}

.collapsible-header:hover {
  color: var(--text-main);
}

.collapsible-body {
  padding-top: 10px;
}

/* Timeline Layout */
.timeline-upper {
  height: 52px;
  position: relative;
  background-color: var(--timeline-bg);
  display: flex;
  align-items: center;
  padding: 0 16px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.timeline-track {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
}

.waveform-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.timeline-playhead-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--primary);
  pointer-events: none;
  box-shadow: 0 0 6px var(--primary-glow);
  z-index: 5;
  transform: translateX(-50%);
}

.playhead-handle {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  background: var(--primary);
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
}

.timeline-lower {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}

.transport-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-transport-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--text-main);
  color: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, opacity 0.15s;
}

.btn-transport-play:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

.timecode-display {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-inset);
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
}

/* Modal Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-content-card {
  width: 100%;
  max-width: 580px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.video-preview-player {
  width: 100%;
  max-height: 340px;
  border-radius: var(--radius-md);
  background: black;
  margin: 16px 0;
  border: 1px solid var(--border-subtle);
}

/* Mobile Portrait Adaptation */
@media (max-width: 900px) {
  body {
    overflow-y: auto;
  }
  .render-top-area {
    flex-direction: column;
    height: auto;
  }
  .top-left-section, .top-right-section {
    width: 100%;
    max-width: 100%;
  }
  .top-middle-section {
    min-height: 260px;
  }
  .render-bottom-area {
    position: sticky;
    bottom: 0;
    z-index: 30;
  }
}
