:root {
  --bg: #14171c;
  --bg-raised: #1b1f26;
  --bg-inset: #0e1013;
  --line: #2a2f38;
  --line-soft: #22262e;
  --text: #e8e6e1;
  --text-dim: #9098a4;
  --text-faint: #5c6470;
  --accent: #e8a33d;
  --accent-dim: #7a5a26;
  --accent-text: #1a1408;
  --danger: #d9654f;
  --radius: 6px;
  --mono: "IBM Plex Mono", "SF Mono", Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ============ HEADER ============ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.12em;
  font-size: 13px;
  color: var(--text);
}

.engine-status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: lowercase;
  letter-spacing: 0.03em;
}
.engine-status.ready { color: var(--accent); }
.engine-status.busy { color: #6fa8dc; }
.engine-status.error { color: var(--danger); }

.error-banner {
  background: #3a1c17;
  color: #ffb4a3;
  border-bottom: 1px solid var(--danger);
  padding: 10px 20px;
  font-size: 12.5px;
  font-family: var(--mono);
  white-space: pre-wrap;
}

/* ============ BODY LAYOUT ============ */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ============ RACK (SIDEBAR) ============ */
.rack {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-raised);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rack-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}
.rack-header h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin: 0;
  font-weight: 600;
}
.rack-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  background: rgba(232, 163, 61, 0.12);
  padding: 1px 7px;
  border-radius: 10px;
}

.drop-zone {
  margin: 8px 16px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(232, 163, 61, 0.05);
}
.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 20px 8px;
  color: var(--text-dim);
  font-size: 12.5px;
}
.drop-icon {
  font-size: 20px;
  color: var(--accent);
  margin-bottom: 2px;
}
.drop-hint { font-size: 11px; color: var(--text-faint); }

.rack-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rack-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--bg-inset);
  transition: border-color 0.12s, background 0.12s;
}
.rack-card:hover { border-color: var(--line); }
.rack-card.selected {
  border-color: var(--accent);
  background: rgba(232, 163, 61, 0.07);
}
.rack-thumb {
  width: 34px;
  height: 42px;
  border-radius: 3px;
  background: #000;
  object-fit: cover;
  flex-shrink: 0;
}
.rack-info { min-width: 0; flex: 1; }
.rack-name {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rack-status {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 2px;
}
.rack-status.done { color: #7cc576; }
.rack-status.error { color: var(--danger); }
.rack-status.processing { color: var(--accent); }

.rack-remove {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  flex-shrink: 0;
}
.rack-remove:hover { color: var(--danger); }

.rack-download {
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
  flex-shrink: 0;
}

.rack-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}

/* ============ WORKSPACE ============ */
.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  gap: 8px;
}
.empty-icon { font-size: 32px; opacity: 0.4; }

.editor {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ---- Preview pane ---- */
.preview-pane {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.preview-frame {
  width: 100%;
  aspect-ratio: 4 / 5;
  background: var(--bg-inset);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.preview-rotator {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.1s linear;
}

#previewVideo, #previewCanvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-controls {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.preview-note {
  font-size: 10.5px;
  color: var(--text-faint);
  line-height: 1.4;
}

/* ---- Controls pane ---- */
.controls-pane {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
}

.panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-num {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent-text);
  background: var(--accent);
  width: 16px;
  height: 16px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mode-toggle {
  display: flex;
  gap: 16px;
  margin-bottom: 10px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.control-row:first-of-type { margin-top: 4px; }

.control-label {
  font-size: 11.5px;
  color: var(--text-dim);
  min-width: 44px;
}

.readout {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  min-width: 44px;
  text-align: right;
}

.radio, .checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
}

input[type="text"], select {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 4px;
  padding: 5px 7px;
  font-size: 12px;
  font-family: var(--sans);
}
input[type="text"] { width: 100px; }

input[type="color"] {
  width: 26px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: none;
  cursor: pointer;
}

/* Fader-style range sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 80px;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 18px;
  border-radius: 3px;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 0 1px var(--accent-dim);
}
input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 18px;
  border-radius: 3px;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.file-chip {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--mono);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-hint {
  font-size: 10px;
  color: var(--text-faint);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

/* ---- Text layer list ---- */
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  cursor: pointer;
  font-size: 12px;
}
.layer-row:hover { border-color: var(--text-faint); }
.layer-row.selected { border-color: var(--accent); background: rgba(232, 163, 61, 0.08); }
.layer-row-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.layer-row-badge {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-faint);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
}

.layer-editor {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

/* Draggable text layer handles on the preview canvas */
.preview-frame { cursor: default; }
.preview-frame.dragging-layer { cursor: grabbing; }

/* ============ BUTTONS ============ */
.btn {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text);
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.06s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-small { padding: 5px 10px; font-size: 11.5px; }
.btn-ghost { background: none; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 50%; }

.btn-primary {
  background: var(--bg-inset);
  border-color: var(--accent-dim);
  color: var(--accent);
}
.btn-primary:hover { background: rgba(232, 163, 61, 0.1); }

.btn-accent {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-accent:hover { background: #f0ae4d; }

/* ============ ACTION BAR ============ */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  border-top: 1px solid var(--line);
  background: var(--bg-raised);
  flex-shrink: 0;
}
.action-bar-status {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
}
.action-bar-buttons { display: flex; gap: 10px; }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
