/* Base variables and reset */
:root {
  --bg-start: 20, 20, 30;
  --bg-end: 40, 40, 60;
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.14);
  --text: #e5e7eb;
  --muted: #cbd5e1;
  --accent: #3b82f6;
  --warn: #d97706;
  --surface: #0f172a;
  --surface-2: #1f2937;
  --yellow: #facc15;
}

/* Visually hidden (for accessible labels) */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font: 500 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  /* Fallback */
  background: url('bg.jpg') center / cover no-repeat fixed, linear-gradient(135deg, rgb(var(--bg-start)), rgb(var(--bg-end)));
  /* Prefer optimized formats when supported */
  background: image-set(
      url('bg.avif') type("image/avif"),
      url('bg.webp') type("image/webp"),
      url('bg.jpg') type("image/jpeg")
    ) center / cover no-repeat fixed,
    linear-gradient(135deg, rgb(var(--bg-start)), rgb(var(--bg-end)));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Layout adjustments for standalone content/SEO pages rendered outside the main app grid */
body.content-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

body.content-page #main {
  flex: 1;
  min-height: 0;
  width: min(960px, calc(100% - 48px));
  margin: 0;
  padding: 24px 24px 80px;
  box-sizing: border-box;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

body.content-page footer.meta-bar {
  width: min(960px, calc(100% - 48px));
  margin: 16px 0 0;
}

.content-top-bar {
  width: min(960px, calc(100% - 48px));
  margin: 24px 0 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.content-top-bar .btn {
  padding: 7px 18px;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.45);
}

.content-top-bar .meta-left,
.content-top-bar .meta-right {
  color: #e5e7eb;
}

a,
a:visited {
  color: #fff;
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9);
  transition: color .2s ease, text-shadow .2s ease;
}

a:hover,
a:focus-visible {
  color: #bae6fd;
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.95);
}

a:active {
  color: #e0f2fe;
  text-shadow: 0 0 6px rgba(255, 255, 255, 1);
}

/* Background elements */
#background-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0;
}
#background-overlay { background: linear-gradient(135deg, rgba(20,20,30,0.8), rgba(40,40,60,0.8)); }

/* Ads default-off switch: keep placeholders hidden unless ads are enabled */
body.ads-off #ad-panel-mobile,
body.ads-off .ad-unit { display: none !important; }

.ad-unit {
  margin: 12px auto 0;
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
}

.ad-unit .ad-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.75);
  color: #e5e7eb;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.ad-unit .ad-close:hover,
.ad-unit .ad-close:focus-visible {
  background: rgba(59, 130, 246, 0.85);
  color: #fff;
}

#script-editor-panel .ad-unit {
  align-self: center;
  width: min(320px, 100%);
}


.ad-unit ins {
  width: 100%;
  min-height: 90px;
  max-width: 100%;
  max-height: 280px;
  display: block;
}

.ad-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Layout */
#main { position: relative; z-index: 1; display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr; gap: 12px; padding: 12px; flex: 1; overflow: hidden; }

#ad-panel-mobile { display: none; }

@media (min-width: 900px) {
  #main { grid-template-columns: 1fr 2fr auto; align-items: stretch; }
}

.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

/* Editor panel */
#script-editor-panel { display: flex; flex-direction: column; padding: 14px; min-height: 0; }
#script-editor-panel .panel-inner { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
#script-editor-panel h2 { margin: 0; font-size: 18px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
#script-editor-panel textarea {
  width: 100%; flex: 1; min-height: 160px; resize: none;
  background: rgba(15,23,42,0.8); color: var(--text);
  border: 1px solid #334155; border-radius: 10px; padding: 10px;
  outline: none; transition: border-color .2s ease;
}
#script-editor-panel textarea:focus { border-color: var(--accent); }

