* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: #000; color: #fff; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }

.screen { display: none; position: fixed; inset: 0; }
.screen.active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- Setup ---------- */
#setup {
  background: #0a0a0a;
  padding: max(env(safe-area-inset-top), 24px) 20px max(env(safe-area-inset-bottom), 24px);
  overflow-y: auto;
}
#setup header { padding: 12px 0 24px; }
#setup h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
#setup .sub { color: #666; font-size: 13px; margin-top: 4px; }

.setup-content { display: flex; flex-direction: column; gap: 18px; flex: 1; }

#script {
  flex: 1;
  min-height: 220px;
  padding: 16px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #2a2a2a;
  border-radius: 14px;
  resize: none;
  outline: none;
}
#script:focus { border-color: #007aff; }

.controls-grid { display: flex; flex-direction: column; gap: 14px; }
.controls-grid label { display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: #aaa; }
.controls-grid label span { display: flex; justify-content: space-between; align-items: center; }
.controls-grid label.check { flex-direction: row; align-items: center; gap: 12px; }
.controls-grid input[type=range] { width: 100%; accent-color: #007aff; }
.controls-grid input[type=checkbox] { width: 20px; height: 20px; accent-color: #007aff; }
output { color: #fff; font-variant-numeric: tabular-nums; }

button {
  padding: 16px 24px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 14px;
  background: #2a2a2a;
  color: #fff;
  cursor: pointer;
  transition: transform 0.05s, opacity 0.15s;
}
button:active { transform: scale(0.97); }
button.primary { background: #007aff; }
button.primary:disabled { background: #003d7f; opacity: 0.6; }
.hint { color: #666; font-size: 13px; text-align: center; margin-top: 4px; }

/* ---------- Recorder ---------- */
#recorder { background: #000; }
#preview {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* preview espelhado pra parecer natural */
}

.prompt-overlay {
  position: absolute;
  top: 0;
  left: 0; right: 0;
  height: 55vh; /* faixa só na parte de cima, perto da câmera */
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.25) 50%, rgba(0,0,0,0) 100%);
  -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 78%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 0%, #000 78%, transparent 100%);
}
.prompt-inner {
  position: absolute;
  left: 0; right: 0;
  padding: 0 24px;
  will-change: transform;
}
.prompt-inner .text {
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.95), 0 0 4px rgba(0,0,0,0.9);
  line-height: 1.45;
  max-width: 900px;
  margin: 0 auto;
  text-align: center;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.prompt-inner .text .w {
  transition: opacity 0.25s, color 0.25s, background 0.15s;
  border-radius: 5px;
  padding: 0 2px;
}
.prompt-inner .text .w.spoken {
  opacity: 0.18;
  color: #888;
  text-shadow: none;
}
.prompt-inner .text .w.current {
  background: rgba(255, 212, 0, 0.92);
  color: #1a1300;
  text-shadow: none;
  box-shadow: 0 0 0 3px rgba(255, 212, 0, 0.92);
}

.reading-line {
  position: absolute;
  top: 10%;
  left: 6%; right: 6%;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(255, 212, 0, 0.55) 15%, rgba(255, 212, 0, 0.55) 85%, transparent);
  border-radius: 2px;
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 0 8px rgba(255, 212, 0, 0.3);
}
.reading-line::before, .reading-line::after {
  content: '';
  position: absolute;
  top: 50%; transform: translateY(-50%);
  width: 0; height: 0;
  border-style: solid;
}
.reading-line::before {
  left: -2px;
  border-width: 6px 0 6px 8px;
  border-color: transparent transparent transparent rgba(255, 212, 0, 0.7);
}
.reading-line::after {
  right: -2px;
  border-width: 6px 8px 6px 0;
  border-color: transparent rgba(255, 212, 0, 0.7) transparent transparent;
}

.countdown {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 220px; font-weight: 800;
  background: rgba(0,0,0,0.45);
  z-index: 20;
  text-shadow: 0 4px 20px rgba(0,0,0,0.8);
}

.rec-bar {
  position: absolute;
  top: max(env(safe-area-inset-top), 16px);
  left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  z-index: 5;
}
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ff3b30;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
#timer {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 600;
  background: rgba(0,0,0,0.55);
  padding: 6px 14px;
  border-radius: 100px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.voice-badge {
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 212, 0, 0.85);
  color: #1a1300;
  padding: 5px 12px;
  border-radius: 100px;
}
.voice-debug {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: rgba(255,255,255,0.75);
  background: rgba(0,0,0,0.55);
  padding: 6px 12px;
  border-radius: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 4;
  pointer-events: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.bottom-controls {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom), 20px);
  left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 14px;
  padding: 16px;
  z-index: 5;
}
.bottom-controls button {
  border-radius: 50%;
  padding: 0;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: #fff;
}
.bottom-controls button.ghost { width: 52px; height: 52px; }
.bottom-controls button.ghost.small { font-size: 14px; font-weight: 700; }
.bottom-controls button.rec {
  width: 78px; height: 78px;
  background: #ff3b30;
  position: relative;
}
.bottom-controls button.rec::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.95);
}
.bottom-controls button.stop {
  width: 78px; height: 78px;
  background: #ff3b30;
  position: relative;
}
.bottom-controls button.stop::before {
  content: '';
  position: absolute;
  inset: 26px;
  background: #fff;
  border-radius: 4px;
}

/* ---------- Review ---------- */
#review { background: #000; padding: 0; }
#recorded {
  flex: 1;
  width: 100%;
  height: calc(100% - 100px);
  object-fit: contain;
  background: #000;
}
#review .bottom-controls button {
  width: auto;
  height: 52px;
  border-radius: 14px;
  padding: 0 22px;
  font-size: 15px;
  font-weight: 600;
}
#review .bottom-controls button.ghost { background: rgba(255,255,255,0.12); }
#review .bottom-controls button.primary { background: #007aff; }

/* Landscape ajustes — câmera fica no topo central também */
@media (orientation: landscape) and (max-height: 500px) {
  #setup { padding: 16px 24px; }
  #script { min-height: 100px; }
  .prompt-overlay { height: 70vh; }
  .reading-line { top: 14%; }
}
