/* Modern Clean Theme */
:root {
  --bg-app: #09090b;
  --bg-panel: rgba(24, 24, 27, 0.85);
  --bg-hover: rgba(255, 255, 255, 0.1);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent: #2dd4bf; /* Teal-400 */
  --accent-glow: rgba(45, 212, 191, 0.3);
  --danger: #fb7185;
  --border: rgba(255, 255, 255, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 24px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* Layout & Screens */
#app { height: 100%; width: 100%; }
.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  transition: opacity 0.3s ease;
}

/* Typography */
h1, h2, h3 { font-weight: 600; letter-spacing: -0.025em; }
button { font-family: inherit; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  cursor: pointer;
  border: 1px solid transparent;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  box-shadow: 0 0 15px var(--accent-glow);
}
.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.1); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }

.btn-danger {
  background: rgba(220, 38, 38, 0.2);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.3);
}
.btn-danger:hover { background: rgba(220, 38, 38, 0.3); }

input[type="text"], input[type="password"] {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  color: white;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}
input:focus { border-color: var(--accent); }

/* --- Login Screen --- */
#login-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1e1e24 0%, #09090b 100%);
}
.login-container {
  width: 100%;
  max-width: 380px;
  padding: 2.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  backdrop-filter: blur(12px);
  text-align: center;
}
.logo {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(to right, #2dd4bf, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle { color: var(--text-secondary); margin-bottom: 2rem; font-size: 0.9rem; }
#login-form { display: flex; flex-direction: column; gap: 1rem; }

.error {
  color: #ff6b6b;
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.2);
  padding: 0.75rem;
  border-radius: 8px;
  margin-top: 1.5rem;
  font-size: 0.9rem;
  display: none;
}

.error:not(:empty) {
  display: block;
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* --- Dashboard --- */
.header {
  height: 64px;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.8);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.logo-small { font-size: 1.25rem; }
.dashboard-main {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
.dashboard-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
.scripts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}
.script-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.script-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.05);
}
.script-card h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.script-card .meta { font-size: 0.8rem; color: var(--text-secondary); }

/* --- Editor --- */
.editor-main {
  flex: 1;
  /* display: flex;  <-- Removed flex */
  /* flex-direction: column; <-- Removed */
  display: block;
  position: relative;
  overflow-y: auto; /* Scrollbar moves to edge */
  min-height: 0;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
}
.script-title-input {
  background: transparent !important;
  border: none !important;
  font-size: 1.5rem;
  font-weight: 600;
  padding: 0.25rem 0 !important;
  width: auto;
  flex: 1;
}
.script-title-input:focus { box-shadow: none; }
#script-content {
  display: block; /* Ensure block behavior */
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 2rem 100px 2rem;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  line-height: 1.6;
  resize: none;
  outline: none;
  overflow: hidden; /* Hide textarea scrollbar */
  min-height: 100%; /* Fill container */
}

/* --- Teleprompter View --- */
#teleprompter-screen {
  background: black;
  position: relative;
}
#teleprompter-display {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  cursor: none; /* Hide cursor when presenting */
}
/* Show cursor when moving mouse */
#teleprompter-display:hover { cursor: default; }

#cue-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px; /* Thicker for better visibility */
  background: var(--accent);
  top: 50%; /* Default */
  z-index: 50;
  box-shadow: 0 0 15px var(--accent);
  pointer-events: none;
  opacity: 0.4;
}
#cue-line::after {
  /* Arrow indicator on the left */
  content: '▶';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 14px;
}
#cue-line::before {
  /* Arrow indicator on the right */
  content: '◀';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 14px;
}

#teleprompter-text {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 50vh 10%; /* Big padding so text starts at center */
  text-align: center;
  font-weight: 600;
  line-height: 1.5;
  white-space: pre-wrap;
  will-change: transform;
  /* Use hardware acceleration */
  transform: translateZ(0); 
}
#teleprompter-text.mirrored { transform: scaleX(-1) translateZ(0); }
#teleprompter-text.flipped { transform: scaleY(-1) translateZ(0); }
#teleprompter-text.mirrored.flipped { transform: scale(-1, -1) translateZ(0); }

/* Control Bar (Island Design) */
.controls-bar {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: 100px;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  z-index: 100;
  transition: opacity 0.3s, transform 0.3s;
}

/* Hide controls when inactive in fullscreen OR when playing (handled by JS) */
.controls-hidden .controls-bar {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
  pointer-events: none;
}

.fullscreen-mode .settings-panel {
  bottom: 70px;
}

.ctrl-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
}
.ctrl-btn:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

/* Play Button Special Style */
.ctrl-btn.btn-play {
  background: var(--text-primary);
  color: black;
  width: 48px;
  height: 48px;
  font-size: 1.2rem;
  margin: 0 0.5rem;
}
.ctrl-btn.btn-play:hover {
  transform: scale(1.05);
  background: var(--accent);
}

.divider {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,0.15);
}

/* Speed Control Group */
.speed-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,255,255,0.05);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
}
.speed-val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
  min-width: 2ch;
  text-align: center;
}
.speed-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-right: 0.25rem;
}

/* Settings Modal */
.settings-panel {
  position: absolute;
  bottom: 6rem;
  right: 50%; /* Center relative to parent? No, relative to screen usually better */
  transform: translateX(50%);
  width: 320px;
  background: #18181b;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  z-index: 101;
  animation: slideUp 0.2s ease-out;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateX(50%) translateY(10px); }
  to { opacity: 1; transform: translateX(50%) translateY(0); }
}

.setting-row { margin-bottom: 1.25rem; }
.setting-row:last-child { margin-bottom: 0; }
.setting-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.setting-header span:last-child { color: var(--accent); font-weight: 600; }

/* Custom Range Slider */
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  cursor: pointer;
  margin-top: -6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}
input[type=range]:focus::-webkit-slider-runnable-track { background: rgba(255,255,255,0.2); }

/* Checkbox */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  background: rgba(255,255,255,0.1);
  border-radius: 11px;
  transition: 0.2s;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}
input:checked + .toggle-switch { background: var(--accent); }
input:checked + .toggle-switch::after { transform: translateX(18px); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Editor Footer - Floating Button */
.editor-footer {
  position: absolute;
  bottom: 2rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  pointer-events: none; /* Let clicks pass through area around button */
  z-index: 10;
}

.editor-footer .btn-large {
  pointer-events: auto;
  width: auto;
  min-width: 240px;
  border-radius: 100px;
  padding: 1rem 2.5rem;
  background: var(--accent);
  color: var(--bg-app);
  font-weight: 700;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 4px 20px rgba(45, 212, 191, 0.4); /* Matches teal accent */
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.editor-footer .btn-large:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 30px rgba(45, 212, 191, 0.6);
  filter: brightness(1.1);
}

.editor-footer .btn-large:active {
  transform: translateY(-1px);
}
