:root {
  --bg: #0d0d0f;
  --panel: #16161a;
  --panel-2: #1e1e24;
  --border: #2a2a32;
  --text: #faf8f5;
  --muted: #8e8e99;
  --primary: #f59e0b;
  --primary-hover: #d97706;
  --danger: #e11d48;
  --danger-hover: #be123c;
  --success: #10b981;
  --highlight-bg: rgba(245, 158, 11, 0.22);
  --highlight-text: #f59e0b;
  --spoken-text: #52525b;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Header */
.topbar {
  height: 52px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
}

.brand h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge-ok {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.1);
}

.badge-warn {
  color: #fde047;
  border-color: rgba(234, 179, 8, 0.35);
  background: rgba(234, 179, 8, 0.1);
}

/* Main Split Layout */
.studio-layout {
  height: calc(100vh - 52px);
  display: grid;
  grid-template-rows: 48% 52%;
  gap: 10px;
  padding: 10px 16px 14px;
}

/* Top Camera Panel */
.camera-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.camera-stage {
  position: relative;
  flex: 1;
  background: #05070c;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}

#cameraPreview {
  height: 100%;
  width: 100%;
  object-fit: contain;
  background: #05070c;
}

#cameraPreview.mirrored {
  transform: scaleX(-1);
}

.camera-hud-top {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.rec-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(11, 15, 23, 0.78);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.rec-dot.recording {
  background: var(--danger);
  animation: pulse 1.1s infinite;
}

.rec-dot.paused {
  background: #eab308;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.rec-timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  margin-left: 4px;
}

.mic-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(11, 15, 23, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 10px;
  border-radius: 999px;
}

.mic-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.mic-bar-track {
  width: 72px;
  height: 7px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
}

.mic-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #eab308, #ef4444);
  transition: width 60ms linear;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 12, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 84px;
  font-weight: 800;
  color: #fff;
  z-index: 5;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  background: rgba(11, 15, 23, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
}

.camera-controls {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.device-selects {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}

.device-selects label {
  display: flex;
  align-items: center;
  gap: 6px;
}

select, input[type="text"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}

select:focus, input[type="text"]:focus, textarea:focus {
  border-color: var(--primary);
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.record-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--panel-2);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: #232e45; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.05); }

.btn-record {
  background: var(--danger);
  color: #fff;
}
.btn-record:hover { background: var(--danger-hover); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-danger-text:hover {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Bottom Script / Teleprompter Panel */
.script-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.script-toolbar {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.script-toolbar-left,
.script-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#scriptSelect {
  max-width: 240px;
}

.mode-switch {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--primary);
  color: #fff;
}

.slider-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.slider-label input[type="range"] {
  width: 72px;
  accent-color: var(--primary);
}

.recite-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.teleprompter-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 10%;
  font-size: 28px;
  line-height: 1.55;
  scroll-behavior: smooth;
  user-select: none;
}

.teleprompter-content .word {
  display: inline-block;
  padding: 1px 4px;
  margin: 0 1px;
  border-radius: 5px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.teleprompter-content .word:hover {
  background: rgba(255, 255, 255, 0.08);
}

.teleprompter-content .word.spoken {
  color: var(--spoken-text);
}

.teleprompter-content .word.current {
  background: var(--highlight-bg);
  color: var(--highlight-text);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.5);
}

.heard-bar {
  padding: 7px 14px;
  border-top: 1px solid var(--border);
  background: rgba(11, 15, 23, 0.7);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.listening-pill {
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.listening-pill.active {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.4);
}

.heard-text {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Edit View */
.edit-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  gap: 10px;
  min-height: 0;
}

.script-title-input {
  width: 100%;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 12px;
}

.script-textarea {
  flex: 1;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  font-family: inherit;
  outline: none;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 720px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header, .modal-footer {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.review-video {
  width: 100%;
  max-height: 360px;
  background: #000;
  border-radius: 8px;
}

.review-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.upload-status {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

/* Library Drawer */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 12, 0.7);
}

.drawer-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.drawer-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h2 {
  margin: 0;
  font-size: 16px;
}

.library-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.library-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.library-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.library-item-title {
  font-weight: 600;
  font-size: 14px;
}

.library-item-meta {
  font-size: 12px;
  color: var(--muted);
}

.library-item video {
  width: 100%;
  border-radius: 6px;
  background: #000;
  max-height: 220px;
}

.library-item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
