:root {
  --now: #ffd84d;
  --said: #9fd18f;
  --red: #ff3b30;
  --punch: #ff3b47;
  --glass: rgba(28, 28, 30, 0.58);
  --card: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.12);
  --muted: rgba(255, 255, 255, 0.55);
  --tick-size: 30px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #e8e6e1;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------- moldura ---------- */
.phone {
  /* texto colado no topo (perto da lente); botões numa linha logo abaixo.
     Declarado aqui porque --tick-size é alterado pelo app neste elemento. */
  --tick-top: calc(6px + var(--safe-t));
  --tick-h: calc(var(--tick-size) * 2);
  --bar-top: calc(var(--tick-top) + var(--tick-h) + 2px);
  position: relative;
  width: min(420px, calc((100vh - 48px) * 0.5));
  width: min(420px, calc((100dvh - 48px) * 0.5));
  height: min(880px, calc(100vh - 48px));
  height: min(880px, calc(100dvh - 48px));
  border-radius: 46px;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 30%, #3a3632 0%, #141312 70%);
  box-shadow: 0 0 0 10px #161616, 0 0 0 11px #2c2c2c, 0 40px 80px rgba(0, 0, 0, 0.35);
  user-select: none;
  -webkit-user-select: none;
}

@media (max-width: 560px), (display-mode: standalone) {
  body { background: #000; }
  .phone {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
}

/* ---------- câmera ---------- */
#camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: transparent;
}
#camera.mirror { transform: scaleX(-1); }

.cam-fallback {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 24%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
  line-height: 1.4;
}
.cam-fallback svg { width: 40px; height: 40px; opacity: 0.6; }
.cam-fallback p { margin: 0; max-width: 280px; }

.shade {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}
.shade-top {
  top: 0;
  height: calc(210px + var(--safe-t));
  background: linear-gradient(rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.25) 60%, transparent);
}
.shade-bottom {
  bottom: 0;
  height: 340px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.35) 40%, rgba(0, 0, 0, 0.6));
}

/* ---------- linha de botões (abaixo do texto) ---------- */
.topbar {
  position: absolute;
  top: var(--bar-top);
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 3;
  transition: opacity 0.25s ease;
}
[data-phase="recording"] .topbar .icon-btn,
[data-phase="countdown"] .topbar .icon-btn { opacity: 0; pointer-events: none; }
.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(40, 40, 40, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  padding: 0;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

/* ---------- ticker ---------- */
/* a caixa passa meia linha acima e abaixo do texto para o brilho da ênfase não ser cortado;
   o centro do texto continua no mesmo lugar */
.ticker {
  position: absolute;
  top: calc(var(--tick-top) - var(--tick-size) * 0.5);
  left: 0;
  right: 0;
  height: calc(var(--tick-h) + var(--tick-size));
  overflow: hidden;
  cursor: pointer;
  z-index: 2;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 7%, #000 93%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 7%, #000 93%, transparent 100%);
}
.ticker-track {
  position: absolute;
  left: 0;
  top: 50%;
  white-space: nowrap;
  font-size: var(--tick-size);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
  will-change: transform;
  transform: translate3d(0, -50%, 0);
}
.w {
  position: relative;
  display: inline-block;
  margin-right: 0.38em;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55), 0 0 2px rgba(0, 0, 0, 0.4);
  transition: color 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
  transform-origin: 50% 70%;
}
.w.para { margin-left: 0.9em; }
.w.said { color: var(--said); opacity: 0.78; }
.w.now { color: var(--now); transform: scale(1.08); }

/* ênfase: vermelha, maior, com brilho quando é a palavra da vez */
.w.punch {
  font-size: 1.28em;
  color: var(--punch);
  letter-spacing: -0.02em;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55), 0 2px 12px rgba(0, 0, 0, 0.5);
}
.w.punch.said { color: var(--said); }
.w.punch.now { color: var(--punch); }
.w.punch.now::before {
  content: "";
  position: absolute;
  left: -0.5em;
  right: -0.5em;
  top: 50%;
  height: 2.3em;
  margin-top: -1.15em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M71.9 76L80.9 86.8M61.6 82L66.4 95.1M50 84L50 98M38.4 82L33.6 95.1M28.1 76L19.1 86.8M28.1 24L19.1 13.2M38.4 18L33.6 4.9M50 16L50 2M61.6 18L66.4 4.9M71.9 24L80.9 13.2' fill='none' stroke='white' stroke-opacity='.8' stroke-width='2' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  pointer-events: none;
  z-index: -1;
  animation: burst 0.45s ease-out both;
}
@keyframes burst { from { transform: scale(0.6); opacity: 0; } }

