:root {
  --bg-primary: #090d16;
  --bg-secondary: #111827;
  --bg-card: rgba(30, 41, 59, 0.72);
  --bg-glass: rgba(15, 23, 42, 0.85);
  --border-subtle: rgba(148, 163, 184, 0.14);
  --accent-primary: #38bdf8;
  --accent-secondary: #818cf8;
  --accent-success: #34d399;
  --accent-warning: #fbbf24;
  --accent-danger: #f87171;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --safe-top: env(safe-area-inset-top, 20px);
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "SF Pro Text", "Helvetica Neue", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea {
  user-select: text;
  -webkit-user-select: text;
  font-family: inherit;
}

/* App Shell */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  position: relative;
}

.view-page {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  padding-top: calc(var(--safe-top) + 8px);
  padding-bottom: calc(var(--safe-bottom) + 68px);
}

.view-page.active {
  display: flex;
}

/* Top Header */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-primary);
  border: 1px solid rgba(56, 189, 248, 0.3);
  -webkit-text-fill-color: var(--accent-primary);
  font-weight: 600;
}

.icon-btn {
  background: rgba(51, 65, 85, 0.45);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn.primary {
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  border-color: rgba(129, 140, 248, 0.4);
  color: #fff;
  font-weight: 600;
}

.icon-btn.danger {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

/* Search & Category Filter Bar */
.toolbar-section {
  padding: 12px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-box {
  display: flex;
  align-items: center;
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 9px 14px;
  gap: 8px;
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 14px;
  width: 100%;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.cat-chip {
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  white-space: nowrap;
  background: rgba(30, 41, 59, 0.6);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
}

.cat-chip.active {
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent-primary);
  border-color: rgba(56, 189, 248, 0.45);
  font-weight: 600;
}

/* Script Cards List */
.scripts-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.script-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 0.15s ease;
}

.script-card:active {
  border-color: var(--accent-primary);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(129, 140, 248, 0.15);
  color: #a5b4fc;
  flex-shrink: 0;
}

.card-excerpt {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  font-size: 12px;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  gap: 8px;
}

.mini-btn {
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.65);
  color: var(--text-main);
  cursor: pointer;
}

.mini-btn.accent {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.4);
  color: var(--accent-primary);
}

.mini-btn.cam {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--accent-success);
}

/* Editor View */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 18px;
  gap: 10px;
  overflow-y: auto;
}

.editor-meta-row {
  display: flex;
  gap: 8px;
}

.title-input {
  flex: 1;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 11px 14px;
  color: var(--text-main);
  font-size: 16px;
  font-weight: 600;
  outline: none;
}

.cat-select {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0 12px;
  color: var(--text-main);
  font-size: 13px;
  outline: none;
}

.editor-tools-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.script-textarea {
  flex: 1;
  min-height: 220px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 14px;
  color: var(--text-main);
  font-size: 16px;
  line-height: 1.65;
  resize: none;
  outline: none;
}

.script-textarea:focus {
  border-color: var(--accent-primary);
}

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(30, 41, 59, 0.5);
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Banned Words Panel */
.banned-result-box {
  display: none;
  background: rgba(127, 29, 29, 0.25);
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.banned-result-box.active {
  display: block;
}

.banned-tag {
  display: inline-block;
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  padding: 2px 8px;
  border-radius: 6px;
  margin: 3px 4px 3px 0;
  font-size: 12px;
  cursor: pointer;
}

/* Bottom Tab Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(62px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 50;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 6px 16px;
}

.nav-item.active {
  color: var(--accent-primary);
  font-weight: 600;
}

.nav-item .nav-icon {
  font-size: 20px;
}

/* =====================================================
   FULLSCREEN PROMPTER & CAMERA OVERLAY
   ===================================================== */
.prompter-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  z-index: 200;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.prompter-overlay.active {
  display: flex;
}

/* Camera Background Layer */
.camera-video-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  display: none;
}

.camera-video-bg.active {
  display: block;
}

.camera-video-bg.mirrored {
  transform: scaleX(-1);
}

/* Ring Light Overlay for dark room selfie fill light */
.ring-light-border {
  position: absolute;
  inset: 0;
  border: 22px solid rgba(255, 250, 240, 0.92);
  box-shadow: inset 0 0 60px rgba(255, 250, 240, 0.85);
  pointer-events: none;
  z-index: 15;
  display: none;
}

.ring-light-border.active {
  display: block;
}