/* Teleprompter */
#teleprompter-container { position: relative; display: flex; flex-direction: column; min-height: 0; }
.teleprompter-display { flex: 1; overflow-y: auto; padding: 24px 4vw; text-align: center; scroll-behavior: smooth; }
.teleprompter-display::-webkit-scrollbar { width: 8px; }
.teleprompter-display::-webkit-scrollbar-track { background: #2d3748; }
.teleprompter-display::-webkit-scrollbar-thumb { background: #4a5568; border-radius: 4px; }
.teleprompter-display::-webkit-scrollbar-thumb:hover { background: #718096; }

.marker { position: absolute; left: 0; top: 40%; width: 100%; transform: translateY(-50%); pointer-events: none; }
.marker-line { height: 3px; background: linear-gradient(to right, rgba(250, 204, 21, 0), rgba(250, 204, 21, 1), rgba(250, 204, 21, 0)); box-shadow: 0 0 10px rgba(250, 204, 21, 0.7); }

.spoken-word { color: var(--yellow); transition: color .25s ease-in-out; }
.spoken-word.current-word { background: rgba(250,204,21,.25); border-radius: 4px; }

.manual-controls { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.icon-btn { width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--glass-border); background: var(--glass-bg); color: var(--text); font-size: 20px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.btn, .icon-btn { user-select: none; -webkit-user-select: none; }
.icon-btn:hover { outline: 2px solid rgba(255,255,255,0.08); }

/* Desktop recordings floating button (relative to teleprompter container) */
.fab { position: absolute; right: 12px; top: 12px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--glass-border); background: var(--glass-bg); color: var(--text); box-shadow: 0 8px 24px rgba(0,0,0,.3); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; z-index: 60; }
.fab:hover { outline: 2px solid rgba(255,255,255,0.08); }
.fab.recordings { border-color: rgba(220,38,38,.35); }
.fab.recordings::before { content: '⏺'; }
/* keep absolute positioning relative to teleprompter container */
.fab .badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; background: #ef4444; color: white; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.4); }

/* Tooltip via data-tip attribute */
.fab[data-tip] { position: relative; }
.fab[data-tip]:hover::after { content: attr(data-tip); position: absolute; top: 110%; right: 0; background: rgba(15,23,42,.95); color: #e5e7eb; border: 1px solid #374151; border-radius: 8px; padding: 6px 8px; font-size: 12px; white-space: nowrap; box-shadow: 0 8px 20px rgba(0,0,0,.35); }
.desktop-only { display: none; }
@media (min-width: 900px) { .desktop-only { display: inline-flex; align-items: center; justify-content: center; } }

/* Enforce desktop-only visibility rules after generic .control rules */
@media (max-width: 899px) { .desktop-only { display: none !important; } }
@media (min-width: 900px) { .desktop-only { display: inline-flex !important; } }

/* Mobile layout: show editor by default; teleprompter only when recording */
@media (max-width: 899px) {
  #teleprompter-container { display: none; }
  body.is-recording #teleprompter-container { display: flex; }
  body.is-recording #script-editor-panel { display: none; }
  /* Mobile: when recordings open, replace script panel */
  #recordings-sidebar { display: none; }
  #recordings-sidebar.open { display: flex; }
  body.mobile-recordings #script-editor-panel { display: none; }
  body.mobile-recordings #recordings-sidebar { display: flex; }
  /* Mobile: privacy view replaces script panel */
  .privacy-panel { display: none; }
  .privacy-panel.open { display: flex; }
  body.mobile-privacy #script-editor-panel { display: none; }
  body.mobile-privacy .privacy-panel { display: flex; }
  /* Mobile: tighten editor spacing */
  #script-editor-panel { padding: 10px; }
  #script-editor-panel .panel-inner { gap: 6px; }
  #script-editor-panel h2 { margin: 0 0 4px; }
  #script-editor-panel .panel-inner p.muted { margin: 2px 0 6px; }
  /* Mobile: show bottom ad panel wrapper, keep hidden by default via body.ads-off */
  #ad-panel-mobile { margin: 0 12px 12px; display: flex; justify-content: center; }
  #ad-panel-mobile .ad-unit { width: min(320px, 100%); margin: 0; }
  /* Compact settings */
  #controls { padding: 6px; }
  .controls-row { gap: 6px; }
  .control { gap: 6px; padding: 4px 6px; background: transparent; border: 0; }
  .control input[type="number"] { width: 56px; }
  .control input[type="range"], .control select, .control input[type="number"] { padding: 4px 6px; font-size: 14px; }
  .btn { padding: 6px 10px; font-size: 14px; }
  .icon-btn { width: 34px; height: 34px; }
  #script-editor-panel .ad-unit { display: none; }
  body.content-page #main {
    width: min(960px, calc(100% - 24px));
    margin: 0;
    padding: 18px 18px 72px;
  }
  body.content-page footer.meta-bar {
    width: min(960px, calc(100% - 24px));
    margin: 12px 0 0;
  }
  .content-top-bar {
    width: min(960px, calc(100% - 24px));
    margin: 16px 0 12px;
    grid-template-columns: 1fr;
    text-align: center;
  }
  .content-top-bar .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Video preview */
#video-preview-container { position: absolute; bottom: 6rem; left: 1rem; width: 200px; height: auto; aspect-ratio: 4 / 3; min-width: 160px; max-width: 360px; min-height: 120px; max-height: 360px; border-radius: 8px; overflow: hidden; border: 2px solid rgba(255,255,255,.2); box-shadow: 0 4px 15px rgba(0,0,0,.4); resize: both; z-index: 70; }
#video-preview-container:hover { border-color: var(--accent); }
#video-preview { width: 100%; height: 100%; object-fit: cover; transform: scaleX(1); cursor: move; }
/* Idle placeholder overlay inside PIP */
.pip-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(15,23,42,.35); color: #e5e7eb; font-size: 38px; pointer-events: none; }

/* Recordings sidebar as in-flow panel */
#recordings-sidebar { padding: 14px; display: none; flex-direction: column; gap: 10px; min-width: 280px; max-height: 100%; overflow: hidden; }
#recordings-sidebar.open { display: flex; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; }
.sidebar-header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.close-btn { background: transparent; color: var(--text); border: 0; font-size: 24px; line-height: 1; cursor: pointer; }
.recordings-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.recordings-list li { background: var(--surface-2); border: 1px solid #374151; padding: 10px; border-radius: 8px; display: flex; flex-direction: column; gap: 8px; }
.recordings-list .recording-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.recordings-list .recording-name { font-weight: 600; }
.recordings-list .recording-actions { display: flex; align-items: center; gap: 8px; }
.recordings-list .recording-player { width: 100%; height: auto; border-radius: 6px; background: #000; }
.recordings-list a { text-decoration: none; color: white; background: var(--accent); border-radius: 6px; padding: 6px 8px; font-size: 12px; }

/* Badge on buttons */
.btn.has-badge { position: relative; }
.btn .badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; background: #ef4444; color: white; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.4); }

/* Mic level meter */
.mic-level { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--glass-border); border-radius: 999px; background: rgba(31,41,55,.35); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.mic-level .mic-dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.6); }
.mic-level .mic-bar { position: relative; width: 120px; height: 8px; background: rgba(255,255,255,.08); border-radius: 999px; overflow: hidden; border: 1px solid rgba(255,255,255,.12); }
.mic-level .mic-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: linear-gradient(90deg, #22c55e, #f59e0b); border-radius: 999px; transition: width .08s linear; }

@media (max-width: 899px) {
  #mic-control { display: none; }
  .mic-level .mic-bar { width: 90px; }
  #reload-devices-btn { display: none; }
}

/* Footer controls */
#controls { position: relative; z-index: 0; margin: 0 12px 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.controls-row { display: flex; align-items: center; gap: 12px; justify-content: center; }
.controls-row.wrap { flex-wrap: wrap; gap: 12px; }
.control { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--glass-border); border-radius: 10px; background: rgba(31,41,55,.35); }
.control#mic-control, #mic-control { max-width: 300px; }
#mic-select { max-width: 100px; }
.control input[type="number"] { width: 64px; text-align: center; }
.control input[type="range"], .control select, .control input[type="number"] {
  background: rgba(31,41,55,.7); color: var(--text); border: 1px solid #374151; border-radius: 8px; padding: 6px 8px;
}
.control.toggle { gap: 12px; }
.toggle-switch { background: transparent; border: 0; padding: 0; cursor: pointer; }
.toggle-switch .track { position: relative; width: 46px; height: 24px; border-radius: 999px; background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.25); display: inline-block; vertical-align: middle; transition: background .2s ease; }
.toggle-switch .thumb { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #e5e7eb; transition: transform .2s ease; }
.toggle-switch[aria-pressed="true"] .track { background: #22c55e; border-color: rgba(255,255,255,0.35); }
.toggle-switch[aria-pressed="true"] .thumb { transform: translateX(22px); }
.link,
.link:visited {
  color: #fff;
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9);
  text-decoration: underline;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.link:hover,
.link:focus-visible {
  color: #bae6fd;
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.95);
}
.version { position: absolute; left: 10px; bottom: 8px; color: #6b7280; font-size: 12px; }
.legal { position: absolute; right: 10px; bottom: 8px; }
.legal a { color: #fff; }
/* Meta bar */
.meta-bar { margin: 0 12px 12px; padding: 8px 12px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.meta-left { justify-self: start; color: #9ca3af; }
.meta-center { justify-self: center; }
.meta-right { justify-self: end; text-align: right; color: #9ca3af; }
.meta-bar a { color: inherit; }
/* Reduce footer meta text size on mobile/desktop */
.meta-bar .small { font-size: 10px; }
body.content-page .meta-bar { margin-top: 16px; }

.content-ad {
  margin: 24px 0;
}

@media (max-height: 700px) {
  body:not(.content-page) .ad-unit {
    padding: 6px;
    margin-top: 8px;
  }
  body:not(.content-page) .ad-unit ins {
    min-height: 40px;
  }
}

@media (min-height: 900px) {
  body:not(.content-page) .ad-unit {
    aspect-ratio: 1 / 1;
    max-width: 320px;
    width: min(320px, calc(100% - 24px));
    margin-left: auto;
    margin-right: auto;
  }
  body:not(.content-page) .ad-unit ins {
    min-height: 280px;
    max-height: 320px;
  }
}

/* Mini countdown next to Start/Stop */
.mini-countdown { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; margin-left: 8px; padding: 0 6px; border-radius: 999px; background: rgba(31,41,55,.6); border: 1px solid rgba(255,255,255,.15); color: #e5e7eb; font-weight: 700; }

/* PWA install banner styles removed; native browser UI is used */

.btn { border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; cursor: pointer; color: white; background: #6b7280; }
.btn.primary { background: var(--accent); }
.btn.warn { background: var(--warn); }
.btn.subtle { background: #374151; }
.btn:disabled { background: #6b7280; cursor: not-allowed; opacity: .7; }
.mobile-only { display: inline-flex; }
@media (min-width: 900px) { .mobile-only { display: none; } }

.trust-panel {
  margin-top: 32px;
  padding: 16px 20px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.6);
}

.trust-panel h2 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1.25rem;
}

.trust-panel p {
  margin-bottom: 12px;
}

.trust-panel ul {
  margin: 0;
  padding-left: 20px;
  list-style: disc;
}

.trust-panel li {
  margin-bottom: 8px;
}

/* Modal overlay for unified panels (privacy/mic/videos) */
.privacy-panel {
  position: fixed; inset: 0; z-index: 2147483000; display: none; flex-direction: column; max-width: 720px; max-height: 80vh;
  margin: auto; padding: 14px; gap: 10px; overflow: hidden;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.privacy-panel.open { display: flex; }
.privacy-panel .privacy-content { overflow-y: auto; }

/* Dim background when modal is open */
/* Background dim removed to avoid mobile interaction issues */

/* Countdown */
#countdown-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.7); z-index: 50; display: flex; align-items: center; justify-content: center; }
#countdown-text { font-size: clamp(4rem, 10vw, 10rem); font-weight: 800; color: #fff; text-shadow: 0 0 20px rgba(0,0,0,.5); animation: pulse 1s infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: 1 } 50% { transform: scale(1.05); opacity: .75 } 100% { transform: scale(1); opacity: 1 } }

/* Loading overlay */
#loading-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.5); z-index: 55; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,.35); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
.loading-text { color: #fff; font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }

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

/* Editor collapse (desktop only) */
@media (min-width: 900px) {
  #script-editor-panel.collapsed { width: 0 !important; padding: 0; overflow: hidden; }
}
