/* Cores em :root. Um só acento (#f5c02a, o amarelo da linha de leitura) em tudo o que está ativo.
   Tema escuro sempre: é um teleprompter. Contraste mínimo 4,5:1 (verificado por ferramentas/qualidade.mjs). */
:root {
  color-scheme: dark;
  --fundo: #0b1222; --cartao: #141c30; --cartao-alto: #1c2540; --contorno: #26304a; --pega: #3a4566;
  --texto: #ffffff; --suave: #8f9ab4; --chevron: #9aa6c2;
  --acento: #f5c02a; --sobre-acento: #0b1222; --erro: #ff8a80; --erro-cheio: #e5484d;
  --leitor: #05080f;
  --letra-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* os botões têm display próprio: sem isto, "hidden" não os escondia */
html { -webkit-text-size-adjust: 100%; background: var(--fundo); }
body {
  margin: 0; min-height: 100dvh; background: var(--fundo); color: var(--texto);
  font: 16px/1.5 var(--letra-ui); -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.a-ler { overflow: hidden; }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
a { color: var(--acento); }
:focus-visible { outline: 3px solid var(--acento); outline-offset: 2px; }
.saltar { position: absolute; left: .5rem; top: .5rem; background: var(--cartao); color: var(--texto); padding: .5rem 1rem; z-index: 10;
  opacity: 0; pointer-events: none; }   /* só aparece com o Tab; não fica fora do ecrã */
.saltar:focus { opacity: 1; pointer-events: auto; }
.so-leitor { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); white-space: nowrap; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

main { width: 100%; max-width: 44rem; margin: 0 auto; padding: 0 20px 120px; }

/* --- Botões ------------------------------------------------------------- */
button, .botao, input, textarea {
  font: inherit; color: var(--texto); background: none; border: 0; border-radius: 12px; min-height: 48px;
}
button, .botao {
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: 0 1.1rem; font-weight: 600; text-decoration: none; min-width: 48px; -webkit-tap-highlight-color: transparent;
}
.principal { background: var(--acento); color: var(--sobre-acento); }
.principal svg { fill: currentColor; stroke: none; }
.secundario { background: var(--cartao-alto); color: var(--texto); }
.perigo-cheio { background: var(--erro-cheio); color: #fff; }
.grande { min-height: 56px; border-radius: 16px; font-size: 1.05rem; font-weight: 700; }
.texto-acento { color: var(--acento); padding: 0 .5rem; font-weight: 700; }
.icone-topo { width: 48px; height: 48px; padding: 0; border-radius: 50%; color: var(--texto); }
.icone-topo:hover, .icone-topo[aria-expanded="true"] { background: var(--cartao); }
.icone-topo circle { fill: currentColor; stroke: none; }
.icone-topo.perigo { color: var(--erro); }
.barra { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.ficheiro { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* --- Barra de topo ------------------------------------------------------ */
.topo { display: flex; align-items: flex-end; justify-content: space-between; gap: .5rem; padding: 28px 0 20px; }
.topo.compacto { align-items: center; padding: 12px 0; margin: 0 -8px; }
.topo.compacto h2 { flex: 1; font-size: 17px; font-weight: 600; color: var(--suave); text-align: center; letter-spacing: 0; }
.titulos { min-width: 0; }
.marca { display: flex; align-items: center; gap: .45rem; margin: 0 0 6px; color: var(--acento); font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.marca img { border-radius: 6px; }
h1 { font-size: 34px; line-height: 1.1; font-weight: 800; }

/* --- Menu de três pontos ------------------------------------------------ */
.menu {
  position: absolute; right: max(12px, calc(50% - 22rem + 12px)); top: calc(env(safe-area-inset-top) + 84px); z-index: 20;
  width: min(20rem, calc(100% - 24px)); padding: 14px; border-radius: 20px;
  background: var(--cartao-alto); box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.menu-rotulo { margin: 2px 4px 8px; color: var(--suave); font-size: 13px; font-weight: 600; }
.menu-item {
  display: flex; align-items: center; justify-content: flex-start; gap: 14px; width: 100%; min-height: 52px;
  padding: 0 10px; border-radius: 12px; color: var(--texto); font-weight: 500; text-decoration: none; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-within { background: rgba(255, 255, 255, .06); }
.menu-item svg { color: var(--chevron); }
.menu .segmentos { margin-bottom: 10px; }
.menu-rodape { margin: 8px 10px 0; color: var(--suave); font-size: 13px; }

/* --- Controlo segmentado (idioma, contagem) ----------------------------- */
.segmentos { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--fundo); }
.segmentos button {
  flex: 1; min-height: 40px; padding: 0 .4rem; border-radius: 10px; color: var(--chevron); font-size: 15px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.segmentos button[aria-checked="true"] { background: var(--acento); color: var(--sobre-acento); }

/* --- Lista -------------------------------------------------------------- */
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.item {
  width: 100%; min-height: 84px; flex-direction: column; align-items: flex-start; justify-content: center; gap: 6px;
  padding: 20px; border-radius: 16px; background: var(--cartao); text-align: left; position: relative;
}
.item::after {
  content: ""; position: absolute; right: 20px; top: 50%; width: 9px; height: 9px; margin-top: -5px;
  border-right: 2px solid var(--chevron); border-top: 2px solid var(--chevron); transform: rotate(45deg);
}
.item strong { font-size: 17px; font-weight: 600; padding-right: 28px; overflow-wrap: anywhere; }
.item span { color: var(--suave); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.item:active { background: var(--cartao-alto); }
.vazio { color: var(--suave); margin: 8px 0 16px; }
.nota { color: var(--suave); font-size: 14px; margin: 24px 4px 0; padding-right: 72px; } /* não fica debaixo do botão + */
.fab {
  position: fixed; right: max(20px, calc(50% - 22rem + 20px)); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 15;
  width: 56px; height: 56px; padding: 0; border-radius: 50%; background: var(--acento); color: var(--sobre-acento);
  box-shadow: 0 8px 24px rgba(245, 192, 42, .35);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }

/* --- Editor ------------------------------------------------------------- */
.titulo-guiao {
  width: 100%; padding: 4px 0; min-height: 44px; font-size: 26px; font-weight: 800; letter-spacing: -.02em;
  border-radius: 0; caret-color: var(--acento);
}
.titulo-guiao::placeholder, textarea::placeholder { color: #5d6884; }
.titulo-guiao:focus { outline: none; box-shadow: inset 0 -2px 0 var(--acento); }
.contagem { color: var(--suave); font-size: 14px; font-weight: 500; margin: 6px 0 16px; font-variant-numeric: tabular-nums; }
textarea {
  display: block; width: 100%; min-height: 50vh; resize: none; padding: 18px 20px;
  background: var(--cartao); border: 1px solid var(--contorno); border-radius: 16px;
  font-size: 17px; line-height: 1.6; caret-color: var(--acento);
}
textarea:focus { outline: none; border-color: var(--acento); }
.acoes-fundo {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; gap: 12px;
  padding: 16px max(20px, calc(50% - 22rem + 20px)) calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--fundo) 70%, rgba(11, 18, 34, 0));
}
.acoes-fundo .principal { flex: 1; }
.confirmar { background: var(--cartao); border-radius: 16px; padding: 16px 20px; margin-bottom: 16px; }
.confirmar p { margin: 0 0 12px; font-weight: 600; }

/* --- Aviso -------------------------------------------------------------- */
.aviso {
  position: fixed; left: 1rem; right: 1rem; bottom: calc(96px + env(safe-area-inset-bottom)); margin: 0 auto; max-width: 30rem; z-index: 40;
  background: var(--texto); color: var(--fundo); border-radius: 14px; padding: .8rem 1rem; font-weight: 500;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.a-ler .aviso { top: max(1rem, env(safe-area-inset-top)); bottom: auto; }   /* no leitor, não tapa os controlos */
.aviso button { background: var(--fundo); color: var(--texto); min-height: 44px; margin-left: .5rem; }

/* --- Leitor -------------------------------------------------------------- */
.leitor {
  position: fixed; inset: 0; z-index: 30; background: var(--leitor); color: #fff;
  overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  --barra: 140px;
}
.leitor[hidden] { display: none; }
.a-ler #principal { visibility: hidden; }   /* o leitor tapa tudo; o que está por trás não se vê nem se toca */
.video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.janela {
  position: absolute; left: 0; right: 0; top: 0; bottom: var(--barra);
  overflow: hidden; cursor: grab; --guia-y: 30%;
  padding-top: env(safe-area-inset-top);
}
/* As linhas já lidas ficam a 35 %: o olho volta sempre à linha certa. */
.leitor:not(.com-camara) .janela:not(.invertida) {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, .35) 96px, rgba(0, 0, 0, .35) calc(var(--guia-y) - 1.2em), #000 var(--guia-y), #000 calc(100% - 96px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, .35) 96px, rgba(0, 0, 0, .35) calc(var(--guia-y) - 1.2em), #000 var(--guia-y), #000 calc(100% - 96px), transparent 100%);
}
.espelho { position: absolute; inset: 0; }
.espelho.espelho-h { transform: scaleX(-1); }
.espelho.espelho-v { transform: scaleY(-1); }
.espelho.espelho-h.espelho-v { transform: scale(-1, -1); }
.rolo {
  position: absolute; left: 0; right: 0; top: var(--guia-y);
  padding: 0 max(var(--margem, 10%), env(safe-area-inset-left)) 50vh;
  font-size: var(--letra, 44px); line-height: 1.35; font-weight: 700; letter-spacing: .005em;
  white-space: pre-wrap; overflow-wrap: break-word; hyphens: manual; will-change: transform;
}
.guia {
  position: absolute; left: 0; right: 0; top: var(--guia-y); height: 1.35em; font-size: var(--letra, 44px); pointer-events: none;
  border-left: 6px solid var(--acento);
  background: linear-gradient(to right, rgba(245, 192, 42, .28), rgba(245, 192, 42, .08));
}
.guia[hidden] { display: none; }
.definicoes-abertas .janela { bottom: var(--folha, min(45%, 26rem)); --guia-y: 16%; }   /* --folha: a altura da folha (js) */
/* Com a folha aberta a linha fica perto do topo: o esbatido de cima não pode chegar a ela, senão a linha fica meio apagada. */
.leitor:not(.com-camara).definicoes-abertas .janela:not(.invertida) {
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .35) 0, rgba(0, 0, 0, .35) calc(var(--guia-y) - 1.2em), #000 var(--guia-y), #000 calc(100% - 48px), transparent 100%);
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .35) 0, rgba(0, 0, 0, .35) calc(var(--guia-y) - 1.2em), #000 var(--guia-y), #000 calc(100% - 48px), transparent 100%);
}

/* Com câmara: o texto fica numa caixa encostada à lente, com fundo escuro para se ler sobre a imagem. */
.com-camara .janela { background: rgba(5, 8, 15, .72); }
.com-camara[data-lente="cima"] .janela { bottom: auto; height: 42%; --guia-y: 18%; }
.com-camara[data-lente="baixo"] .janela { top: auto; bottom: var(--barra); height: 42%; --guia-y: 18%; }
.com-camara[data-lente="esquerda"] .janela { right: auto; width: 52%; }
.com-camara[data-lente="direita"] .janela { left: auto; width: 52%; }
.com-camara .rolo { font-size: min(var(--letra, 44px), 9vmin); }
.com-camara .guia { font-size: min(var(--letra, 44px), 9vmin); }

.controlos {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; gap: 10px;
  padding: 12px max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(11, 18, 34, .9); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); color: #fff;
}
.ajustes, .transporte { display: flex; align-items: center; justify-content: center; gap: 12px; }
.ajustes { justify-content: space-between; }
.comprimido { display: flex; align-items: center; height: 48px; padding: 0 4px; border-radius: 24px; background: var(--cartao-alto); }
.mini { width: 40px; height: 40px; min-height: 40px; min-width: 40px; padding: 0; border-radius: 50%; color: #fff; }
.mini svg { width: 20px; height: 20px; stroke-width: 2.4; }
.letra span { font-size: 14px; font-weight: 800; }
.letra.maior span { font-size: 21px; }
.vel { min-width: 3.4rem; text-align: center; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; color: #fff; }
.restante { min-width: 4.5rem; text-align: right; font-size: 14px; font-weight: 600; color: var(--chevron); font-variant-numeric: tabular-nums; }
.icone { width: 48px; height: 48px; padding: 0; border-radius: 50%; background: var(--cartao-alto); color: #fff; }
.icone.play {
  width: 72px; height: 72px; background: var(--acento); color: var(--sobre-acento); margin: 0 6px;
  box-shadow: 0 8px 24px rgba(245, 192, 42, .35);
}
.icone.play svg { width: 30px; height: 30px; stroke-width: 2.6; }
.icone.play svg path.so-ler { fill: currentColor; stroke: none; }
.icone .so-pausa, .icone.a-correr .so-ler { display: none; }
.icone.a-correr .so-pausa { display: inline; }
.icone.gravar { color: #ff6b6b; }
.icone.gravar svg circle, .icone.gravar svg rect { fill: currentColor; stroke: none; }
.icone.gravar.a-correr { background: #b4232a; color: #fff; }
.icone[aria-expanded="true"] { background: #fff; color: var(--sobre-acento); }
@media (min-width: 720px) {
  .controlos { flex-direction: row; justify-content: center; align-items: center; gap: 28px; }
  .ajustes { order: 2; gap: 12px; }
  .leitor { --barra: 96px; }
}
.contagem-dec {
  position: absolute; inset: 0 0 var(--barra); display: grid; place-items: center; pointer-events: none;
  font-size: min(40vmin, 14rem); font-weight: 800; color: var(--acento); text-shadow: 0 4px 24px #000;
}
.contagem-dec[hidden], .estado-camara[hidden], .rec[hidden], .definicoes[hidden], .gravado[hidden] { display: none; }
.estado-camara {
  position: absolute; left: 1rem; right: 1rem; bottom: calc(var(--barra) + 1rem); margin: 0 auto; max-width: 32rem;
  background: var(--cartao); color: #fff; border-radius: 14px; padding: .8rem 1rem;
}
.rec {
  position: absolute; right: 1rem; bottom: calc(var(--barra) + .75rem); margin: 0;
  background: #b4232a; color: #fff; border-radius: 999px; padding: .25rem .75rem; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* Definições: folha inferior que não tapa a linha de leitura. */
.definicoes {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; margin: 0 auto; width: min(100%, 36rem);
  max-height: max(min(45%, 26rem), min(100% - 9rem, 27rem)); overflow: auto; touch-action: auto; user-select: text;
  padding: 10px 20px calc(16px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0;
  background: rgba(20, 28, 48, .95); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); color: var(--texto);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .45);
}
.pega { width: 36px; height: 4px; margin: 0 auto 6px; border-radius: 2px; background: var(--pega); }
.folha-topo { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.folha-topo h3 { font-size: 17px; font-weight: 700; letter-spacing: 0; }
.linha {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px;
  border-top: 1px solid rgba(255, 255, 255, .06); font-weight: 500; cursor: pointer;
}
.linha.coluna { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 0; cursor: default; }
.linha input[type="range"] { flex: 0 1 12rem; }
.interruptor {
  -webkit-appearance: none; appearance: none; flex: none; position: relative; width: 60px; height: 40px; min-height: 40px; margin: 0;
  border: 4px solid transparent; background-clip: padding-box;   /* alvo de 40 px, interruptor de 52 x 32 */
  border-radius: 20px; background-color: #26304a; cursor: pointer; transition: background .15s;
}
.interruptor::after {
  content: ""; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: #c9d1e3;
  transition: transform .15s, background .15s;
}
.interruptor:checked { background-color: var(--acento); }
.interruptor:checked::after { transform: translateX(20px); background: var(--sobre-acento); }
input[type="range"] { min-height: 40px; padding: 0; accent-color: var(--acento); background: transparent; }
.ajuda { border-top: 1px solid rgba(255, 255, 255, .06); padding: 4px 0; color: var(--suave); font-size: 14px; }
.ajuda summary { cursor: pointer; font-weight: 600; color: var(--chevron); min-height: 40px; display: flex; align-items: center; }
.ajuda p { margin: 8px 0 0; }
.gravado {
  position: absolute; left: 0; right: 0; bottom: calc(var(--barra) + .75rem); margin: 0 auto; width: min(26rem, calc(100% - 1.5rem));
  background: var(--cartao); color: var(--texto); border-radius: 20px; padding: 18px 20px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  touch-action: auto; user-select: text;
}
.gravado p { margin: 0 0 12px; font-weight: 600; }

@media (max-width: 360px) {
  .ajustes { gap: 6px; }
  .transporte { gap: 8px; }
  .restante { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* A folha cabe inteira no ecrã (auditoria visual, 23/11/2026): linhas mais baixas e, num telemóvel deitado, duas colunas. */
.definicoes .linha { min-height: 48px; }
.definicoes .linha.coluna { gap: 6px; padding: 8px 0; }
@media (orientation: landscape) and (max-height: 560px) {
  .definicoes {
    width: min(100%, 52rem); display: grid; grid-template-columns: 1fr 1fr; column-gap: 28px; align-content: start;
    max-height: calc(100% - 6.5rem);
  }
  .definicoes .pega, .definicoes .folha-topo { grid-column: 1 / -1; }
}
