:root {
  --bg: #080d17;
  --panel: #0e1727;
  --panel-2: #111c2e;
  --line: #24344d;
  --line-soft: #1b2a41;
  --text: #e6edf7;
  --muted: #8ea0b8;
  --muted-2: #64748b;
  --accent: #4da3ff;
  --accent-strong: #2f7ac4;
  --accent-soft: rgba(77, 163, 255, .14);
  --green: #4ade80;
  --red: #fb7185;
  --amber: #fbbf24;
  --radius: 14px;
  --mono: "Cascadia Code", "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 8% -8%, #14233a 0, transparent 40%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

h1, h2, p { margin: 0; }

button { cursor: pointer; }

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  min-height: 72px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 18, 31, .92);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 230px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, #2f7ac4, #164a83);
  color: #fff;
  box-shadow: 0 8px 22px rgba(47, 122, 196, .3);
}

.brand h1 { font-size: 1.04rem; letter-spacing: -.01em; }

.brand p { margin-top: 2px; color: var(--muted); font-size: .76rem; }

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

/* Form controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: .82rem;
  font-weight: 700;
  line-height: 1.2;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}

.btn:hover { transform: translateY(-1px); }

.btn:disabled {
  transform: none;
  opacity: .45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-strong);
  color: #fff;
  box-shadow: 0 6px 16px rgba(28, 95, 168, .28);
}

.btn-primary:hover { background: #1c5fa8; }

.btn-ghost {
  border-color: var(--line);
  background: #0f1a2a;
  color: var(--text);
}

.btn-ghost:hover { border-color: #3b5575; background: #142238; }

.btn-soft {
  border-color: #2a405d;
  background: #16253a;
  color: #c9dcf2;
}

.btn-soft:hover { background: #1b3049; color: #fff; }

.btn-accent {
  border-color: rgba(77, 163, 255, .45);
  background: var(--accent-soft);
  color: #9ecbff;
}

.btn-accent:hover { background: rgba(77, 163, 255, .24); color: #dceeff; }

.btn-small { min-height: 30px; padding: 6px 10px; font-size: .76rem; }

.select {
  min-height: 36px;
  padding: 8px 32px 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0f1a2a;
  color: var(--text);
  font-size: .82rem;
  outline: none;
}

.select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(77, 163, 255, .14); }

.select.compact { max-width: 170px; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0f1a2a;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.switch input { position: absolute; opacity: 0; pointer-events: none; }

.switch-track {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 99px;
  background: #263a54;
  transition: background .15s ease;
}

.switch-track span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #8ea0b8;
  transition: transform .15s ease, background .15s ease;
}

.switch input:checked + .switch-track { background: var(--accent-strong); }
.switch input:checked + .switch-track span { transform: translateX(14px); background: #fff; }

/* Layout */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(340px, 1fr);
  gap: 0;
}

.video-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 16px;
  gap: 12px;
}

.video-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #03060c;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}

.video-stage video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

.video-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 30%, rgba(77, 163, 255, .13), transparent 42%),
    #050a13;
  text-align: center;
}

.video-empty.hidden { display: none; }

.empty-kicker {
  color: #7dd3fc;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.video-empty h2 {
  margin: 8px 0 4px;
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  letter-spacing: -.02em;
}

.video-empty p { color: var(--muted); font-size: .9rem; }

.preset-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.cc-overlay {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: min(900px, 88%);
  padding: 10px 16px;
  border-radius: 9px;
  background: rgba(0, 0, 0, .78);
  color: #fff;
  font-size: clamp(.9rem, 1.35vw, 1.12rem);
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  pointer-events: none;
}

.cc-overlay[hidden] { display: none; }

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 6, 12, .72);
  color: #fff;
  font-size: clamp(4rem, 10vw, 8rem);
  font-weight: 800;
  letter-spacing: -.05em;
  backdrop-filter: blur(4px);
}

.countdown[hidden] { display: none; }

.preview-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid rgba(77, 163, 255, .38);
  border-radius: 999px;
  background: rgba(10, 22, 38, .88);
  color: #9ecbff;
  font-size: .74rem;
  font-weight: 700;
}

.preview-badge[hidden] { display: none; }

.preview-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(77, 163, 255, .16);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: .45; transform: scale(.82); }
}

/* Transport */
.transport {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
}

.transport-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }

.sentence-nav { display: inline-flex; gap: 5px; margin-left: 4px; padding-left: 8px; border-left: 1px solid var(--line); }

.transport-meta {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}

.rec-state { display: inline-flex; align-items: center; gap: 7px; }

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
}

