/* ============================================================
   HG Teleprompter — styles
   Dark, functional, brand-aligned. Camera behind text.
   ============================================================ */

:root {
  --bg: #000000;
  --navy: #0D1B2A;
  --panel: #0F2236;
  --panel-2: #13304B;
  --border: #1E3A5F;
  --accent: #5B9BD5;
  --accent-bright: #7DB5E5;
  --text: #FFFFFF;
  --muted: #8BA0B8;
  --danger: #E5736B;
  color-scheme: dark only;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background: var(--bg) !important;
  color: var(--text) !important;
  font-family: 'Inter', sans-serif;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  forced-color-adjust: none;
  -webkit-forced-color-adjust: none;
}

@media (prefers-color-scheme: light) {
  html, body { background: #000 !important; color: #fff !important; }
}

/* Prevent text selection on controls; allow in textarea */
body { -webkit-user-select: none; user-select: none; }
textarea, input, select { -webkit-user-select: text; user-select: text; }

/* ============ CAMERA LAYER ============ */
.camera-feed {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  background: #000;
  display: none; /* shown when camera active */
}
.camera-feed.active { display: block; }
.camera-feed.mirrored { transform: scaleX(-1); }

/* Dark scrim over camera so white text stays readable on any footage */
.camera-scrim {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  display: none;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.35) 30%, rgba(0,0,0,0.35) 70%, rgba(0,0,0,0.75) 100%),
    linear-gradient(180deg, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.2) 25%, rgba(0,0,0,0.2) 75%, rgba(0,0,0,0.6) 100%);
}
.camera-scrim.active { display: block; }

/* Plain background when camera is off — subtle HG navy, not pure flat black */
.no-camera-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(91,155,213,0.06) 0%, transparent 55%),
    linear-gradient(180deg, var(--navy) 0%, #060B12 100%);
}
.no-camera-bg.hidden { display: none; }

