:root {
  --bg-app: #141416;
  --bg-panel: #1b1b1e;
  --bg-elevated: #232328;
  --bg-hover: #2c2c33;
  --bg-input: #121214;
  --border: #2c2c32;
  --border-subtle: #242429;
  --text: #e6e6eb;
  --text-dim: #8a8a96;
  --accent: #e5484d;
  --accent-blue: #3e8ef7;
  --key: #f5b938;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Space Mono", "Consolas", monospace;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* Custom thin scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #33333b;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #474752;
}

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

/* TOP BAR */
.topbar {
  height: 44px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: -0.01em;
}

.brand-icon {
  color: var(--accent);
}

.v-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}

.v-sep.sm {
  height: 14px;
}

.top-select {
  height: 28px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 8px;
  font-size: 12px;
  font-family: var(--font-ui);
  outline: none;
  cursor: pointer;
}

.top-select:hover,
.top-select:focus {
  border-color: #45454f;
}

.top-pill-input {
  height: 28px;
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 7px;
  color: var(--text-dim);
  font-size: 11.5px;
}

.top-pill-input input[type="number"] {
  width: 38px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11.5px;
  text-align: center;
  outline: none;
}

.mini-swatch {
  width: 18px;
  height: 18px;
  border: 1px solid #444;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.top-toggle {
  height: 28px;
  padding: 0 9px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.12s ease;
}

.top-toggle:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.top-toggle.active {
  background: rgba(62, 142, 247, 0.16);
  border-color: rgba(62, 142, 247, 0.5);
  color: #7ab3ff;
}

.btn-subtle {
  height: 28px;
  padding: 0 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: 0.12s ease;
}

.btn-subtle:hover {
  background: var(--bg-hover);
  border-color: #42424c;
}

.btn-subtle.sm {
  height: 26px;
  padding: 0 8px;
  font-size: 11px;
}

.btn-primary {
  height: 28px;
  padding: 0 12px;
  background: var(--accent-blue);
  border: 1px solid var(--accent-blue);
  border-radius: 5px;
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: 0.12s ease;
}

.btn-primary:hover {
  background: #2f7ee8;
}

/* WORKSPACE */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 232px 1fr 296px;
  min-height: 0;
}

.panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-left {
  border-right: 1px solid var(--border);
}

.panel-right {
  border-left: 1px solid var(--border);
}

.panel-header {
  height: 34px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  flex-shrink: 0;
}

.count-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  background: var(--bg-input);
  padding: 1px 6px;
  border-radius: 4px;
}

/* LEFT: LAYERS */
.add-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.tool-chip {
  height: 26px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.12s;
}

.tool-chip:hover {
  background: var(--bg-hover);
  border-color: #44444e;
}

.tool-chip.wide {
  grid-column: 1 / -1;
}

.layers-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer-item {
  height: 30px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 8px;
  border-radius: 4px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text);
}

.layer-item:hover {
  background: var(--bg-elevated);
}

.layer-item.selected {
  background: rgba(62, 142, 247, 0.16);
  border-color: rgba(62, 142, 247, 0.45);
}

.layer-type-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  font-weight: 500;
}

.layer-mini-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}

.layer-mini-btn:hover {
  opacity: 1;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

/* CENTER: MONITOR / VIEWPORT */
.stage-area {
  display: flex;
  flex-direction: column;
  background: #0e0e10;
  min-width: 0;
  min-height: 0;
}

.stage-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 20px;
  position: relative;
}

/* FIX: Exact aspect-ratio frame box so Flexbox NEVER squishes 1920x1080 into a square! */
.stage-frame {
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px #2f2f38;
}

.stage-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  overflow: hidden;
}

.stage-wrapper.checker {
  background-image:
    linear-gradient(45deg, #1a1a1f 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a1f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a1f 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a1f 75%);
  background-size: 32px 32px;
  background-position: 0 0, 0 16px, 16px -16px, -16px 0;
  background-color: #121215;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 1400px;
  overflow: hidden;
}

.stage-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 96px 96px;
  pointer-events: none;
}

