/* =====================================================================
   main.css — paleta, tipografia e estrutura das telas
   ---------------------------------------------------------------------
   TABELA DE CORES (tokens em :root — troque aqui e o site inteiro muda)
   ---------------------------------------------------------------------
   TOKEN                        VALOR                       USO
   --color-bg                   #0a0a0b    fundo geral da obra (escuro)
   --color-bg-soft              #141416    fundo da área de vídeo ausente
   --color-bg-missing           #1d1d20    bloco de "vídeo não encontrado"
   --color-text                 #ffffff    texto padrão (briefing)
   --color-text-muted           rgba(255,255,255,.64)  textos secundários
   --color-text-faint           rgba(255,255,255,.38)  dicas/legendas
   --color-title                #ffd400    título do projeto e da tela final
   --color-accent               #ffd400    amarelo de destaque (guia, knob)
   --color-accent-soft          rgba(255,212,0,.18)    halo do nó ativo
   --color-guide-bg             rgba(10,10,11,.72)     fundo do rodapé-guia
   --color-guide-border         rgba(255,255,255,.14)  borda superior do guia
   --color-guide-line           rgba(255,255,255,.22)  linha horizontal base
   --color-guide-node           #ffd400    bolinhas (nós) do guia
   --color-guide-label          rgba(255,255,255,.55)  nomes dos pontos
   --color-guide-label-active   #ffd400    nome do ponto atual
   --color-timebar-bg           rgba(255,255,255,.30)  barra de horários
   --color-timebar-divider      #000000    divisórias horizontais
   --color-timebar-text         #ffffff    rótulos Manhã/Tarde/Noite
   --color-timebar-active-bg    rgba(0,0,0,.55)         área do horário ativo
   --color-timebar-active-mark  #ffd400    marca vertical do horário ativo
   --color-overlay-bg           rgba(10,10,11,.94)     overlay de orientação
   --color-debug-bg             rgba(0,0,0,.72)         overlay de debug
   --color-debug-text           #9dffa1    texto do overlay de debug
   ===================================================================== */

:root {
  /* --- Paleta ------------------------------------------------------ */
  --color-bg: #0a0a0b;
  --color-bg-soft: #141416;
  --color-bg-missing: #1d1d20;

  --color-text: #ffffff;
  --color-text-muted: rgba(255, 255, 255, 0.64);
  --color-text-faint: rgba(255, 255, 255, 0.38);

  --color-title: #ffd400;
  --color-accent: #ffd400;
  --color-accent-soft: rgba(255, 212, 0, 0.18);

  --color-guide-bg: rgba(10, 10, 11, 0.72);
  --color-guide-border: rgba(255, 255, 255, 0.14);
  --color-guide-line: rgba(255, 255, 255, 0.22);
  --color-guide-node: #ffd400;
  --color-guide-label: rgba(255, 255, 255, 0.55);
  --color-guide-label-active: #ffd400;

  --color-timebar-bg: rgba(255, 255, 255, 0.3);
  --color-timebar-divider: #000000;
  --color-timebar-text: #ffffff;
  --color-timebar-active-bg: rgba(0, 0, 0, 0.55);
  --color-timebar-active-mark: #ffd400;

  --color-overlay-bg: rgba(10, 10, 11, 0.94);
  --color-debug-bg: rgba(0, 0, 0, 0.72);
  --color-debug-text: #9dffa1;

  /* --- Tipografia -------------------------------------------------- */
  --font-sans: 'Roboto', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --font-mono: ui-monospace, 'Roboto Mono', Consolas, 'Courier New', monospace;

  /* --- Métricas de layout ------------------------------------------ */
  --guide-height: 70px;
  --timebar-width: 60px;
  --guide-inline-padding: 32px;

  /* --- Tempos (espelham o CONFIG.video, via CSS custom properties) -- */
  --visual-fade: 3s;
  --ui-fade: 0.35s;
}

/* --- Base ---------------------------------------------------------- */

html {
  background: var(--color-bg);
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: 1.4;
  overflow: hidden;
  overscroll-behavior: none;
}

/* Cursor escondido no modo quiosque (briefing §10.2). */
html[data-mode='kiosk'] body,
html[data-mode='kiosk'] body * {
  cursor: none !important;
}

html[data-mode='kiosk'] body {
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  overflow: hidden;
}

/* --- Scroller horizontal com CSS Scroll Snap ---------------------- */

.scroller {
  display: flex;
  flex-flow: row nowrap;
  align-items: stretch;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: auto; /* o scroll é animado por JS (navigation.js) */
  overscroll-behavior-x: none;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.scroller::-webkit-scrollbar {
  display: none;
}

/* Durante a animação por requestAnimationFrame o snap é desligado para o
   navegador não "brigar" com a animação; ele volta ao terminar. */
.scroller.is-scrolling {
  scroll-snap-type: none;
}

.screen {
  position: relative;
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background: var(--color-bg);
}

/* Área de vídeo (uma por tela de ponto/transição) */
.media {
  position: absolute;
  inset: 0;
  background: var(--color-bg-soft);
  overflow: hidden;
}

.media video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transition: opacity var(--visual-fade) linear;
  will-change: opacity;
}