/* ============ TOP CONTROLS ============ */
.controls {
  position: fixed;
  top: 0; left: 0; right: 0;
  min-height: 60px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(6, 11, 18, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  transition: opacity 0.35s ease;
}
.controls::-webkit-scrollbar { display: none; }
/* Auto-hidden while scrolling: fade out + go click-through for a clean read */
.controls.hidden { opacity: 0; pointer-events: none; }

.ctrl-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.ctrl-cluster.grow { flex: 1; min-width: 0; justify-content: center; }

/* Subtle dividers so the bar reads as grouped sets, not one button wall */
.ctrl-cluster + .ctrl-cluster {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  padding-left: 12px;
}
/* Don't fence in the flexible script-tabs cluster */
.ctrl-cluster.grow,
.ctrl-cluster.grow + .ctrl-cluster {
  border-left: none;
  padding-left: 0;
}

/* Mirror + front/back camera buttons only matter once the camera is live */
body:not(.camera-active) #camera-flip,
body:not(.camera-active) #camera-switch { display: none; }

.btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:active { transform: scale(0.95); }
.btn:hover { background: var(--panel-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.icon {
  width: 46px;
  height: 46px;
  font-size: 18px;
  padding: 0;
}
.btn.small { padding: 9px 14px; min-height: 40px; font-size: 13px; }
.btn.tiny { padding: 6px 12px; min-height: 34px; font-size: 13px; font-weight: 700; }
.btn-primary {
  background: var(--accent);
  color: var(--navy);
  border-color: var(--accent);
  font-weight: 800;
}
.btn-primary:hover { background: var(--accent-bright); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: rgba(229,115,107,0.12); }
.btn.active-state { background: var(--accent); color: var(--navy); border-color: var(--accent); }

/* Record button */
.btn-record {
  position: relative;
}
.rec-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  display: block;
  transition: all 0.2s;
}
.btn-record.recording {
  border-color: var(--danger);
  background: rgba(229, 115, 107, 0.15);
}
.btn-record.recording .rec-dot {
  border-radius: 3px;       /* dot becomes a square "stop" icon */
  width: 14px;
  height: 14px;
  animation: rec-pulse 1.4s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.rec-timer {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 500;
  color: var(--danger);
  min-width: 44px;
  text-align: center;
  display: none;
}
.rec-timer.active { display: block; }

.readout {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  min-width: 52px;
  text-align: center;
}

/* Script tabs */
.script-tabs {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
}
.script-tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 9px 15px;
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  flex-shrink: 0;
}
.tab:hover { color: var(--text); border-color: var(--accent); }
.tab.active {
  background: var(--accent);
  color: var(--navy);
  border-color: var(--accent);
  font-weight: 700;
}

/* ============ READING GUIDE BAR ============ */
.guide-bar {
  position: fixed;
  left: 0; right: 0;
  top: 50%;
  height: 0;
  z-index: 20;
  pointer-events: none;
  border-top: 2px solid rgba(91,155,213,0.45);
}
.guide-bar::before, .guide-bar::after {
  content: '';
  position: absolute;
  top: -9px;
  width: 0; height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}
.guide-bar::before { left: 10px; border-left: 15px solid var(--accent); }
.guide-bar::after { right: 10px; border-right: 15px solid var(--accent); }

/* ============ SCROLL AREA ============ */
.scroll-area {
  position: fixed;
  inset: 0;
  top: 0;
  z-index: 10;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scroll-area::-webkit-scrollbar { display: none; }

.script-content {
  padding: 46vh 8vw 54vh;
}

.section-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(14px, 2.4vw, 22px);
  font-weight: 500;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 54px 0 22px;
  text-shadow: 0 2px 12px rgba(0,0,0,0.8);
}
.section-label:first-child { margin-top: 0; }

.line {
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: var(--line-size, 52px);
  line-height: 1.26;
  letter-spacing: -0.012em;
  color: var(--text);
  margin-bottom: 26px;
  text-shadow: 0 2px 16px rgba(0,0,0,0.85), 0 0 2px rgba(0,0,0,0.6);
}
.line .hl {
  color: var(--accent-bright);
}

/* ============ EDIT PANEL ============ */
.edit-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(460px, 100vw);
  z-index: 50;
  background: var(--navy);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
  display: flex;
  flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,0.5);
}
.edit-panel.open { transform: translateX(0); }

.edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  padding-top: max(18px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}
.edit-header h2 {
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.edit-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.edit-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.edit-hint {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}
.edit-hint code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--panel);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent-bright);
  font-size: 12px;
}

input[type="text"], select, textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  padding: 12px 14px;
  width: 100%;
}
input[type="text"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea {
  min-height: 280px;
  resize: vertical;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  line-height: 1.6;
}

.edit-toolbar {
  display: flex;
  gap: 6px;
}

.edit-row {
  display: flex;
  gap: 10px;
}
.edit-row .btn { flex: 1; }

.edit-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.edit-actions .btn { flex: 1; }
#edit-save {
  background: var(--accent);
  color: var(--navy);
  border-color: var(--accent);
  font-weight: 700;
  padding: 13px;
}
#edit-save:hover { background: var(--accent-bright); }

.edit-io {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.edit-io .btn { flex: 1; text-align: center; }

.edit-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ============ HINT TOAST ============ */
.hint-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: rgba(15, 34, 54, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 11px 22px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
  transition: opacity 0.5s ease;
  pointer-events: none;
}
.hint-toast.hidden { opacity: 0; }

/* ============ RESPONSIVE ============ */
@media (max-width: 700px) {
  .btn.icon { width: 42px; height: 42px; font-size: 16px; }
  .controls { gap: 6px; padding: 6px 10px; }
  .ctrl-cluster.grow { order: 10; flex-basis: 100%; justify-content: flex-start; }
  /* On narrow screens, let tabs wrap to a second row */
  .controls { flex-wrap: wrap; min-height: auto; }
}

@media (min-width: 1200px) {
  .script-content { padding-left: 12vw; padding-right: 12vw; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
