/* ==========================================================================
   base.css — Reset moderno, tipografia, foco visivel, scrollbar
   Depende de tokens.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. RESET
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  /* Rolagem suave por opcao do usuario; sobrescrita em reduced-motion. */
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Ancoras nao ficam sob a topbar fixa */
  scroll-padding-top: calc(var(--epg-topbar-h) + var(--epg-space-lg));
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--epg-surf-void);
  color: var(--epg-txt);
  font-family: var(--epg-font-sans);
  font-size: var(--epg-fs-base);
  font-weight: var(--epg-fw-regular);
  line-height: var(--epg-lh-base);
  letter-spacing: var(--epg-ls-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* Numeros tabulares em toda a interface: colunas de horario alinhadas. */
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1, 'cv05' 1;
  overflow-x: hidden; /* nenhuma rolagem horizontal na pagina; so na grade */
}

img,
picture,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

svg {
  fill: currentColor;
  flex: none;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  background: none;
  border: none;
}

button {
  cursor: pointer;
  text-align: inherit;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
}

ul,
ol {
  list-style: none;
}

a {
  color: var(--epg-live);
  text-decoration: none;
  text-decoration-color: var(--epg-live-borda);
  text-underline-offset: 0.18em;
  transition: color var(--epg-dur-fast) var(--epg-ease-standard),
              text-decoration-color var(--epg-dur-fast) var(--epg-ease-standard);
}

a:hover {
  color: var(--epg-live-claro);
  text-decoration: underline;
  text-decoration-color: currentColor;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--epg-line);
}

/* Quebra segura para titulos longos de programas */
p,
h1, h2, h3, h4, h5, h6,
li, dd, dt, figcaption {
  overflow-wrap: break-word;
  hyphens: auto;
}

/* --------------------------------------------------------------------------
   2. TIPOGRAFIA
   -------------------------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--epg-font-display);
  font-weight: var(--epg-fw-display);
  line-height: var(--epg-lh-tight);
  letter-spacing: var(--epg-ls-tight);
  color: var(--epg-txt);
  text-wrap: balance;
}

h1 { font-size: var(--epg-fs-3xl); }
h2 { font-size: var(--epg-fs-2xl); }
h3 { font-size: var(--epg-fs-xl); }
h4 { font-size: var(--epg-fs-lg); }
h5 { font-size: var(--epg-fs-base); }
h6 {
  font-size: var(--epg-fs-2xs);
  font-weight: var(--epg-fw-semibold);
  letter-spacing: var(--epg-ls-caps);
  text-transform: uppercase;
  color: var(--epg-txt-3);
}

p { text-wrap: pretty; }

strong, b { font-weight: var(--epg-fw-semibold); }
small { font-size: var(--epg-fs-xs); }

code, kbd, samp, pre, time {
  font-family: var(--epg-font-mono);
  font-variant-numeric: tabular-nums;
}

/* Horarios: mono, tabular, tracking levemente aberto (leitura de relance) */
time {
  font-size: var(--epg-fs-xs);
  font-weight: var(--epg-fw-medium);
  letter-spacing: var(--epg-ls-wide);
  font-feature-settings: 'tnum' 1, 'zero' 1;
}

::selection {
  background-color: var(--epg-noar-fundo-forte);
  color: var(--epg-noar-claro);
}

/* --------------------------------------------------------------------------
   3. UTILITARIOS DE ACESSIBILIDADE
   -------------------------------------------------------------------------- */

/* Conteudo so para leitores de tela */
.epg-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Link de salto — aparece so no foco */
.epg-skip-link {
  position: fixed;
  top: var(--epg-space-sm);
  left: var(--epg-space-sm);
  z-index: var(--epg-z-toast);
  padding: var(--epg-space-sm) var(--epg-space-lg);
  font-size: var(--epg-fs-md);
  font-weight: var(--epg-fw-semibold);
  color: var(--epg-txt-inv);
  background-color: var(--epg-noar);
  border-radius: var(--epg-radius-sm);
  box-shadow: var(--epg-elev-3);
  transform: translateY(-160%);
  transition: transform var(--epg-dur-base) var(--epg-ease-decel);
}

.epg-skip-link:focus-visible {
  transform: translateY(0);
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   4. FOCO VISIVEL
   Anel frio de 2px + halo, sempre destacado do fundo escuro.
   Regra unica para todo elemento interativo; :focus (mouse) nao desenha anel.
   -------------------------------------------------------------------------- */

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--epg-foco);
  outline-offset: 2px;
  border-radius: var(--epg-radius-xs);
}

/* Elementos com fundo proprio ganham halo em vez de offset (evita corte
   dentro de containers com overflow hidden, como a trilha da grade). */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--epg-foco);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--epg-foco-sombra);
}

/* Modo de cores forcadas (Windows High Contrast) */
@media (forced-colors: active) {
  :focus-visible {
    outline: 2px solid CanvasText;
  }
}

/* --------------------------------------------------------------------------
   5. SCROLLBAR ESTILIZADA
   Fina, fria, com trilho quase invisivel — instrumento, nao ornamento.
   -------------------------------------------------------------------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--epg-surf-5) transparent;
}

::-webkit-scrollbar {
  width: var(--epg-scrollbar-w);
  height: var(--epg-scrollbar-w);
}

::-webkit-scrollbar-track {
  background-color: transparent;
  border-radius: var(--epg-radius-pill);
}

::-webkit-scrollbar-thumb {
  background-color: var(--epg-surf-5);
  background-clip: content-box;
  border: 2px solid transparent;
  border-radius: var(--epg-radius-pill);
  transition: background-color var(--epg-dur-fast) var(--epg-ease-standard);
}

::-webkit-scrollbar-thumb:hover {
  background-color: #33445E;
}

::-webkit-scrollbar-thumb:active {
  background-color: var(--epg-noar-borda);
}

/* Canto onde as duas barras se encontram (grade com scroll nos 2 eixos) */
::-webkit-scrollbar-corner {
  background-color: transparent;
}

/* --------------------------------------------------------------------------
   6. MOVIMENTO REDUZIDO
   Desliga animacoes, transicoes e rolagem suave em toda a folha.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
    animation-delay: 0ms;
    transition-duration: 0.01ms;
    transition-delay: 0ms;
    scroll-behavior: auto;
  }
}

/* ==========================================================================
   DESEMPENHO DE ROLAGEM
   A grade chega a 250 cartões e 10 mil elementos. content-visibility deixa o
   navegador PULAR a renderização do que está fora da tela; contain-intrinsic-size
   informa a altura estimada para a barra de rolagem não "pular" enquanto rola.
   Ganho maior no Firefox, que repinta listas longas de forma mais custosa.
   ========================================================================== */

@supports (content-visibility: auto) {
  .epg-linha,
  .epg-item,
  .epg-faixa {
    content-visibility: auto;
  }

  .epg-linha { contain-intrinsic-size: auto var(--epg-linha-h, 6.5rem); }
  .epg-item  { contain-intrinsic-size: auto 4.5rem; }
  .epg-faixa { contain-intrinsic-size: auto 16rem; }
}