/* segurar: sublinhado amarelo (verde depois de dita) */
.w.hold {
  background: linear-gradient(var(--now), var(--now)) 0 100% / 100% max(3px, 0.09em) no-repeat;
  padding-bottom: 0.06em;
}
.w.hold.said { background-image: linear-gradient(var(--said), var(--said)); }

/* baixar a voz: traço curvo embaixo */
.w.end::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -0.22em;
  height: 0.3em;
  border-bottom: max(2px, 0.07em) solid currentColor;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
  transform: rotate(-3deg);
  opacity: 0.85;
}

/* pausa: ⌞⌟ desenhado em CSS (a fonte do celular pode não ter o caractere) */
.w.pause {
  width: 0.7em;
  height: 0.45em;
  opacity: 0.6;
}
.w.pause::before,
.w.pause::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 0.2em;
  height: 0.2em;
  border-bottom: max(2px, 0.07em) solid currentColor;
}
.w.pause::before { left: 0; border-left: max(2px, 0.07em) solid currentColor; }
.w.pause::after { right: 0; border-right: max(2px, 0.07em) solid currentColor; }
.w.pause.now { opacity: 1; }

/* linha vertical na direção da câmera */
.eye-line {
  position: absolute;
  left: 50%;
  top: calc(var(--tick-top) - 4px);
  height: calc(var(--tick-h) + 26px);
  width: 1px;
  margin-left: -0.5px;
  background: linear-gradient(transparent, rgba(255, 255, 255, 0.5) 25%, rgba(255, 255, 255, 0.5) 70%, transparent);
  pointer-events: none;
  z-index: 1;
}

/* guia de enquadramento: cabeça e ombros */
.frame-guide {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.4s ease;
}
[data-phase="recording"] .frame-guide,
.phone.nocam .frame-guide { opacity: 0; }
.fg-head {
  position: absolute;
  left: 50%;
  top: 18%;
  width: 52%;
  aspect-ratio: 0.76;
  transform: translateX(-50%);
  border: 2.5px dashed rgba(255, 255, 255, 0.5);
  border-radius: 50%;
}
.fg-shoulders {
  position: absolute;
  left: -48%;
  width: 196%;
  top: 90%;
  height: 110%;
  border: 2.5px dashed rgba(255, 255, 255, 0.5);
  border-bottom: 0;
  border-radius: 50% 50% 0 0 / 55% 55% 0 0;
}

.badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 48px);
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 2;
}
.badge.off { opacity: 0; }

/* ---------- contagem / toast ---------- */
/* contagem por cima do texto, perto da câmera, como no Earshot */
.countdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--tick-top) - 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #fff;
  pointer-events: none;
  z-index: 4;
}
.cd-num {
  font-size: 104px;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.5);
}
.cd-num.tick { animation: pop 0.9s ease-out both; }
.cd-label {
  font: 600 12px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.3em;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}
@keyframes pop {
  0% { transform: scale(1.5); opacity: 0; }
  25% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.2; }
}

.toast {
  position: absolute;
  left: 50%;
  top: calc(var(--bar-top) + 48px);
  transform: translateX(-50%);
  max-width: calc(100% - 48px);
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(20, 20, 20, 0.85);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  z-index: 6;
}

/* ---------- painel ---------- */
.panel {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(122px + var(--safe-b));
  padding: 10px;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  z-index: 3;
}
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 58px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 0;
  background: var(--card);
  text-align: left;
}
button.card:active { background: rgba(255, 255, 255, 0.14); }
.card[aria-expanded="true"] { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3); }
.label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.value {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}
.meter {
  height: 6px;
  margin-top: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: #4cd964;
  transform-origin: left center;
  transform: scaleX(0);
}

.pace-slider {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.step-btn {
  height: 32px;
  border-radius: 10px;
  border: 0;
  background: var(--card);
  font-size: 18px;
  font-weight: 700;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--now);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
  margin-top: 10px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.72);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-hint { color: var(--muted); }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.now { background: var(--now); }
.dot.said { background: var(--said); }