.stage-guides {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.guide-h,
.guide-v {
  position: absolute;
  background: var(--accent-blue);
  display: none;
}
.guide-h { left: 0; right: 0; height: 2px; top: 50%; }
.guide-v { top: 0; bottom: 0; width: 2px; left: 50%; }

.stage-layer {
  position: absolute;
  transform-origin: center center;
  cursor: move;
}

.stage-layer.selected {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

.stage-statusbar {
  height: 26px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
}

.status-mid {
  font-family: var(--font-ui);
  font-size: 11px;
  color: #6b6b76;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
}

.zoom-btn:hover {
  color: var(--text);
}

/* RIGHT: INSPECTOR */
.btn-kf {
  height: 22px;
  padding: 0 8px;
  background: rgba(245, 185, 56, 0.14);
  border: 1px solid rgba(245, 185, 56, 0.45);
  border-radius: 4px;
  color: var(--key);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-kf:hover {
  background: rgba(245, 185, 56, 0.25);
}

.kf-icon {
  width: 7px;
  height: 7px;
  background: var(--key);
  transform: rotate(45deg);
  display: inline-block;
}

.inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  color: var(--text-dim);
  text-align: center;
  padding: 36px 14px;
  font-size: 12px;
}

.insp-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.insp-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-row label {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 74px;
}

/* Custom DaVinci-style thin sliders */
.field-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: #35353f;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.field-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #d8d8e2;
  border: 1px solid #141416;
  cursor: pointer;
  transition: transform 0.1s;
}

.field-row input[type="range"]::-webkit-slider-thumb:hover {
  background: #ffffff;
  transform: scale(1.18);
}

.field-row input[type="number"] {
  width: 60px;
  height: 23px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: right;
  outline: none;
}

.field-row input[type="number"]:focus {
  border-color: var(--accent-blue);
}

.field-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-col label {
  font-size: 10.5px;
  color: var(--text-dim);
}

.field-col textarea,
.field-col input[type="text"],
.ctrl-text {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 7px;
  font-size: 11.5px;
  font-family: var(--font-ui);
  resize: vertical;
  outline: none;
}

.field-col textarea:focus,
.field-col input[type="text"]:focus {
  border-color: var(--accent-blue);
}

.color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.color-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 11px;
  color: var(--text-dim);
}

.ctrl-color {
  width: 22px;
  height: 18px;
  border: none;
  background: transparent;
  cursor: pointer;
}

/* BOTTOM: TIMELINE */
.timeline-panel {
  height: 225px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.timeline-toolbar {
  height: 36px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 12px;
}

.transport,
.timecode-box,
.timeline-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  width: 28px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.icon-btn.play-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  width: 34px;
}

.icon-btn.play-btn:hover {
  background: #d1383d;
}

.tc-input {
  width: 68px;
  height: 24px;
  background: var(--bg-input);
  color: var(--key);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  text-align: right;
  outline: none;
}

.tc-unit {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
}

.tc-readout {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
}

.timeline-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.timeline-ruler-row {
  height: 24px;
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-input);
}

.track-label-col {
  width: 210px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 0 10px;
  display: flex;
  align-items: center;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 600;
}

.timeline-ruler {
  flex: 1;
  position: relative;
  cursor: ew-resize;
  overflow: hidden;
}

.ruler-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ruler-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px solid #2e2e36;
  padding-left: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  padding-top: 3px;
}

.playhead-head {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 11px;
  margin-left: -5.5px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 58%, 50% 100%, 0 58%);
  pointer-events: none;
  z-index: 10;
}

.timeline-tracks-wrap {
  flex: 1;
  overflow-y: auto;
  position: relative;
  background: #151518;
}

.timeline-tracks {
  display: flex;
  flex-direction: column;
}

.track-row {
  height: 28px;
  display: flex;
  border-bottom: 1px solid #202026;
}

.track-row.selected {
  background: rgba(62, 142, 247, 0.08);
}

.track-name {
  width: 210px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  background: var(--bg-panel);
}

.track-lane {
  flex: 1;
  position: relative;
}

.track-bar {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 3px;
  background: #283548;
  border: 1px solid #3c5475;
  cursor: grab;
}

.track-row.selected .track-bar {
  background: #2d4669;
  border-color: var(--accent-blue);
}

.kf-diamond {
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  margin-left: -4.5px;
  margin-top: -4.5px;
  background: var(--key);
  border: 1px solid #141416;
  transform: rotate(45deg);
  cursor: pointer;
  z-index: 5;
}

.kf-diamond:hover,
.kf-diamond.active {
  background: #ffffff;
  border-color: var(--accent);
  transform: rotate(45deg) scale(1.3);
}

.playhead-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background: var(--accent);
  pointer-events: none;
  z-index: 20;
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.progress-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-blue);
  transition: width 0.1s linear;
}
