/* ===========================================================
   Ribeira+ Live Player — estilos
   Design limpo e premium, inspirado em players profissionais.
   Sem glassmorphism, sem neon, sem efeitos exagerados.
   =========================================================== */

:root {
  --bg: #000;
  --surface: #141414;
  --text: #f5f5f5;
  --text-dim: #b3b3b3;
  --accent: #e50914;          /* vermelho LIVE / destaque */
  --accent-hover: #f6121d;
  --control-size: 44px;
  --radius: 6px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --controls-fade: 280ms;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
}

button { font-family: inherit; }

/* ---------- Player container: ocupa toda a tela ---------- */
.player {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  cursor: default;
  user-select: none;
}
.player.is-idle { cursor: none; }

.video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain; /* evita distorção em qualquer resolução */
  background: var(--bg);
}

/* ---------- Overlays (loading / erro) ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 30;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.4), rgba(0,0,0,.75));
  text-align: center;
  padding: 24px;
}
/* Respeita o atributo [hidden] mesmo com display: flex */
.overlay[hidden] { display: none; }
.overlay__text {
  margin: 0;
  font-size: clamp(.9rem, 2vw, 1.05rem);
  color: var(--text-dim);
  letter-spacing: .2px;
}

/* Spinner discreto */
.spinner {
  width: 52px;
  height: 52px;
  border: 3px solid rgba(255, 255, 255, .18);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
.spinner--sm { width: 40px; height: 40px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Buffering durante a reprodução */
.buffering {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 25;
  pointer-events: none;
}
.buffering.is-active { display: flex; }

/* ---------- Tela de estado (erro / offline) ---------- */
.overlay--state { background: rgba(8, 8, 8, .92); }
.state-card {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: fade-up 320ms var(--ease) both;
}
.state-card__icon { width: 56px; height: 56px; fill: var(--text-dim); }
.state-card__title { margin: 0; font-size: clamp(1.15rem, 3vw, 1.5rem); font-weight: 600; }
.state-card__msg { margin: 0; color: var(--text-dim); font-size: clamp(.88rem, 2vw, 1rem); line-height: 1.5; }
.state-card__hint { margin: 4px 0 0; color: var(--text-dim); font-size: .85rem; }

.btn-retry {
  margin-top: 6px;
  padding: 11px 26px;
  background: #fff;
  color: #111;
  border: none;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms var(--ease), background 160ms var(--ease);
}
.btn-retry:hover { background: #e6e6e6; }
.btn-retry:active { transform: scale(.97); }
.btn-retry:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Botão central de play (autoplay bloqueado) ---------- */
.big-play {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: clamp(64px, 12vw, 88px);
  height: clamp(64px, 12vw, 88px);
  border-radius: 50%;
  border: none;
  background: rgba(20, 20, 20, .82);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 28;
  transition: transform 150ms var(--ease), background 150ms var(--ease);
}
.big-play[hidden] { display: none; }
.big-play svg { width: 46%; height: 46%; fill: #fff; margin-left: 6%; }
.big-play:hover { background: rgba(40, 40, 40, .9); transform: translate(-50%, -50%) scale(1.05); }
.big-play:active { transform: translate(-50%, -50%) scale(.96); }
.big-play:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

/* ===========================================================
   Controles personalizados
   =========================================================== */
.controls {
  position: absolute;
  inset: 0;
  z-index: 20;
  opacity: 1;
  transition: opacity var(--controls-fade) var(--ease);
}
.controls.is-hidden { opacity: 0; pointer-events: none; }

.controls__scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(0,0,0,.78) 0%, rgba(0,0,0,.35) 22%, rgba(0,0,0,0) 42%),
    linear-gradient(to bottom, rgba(0,0,0,.55) 0%, rgba(0,0,0,0) 18%);
}

/* ---------- Topbar ---------- */
.topbar {
  position: absolute;
  top: calc(16px + var(--safe-t));
  left: calc(20px + var(--safe-l));
  right: calc(20px + var(--safe-r));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  background: var(--accent);
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .6px;
  color: #fff;
}
.live-badge__dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 2s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}
.uptime {
  font-size: .78rem;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}

/* ---------- Barra de progresso ---------- */
.controls .progress {
  position: absolute;
  left: calc(20px + var(--safe-l));
  right: calc(20px + var(--safe-r));
  bottom: calc(64px + var(--safe-b));
  height: 18px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}
.progress:focus-visible { outline: none; }
.progress:focus-visible .progress__track { box-shadow: 0 0 0 2px var(--accent); }
.progress__track {
  position: relative;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, .28);
  border-radius: 99px;
  transition: height 120ms var(--ease);
}
.progress:hover .progress__track,
.progress.is-dragging .progress__track { height: 6px; }
.progress__buffer {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  width: 0;
  background: rgba(255, 255, 255, .45);
  border-radius: 99px;
}
.progress__played {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
}
.progress__thumb {
  position: absolute;
  right: 0;
  top: 50%;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(50%, -50%) scale(0);
  transition: transform 120ms var(--ease);
  box-shadow: 0 0 0 1px rgba(0,0,0,.2);
}
.progress:hover .progress__thumb,
.progress.is-dragging .progress__thumb { transform: translate(50%, -50%) scale(1); }

