/* =========================================================
   PromptRec Mac — Design System & Styles
   ========================================================= */

/* --- CSS Variables / Design Tokens --- */
:root {
  --bg: #0a0a0a;
  --bg-elevated: #1a1a1e;
  --surface: rgba(30, 30, 34, 0.82);
  --surface-hover: rgba(44, 44, 50, 0.9);
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.12);
  --text-primary: #f5f5f7;
  --text-secondary: rgba(245, 245, 247, 0.55);
  --text-tertiary: rgba(245, 245, 247, 0.3);
  --accent: #0A84FF;
  --accent-hover: #409CFF;
  --danger: #FF453A;
  --danger-hover: #FF6961;
  --success: #30D158;
  --warning: #FFD60A;
  --ring-thickness: clamp(30px, 4vmin, 80px);
  --ring-color: rgba(255, 250, 240, 0.8);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-panel: 0 8px 32px rgba(0,0,0,0.45), 0 0 0 1px var(--border);
  --transition-fast: 0.15s ease;
  --transition-med: 0.25s ease;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-hover: rgba(240, 240, 245, 0.9);
  --border: rgba(0, 0, 0, 0.08);
  --border-light: rgba(0, 0, 0, 0.12);
  --text-primary: #1d1d1f;
  --text-secondary: rgba(29, 29, 31, 0.55);
  --text-tertiary: rgba(29, 29, 31, 0.25);
  --accent: #007AFF;
  --accent-hover: #0066CC;
  --danger: #FF3B30;
  --danger-hover: #CC2F26;
  --shadow-panel: 0 8px 32px rgba(0,0,0,0.12), 0 0 0 1px var(--border);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  overflow: hidden;
  transition: background var(--transition-med), color var(--transition-med);
  -webkit-font-smoothing: antialiased;
}

/* --- Ring Light (4 solid edge strips, no blur) --- */
.ring-light {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 200;
}
.ring-light::before,
.ring-light::after,
.ring-light .rl-left,
.ring-light .rl-right {
  content: ''; position: fixed;
  background: transparent;
  transition: background 0.3s ease;
}
/* Top strip */
.ring-light::before {
  top: 0; left: 0; right: 0;
  height: var(--ring-thickness);
}
/* Bottom strip */
.ring-light::after {
  bottom: 0; left: 0; right: 0;
  height: var(--ring-thickness);
}
/* Left strip */
.ring-light .rl-left {
  top: 0; left: 0; bottom: 0;
  width: var(--ring-thickness);
}
/* Right strip */
.ring-light .rl-right {
  top: 0; right: 0; bottom: 0;
  width: var(--ring-thickness);
}
.ring-light.on::before,
.ring-light.on::after,
.ring-light.on .rl-left,
.ring-light.on .rl-right {
  background: var(--ring-color);
}

/* --- Toast --- */
#toast-container {
  position: fixed; top: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 10001;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-light);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-panel);
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
  pointer-events: auto;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }

/* --- App Layout --- */
.app-container {
  position: relative;
  width: 100vw; height: 100vh;
  display: flex; flex-direction: column;
}

