:root {
  --bg: #0d0d0f;
  --panel: #18181b;
  --panel-border: #2a2a2e;
  --text: #f5f5f5;
  --text-dim: #9a9aa0;
  --red: #ef4444;
  --orange: #f97316;
  --green: #22c55e;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

.view { width: 100%; min-height: 100vh; }

/* ---------- SETUP VIEW ---------- */

#setup-view {
  padding: 2.5rem 1.5rem 4rem;
  display: flex;
  justify-content: center;
}

.setup-container { width: 100%; max-width: 980px; }

.setup-header h1 {
  margin: 0 0 0.35rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.setup-header .subtitle {
  margin: 0 0 2rem;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 800px) {
  .setup-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.settings-panel h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel-row { margin-bottom: 0.75rem; }

.panel-row label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.script-select-row { display: flex; gap: 0.5rem; }

#script-select {
  flex: 1;
}

#script-input {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  background: #101012;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.9rem;
  font-size: 1rem;
  line-height: 1.5;
  font-family: inherit;
}

#script-input:focus, select:focus, input:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
}

.script-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

#script-name {
  flex: 1;
  background: #101012;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
}

.word-count {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

select, .btn-secondary, .btn-primary, #script-name {
  font-family: inherit;
}

select {
  background: #101012;
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
}

.setting { margin-bottom: 1.1rem; }

.setting-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.setting-value { color: var(--text); font-variant-numeric: tabular-nums; }

.setting label { font-size: 0.85rem; color: var(--text-dim); display: block; margin-bottom: 0.35rem; }

.setting select { width: 100%; }

input[type="range"] {
  width: 100%;
  accent-color: var(--orange);
}

.setting-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.setting-toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.85rem;
  margin-bottom: 0.85rem;
  cursor: pointer;
  color: var(--text);
}

.setting-toggle input { margin-top: 0.2rem; accent-color: var(--orange); }
.setting-toggle small { color: var(--text-dim); display: block; }

#camera-settings-group {
  transition: opacity 0.2s ease;
}

#camera-settings-group.dimmed {
  opacity: 0.4;
  pointer-events: none;
}

.device-error {
  margin-top: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 0.82rem;
  line-height: 1.4;
}

.btn-primary, .btn-secondary, .btn-icon {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.12s ease, background 0.15s ease;
}

.btn-primary {
  background: var(--red);
  color: #fff;
  padding: 0.65rem 1.1rem;
  font-size: 0.95rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary:hover { background: #dc2626; }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: #26262b;
  color: var(--text);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  border: 1px solid var(--panel-border);
}

.btn-secondary:hover { background: #303036; }

.btn-icon {
  background: #26262b;
  color: var(--text);
  border: 1px solid var(--panel-border);
  width: 42px;
  font-size: 1rem;
}

.btn-start {
  width: 100%;
  margin-top: 1.5rem;
  padding: 1rem;
  font-size: 1.05rem;
}

.app-footer {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--panel-border);
  text-align: center;
}

.app-footer p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.app-footer a {
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.app-footer a:hover {
  color: var(--orange);
  border-bottom-color: var(--orange);
}

/* ---------- PROMPTER VIEW ---------- */

#prompter-view {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #1a1a1e, #050506);
  overflow: hidden;
}

#camera-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#camera-preview.mirrored { transform: scaleX(-1); }

/* Text sits at the top, right under the front camera lens, so the eyes stay near it. */
#text-overlay-wrap {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 4%;
  right: 4%;
  height: 46%;
  display: flex;
  flex-direction: column;
}

#text-overlay {
  flex: 1;
  overflow: hidden;
  border-radius: 18px;
  padding: 0 3rem;
  background: rgba(0, 0, 0, 0.4);
  -webkit-mask-image: linear-gradient(transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(transparent, #000 12%, #000 88%, transparent);
}

#text-overlay.mirrored { transform: scaleX(-1); }

#scroll-content {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-weight: 600;
  font-size: 48px;
  line-height: 1.4;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 12px rgba(0, 0, 0, 0.6);
  padding: 12vh 0 40vh;
  will-change: transform;
}

.reading-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 30%;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.85), transparent);
  pointer-events: none;
  z-index: 2;
}

#countdown-screen {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

#countdown-number {
  font-size: 14rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 40px rgba(239, 68, 68, 0.6);
}

#rec-indicator {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 6.5rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.6);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  z-index: 4;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse 1.2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#controls-bar {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1.25rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(20, 20, 22, 0.75);
  backdrop-filter: blur(6px);
  padding: 0.6rem;
  border-radius: 999px;
  z-index: 4;
  transition: opacity 0.5s ease;
}

.controls-row { display: flex; align-items: center; gap: inherit; }

.ctrl-btn-text { font-size: 0.95rem; font-weight: 700; }

#controls-bar.faded, .hint-bar.faded {
  opacity: 0;
  pointer-events: none;
}

.ctrl-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: #2a2a2e;
  color: #fff;
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.12s ease;
}

.ctrl-btn:hover { background: #3a3a40; }
.ctrl-btn:active { transform: scale(0.95); }

.ctrl-btn-big { width: 56px; height: 56px; font-size: 1.4rem; background: #3a3a40; }

.ctrl-btn-record {
  width: auto;
  border-radius: 999px;
  padding: 0 1.1rem;
  background: var(--red);
  font-size: 0.95rem;
  font-weight: 600;
  gap: 0.4rem;
}

.ctrl-btn-record:hover { background: #dc2626; }
.ctrl-btn-record.active { background: #7f1d1d; }
.ctrl-btn-record.disabled { opacity: 0.4; pointer-events: none; }

.hint-bar {
  position: absolute;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.55);
  background: rgba(0, 0, 0, 0.4);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  white-space: nowrap;
  transition: opacity 0.5s ease;
  z-index: 4;
}

/* ---------- REVIEW VIEW ---------- */

#review-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.review-container {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

#review-video {
  width: 100%;
  max-height: 70vh;
  border-radius: var(--radius);
  background: #000;
}

.review-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---------- TOAST ---------- */

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: #26262b;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  font-size: 0.9rem;
  max-width: 90vw;
  text-align: center;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transition: opacity 0.3s ease;
}

@media (max-width: 640px) {
  #countdown-number { font-size: 8rem; }
  #text-overlay { padding: 0 1.1rem; }
  #rec-indicator { bottom: calc(env(safe-area-inset-bottom, 0px) + 9.5rem); }
  #controls-bar { gap: 0.5rem; flex-direction: column; border-radius: 26px; }
  .ctrl-btn { width: 40px; height: 40px; font-size: 1rem; }
  .ctrl-btn-big { width: 50px; height: 50px; }
  .ctrl-btn-record { width: auto; padding: 0 1rem; white-space: nowrap; }
  .hint-bar { display: none; }
}
