/* Ditando
   1. Tokens   2. Base   3. Botões   4. Início   5. Leitura
   6. Pausa    7. Ajustes   8. Horizontal   9. Movimento reduzido */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  --bg: #0c0a1d;
  --bg-2: #15122b;
  --bg-3: #1f1b3d;
  --ink: 12, 10, 29;              /* --bg em RGB, pra véus e sombras */
  --line: #2c2852;
  --line-soft: #221e40;
  --track: #34305c;
  --off: #4a4675;
  --text: #fff;
  --text-2: #ecebf7;
  --mut: #b3b0d6;
  --dim: #807ca8;
  --lavender: #8f93f2;
  --orchid: #d77fd0;
  --peach: #f7c08f;
  --grad: linear-gradient(100deg, var(--lavender) 0%, var(--orchid) 45%, var(--peach) 100%);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.2, 1.5, .35, 1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --gutter-l: max(24px, var(--sal));
  --gutter-r: max(24px, var(--sar));
}

/* 2. Base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); color-scheme: dark; -webkit-text-size-adjust: 100%; }
body {
  font: 16px/1.4 "Inter Tight", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nw { white-space: nowrap; }

* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .12) transparent; }
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 3px; }
::-webkit-scrollbar-button { display: none; }

/* 3. Botões ---------------------------------------------------------------- */
.btn {
  -webkit-appearance: none; appearance: none; border: 0; border-radius: 999px;
  min-height: 58px; max-width: 420px; padding: 0 34px;
  background: #fff; color: var(--bg);
  font-weight: 900; font-size: 16px; letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer; touch-action: manipulation; transition: transform .12s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }

.icon-btn {
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .14); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  cursor: pointer; touch-action: manipulation;
}
.icon-btn svg { width: 20px; height: 20px; fill: #fff; transition: transform .3s var(--spring); }
.icon-btn:active { background: rgba(255, 255, 255, .3); }
.icon-btn:active svg { transform: scale(.8); }

.link { background: none; border: 0; padding: 8px 0 0; color: var(--orchid); font-weight: 700; font-size: 15px; cursor: pointer; }

/* 4. Início ---------------------------------------------------------------- */
#home {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: calc(20px + var(--sat)) var(--gutter-r) calc(72px + var(--sab)) var(--gutter-l);
  background:
    linear-gradient(180deg, rgba(var(--ink), .25) 0%, rgba(var(--ink), 0) 30%, rgba(var(--ink), .75) 62%, var(--bg) 100%),
    url("../img/bg.webp") center 35% / cover no-repeat,
    var(--bg);
}

.brand {
  position: absolute; top: calc(16px + var(--sat)); left: var(--gutter-l);
  font-weight: 900; font-size: 20px; letter-spacing: .04em; text-transform: uppercase;
}