/* --- Top Bar --- */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 500;
  height: 46px;
  flex-shrink: 0;
  position: relative;
}
.top-bar-left, .top-bar-right { display: flex; align-items: center; gap: 10px; }
.top-bar-center { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; font-weight: 500; font-size: 0.9rem; }
.logo { font-weight: 700; font-size: 0.95rem; letter-spacing: -0.02em; }
.mode-badge {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--accent); color: #fff;
  padding: 2px 8px; border-radius: var(--radius-pill);
}
.top-icon-btn {
  background: transparent; border: none; color: var(--text-secondary);
  cursor: pointer; padding: 6px; border-radius: var(--radius-sm);
  display: flex; align-items: center;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.top-icon-btn:hover { color: var(--text-primary); background: var(--surface-hover); }

/* --- Preview Area --- */
.preview-area {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; background: #000;
}
[data-theme="light"] .preview-area { background: #e8e8ea; }

#live-preview {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}

#audio-visualizer {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}

/* --- Empty State --- */
.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; text-align: center;
  color: var(--text-secondary);
  z-index: 5; padding: 40px;
}
.empty-state h2 { font-size: 1.4rem; font-weight: 600; color: var(--text-primary); }
.empty-state p { font-size: 0.9rem; max-width: 400px; line-height: 1.5; }
.empty-state .hint { font-size: 0.8rem; color: var(--text-tertiary); margin-top: 8px; }
kbd {
  background: var(--surface); border: 1px solid var(--border-light);
  padding: 2px 6px; border-radius: 4px; font-size: 0.8em;
  font-family: var(--font-sans);
}

/* --- Countdown --- */
.countdown-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(8px);
  z-index: 300;
}
#countdown-number {
  font-size: 8rem; font-weight: 700; color: #fff;
  animation: countdown-pulse 1s ease infinite;
  text-shadow: 0 0 60px rgba(10,132,255,0.5);
}
@keyframes countdown-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.7; }
}

/* --- Recording Indicator --- */
.red-dot {
  width: 10px; height: 10px;
  background: var(--danger); border-radius: 50%;
  animation: blink 1s ease infinite alternate;
}
@keyframes blink { from { opacity: 1; } to { opacity: 0.25; } }
#recording-paused-label {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.05em;
  color: var(--warning); text-transform: uppercase;
}

/* --- Mic Level Meter --- */
.mic-meter-container {
  position: absolute; bottom: 110px; left: 20px;
  display: flex; align-items: center; gap: 8px; z-index: 50;
}
.mic-meter-label { font-size: 0.65rem; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.06em; }
.mic-meter-track {
  width: 120px; height: 6px;
  background: rgba(255,255,255,0.08); border-radius: 3px;
  overflow: hidden;
}
.mic-meter-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--success), var(--warning), var(--danger));
  border-radius: 3px;
  transition: width 0.08s linear;
}

/* --- Floating Bar (QuickTime-style bottom controls) --- */
.floating-bar {
  position: fixed; bottom: 32px; left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-light);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  display: flex; align-items: center; gap: 16px;
  z-index: 500;
  box-shadow: var(--shadow-panel);
  transition: opacity var(--transition-med);
}
.bar-section { display: flex; align-items: center; gap: 8px; }
.bar-section + .bar-section { border-left: 1px solid var(--border); padding-left: 16px; }

/* --- Selects --- */
select {
  font-family: var(--font-sans); font-size: 0.8rem; font-weight: 500;
  background: var(--bg-elevated); color: var(--text-primary);
  border: 1px solid var(--border-light);
  padding: 5px 10px; border-radius: var(--radius-sm);
  cursor: pointer; outline: none;
  transition: border-color var(--transition-fast);
  max-width: 150px;
}
select:focus { border-color: var(--accent); }
select option { background: var(--bg-elevated); color: var(--text-primary); }

/* --- Round Buttons --- */
.round-btn {
  width: 42px; height: 42px;
  border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
}
.round-btn:hover { transform: scale(1.08); }
.round-btn:active { transform: scale(0.95); }

.round-btn.record {
  background: rgba(255,255,255,0.12);
  border: 2px solid rgba(255,255,255,0.2);
}
[data-theme="light"] .round-btn.record {
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.15);
}
.record-dot {
  width: 22px; height: 22px;
  background: var(--danger); border-radius: 50%;
  transition: all 0.25s ease;
}
.round-btn.record.is-recording .record-dot {
  width: 14px; height: 14px; border-radius: 3px;
}

.ctrl-btn {
  background: var(--surface-hover); color: var(--text-primary);
  width: 34px; height: 34px;
}

