:root {
  color-scheme: dark;
  --bg: #0e0f17;
  --panel: #181a26;
  --panel-2: #1c1e2b;
  --chip: #262936;
  --border: #2a2e3d;
  --text: #e6e6ee;
  --muted: #9aa0b4;
  --accent: #7d6cf0;
  --select-ring: #e8a33d;
  --queen: #b18cf7;
  --king: #f0b541;
  --skeleton: #5ec98f;
  --barbarian: #f06d5a;
  --narrator: #8aa0b8;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { color: var(--accent); font-weight: 700; font-size: 17px; white-space: nowrap; }
.topbar-center { display: flex; align-items: center; gap: 12px; flex: 1; justify-content: center; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

select, input[type="text"], .version-name {
  background: var(--chip);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
#video-select { min-width: 280px; }
#version-select { max-width: 280px; }

.save-status { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.save-status.saved { color: #6fdc8c; }
.save-status.saving { color: var(--king); }
.save-status.dirty { color: var(--king); }

.version-badge {
  background: #3543c9;
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
}
.version-name { width: 110px; }

.pill {
  border: none;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  cursor: default;
}
.pill.published { background: #123c26; color: #4ade80; border: 1px solid #1f6f44; }
.pill.draft { background: #3d2e10; color: var(--king); border: 1px solid #7a5c1e; cursor: pointer; }

.btn-accent {
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-accent:hover { background: #5b52f0; }

/* ---------- Workspace ---------- */
.workspace { display: flex; flex: 1 1 auto; min-height: 0; }

.player-pane { flex: 0 0 30%; background: #000; display: flex; }
.player-pane video { width: 100%; height: 100%; object-fit: contain; background: #000; }

.info-pane {
  flex: 0 0 23%;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
  overflow-y: auto;
}
.current-sub {
  background: var(--panel-2);
  border-left: 3px solid var(--king);
  border-radius: 6px;
  padding: 12px 14px;
}
.current-sub.hidden { visibility: hidden; }
.current-speaker { font-weight: 700; font-size: 13px; margin-bottom: 6px; color: var(--king); }
.current-text { font-style: italic; font-size: 14px; color: #d8d8e2; }
.video-info {
  background: var(--panel-2);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.video-info span { color: var(--text); }

/* ---------- Subtitle rows ---------- */
.lines-pane { flex: 1 1 auto; overflow-y: auto; padding: 12px 14px; }
#lines { display: flex; flex-direction: column; gap: 8px; }

.line-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
}
.line-row.selected { border-color: var(--select-ring); box-shadow: 0 0 0 1px var(--select-ring); }
.line-row.active { background: #20232f; }

.row-play {
  background: var(--chip);
  border: none;
  color: var(--muted);
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  flex: 0 0 auto;
}
.row-play:hover { color: var(--text); }

.time-input {
  width: 64px;
  background: #11131c;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: #8fb8ff;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  padding: 5px 6px;
  text-align: center;
}

.speaker-select {
  border: none;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 6px;
  cursor: pointer;
  color: #14151f;
}
.speaker-QUEEN { background: var(--queen); }
.speaker-KING { background: var(--king); }
.speaker-SKELETON { background: var(--skeleton); }
.speaker-BARBARIAN { background: var(--barbarian); }
.speaker-NARRATOR { background: var(--narrator); }

.text-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13.5px;
  padding: 5px 4px;
  outline: none;
}

.row-handle { color: #4a4e5e; cursor: grab; font-size: 14px; flex: 0 0 auto; user-select: none; }
.row-del { background: none; border: none; color: #4a4e5e; cursor: pointer; font-size: 13px; flex: 0 0 auto; }
.row-del:hover { color: var(--barbarian); }

/* ---------- Timeline ---------- */
.timeline-area {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 8px 14px 14px;
}
.timeline-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.time-readout {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 14px;
  color: var(--accent);
}
.timeline-buttons { display: flex; gap: 6px; }
.btn-square, .btn-flat {
  background: var(--chip);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  padding: 6px 10px;
}
.btn-square { width: 34px; }
.btn-square:hover, .btn-flat:hover { background: #303446; }

.timeline {
  position: relative;
  height: 64px;
  background: #11131c;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: crosshair;
}
.ruler { position: absolute; inset: 0; }
.tick { position: absolute; top: 0; bottom: 0; width: 1px; background: #232636; }
.tick-label { position: absolute; top: 2px; font-size: 9.5px; color: #4a4e5e; transform: translateX(3px); }

.blocks { position: absolute; left: 0; right: 0; bottom: 6px; height: 30px; }
.block {
  position: absolute;
  height: 100%;
  border-radius: 999px;
  font-size: 11px;
  line-height: 30px;
  color: #14151f;
  font-weight: 600;
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: grab;
  user-select: none;
}
.block.selected { outline: 2px solid #fff; }
.block .resize { position: absolute; right: 0; top: 0; bottom: 0; width: 8px; cursor: ew-resize; }

.playhead {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: #e84d4d;
  pointer-events: none;
}
.playhead::before {
  content: "";
  position: absolute;
  top: 0; left: -4px;
  border: 5px solid transparent;
  border-top-color: #e84d4d;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 22px;
  bottom: 120px;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}
.fab:hover { background: #8f80f5; }
