:root {
  color-scheme: dark;
  --bg: #17181c;
  --bg-2: #1f2127;
  --bg-3: #26282f;
  --border: #34363e;
  --text: #e8e8ec;
  --text-dim: #9a9ca6;
  --accent: #6c5ce7;
  --accent-2: #00d4a0;
  --danger: #ff5c72;
}

* { box-sizing: border-box; }
/* Without this, any class below that sets its own unconditional `display`
   (flex/grid/etc.) silently wins over the browser's default `[hidden]`
   handling at equal specificity — the element keeps rendering (and
   intercepting clicks) even after JS sets `.hidden = true`, since that
   property only toggles the HTML attribute, not visibility on its own.
   Confirmed live: `.ai-settings` and `.ai-tier-group` both had exactly
   this bug (display:flex unconditionally beat [hidden]) until this rule
   was added. !important guarantees hidden always wins regardless of any
   future class's specificity. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

#app {
  display: grid;
  grid-template-rows: 56px 1fr auto 260px;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--bg-3);
  transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn-primary { background: var(--accent); color: white; }
.btn-accent { background: var(--accent-2); color: #06231c; }
.btn-secondary { background: var(--bg-3); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-block { width: 100%; margin-bottom: 10px; }
.btn-icon { width: 40px; padding: 8px; text-align: center; }

.workspace {
  display: grid;
  grid-template-columns: 1fr 320px;
  overflow: hidden;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: #101114;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#previewCanvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: black;
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--border);
}
.drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  background: rgba(16, 17, 20, 0.85);
  border: 2px dashed var(--border);
  border-radius: 6px;
  line-height: 1.6;
  pointer-events: none;
}
.drop-hint span { font-size: 12px; opacity: 0.8; }
.drop-hint.hidden { display: none; }

.transport { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.time-label { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 12px; }

.side-panel {
  border-left: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.side-tabs { display: flex; border-bottom: 1px solid var(--border); }
.side-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 12px 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  border-bottom: 2px solid transparent;
}
.side-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.side-tab-content { padding: 14px; overflow-y: auto; flex: 1; }

.panel-hint { color: var(--text-dim); font-size: 12px; line-height: 1.5; }
.panel-divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.content-analysis { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.content-analysis-item {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
  line-height: 1.4;
}
.content-analysis-item .ts { color: var(--accent-2); font-variant-numeric: tabular-nums; margin-right: 6px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }
.field-row label { color: var(--text-dim); font-size: 12px; }
.field-row input, .field-row select { width: 140px; }
input, select, textarea {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
}
.field-textarea { width: 100%; margin-bottom: 8px; resize: vertical; }
label > span { margin-left: 6px; }

.ai-command-area {
  position: relative;
}
.ai-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}
.ai-bar input { flex: 1; padding: 10px 12px; font-size: 13px; }
/* Floats above the command bar instead of pushing the layout around — the
   settings list keeps growing (modes, tiers, key fields) and must never be
   able to squeeze the video preview above it. Deliberately anchored to the
   left and width-capped, like a normal dropdown off the gear icon, rather
   than spanning the full width: full-width made it grow tall enough on
   ordinary window sizes to cover the right sidebar's tab bar above it
   (Text/Zoom/Auto-Cut), blocking clicks there until the panel was closed. */
.ai-settings {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: min(640px, 100%);
  max-height: 60vh;
  overflow-y: auto;
  padding: 10px 16px;
  background: var(--bg-3);
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
}
.ai-settings input[type="password"] { width: 320px; }
.ai-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.ai-mode-option:has(input:checked) { border-color: var(--accent); background: var(--bg-3); }
.ai-mode-option input[type="radio"] { margin-top: 3px; flex-shrink: 0; }
.ai-mode-option span { font-size: 12px; line-height: 1.5; color: var(--text-dim); }
.ai-mode-option code { background: var(--bg); padding: 1px 4px; border-radius: 4px; font-size: 11px; }
.ai-tier-group { display: flex; flex-direction: column; gap: 6px; margin-left: 28px; margin-top: -4px; }
.ai-tier-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
}
.ai-tier-option:has(input:checked) { border-color: var(--accent-2); background: var(--bg-3); }
.ai-tier-option input[type="radio"] { margin-top: 2px; flex-shrink: 0; }
.ai-tier-option .tier-note { color: var(--text-dim); }

.timeline-pane {
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.timeline-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.status-log { font-size: 12px; color: var(--text-dim); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-bar { width: 180px; height: 6px; background: var(--bg-3); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent-2); transition: width 0.2s ease; }

.timeline-scroll { flex: 1; overflow: auto; position: relative; padding: 8px 16px; }
.timeline-scroll-inner { position: relative; }

.timeline-ruler { position: relative; height: 20px; }
.tick { position: absolute; top: 0; width: 1px; height: 6px; background: var(--border); }
.tick-major { height: 10px; background: var(--text-dim); }
.tick-label { position: absolute; top: 10px; left: 2px; font-size: 10px; color: var(--text-dim); white-space: nowrap; }

.clip-track, .overlay-track, .zoom-track, .sfx-track { position: relative; height: 40px; margin-top: 4px; }
.overlay-track, .zoom-track, .sfx-track { height: 24px; }

.clip-block {
  position: absolute;
  top: 0;
  height: 100%;
  background: linear-gradient(180deg, #3a3f56, #2b2f42);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  overflow: hidden;
  cursor: grab;
}
.clip-block.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.clip-label { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.trim-handle { position: absolute; top: 0; width: 8px; height: 100%; cursor: ew-resize; }
.trim-left { left: 0; }
.trim-right { right: 0; }

.overlay-chip, .zoom-chip, .sfx-chip {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 4px;
  font-size: 10px;
  padding: 2px 6px;
  overflow: hidden;
  white-space: nowrap;
  cursor: pointer;
}
.overlay-chip { background: #3f2b52; border: 1px solid #5c3d78; }
.overlay-chip.selected { border-color: var(--accent-2); }
.zoom-chip { background: #1f3f3a; border: 1px solid #2d5c53; }
.sfx-chip { background: #4a2f1a; border: 1px solid #7a4d26; }
.sfx-chip.selected { border-color: var(--accent-2); }

.sfx-builtin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.sfx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  background: var(--panel-2, #21243a);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 12px;
}
.sfx-item .sfx-item-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sfx-search-row { display: flex; gap: 6px; margin-bottom: 10px; }
.sfx-search-row input { flex: 1; }

.playhead {
  position: absolute;
  top: 0;
  width: 2px;
  background: var(--danger);
  z-index: 5;
  pointer-events: none;
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side-panel { border-left: none; border-top: 1px solid var(--border); max-height: 240px; }
}