/* --- Icon Buttons --- */
.icon-btn {
  background: transparent; border: none;
  font-size: 1.1rem; cursor: pointer;
  opacity: 0.6; padding: 6px;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  border-radius: var(--radius-sm);
}
.icon-btn:hover { opacity: 1; transform: scale(1.1); }
.icon-btn.active { opacity: 1; background: rgba(10,132,255,0.15); }

/* --- Floating Panels --- */
.floating-panel {
  position: absolute; top: 56px;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: var(--radius-lg);
  z-index: 500;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-panel);
  overflow: hidden;
  animation: panel-in 0.2s ease;
}
.panel-right { right: 16px; }
.panel-offset { top: 56px; right: 330px; }
@keyframes panel-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.panel-header {
  font-weight: 600; font-size: 0.85rem;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}
.close-btn {
  background: transparent; border: none;
  color: var(--text-secondary); font-size: 1.3rem;
  cursor: pointer; line-height: 1;
  transition: color var(--transition-fast);
}
.close-btn:hover { color: var(--text-primary); }

.panel-body {
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; max-height: calc(100vh - 180px);
}

/* --- Form Fields --- */
.field-label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.8rem; font-weight: 500; color: var(--text-secondary);
}
.field-label.compact { gap: 2px; }
.field-label.inline { flex-direction: row; align-items: center; gap: 6px; cursor: pointer; }
.field-label.switch-row { flex-direction: row; align-items: center; justify-content: space-between; }
.field-value { font-weight: 400; color: var(--text-tertiary); margin-left: auto; font-size: 0.75rem; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

textarea {
  font-family: var(--font-sans); font-size: 0.85rem;
  background: rgba(0,0,0,0.15); color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px 10px; resize: vertical;
  outline: none;
  transition: border-color var(--transition-fast);
}
[data-theme="light"] textarea { background: rgba(0,0,0,0.04); }
textarea:focus { border-color: var(--accent); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  background: var(--border-light); border-radius: 2px;
  outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px;
  background: var(--accent); border-radius: 50%;
  border: none; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
input[type="number"] {
  font-family: var(--font-sans); font-size: 0.85rem;
  background: rgba(0,0,0,0.15); color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 5px 8px; width: 80px; outline: none;
}
[data-theme="light"] input[type="number"] { background: rgba(0,0,0,0.04); }
input[type="number"]:focus { border-color: var(--accent); }

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px; height: 15px; cursor: pointer;
}

/* Toggle Switch */
.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border-light); border-radius: 22px;
  transition: background var(--transition-fast);
}
.slider::before {
  content: ''; position: absolute;
  width: 16px; height: 16px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%;
  transition: transform var(--transition-fast);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.help-text {
  font-size: 0.75rem; color: var(--text-tertiary);
  line-height: 1.4; padding: 6px 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.tp-actions { display: flex; gap: 6px; }

/* --- Teleprompter Overlay --- */
#teleprompter-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 20px;
  z-index: 40;
}
.tp-content {
  max-width: 800px; width: var(--tp-width, 60%);
  height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  pointer-events: auto;
  background: rgba(0,0,0,0.5);
  padding: 32px 28px;
  border-radius: var(--radius-lg);
  text-align: center; color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,0.7);
  cursor: grab;
  scroll-behavior: smooth;
}
.tp-content:active { cursor: grabbing; }
/* Custom scrollbar for teleprompter */
.tp-content::-webkit-scrollbar { width: 6px; }
.tp-content::-webkit-scrollbar-track { background: transparent; }
.tp-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.25); border-radius: 3px; }
.tp-content::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.45); }
.tp-content.mirror { transform: scaleX(-1); }
.tp-scroll-inner {
  font-size: 32px; line-height: 1.6;
  white-space: pre-wrap;
  padding-top: 30vh;
  padding-bottom: 60vh;
  user-select: none;
}

/* --- Modals --- */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
  animation: modal-fade-in 0.2s ease;
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  cursor: pointer;
}