/* ---------- Barra de controles ---------- */
.controlbar {
  position: absolute;
  left: calc(12px + var(--safe-l));
  right: calc(12px + var(--safe-r));
  bottom: calc(8px + var(--safe-b));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.controlbar__group {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Botões base */
.ctrl {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control-size);
  height: var(--control-size);
  padding: 0 8px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: background 140ms var(--ease), transform 120ms var(--ease), opacity 140ms var(--ease);
}
.ctrl:hover { background: rgba(255, 255, 255, .12); }
.ctrl:active { transform: scale(.92); }
.ctrl:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.ctrl .icon { width: 24px; height: 24px; fill: currentColor; display: none; }

/* Estados de ícones */
#playBtn .icon--pause { display: block; }
.player.is-paused #playBtn .icon--pause { display: none; }
.player.is-paused #playBtn .icon--play { display: block; }

#muteBtn .icon--vol-high { display: block; }
.player.is-muted #muteBtn .icon--vol-high,
.player.is-low #muteBtn .icon--vol-high { display: none; }
.player.is-low:not(.is-muted) #muteBtn .icon--vol-mid { display: block; }
.player.is-muted #muteBtn .icon--vol-mute { display: block; }

#fullscreenBtn .icon--fs-open { display: block; }
.player.is-fullscreen #fullscreenBtn .icon--fs-open { display: none; }
.player.is-fullscreen #fullscreenBtn .icon--fs-close { display: block; }

/* Botão "AO VIVO" na barra (indica se está no ponto da live) */
.ctrl--live {
  gap: 7px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--text-dim);
}
.ctrl--live__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 160ms var(--ease);
}
.player.is-live .ctrl--live { color: #fff; }
.player.is-live .ctrl--live__dot { background: var(--accent); }

.ctrl--text { font-size: .82rem; font-weight: 600; min-width: auto; }

.time {
  font-size: .8rem;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  padding: 0 8px;
  white-space: nowrap;
}

/* ---------- Volume ---------- */
.volume { display: flex; align-items: center; }
.volume__slider {
  width: 0;
  overflow: hidden;
  opacity: 0;
  transition: width 200ms var(--ease), opacity 200ms var(--ease);
  display: flex;
  align-items: center;
  height: var(--control-size);
  cursor: pointer;
  touch-action: none;
}
.volume:hover .volume__slider,
.volume:focus-within .volume__slider,
.volume__slider.is-open { width: 76px; opacity: 1; padding: 0 8px; }
.volume__track {
  position: relative;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, .3);
  border-radius: 99px;
}
.volume__fill {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  width: 100%;
  background: #fff;
  border-radius: 99px;
}
.volume__slider:focus-visible { outline: none; }
.volume__slider:focus-visible .volume__track { box-shadow: 0 0 0 2px #fff; }

/* ---------- Menu de qualidade ---------- */
.quality { position: relative; }
.quality__menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 130px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
  animation: fade-up 160ms var(--ease) both;
}
.quality__item {
  padding: 9px 12px;
  border-radius: 5px;
  font-size: .85rem;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.quality__item:hover { background: rgba(255, 255, 255, .08); color: var(--text); }
.quality__item.is-active { color: #fff; font-weight: 600; }
.quality__item.is-active::after { content: "✓"; color: var(--accent); }

/* ===========================================================
   Responsividade
   =========================================================== */

/* Telas pequenas (celular retrato) */
@media (max-width: 600px) {
  :root { --control-size: 42px; }
  .controls .progress { bottom: calc(58px + var(--safe-b)); }
  .time { display: none !important; }
  .volume:hover .volume__slider { width: 0; opacity: 0; padding: 0; }
  .volume__slider.is-open { width: 64px; opacity: 1; padding: 0 6px; }
  .topbar { top: calc(12px + var(--safe-t)); left: calc(14px + var(--safe-l)); right: calc(14px + var(--safe-r)); }
  .ctrl--text { font-size: .78rem; }
}

/* Celular em paisagem (altura reduzida) */
@media (max-height: 430px) and (orientation: landscape) {
  .controls .progress { bottom: calc(54px + var(--safe-b)); }
  .live-badge { padding: 4px 9px; font-size: .68rem; }
}

/* TV / telas muito grandes — escala os controles */
@media (min-width: 1921px) {
  :root { --control-size: 60px; }
  .ctrl .icon { width: 32px; height: 32px; }
  .live-badge { font-size: .95rem; padding: 9px 16px; }
  .uptime, .time, .ctrl--text, .ctrl--live { font-size: 1.05rem; }
  .controls .progress { bottom: calc(86px + var(--safe-b)); height: 24px; }
}

/* Ultrawide — limita a barra de progresso para não ficar gigante */
@media (min-aspect-ratio: 21/9) and (min-width: 1600px) {
  .video { object-fit: contain; }
}

/* Foco por teclado mais visível em alto contraste */
@media (prefers-contrast: more) {
  .progress__track, .volume__track { background: rgba(255,255,255,.55); }
}

/* Reduz animações para quem prefere */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .spinner { animation: spin 1s linear infinite !important; }
}
