:root {
  --bg-viewfinder: #090B0E;
  --bg-housing: #14181F;
  --bg-housing-elevated: #1C222C;
  --border-machined: #262E3B;
  --text-primary: #F6F7F9;
  --text-muted: #9BA5B4;
  --accent-amber: #F5A623;
  --accent-amber-soft: rgba(245, 166, 35, 0.18);
  --tally-red: #E53935;
  --tally-red-glow: rgba(229, 57, 53, 0.35);

  --prompter-bg-alpha: 0.58;
  --prompter-height: 42vh;
  --prompter-font-size: 30px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --punch-hole-safe: max(env(safe-area-inset-top, 0px), 14px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-viewfinder);
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
}

.studio-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-viewfinder);
  overflow: hidden;
}

/* ---------------- Visor da Câmera ---------------- */
.viewfinder-layer {
  position: absolute;
  inset: 0;
  background: var(--bg-viewfinder);
}

#cameraPreview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
  will-change: transform;
  contain: strict;
}

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

.studio-shell.prompt-only #cameraPreview {
  opacity: 0;
}

.camera-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 25%, #161C25 0%, #090B0E 70%);
  z-index: 2;
}

.fallback-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-housing);
  border: 1px solid var(--border-machined);
  border-radius: 18px;
  padding: 24px 20px;
  text-align: center;
}

.fallback-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--accent-amber-soft);
  color: var(--accent-amber);
  display: grid;
  place-items: center;
}

.fallback-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 600;
}

.fallback-card p {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted);
}

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

/* Grade regra dos terços */
.framing-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.framing-grid span {
  position: absolute;
  background: rgba(255, 255, 255, 0.16);
}

.framing-grid span:nth-child(1) { top: 33.33%; left: 0; right: 0; height: 1px; }
.framing-grid span:nth-child(2) { top: 66.66%; left: 0; right: 0; height: 1px; }
.framing-grid span:nth-child(3) { left: 33.33%; top: 0; bottom: 0; width: 1px; }
.framing-grid span:nth-child(4) { left: 66.66%; top: 0; bottom: 0; width: 1px; }

/* ---------------- Barra Superior ---------------- */
.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: calc(var(--punch-hole-safe) + 4px) 12px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, rgba(9, 11, 14, 0.78) 0%, rgba(9, 11, 14, 0) 100%);
  transition: opacity 0.25s ease;
}

.install-btn {
  border-color: rgba(245, 166, 35, 0.65);
  color: var(--accent-amber);
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rec-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(20, 24, 31, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #626D7E;
}

.studio-shell.is-recording .rec-badge {
  border-color: rgba(229, 57, 53, 0.65);
  background: rgba(229, 57, 53, 0.22);
}

.studio-shell.is-recording .rec-dot {
  background: var(--tally-red);
  box-shadow: 0 0 10px var(--tally-red);
  animation: pulseDot 1.1s ease-in-out infinite;
}

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

.meta-pill {
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  background: rgba(20, 24, 31, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--accent-amber);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 500;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(20, 24, 31, 0.74);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-primary);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn.active {
  border-color: var(--accent-amber);
  color: var(--accent-amber);
}

/* ---------------- Janela do Teleprompter ---------------- */
.prompter-dock {
  position: absolute;
  top: calc(var(--punch-hole-safe) + 52px);
  left: 10px;
  right: 10px;
  height: var(--prompter-height);
  z-index: 15;
  border-radius: 16px;
  background: rgba(9, 11, 14, var(--prompter-bg-alpha));
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
}

.studio-shell.prompt-only .prompter-dock {
  top: calc(var(--punch-hole-safe) + 54px);
  height: calc(100dvh - var(--punch-hole-safe) - var(--safe-bottom) - 220px);
  background: rgba(14, 17, 23, 0.96);
}

@media (display-mode: standalone), (display-mode: fullscreen) {
  .prompter-dock {
    top: calc(var(--punch-hole-safe) + 54px);
  }
}

.eyeline-guide {
  position: absolute;
  top: 26%;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  pointer-events: none;
  z-index: 4;
}

.eyeline-marker {
  width: 0;
  height: 0;
  margin-left: 4px;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 9px solid var(--accent-amber);
}

.eyeline-line {
  flex: 1;
  height: 1px;
  margin-left: 6px;
  background: linear-gradient(90deg, rgba(245, 166, 35, 0.48) 0%, rgba(245, 166, 35, 0.06) 80%, transparent 100%);
}

.prompter-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 22px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  mask-image: linear-gradient(180deg, transparent 0%, #000 14%, #000 84%, transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 14%, #000 84%, transparent 100%);
}

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

.prompter-spacer-top {
  height: 24%;
}

.prompter-spacer-bottom {
  height: 76%;
}

.prompter-text {
  font-size: var(--prompter-font-size);
  line-height: 1.46;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  white-space: pre-wrap;
  word-break: break-word;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85);
}

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