.modal-content {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  padding: 28px;
  border-radius: var(--radius-lg);
  width: 90%; max-width: 520px;
  display: flex; flex-direction: column; gap: 18px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  z-index: 1;
  max-height: 85vh; overflow-y: auto;
}
.modal-wide { max-width: 700px; }

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h2 { font-size: 1.15rem; font-weight: 600; }

#recorded-video {
  width: 100%; border-radius: var(--radius-md);
  background: #000; max-height: 380px;
}

.trim-controls {
  display: flex; gap: 12px; align-items: flex-end;
  flex-wrap: wrap;
}

.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  padding-top: 10px; border-top: 1px solid var(--border);
}

/* --- Settings Grid --- */
.settings-grid { display: flex; flex-direction: column; gap: 16px; }
fieldset {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
legend {
  font-weight: 600; font-size: 0.8rem; padding: 0 6px;
  color: var(--text-secondary);
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-sans);
  font-size: 0.82rem; font-weight: 500;
  padding: 7px 16px;
  border-radius: var(--radius-sm); border: none;
  cursor: pointer;
  background: var(--surface-hover); color: var(--text-primary);
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.btn:hover { background: var(--border-light); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-small { padding: 4px 10px; font-size: 0.75rem; }

/* --- Info Modal --- */
.info-body { font-size: 0.85rem; line-height: 1.6; }
.info-body h3 { font-size: 0.95rem; margin: 16px 0 6px; color: var(--text-primary); }
.info-body h3:first-child { margin-top: 0; }
.info-body ul { padding-left: 18px; }
.info-body li { margin-bottom: 4px; color: var(--text-secondary); }
.info-body code { background: var(--surface); padding: 1px 5px; border-radius: 3px; font-size: 0.8em; }

.shortcuts-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.shortcuts-table td, .shortcuts-table th {
  padding: 5px 10px; text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem; color: var(--text-secondary);
}
.shortcuts-table th { color: var(--text-primary); font-weight: 600; }

/* --- Utilities --- */
.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .floating-bar { padding: 8px 12px; gap: 10px; bottom: 16px; flex-wrap: wrap; justify-content: center; }
  .bar-section + .bar-section { border-left: none; padding-left: 0; }
  .floating-panel { width: calc(100vw - 32px); right: 16px; }
  .panel-offset { right: 16px; top: auto; bottom: 16px; }
  select { max-width: 120px; font-size: 0.75rem; }
  .modal-content { padding: 20px; }
}

/* --- Camera PiP Overlay --- */
.pip-overlay {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 240px;
  background: #000;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 0 1px var(--border);
  z-index: 9999;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.pip-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}
#pip-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.pip-drag-handle {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 24px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
  cursor: grab;
  display: flex;
  align-items: flex-start;
  padding: 4px 8px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.pip-overlay:hover .pip-drag-handle {
  opacity: 1;
}
.pip-drag-handle:active {
  cursor: grabbing;
}
.pip-label {
  font-size: 0.65rem;
  color: #fff;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
.pip-controls {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  padding: 4px;
  border-radius: var(--radius-pill);
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.pip-overlay:hover .pip-controls {
  opacity: 1;
}
.pip-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}
.pip-btn:hover {
  background: rgba(255,255,255,0.2);
}
.pip-btn-close {
  color: var(--danger);
}
.pip-btn-close:hover {
  background: rgba(255, 69, 58, 0.2);
}
.pip-resize-handle {
  position: absolute;
  bottom: 0; right: 0;
  width: 16px; height: 16px;
  cursor: se-resize;
  z-index: 10;
}
.pip-resize-handle::after {
  content: '';
  position: absolute;
  bottom: 4px; right: 4px;
  width: 6px; height: 6px;
  border-right: 2px solid rgba(255,255,255,0.5);
  border-bottom: 2px solid rgba(255,255,255,0.5);
}
