:root {
  --fundo: #0b0d12;
  --fundo-2: #141821;
  --fundo-3: #1d2330;
  --linha: #262d3b;
  --texto: #f3f5f9;
  --texto-2: #9aa3b5;
  --cor: #6d5dfc;
  --cor-2: #8b7dff;
  --verm: #ff5a6a;
  --raio: 14px;
  --topo: env(safe-area-inset-top, 0px);
  --baixo: env(safe-area-inset-bottom, 0px);
  --esq: env(safe-area-inset-left, 0px);
  --dir: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--fundo); color: var(--texto); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; -webkit-user-select: text; user-select: text; }
svg { fill: currentColor; }
[hidden] { display: none !important; }

/* ---------- Entrar ---------- */
#login {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--topo)) 20px calc(24px + var(--baixo));
  background: radial-gradient(120% 60% at 50% 0%, #2a2361 0%, var(--fundo) 60%);
}
.login-caixa { width: 100%; max-width: 400px; text-align: center; }
.login-icone { width: 76px; height: 76px; border-radius: 18px; box-shadow: 0 10px 30px #6d5dfc55; }
.login-caixa h1 { margin: 14px 0 4px; font-size: 28px; }
.sub { color: var(--texto-2); margin: 0 0 22px; }
#form-login { text-align: left; display: grid; gap: 12px; }
#form-login label { display: grid; gap: 6px; font-size: 14px; color: var(--texto-2); }
.opc { opacity: .7; }
#form-login input {
  width: 100%; padding: 14px; border-radius: 12px;
  background: var(--fundo-2); border: 1px solid var(--linha); color: var(--texto);
  font-size: 16px; outline: none;
}
#form-login input:focus { border-color: var(--cor); }
.ou { display: flex; align-items: center; gap: 10px; color: var(--texto-2); font-size: 13px; }
.ou::before, .ou::after { content: ""; flex: 1; height: 1px; background: var(--linha); }
.btn-principal {
  margin-top: 6px; padding: 15px; border-radius: 12px; font-weight: 600; font-size: 17px;
  background: linear-gradient(135deg, var(--cor), #4f8cff); color: #fff;
}
.btn-principal:disabled { opacity: .6; }
.btn-codigo { padding: 12px; color: var(--cor-2); font-weight: 600; font-size: 15px; }
#form-codigo { display: grid; gap: 14px; }
.input-codigo {
  width: 100%; padding: 16px; border-radius: 14px; text-align: center;
  font-size: 34px; letter-spacing: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--fundo-2); border: 1px solid var(--linha); color: var(--texto); outline: none;
}
.input-codigo:focus { border-color: var(--cor); }
.codigo-grande {
  text-align: center; font-size: 46px; font-weight: 800; letter-spacing: 6px; font-variant-numeric: tabular-nums;
  margin: 18px 0 4px; padding: 16px; border-radius: 16px; background: var(--fundo-3);
  -webkit-user-select: text; user-select: text;
}
.erro { color: var(--verm); margin: 0; font-size: 14px; }
.nota { color: var(--texto-2); font-size: 13px; margin-top: 18px; }

/* ---------- Estrutura ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
.topo {
  padding: calc(10px + var(--topo)) calc(16px + var(--dir)) 8px calc(16px + var(--esq));
  background: linear-gradient(var(--fundo) 80%, #0b0d12ee);
  position: relative; z-index: 2;
}
.topo h1 { margin: 4px 0 10px; font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.pesquisa {
  display: flex; align-items: center; gap: 8px;
  background: var(--fundo-3); border-radius: 12px; padding: 0 12px; height: 40px;
}
.pesquisa svg { width: 18px; height: 18px; color: var(--texto-2); flex: none; }
.pesquisa input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--texto); font-size: 16px; height: 100%; }
.pesquisa input::-webkit-search-cancel-button { display: none; }
.limpar { color: var(--texto-2); font-size: 14px; padding: 6px; }
.cats-linha { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.cats { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; flex: 1; scroll-behavior: smooth; }
.cats::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 999px; background: var(--fundo-3); color: var(--texto-2);
  font-size: 14px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.chip.ativa { background: var(--texto); color: #000; font-weight: 600; }
.chip-todas { padding: 7px 10px; display: grid; place-items: center; }
.chip-todas svg { width: 18px; height: 18px; }

.conteudo {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 6px calc(16px + var(--dir)) calc(90px + var(--baixo)) calc(16px + var(--esq));
  overscroll-behavior: contain;
}

/* Abas em baixo (estilo iOS) */
.abas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  padding: 6px var(--dir) calc(6px + var(--baixo)) var(--esq);
  background: rgba(16, 19, 26, .82);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--linha);
}
.abas button { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 4px 0; color: var(--texto-2); font-size: 11px; font-weight: 500; }
.abas svg { width: 25px; height: 25px; }
.abas button.ativa { color: var(--cor-2); }