.media video.is-visible {
  opacity: 1;
}

/* Ponto: a imagem só aparece quando o evento `playing` confirma que o vídeo
   está REALMENTE rodando. É o que impede a imagem parada (da transição ou de
   um horário anterior) de ficar em cima do ponto. */
.media[data-media='point'] video {
  opacity: 0;
  /* Sem fade na entrada do ponto (a passagem é o scroll): aparece direto. */
  transition: none;
}

/* O fade de 3s só vale na TROCA DE HORÁRIO (classe temporária). */
.media[data-media='point'].is-crossfading video {
  transition: opacity var(--visual-fade) linear;
}

.media[data-media='point'].is-playing video.is-visible {
  opacity: 1;
}

/* Aviso de buffering (só no modo debug, para não poluir a obra). */
.media::after {
  content: 'bufferizando…';
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--guide-height) + 18px);
  display: none;
  color: var(--color-text-faint);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
}

html[data-debug='true'] .media.is-buffering::after {
  display: block;
}

/* O vídeo da transição é scrubado: não deve ter fade de entrada. */
.media[data-media='transition'] video {
  transition: none;
}

/* --- Fallback: arquivo de mídia ausente (briefing §12) ------------ */

.media__missing {
  position: absolute;
  inset: 0;
  display: none;
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background:
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.03) 0 12px,
      rgba(255, 255, 255, 0.06) 12px 24px
    ),
    var(--color-bg-missing);
}

.media.is-missing .media__missing {
  display: grid;
}

.media__missing-title {
  color: var(--color-text-muted);
  font-size: clamp(14px, 1.4vw, 20px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.media__missing-file {
  color: var(--color-text-faint);
  font-family: var(--font-mono);
  font-size: clamp(12px, 1.1vw, 15px);
  word-break: break-all;
}

/* Indicador de scrub da transição (visível no debug ou quando falta o
   arquivo — ajuda a validar o knob mesmo sem mídia). */
.scrub-meter {
  position: absolute;
  left: var(--timebar-width);
  right: 0;
  bottom: var(--guide-height);
  height: 2px;
  background: rgba(255, 255, 255, 0.12);
  opacity: 0;
  transition: opacity var(--ui-fade) linear;
  pointer-events: none;
}

.scrub-meter__bar {
  width: 0;
  height: 100%;
  background: var(--color-accent);
}

html[data-debug='true'] .scrub-meter,
.screen--transition:has(.media.is-missing) .scrub-meter {
  opacity: 1;
}

/* --- Tela inicial -------------------------------------------------- */

.screen--initial {
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 50% 10%, rgba(255, 212, 0, 0.06) 0%, transparent 60%),
    var(--color-bg);
}

.initial {
  display: grid;
  justify-items: center;
  gap: clamp(18px, 3vh, 34px);
  padding: 0 6vw;
  text-align: center;
}

.initial__title {
  color: var(--color-title);
  font-size: clamp(38px, 8.2vw, 128px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 0.96;
  text-transform: none;
}

.initial__hint {
  color: var(--color-text-faint);
  font-size: clamp(11px, 1vw, 14px);
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

/* --- Tela final ---------------------------------------------------- */

.screen--final {
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 50% 100%, rgba(255, 212, 0, 0.05) 0%, transparent 60%),
    var(--color-bg);
}

.final {
  display: grid;
  justify-items: center;
  gap: clamp(16px, 2.6vh, 28px);
  width: min(760px, 78vw);
  text-align: center;
}

.final__title {
  color: var(--color-title);
  font-size: clamp(22px, 2.6vw, 40px);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.final__text {
  display: grid;
  gap: 0.8em;
  color: var(--color-text-muted);
  font-size: clamp(13px, 1.15vw, 17px);
  line-height: 1.65;
}

.final__back {
  margin-top: 8px;
  padding: 12px 26px;
  border: 1px solid var(--color-accent);
  border-radius: 999px;
  color: var(--color-accent);
  font-size: clamp(12px, 1vw, 14px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  transition: background var(--ui-fade) linear, color var(--ui-fade) linear;
}

.final__back:hover,
.final__back:focus-visible {
  background: var(--color-accent);
  color: var(--color-bg);
}

/* --- Overlay de depuração (?debug=1) ------------------------------ */

.debug {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 60;
  max-width: min(430px, 44vw);
  max-height: 68vh;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border-radius: 8px;
  background: var(--color-debug-bg);
  color: var(--color-debug-text);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  pointer-events: none;
}

/* Painel do selftest (aparece em ?selftest=1) */
.selftest {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 61;
  max-width: min(560px, 60vw);
  max-height: 60vh;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border-radius: 8px;
  background: var(--color-debug-bg);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
  pointer-events: none;
}

.selftest[data-result='ok'] {
  border: 1px solid #46d369;
}

.selftest[data-result='fail'] {
  border: 1px solid #ff5c5c;
  color: #ff9b9b;
}

/* --- Preferência por menos movimento ------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .media video {
    transition-duration: 0.001s;
  }

  .scrub-meter {
    transition-duration: 0.001s;
  }
}