/* Camera Grid Lines */
.camera-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  display: none;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.18) 1px, transparent 1px);
  background-size: 33.333% 33.333%;
}

.camera-grid.active {
  display: block;
}

/* Top Eye-Contact Lens Indicator */
.lens-look-bar {
  position: relative;
  z-index: 20;
  padding-top: calc(var(--safe-top) + 4px);
  padding-bottom: 6px;
  padding-left: 14px;
  padding-right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,0,0.82), rgba(0,0,0,0.2));
}

.lens-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #38bdf8;
  font-weight: 600;
}

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 10px #38bdf8;
  animation: pulseAnim 1.4s infinite ease-in-out;
}

.pulse-dot.recording {
  background: #ef4444;
  box-shadow: 0 0 12px #ef4444;
}

@keyframes pulseAnim {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.55; }
}

/* Eye-Contact Focus Reading Zone (Near Top Camera!) */
.prompter-stage {
  position: relative;
  flex: 1;
  z-index: 10;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.focus-guide-band {
  position: absolute;
  top: 14%;
  left: 0;
  right: 0;
  height: 110px;
  border-top: 2px solid rgba(56, 189, 248, 0.75);
  border-bottom: 2px solid rgba(56, 189, 248, 0.35);
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.14), rgba(129, 140, 248, 0.08));
  pointer-events: none;
  z-index: 12;
  display: flex;
  align-items: center;
}

.focus-arrow {
  position: absolute;
  left: 8px;
  color: #38bdf8;
  font-size: 16px;
  font-weight: bold;
}

/* Scrolling Text Viewport */
.scroll-viewport {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: auto;
  padding-top: 15%;
  padding-bottom: 70%;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.scroll-viewport::-webkit-scrollbar {
  display: none;
}

.scroll-content {
  transition: transform 0.08s linear;
  transform-origin: center center;
}

.scroll-content.mirror-h {
  transform: scaleX(-1);
}

.scroll-content.mirror-v {
  transform: scaleY(-1);
}

.scroll-content.mirror-hv {
  transform: scale(-1, -1);
}

.sentence-line {
  padding: 8px 4px;
  border-radius: 10px;
  transition: opacity 0.2s ease, color 0.2s ease, transform 0.2s ease;
  opacity: 0.78;
  cursor: pointer;
}

.sentence-line.passed {
  opacity: 0.28;
}

.sentence-line.active-line {
  opacity: 1;
  color: #38bdf8;
  font-weight: 700;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
}

/* Voice Recognition Live Status Pill */
.asr-live-pill {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #e2e8f0;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  max-width: 88%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: none;
}

.asr-live-pill.active {
  display: block;
}

/* Prompter Bottom Control Deck */
.prompter-controls {
  position: relative;
  z-index: 25;
  background: rgba(9, 13, 22, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  padding: 12px 16px calc(var(--safe-bottom) + 10px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
}

.slider-group input[type="range"] {
  flex: 1;
  accent-color: var(--accent-primary);
}

.play-fab {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  color: #fff;
  font-size: 20px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(56, 189, 248, 0.4);
}

.rec-fab {
  height: 46px;
  padding: 0 14px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.45);
  white-space: nowrap;
}

.rec-fab.recording {
  background: #dc2626;
  border-color: #fef08a;
  animation: pulseAnim 1s infinite;
}

/* Video Preview & Save-to-Album Modal */
.video-modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.video-modal-mask.active {
  display: flex;
}

.video-modal-card {
  width: 100%;
  max-width: 420px;
  background: #111827;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

.video-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 700;
  color: #f8fafc;
}

.recorded-preview-video {
  width: 100%;
  max-height: 46vh;
  background: #000;
  border-radius: 12px;
  object-fit: contain;
}

.video-modal-tip {
  font-size: 12.5px;
  line-height: 1.5;
  color: #cbd5e1;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
}

.video-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.full-btn {
  width: 100%;
  justify-content: center;
  padding: 13px 16px;
  font-size: 15px;
  border-radius: 12px;
}

/* Countdown Overlay */
.countdown-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.countdown-mask.active {
  display: flex;
}

.countdown-num {
  font-size: 96px;
  font-weight: 800;
  color: #38bdf8;
  text-shadow: 0 0 30px rgba(56, 189, 248, 0.7);
}

/* Toast Notification */
.toast-msg {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  display: none;
}

.toast-msg.show {
  display: block;
}

/* Settings & AI Cards */
.settings-list {
  padding: 14px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setting-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting-card h3 {
  font-size: 15px;
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.text-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
}