.prompter-progress {
  height: 3px;
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
}

.prompter-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-amber);
  transition: width 0.08s linear;
}

/* ---------------- Contagem Regressiva ---------------- */
.countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(9, 11, 14, 0.56);
  backdrop-filter: blur(4px);
}

.countdown-digit {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 112px;
  font-weight: 600;
  color: var(--accent-amber);
  text-shadow: 0 12px 36px rgba(0, 0, 0, 0.65);
}

/* ---------------- Controle Inferior ---------------- */
.control-deck {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 12px 16px calc(var(--safe-bottom) + 16px);
  background: linear-gradient(0deg, rgba(9, 11, 14, 0.92) 45%, rgba(9, 11, 14, 0) 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.quick-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 440px;
  width: 100%;
  margin: 0 auto;
}

.chip-btn {
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(20, 24, 31, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn:active {
  background: rgba(245, 166, 35, 0.22);
  border-color: var(--accent-amber);
}

.shutter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 340px;
  width: 100%;
  margin: 0 auto;
}

.deck-action {
  width: 78px;
  height: 60px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(20, 24, 31, 0.82);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.deck-action.scrolling {
  border-color: var(--accent-amber);
  color: var(--accent-amber);
}

.rec-shutter {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 4px solid rgba(246, 247, 249, 0.92);
  background: transparent;
  padding: 5px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.rec-shutter-core {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--tally-red);
  box-shadow: 0 0 18px var(--tally-red-glow);
  transition: border-radius 0.18s ease, transform 0.18s ease;
}

.studio-shell.is-recording .rec-shutter-core {
  border-radius: 10px;
  transform: scale(0.56);
}

.studio-shell.prompt-only .rec-shutter {
  opacity: 0.35;
}

/* ---------------- Painéis Deslizantes (Sheets) ---------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 7, 10, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-panel {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-housing);
  border-top: 1px solid var(--border-machined);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 20px);
  user-select: text;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: var(--border-machined);
  margin: 0 auto 12px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.sheet-close {
  border: none;
  background: transparent;
  color: var(--accent-amber);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
}

.script-selector-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.editor-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.editor-stats {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--accent-amber);
}

.field-select,
.field-input,
.field-textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border-machined);
  background: var(--bg-housing-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  padding: 11px 12px;
  outline: none;
}

.field-select:focus,
.field-input:focus,
.field-textarea:focus {
  border-color: var(--accent-amber);
}

.field-textarea {
  resize: vertical;
  min-height: 180px;
  line-height: 1.5;
}

.inline-select {
  width: auto;
  padding: 8px 12px;
  font-size: 14px;
}

.sheet-footer {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  flex: 1;
  height: 46px;
  border-radius: 12px;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--accent-amber);
  color: #111318;
}

.btn-secondary {
  background: var(--bg-housing-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-machined);
}

.btn-danger {
  background: rgba(229, 57, 53, 0.16);
  color: #FF8A80;
  border: 1px solid rgba(229, 57, 53, 0.32);
}

.btn-compact {
  flex: 0 0 auto;
  height: 44px;
  padding: 0 14px;
}

/* Ajustes */
.setting-group {
  margin-bottom: 16px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
}

.setting-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--accent-amber);
}

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

.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-machined);
}

.toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
}

.toggle-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent-amber);
  flex-shrink: 0;
}

/* Revisão pós-gravação */
.review-video-wrap {
  width: 100%;
  max-height: 46dvh;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border-machined);
}

#reviewVideo {
  width: 100%;
  max-height: 46dvh;
  display: block;
}

.review-meta {
  margin: 10px 0 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-amber);
}

.review-hint {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  top: calc(var(--safe-top) + 64px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(20, 24, 31, 0.94);
  border: 1px solid var(--accent-amber);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

[hidden] {
  display: none !important;
}