.rec-state.is-recording .rec-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(251, 113, 133, .13); }
.rec-state.is-recording { color: #fda4af; }
.rec-state.is-paused .rec-dot { background: var(--amber); }
.rec-state.is-done .rec-dot { background: var(--green); }

.audio-meter {
  width: 72px;
  height: 7px;
  overflow: hidden;
  border-radius: 99px;
  background: #1b2a41;
}

.audio-meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4ade80, #fbbf24, #fb7185);
  transition: width .06s linear;
}

.take-result {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border: 1px solid #27533c;
  border-radius: 11px;
  background: rgba(34, 197, 94, .07);
}

.take-result[hidden] { display: none; }

.take-result > div { min-width: 130px; }

.take-kicker { display: block; color: var(--green); font-size: .68rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }

.take-result strong { display: block; margin-top: 2px; font-size: .8rem; overflow-wrap: anywhere; }

.take-result audio { flex: 1; min-width: 180px; height: 34px; }

.render-status { padding: 0 12px; color: var(--muted); font-size: .76rem; }
.render-status.is-error { color: #fda4af; }

.status-line {
  min-height: 20px;
  color: var(--muted);
  font-size: .78rem;
}

/* Script panel */
.script-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 16px 14px;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(17, 28, 46, .8), rgba(10, 18, 31, .92));
}

.script-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.panel-kicker {
  color: var(--accent);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.script-header h2 { margin-top: 2px; font-size: 1.25rem; letter-spacing: -.02em; }

.script-header p { margin-top: 2px; color: var(--muted); font-size: .74rem; }

.robot-actions { display: flex; flex-direction: column; gap: 6px; }

.voice-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: rgba(15, 26, 42, .7);
}

.field { display: grid; gap: 4px; color: var(--muted); font-size: .72rem; font-weight: 700; }

.field strong { color: var(--text); font-weight: 700; }

.rate-field { gap: 7px; }

.hint { color: var(--muted-2); font-size: .72rem; line-height: 1.4; }

.script-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 6px 18px 2px;
  scroll-behavior: smooth;
}

.script-scroll::-webkit-scrollbar { width: 8px; }
.script-scroll::-webkit-scrollbar-thumb { background: #263a54; border-radius: 8px; }

.script-view { padding-right: 4px; }

.script-empty {
  padding: 24px 12px;
  border: 1px dashed #2a405d;
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
  font-size: .84rem;
}

.script-empty strong { display: block; margin-bottom: 4px; color: var(--text); }

.script-section {
  margin: 16px 0 5px;
  color: var(--accent);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.sentence {
  margin: 0 0 9px;
  padding: 7px 10px;
  border-left: 3px solid transparent;
  border-radius: 0 8px 8px 0;
  color: #b7c6d9;
  font-size: 1.02rem;
  line-height: 1.72;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}

.sentence:hover { background: rgba(77, 163, 255, .09); color: #fff; }

.sentence.is-current {
  border-left-color: var(--accent);
  background: rgba(77, 163, 255, .14);
  color: #f1f7ff;
}

.script-editor {
  border-top: 1px solid var(--line-soft);
  padding-top: 9px;
}

.script-editor summary {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.script-editor summary:hover { color: var(--text); }

.script-editor textarea {
  width: 100%;
  min-height: 104px;
  margin-top: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
  background: #0a1321;
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: .8rem;
  line-height: 1.5;
  outline: none;
}

.script-editor textarea:focus { border-color: var(--accent); }

.editor-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }

/* Toast */
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: 380px;
  padding: 10px 14px;
  border: 1px solid #2a405d;
  border-radius: 9px;
  background: #101b2b;
  color: var(--text);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .35);
  font-size: .8rem;
  line-height: 1.4;
}

.toast.is-error { border-color: #71333b; color: #fecdd3; }
.toast[hidden] { display: none; }

/* Responsive */
@media (max-width: 1000px) {
  body { overflow: auto; }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .video-panel { min-height: 58vh; }

  .script-panel {
    min-height: 520px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .topbar { align-items: flex-start; flex-direction: column; padding: 14px 16px; }

  .top-actions { justify-content: flex-start; }
}

@media (max-width: 620px) {
  .video-panel { padding: 12px; }
  .video-stage { min-height: 34vh; }
  .transport { align-items: flex-start; flex-direction: column; }
  .transport-meta { width: 100%; justify-content: space-between; }
  .take-result { flex-wrap: wrap; }
  .sentence-nav { width: 100%; margin-left: 0; padding-left: 0; border-left: 0; }
  .take-result audio { flex-basis: 100%; }
  .script-panel { padding: 14px 12px; }
}