/* contador de pessoas online */
.online {
  position: absolute; top: calc(12px + var(--sat)); right: var(--gutter-r);
  display: flex; align-items: center; gap: 7px; padding: 6px 12px 6px 10px; border-radius: 999px;
  background: rgba(var(--ink), .55); border: 1px solid rgba(255, 255, 255, .08);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 13px; font-weight: 500; color: var(--text-2); font-variant-numeric: tabular-nums;
  opacity: 0; transform: translateY(-6px); transition: opacity .4s, transform .4s var(--ease-out);
}
.online.show { opacity: 1; transform: none; }
.online svg { width: 17px; height: 17px; fill: var(--lavender); }
.online b { font-weight: 800; color: #fff; }
.online.bump svg { animation: bump .5s var(--spring); }

/* título: "ESCUTE" branco + "A LEGENDA" em degradê com reflexo */
h1 { margin: 0; font-weight: 900; text-transform: uppercase; line-height: .9; letter-spacing: -.02em; font-size: clamp(48px, 15vw, 140px); }
h1 span { display: block; width: fit-content; white-space: nowrap; }
h1 .l1 { margin-left: -.035em; color: #fff; animation: rise .7s var(--ease-out) both; } /* ajuste óptico: alinha o E com o A */
h1 .l2 {
  background: linear-gradient(100deg, transparent 42%, rgba(255, 255, 255, .95) 50%, transparent 58%), var(--grad);
  background-size: 300% 100%, 100% 100%; background-repeat: no-repeat;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: rise .7s var(--ease-out) .12s both, shine 6s ease-in-out 1.2s infinite;
}
.lede { margin: 16px 0 24px; font-size: clamp(14px, 4.3vw, 17px); color: var(--text-2); animation: fade .6s ease .35s both; }
#home .btn { width: 100%; animation: fade .6s ease .5s both; }

.notice {
  max-width: 420px; margin: 0 0 14px; padding: 12px 14px; border-radius: 12px;
  background: rgba(var(--ink), .8); border: 1px solid var(--line); font-size: 14px; color: var(--text-2);
}
.notice b { color: #fff; }
.notice a { display: inline-block; margin-top: 8px; color: var(--orchid); font-weight: 800; text-decoration: none; }
.err { max-width: 520px; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: rgba(60, 10, 20, .9); border: 1px solid #6b1d2c; font-size: 14px; }

/* crédito que se digita sozinho, como uma legenda aparecendo */
.credit {
  position: absolute; bottom: calc(18px + var(--sab)); left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 6px;
  background: rgba(0, 0, 0, .55); color: #fff; text-decoration: none; white-space: nowrap;
  font-size: 13px; font-weight: 600; transition: background .2s;
  animation: fade .6s ease .8s both;
}
.credit:hover, .credit:focus-visible { background: rgba(0, 0, 0, .8); }
.credit b { font-weight: 800; }

@keyframes rise { from { opacity: 0; transform: translateY(45%); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes shine { 0% { background-position: 100% 0, 0 0; } 30%, 100% { background-position: 0% 0, 0 0; } }
@keyframes bump { 40% { transform: scale(1.25); } }

/* 5. Leitura --------------------------------------------------------------- */
#run { position: fixed; inset: 0; background: var(--bg); }
#stage { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); touch-action: none; }
video { display: block; width: 100%; height: 100%; background: var(--bg); }

#box { position: absolute; outline: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(var(--ink), .5); touch-action: none; cursor: move; }
#box::before, #box::after { content: ""; position: absolute; width: 16px; height: 16px; border: 3px solid var(--orchid); }
#box::before { left: -5px; top: -5px; border-right: 0; border-bottom: 0; }
#box::after { right: -5px; bottom: -5px; border-left: 0; border-top: 0; }
#handle { position: absolute; right: -22px; bottom: -22px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; touch-action: none; cursor: nwse-resize; }
#handle::after { content: ""; width: 20px; height: 20px; border-radius: 50%; background: var(--orchid); box-shadow: 0 0 0 4px rgba(var(--ink), .5); }
#hint {
  position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -10px); pointer-events: none; white-space: nowrap;
  padding: 7px 12px; border-radius: 999px; background: #fff; color: var(--bg);
  font-size: 12px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase;
}

.bar {
  position: absolute; z-index: 3; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--sat)) max(12px, var(--sar)) 10px max(12px, var(--sal));
  background: linear-gradient(rgba(var(--ink), .8), rgba(var(--ink), 0)); pointer-events: none;
}
.bar > * { pointer-events: auto; }
.icons { display: flex; gap: 8px; }

/* status: barrinhas de equalizador que reagem à voz */
.status { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.eq { display: inline-flex; align-items: center; gap: 2px; height: 14px; }
.eq i { width: 3px; height: 100%; border-radius: 2px; background: linear-gradient(to top, var(--lavender), var(--orchid) 60%, var(--peach)); transform-origin: center; transform: scaleY(.3); }
[data-state="loading"] .eq i { animation: eq-load 1s ease-in-out infinite; }
[data-state="reading"] .eq i { animation: eq-idle 2.4s ease-in-out infinite; }
[data-state="reading"].speaking .eq i { animation: eq-talk .7s ease-in-out infinite; }
[data-state="paused"] .eq i { background: var(--off); transform: scaleY(.25); animation: none; }
.eq i:nth-child(2) { animation-delay: -.25s !important; }
.eq i:nth-child(3) { animation-delay: -.5s !important; }
.eq i:nth-child(4) { animation-delay: -.12s !important; }
@keyframes eq-load { 0%, 100% { transform: scaleY(.2); opacity: .5; } 50% { transform: scaleY(.6); opacity: 1; } }
@keyframes eq-idle { 0%, 100% { transform: scaleY(.25); } 50% { transform: scaleY(.45); } }
@keyframes eq-talk { 0%, 100% { transform: scaleY(.3); } 30% { transform: scaleY(1); } 60% { transform: scaleY(.55); } }

#cap {
  position: absolute; left: 0; right: 0; bottom: 0; text-align: center; pointer-events: none;
  padding: 28px max(16px, var(--sar)) calc(16px + var(--sab)) max(16px, var(--sal));
  background: linear-gradient(rgba(var(--ink), 0), rgba(var(--ink), .87) 40%);
}
#now { font-size: clamp(18px, 5vw, 26px); font-weight: 700; line-height: 1.25; text-shadow: 0 2px 8px var(--bg); }
#now.hint { font-size: 14px; font-weight: 500; color: var(--mut); }

/* 6. Pausa ----------------------------------------------------------------- */
#pause {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 34px;
  background: rgba(var(--ink), .6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity .3s ease;
}
[data-state="paused"] #pause { opacity: 1; pointer-events: auto; }
#pause span { font-size: 12px; font-weight: 900; letter-spacing: .24em; text-transform: uppercase; color: var(--text-2); transform: translateY(8px); opacity: 0; transition: .4s .15s; }
[data-state="paused"] #pause span { transform: none; opacity: 1; }

#play {
  position: relative; width: 104px; height: 104px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--lavender) 0%, var(--orchid) 50%, var(--peach) 100%);
  transform: scale(.3) rotate(-120deg); opacity: 0; transition: transform .6s cubic-bezier(.2, 1.6, .35, 1), opacity .25s;
}
[data-state="paused"] #play { transform: none; opacity: 1; animation: glow 2.4s ease-in-out .6s infinite; }
#play:active { transform: scale(.9); transition-duration: .15s; }
#play svg { position: relative; z-index: 1; display: block; width: 46px; height: 46px; fill: #fff; filter: drop-shadow(0 2px 6px rgba(60, 40, 120, .45)); }
[data-state="paused"] #play svg { animation: nudge 2.4s ease-in-out .6s infinite; }
#play::before { /* anel de luz girando */
  content: ""; position: absolute; inset: -10px; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(215, 127, 208, 0) 0deg, var(--lavender) 120deg, var(--peach) 220deg, rgba(247, 192, 143, 0) 300deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  animation: spin 1.6s linear infinite;
}
#play::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--orchid); opacity: 0; } /* onda */
[data-state="paused"] #play::after { animation: wave 2.4s cubic-bezier(.2, .6, .3, 1) .6s infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes wave { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.9); opacity: 0; } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 24px 2px rgba(215, 127, 208, .45); } 50% { box-shadow: 0 0 48px 8px rgba(143, 147, 242, .6), 0 0 90px 10px rgba(215, 127, 208, .25); } }
@keyframes nudge { 0%, 100% { transform: translateX(0) scale(1); } 50% { transform: translateX(2px) scale(1.06); } }