/* ---------- Listas ---------- */
.lista-canais { display: grid; gap: 2px; grid-template-columns: minmax(0, 1fr); }
.canal {
  display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 12px; text-align: left; width: 100%;
}
.canal:active { background: var(--fundo-3); }
.canal-logo {
  width: 56px; height: 42px; flex: none; border-radius: 8px; background: var(--fundo-2);
  display: grid; place-items: center; overflow: hidden; font-weight: 700; color: var(--texto-2); font-size: 13px;
}
.canal-logo img { width: 100%; height: 100%; object-fit: contain; }
.canal-txt { min-width: 0; flex: 1; }
.canal-nome, .canal-epg { display: block; }
.canal-nome { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canal-epg { font-size: 13px; color: var(--texto-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 18px; }
.canal { cursor: pointer; min-width: 0; }
.canal-fav {
  width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; color: var(--texto-2); margin-right: -6px;
}
.canal-fav:active { background: #ffffff14; }
.canal-fav.ativo { color: var(--verm); }

.grelha { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; }
.poster { text-align: left; min-width: 0; }
.poster-img {
  aspect-ratio: 2 / 3; border-radius: 10px; background: var(--fundo-2) center / cover no-repeat;
  position: relative; overflow: hidden; display: grid; place-items: center; padding: 6px;
  color: var(--texto-2); font-size: 12px; text-align: center;
}
.poster-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.poster-nota {
  position: absolute; top: 6px; right: 6px; background: #000a; color: #ffd166; font-size: 11px;
  padding: 2px 6px; border-radius: 6px; font-weight: 600;
}
.poster-barra { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--verm); }
.poster-nome { font-size: 13px; margin-top: 6px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.secao-titulo { font-size: 20px; font-weight: 700; margin: 18px 0 10px; }
.secao-titulo:first-child { margin-top: 6px; }
.fila { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.fila::-webkit-scrollbar { display: none; }
.fila .poster { width: 110px; flex: none; }

.vazio { text-align: center; color: var(--texto-2); padding: 60px 20px; }
.vazio b { display: block; color: var(--texto); font-size: 18px; margin-bottom: 6px; }
.carregar { display: grid; place-items: center; padding: 50px 0; }
.roda { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--fundo-3); border-top-color: var(--cor-2); animation: roda .8s linear infinite; }
@keyframes roda { to { transform: rotate(360deg); } }
.sentinela { height: 1px; }

/* Conta */
.cartao { background: var(--fundo-2); border-radius: var(--raio); padding: 4px 16px; margin-bottom: 16px; }
.linha-conta { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: .5px solid var(--linha); }
.linha-conta:last-child { border-bottom: 0; }
.linha-conta span:first-child { color: var(--texto-2); }
.linha-conta span:last-child { text-align: right; word-break: break-all; }
.btn-linha { width: 100%; text-align: left; padding: 14px 0; border-bottom: .5px solid var(--linha); color: var(--cor-2); }
.btn-linha:last-child { border-bottom: 0; }
.btn-linha.perigo { color: var(--verm); }
.seg { display: flex; background: var(--fundo-3); border-radius: 10px; padding: 3px; margin: 10px 0 14px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 8px; font-size: 13px; color: var(--texto-2); }
.seg button.ativa { background: var(--fundo); color: var(--texto); font-weight: 600; }
.dica { color: var(--texto-2); font-size: 13px; margin: -6px 0 16px; }

/* ---------- Folha ---------- */
.folha-fundo { position: fixed; inset: 0; background: #0009; z-index: 10; animation: aparece .2s; }
.folha {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-height: calc(100% - 40px - var(--topo)); overflow: hidden;
  background: var(--fundo-2); border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column;
  animation: sobe .28s cubic-bezier(.2, .9, .3, 1);
}
.folha-pega { width: 38px; height: 5px; border-radius: 3px; background: #ffffff30; margin: 8px auto 0; flex: none; }
.folha-fechar {
  position: absolute; top: 12px; right: 14px; z-index: 2; width: 32px; height: 32px; border-radius: 50%;
  background: #000a; color: #fff; font-size: 14px;
}
.folha-corpo { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 0 calc(24px + var(--baixo)); }
@keyframes sobe { from { transform: translateY(100%); } }
@keyframes aparece { from { opacity: 0; } }

.det-capa { height: 210px; background: var(--fundo-3) center / cover no-repeat; position: relative; margin-top: -13px; }
.det-capa::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, var(--fundo-2)); }
.det { padding: 0 18px; margin-top: -60px; position: relative; }
.det h2 { margin: 0 0 6px; font-size: 24px; line-height: 1.2; }
.det-meta { color: var(--texto-2); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 14px; }
.det-meta .estrela { color: #ffd166; }
.det-botoes { display: flex; gap: 10px; margin-bottom: 16px; }
.btn-play {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px;
  border-radius: 12px; background: var(--texto); color: #000; font-weight: 700; font-size: 16px;
}
.btn-play svg { width: 20px; height: 20px; }
.btn-sec { padding: 13px 16px; border-radius: 12px; background: var(--fundo-3); font-weight: 600; }
.btn-sec.ativo { color: var(--verm); }
.det-plot { color: #d5dae4; font-size: 15px; line-height: 1.5; margin: 0 0 12px; -webkit-user-select: text; user-select: text; }
.det-extra { color: var(--texto-2); font-size: 13px; margin: 0 0 6px; }
.temporadas { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 10px 0 12px; }
.temporadas::-webkit-scrollbar { display: none; }
.episodio { display: flex; gap: 12px; padding: 10px 0; border-top: .5px solid var(--linha); text-align: left; width: 100%; align-items: center; }
.ep-img { width: 120px; aspect-ratio: 16 / 9; border-radius: 8px; background: var(--fundo-3) center / cover; flex: none; position: relative; overflow: hidden; }
.ep-txt { min-width: 0; flex: 1; }
.ep-nome { font-weight: 600; font-size: 15px; }
.ep-info { color: var(--texto-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lista-cats { padding: 30px 8px 10px; }
.lista-cats h3 { margin: 0 12px 10px; font-size: 20px; }
.item-cat { display: flex; justify-content: space-between; width: 100%; padding: 13px 12px; border-radius: 10px; text-align: left; }
.item-cat:active, .item-cat.ativa { background: var(--fundo-3); }
.item-cat.ativa { color: var(--cor-2); font-weight: 600; }

/* ---------- Leitor ---------- */
.leitor {
  position: fixed; inset: 0; z-index: 20; background: #000;
  display: flex; flex-direction: column;
  padding: var(--topo) var(--dir) var(--baixo) var(--esq);
}
.leitor.minimizado { opacity: 0; pointer-events: none; }
.leitor-topo { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.leitor-info { flex: 1; min-width: 0; }
.leitor-titulo { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leitor-epg { font-size: 13px; color: var(--texto-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leitor-btn { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.leitor-btn:active { background: #ffffff1a; }
.leitor-btn svg { width: 24px; height: 24px; }
.leitor-btn.grande { width: 56px; height: 56px; background: #ffffff14; }
#leitor-fav.ativo { color: var(--verm); }
.leitor-video { flex: 1; position: relative; display: grid; place-items: center; min-height: 0; }
.leitor-video video { width: 100%; height: 100%; max-height: 100%; background: #000; }
.leitor-estado {
  position: absolute; inset: auto 16px 50% 16px; transform: translateY(50%); text-align: center;
  color: #fff; background: #000c; padding: 16px; border-radius: 14px; font-size: 15px; pointer-events: auto;
}
.leitor-estado .roda { margin: 0 auto 10px; }
.leitor-estado button { margin-top: 12px; padding: 10px 16px; border-radius: 10px; background: var(--fundo-3); font-weight: 600; }
.leitor-baixo { display: flex; justify-content: center; align-items: center; gap: 22px; padding: 12px 0 14px; }
.leitor-txt svg { width: 20px; height: 20px; }
.leitor-txt { display: flex; align-items: center; gap: 8px; color: var(--texto) !important; }
.leitor-txt { padding: 10px 14px; border-radius: 10px; background: #ffffff14; font-size: 14px; color: var(--texto-2); }

.aviso {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--baixo)); z-index: 30;
  background: #222a; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  background-color: rgba(40, 44, 56, .92); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); animation: aparece .2s;
}

/* ---------- Ecrãs maiores ---------- */
@media (min-width: 560px) { .grelha { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 760px) {
  .grelha { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 18px 14px; }
  .lista-canais { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; }
  .folha { left: 50%; right: auto; width: 640px; transform: translateX(-50%); bottom: 50%; transform: translate(-50%, 50%); border-radius: 18px; max-height: 86%; animation: aparece .2s; }
  .folha-pega { display: none; }
  .det-capa { margin-top: 0; height: 280px; }
  .fila .poster { width: 140px; }
}
@media (min-width: 1024px) {
  #app { display: grid; grid-template-rows: auto 1fr; }
  .abas {
    position: fixed; top: 0; bottom: 0; right: auto; width: 92px; flex-direction: column; justify-content: flex-start;
    gap: 6px; padding: calc(20px + var(--topo)) 0 20px; border-top: 0; border-right: .5px solid var(--linha);
  }
  .topo, .conteudo { margin-left: 92px; }
  .topo { padding-left: 32px; padding-right: 32px; }
  .conteudo { padding: 10px 32px 40px; min-height: 0; }
  .grelha { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .lista-canais { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .aviso { bottom: 30px; }
  .pesquisa { max-width: 460px; }
  .fila { margin: 0 -32px; padding: 0 32px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .leitor-topo, .leitor-baixo { position: absolute; left: 0; right: 0; z-index: 2; background: linear-gradient(#000c, transparent); transition: opacity .3s; }
  .leitor-topo { top: 0; padding-top: calc(8px + var(--topo)); padding-left: calc(10px + var(--esq)); padding-right: calc(10px + var(--dir)); }
  .leitor-baixo { bottom: 0; background: linear-gradient(transparent, #000c); padding-bottom: calc(10px + var(--baixo)); }
  .leitor { padding: 0; }
  .leitor.calmo .leitor-topo, .leitor.calmo .leitor-baixo { opacity: 0; pointer-events: none; }
}