/* ---------- controles ---------- */
.controls {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(30px + var(--safe-b));
  display: grid;
  grid-template-columns: 1fr auto auto auto 1fr;
  column-gap: 16px;
  align-items: center;
  z-index: 3;
}
.timer {
  justify-self: end;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.8);
}
.round-btn {
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(40, 40, 40, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
}
.round-btn svg { width: 20px; height: 20px; }
.round-btn:active { background: rgba(255, 255, 255, 0.16); }
.ico-pause,
[data-playing="true"] .ico-play { display: none; }
[data-playing="true"] .ico-pause { display: block; }
[data-phase="countdown"] .round-btn,
[data-phase="recording"] .round-btn,
[data-phase="idle"] .side-label { visibility: hidden; }
.side-label {
  justify-self: start;
  padding: 6px 4px;
  border: 0;
  background: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.8);
}
.rec-btn {
  width: 76px;
  height: 76px;
  padding: 5px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  display: grid;
  place-items: center;
}
.rec-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--red);
  transition: transform 0.2s ease;
}
.rec-btn:active .rec-inner { transform: scale(0.92); }
.rec-inner::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 5px;
  background: #fff;
  transform: scale(0);
  transition: transform 0.2s ease;
}
[data-phase="recording"] .rec-inner::after { transform: scale(1); }
.rec-count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 700;
  color: #fff;
}
[data-phase="recording"] .timer { color: #fff; }
[data-phase="recording"] .timer::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--red);
  vertical-align: 1px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.progress {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(12px + var(--safe-b));
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
  z-index: 3;
}
.progress-fill {
  height: 100%;
  width: 100%;
  background: #fff;
  transform-origin: left center;
  transform: scaleX(0);
}

/* ---------- sheets ---------- */
.sheet {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-b));
  background: rgba(0, 0, 0, 0.45);
  z-index: 10;
  animation: fade 0.2s ease both;
}
.sheet-card {
  width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px 16px;
  border-radius: 22px;
  background: rgba(28, 28, 30, 0.94);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  animation: rise 0.25s ease both;
  overflow-y: auto;
  user-select: text;
  -webkit-user-select: text;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

.sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-meta { font-size: 12px; color: var(--muted); }

.script-picker {
  display: flex;
  gap: 8px;
  align-items: center;
}
#scriptPicker {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
  font-size: 14px;
}
#scriptPicker option { background: #1c1c1e; color: #fff; }

.mark-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.mark-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}
.mark-btn:active { background: rgba(255, 255, 255, 0.16); }
code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  font: 11.5px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap;
}

/* amostras das marcações (legenda, editor, ajuda) */
.lg-punch { color: var(--punch); font-weight: 800; }
.lg-hold {
  font-weight: 700;
  background: linear-gradient(var(--now), var(--now)) 0 100% / 100% 2px no-repeat;
  padding-bottom: 1px;
}
.lg-end { position: relative; font-weight: 700; }
.lg-end::after {
  content: "";
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: -4px;
  height: 5px;
  border-bottom: 1.5px solid currentColor;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.lg-pause {
  position: relative;
  display: inline-block;
  width: 11px;
  height: 7px;
}
.lg-pause::before,
.lg-pause::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 3px;
  height: 3px;
  border-bottom: 1.5px solid currentColor;
}
.lg-pause::before { left: 0; border-left: 1.5px solid currentColor; }
.lg-pause::after { right: 0; border-right: 1.5px solid currentColor; }

#scriptInput {
  width: 100%;
  min-height: 150px;
  flex: 1;
  resize: none;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font: 15px/1.5 inherit;
  font-family: inherit;
  outline: none;
}
#scriptInput:focus { border-color: rgba(255, 216, 77, 0.6); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: rgba(255, 255, 255, 0.8); }

.sheet-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 10px;
}

.pill-btn {
  height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.1);
  font-size: 14px;
  font-weight: 600;
}
.pill-btn.primary { background: #fff; color: #111; border-color: #fff; }
.pill-btn.ghost { background: rgba(255, 255, 255, 0.08); }
.pill-btn:disabled { opacity: 0.4; cursor: default; }

.help-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13.5px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.85);
  overflow-y: auto;
}
kbd {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  margin: 0 1px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
  font: 11px/18px inherit;
  font-family: inherit;
  text-align: center;
}

.label-hint { letter-spacing: 0.06em; opacity: 0.7; }

.mic-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 40vh;
  overflow-y: auto;
  font-size: 13px;
  color: var(--muted);
}
.mic-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  font-size: 14px;
  text-align: left;
}
.mic-item::before {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
}
.mic-item[aria-checked="true"] { border-color: rgba(76, 217, 100, 0.6); background: rgba(76, 217, 100, 0.1); }
.mic-item[aria-checked="true"]::before { border-color: #4cd964; background: radial-gradient(#4cd964 45%, transparent 50%); }

.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  line-height: 1.35;
}
.switch-row input { margin-top: 2px; width: 18px; height: 18px; accent-color: #4cd964; flex: none; }
.switch-row small { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); }
.sheet-note { margin: 0; font-size: 12px; line-height: 1.4; color: var(--muted); }

.review .sheet-card { height: 100%; }
#reviewVideo {
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 14px;
  background: #000;
  object-fit: contain;
}

.brand-line {
  margin: 2px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
.brand-line a { color: rgba(255, 255, 255, 0.85); }