/* 7. Ajustes --------------------------------------------------------------- */
#veil { position: fixed; inset: 0; z-index: 9; background: rgba(var(--ink), .5); opacity: 0; pointer-events: none; transition: opacity .2s; }
#sheet {
  position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  max-height: 82vh; max-height: 82svh; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 6px 20px calc(20px + var(--sab)); border-radius: 18px 18px 0 0;
  background: var(--bg-2); border-top: 1px solid var(--line);
  transform: translateY(105%); transition: transform .25s var(--ease-out);
}
.settings-open #sheet { transform: none; }
.settings-open #veil { opacity: 1; pointer-events: auto; }
.grab { width: 40px; height: 4px; margin: 6px auto 10px; border-radius: 2px; background: var(--off); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sheet-head b { font-weight: 900; font-size: 13px; letter-spacing: .16em; text-transform: uppercase; }

.field { padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.field:last-child { border-bottom: 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 500; font-size: 15px; }
.row b { font-weight: 900; font-variant-numeric: tabular-nums; }
.row.sub { margin-top: 6px; font-size: 14px; color: var(--mut); }
.note { margin-top: 4px; font-size: 13px; color: var(--dim); }
.tip-box { margin-top: 4px; padding: 12px 14px; border: 0; border-radius: 12px; background: var(--bg-3); font-size: 14px; color: var(--text-2); }
.tip-box b { color: #fff; }
.note a { color: var(--orchid); font-weight: 700; text-decoration: none; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 34px; margin: 2px 0 0; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -10px; border-radius: 50%; background: #fff; }
input[type=range]::-moz-range-thumb { width: 24px; height: 24px; border: 0; border-radius: 50%; background: #fff; }
input[type=range]:disabled { opacity: .3; }

.switch { position: relative; flex: none; width: 50px; height: 30px; }
.switch input { position: absolute; inset: 0; z-index: 1; margin: 0; opacity: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--track); transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--orchid); }
.switch input:checked + span::after { transform: translateX(20px); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.segmented button { min-height: 42px; border: 0; border-radius: 999px; background: transparent; color: var(--mut); font-weight: 900; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; cursor: pointer; }
.segmented button.on { background: #fff; color: var(--bg); }

.voices { display: grid; gap: 6px; margin-top: 10px; }
.voice {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 52px; padding: 12px 14px;
  border-radius: 12px; background: var(--bg); border: 1px solid var(--line); text-align: left; cursor: pointer;
  transition: border-color .2s, background .2s;
}
.voice:active { transform: scale(.99); }
.voice b { font-weight: 700; font-size: 15px; }
.voice small { display: block; margin-top: 2px; color: var(--orchid); font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.voice i { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--off); transition: .2s; }
.voice.on { border-color: #fff; background: var(--bg-3); }
.voice.on i { border-color: var(--orchid); background: var(--orchid); box-shadow: inset 0 0 0 4px var(--bg-3); }
.voices-empty { margin-top: 10px; font-size: 14px; color: var(--dim); }

#preview { display: block; width: 100%; max-height: 90px; margin-top: 8px; border-radius: 6px; background: #fff; object-fit: contain; }

/* 8. Horizontal (modo principal) ------------------------------------------ */
@media (min-aspect-ratio: 1/1) {
  #home {
    justify-content: center; padding-bottom: calc(28px + var(--sab));
    background:
      linear-gradient(90deg, rgba(var(--ink), .85) 0%, rgba(var(--ink), .6) 35%, rgba(var(--ink), .15) 60%, rgba(var(--ink), 0) 75%),
      linear-gradient(0deg, rgba(var(--ink), .45), rgba(var(--ink), 0) 40%),
      url("../img/bg-wide.webp") center / cover no-repeat,
      var(--bg);
  }
  #home .btn { width: auto; }
  .credit { left: auto; right: var(--gutter-r); transform: none; }
}
/* mais largo que 16:9 (celular deitado): imagem inteira, sem zoom, encostada à direita */
@media (min-aspect-ratio: 16/9) {
  #home {
    background:
      linear-gradient(90deg, var(--bg) 0%, rgba(var(--ink), .85) 20%, rgba(var(--ink), .55) 40%, rgba(var(--ink), .1) 62%, rgba(var(--ink), 0) 75%),
      url("../img/bg-wide.webp") right center / auto 100% no-repeat,
      #141130;
  }
}
@media (orientation: landscape) {
  h1 { font-size: clamp(42px, 19vh, 140px); }
  .lede { margin: 12px 0 18px; font-size: clamp(15px, 4.4vh, 19px); }
  #home .btn { min-height: clamp(46px, 13vh, 58px); }

  /* leitura: ícones em coluna na faixa da direita, status no canto */
  .bar { inset: 0 auto 0 0; width: 100%; height: 0; padding: 0; background: none; }
  .status { position: absolute; top: calc(12px + var(--sat)); left: max(14px, var(--sal)); }
  .icons { position: fixed; top: 50%; right: max(12px, var(--sar)); transform: translateY(-50%); flex-direction: column; gap: 12px; }
  .icon-btn { width: 48px; height: 48px; }
  /* texto lido no topo, pra não cobrir a legenda (que fica embaixo) */
  #cap { top: 0; bottom: auto; padding: calc(10px + var(--sat)) calc(84px + var(--sar)) 28px calc(110px + var(--sal)); background: linear-gradient(rgba(var(--ink), .87) 30%, rgba(var(--ink), 0)); }
  #now { font-size: clamp(16px, 5.2vh, 26px); }

  /* ajustes como painel lateral */
  #sheet {
    left: auto; right: 0; top: 0; bottom: 0; margin: 0; width: min(360px, 85vw); max-width: none; max-height: none; height: 100%;
    padding: calc(10px + var(--sat)) max(20px, var(--sar)) calc(16px + var(--sab)) 20px;
    border-radius: 18px 0 0 18px; border-top: 0; border-left: 1px solid var(--line);
    transform: translateX(105%);
  }
  .grab { display: none; }
}

/* 9. Movimento reduzido ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
