/* ============================================================
   Splash de abertura ("vire o celular" + botão JOGAR) + Fullscreen toggle
   Mobile-first. Dark premium + esmeralda (#2bd47d).
   Combina com playersbar.css (mesmos tokens de cor/safe-area).

   Substitui a antiga pílula discreta #orientationHint por uma
   TELA DE ABERTURA fullscreen com botão JOGAR. O botão libera o
   jogo SEMPRE (não depende de detectar orientação — funciona mesmo
   com a rotação travada no celular) e aproveita o toque pra pedir
   fullscreen + tentar travar landscape.
   ============================================================ */

:root {
  --ohud-emerald: #2bd47d;
  --ohud-emerald-2: #19b365;
  --ohud-bg: rgba(13, 27, 42, 0.82);
  --ohud-stroke: rgba(255, 255, 255, 0.1);
  --ohud-text: rgba(255, 255, 255, 0.92);
}

/* ------------------------------------------------------------
   1) SPLASH DE ABERTURA — overlay fullscreen.
   Cobre tudo ao carregar. Some (fade) ao tocar JOGAR.
   ------------------------------------------------------------ */
#splashScreen {
  position: fixed;
  inset: 0;
  z-index: 99999; /* acima de TUDO (players bar 1500, fullscreen 1600) */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(22px, 5vh, 40px);
  padding: calc(24px + env(safe-area-inset-top))
    calc(24px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(24px + env(safe-area-inset-left));
  text-align: center;

  /* dark premium com brilho esmeralda ao fundo */
  background:
    radial-gradient(
      120% 90% at 50% 0%,
      rgba(43, 212, 125, 0.16) 0%,
      rgba(43, 212, 125, 0) 55%
    ),
    radial-gradient(
      100% 80% at 50% 120%,
      rgba(25, 179, 101, 0.12) 0%,
      rgba(25, 179, 101, 0) 60%
    ),
    linear-gradient(160deg, #0b1622 0%, #0a1320 55%, #070d16 100%);
  color: var(--ohud-text);
  font-family: var(--font-family-primary, "Segoe UI", system-ui, sans-serif);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  opacity: 1;
  transition: opacity 0.45s ease;
}

/* estado de saída (aplicado por JS ao tocar JOGAR) */
#splashScreen.is-hiding {
  opacity: 0;
  pointer-events: none;
}
#splashScreen[hidden] {
  display: none !important;
}

/* ícone do celular girando retrato -> paisagem */
.splash-phone {
  width: clamp(64px, 18vw, 96px);
  height: clamp(64px, 18vw, 96px);
  color: var(--ohud-emerald);
  filter: drop-shadow(0 6px 18px rgba(43, 212, 125, 0.35));
  animation: splashTilt 2.5s ease-in-out infinite;
  transform-origin: 50% 50%;
}
.splash-phone svg {
  width: 100%;
  height: 100%;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* retrato -> paisagem -> retrato (sugere deitar o aparelho) */
@keyframes splashTilt {
  0%   { transform: rotate(0deg) scale(1); }
  30%  { transform: rotate(0deg) scale(1); }
  55%  { transform: rotate(-90deg) scale(1.04); }
  82%  { transform: rotate(-90deg) scale(1.04); }
  100% { transform: rotate(0deg) scale(1); }
}

.splash-title {
  margin: 0;
  font-size: clamp(20px, 5.4vw, 28px);
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.25;
  max-width: 18ch;
}
.splash-title b {
  color: var(--ohud-emerald);
  font-weight: 800;
}

.splash-sub {
  margin: -10px 0 0;
  font-size: clamp(13px, 3.6vw, 15px);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  max-width: 26ch;
}

/* botão JOGAR — grande, touch-friendly, esmeralda com glow */
#splashPlay {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  cursor: pointer;
  min-width: min(78vw, 280px);
  min-height: 56px;
  padding: 16px 40px;
  border-radius: 16px;
  font-family: inherit;
  font-size: clamp(17px, 4.8vw, 20px);
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #04150c;
  background: linear-gradient(
    180deg,
    var(--ohud-emerald) 0%,
    var(--ohud-emerald-2) 100%
  );
  box-shadow:
    0 10px 28px rgba(43, 212, 125, 0.45),
    0 2px 0 rgba(255, 255, 255, 0.25) inset,
    0 -2px 0 rgba(0, 0, 0, 0.18) inset;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, box-shadow 0.18s ease, filter 0.18s ease;
  animation: splashPulse 2.4s ease-in-out infinite;
}
#splashPlay:hover {
  filter: brightness(1.05);
  box-shadow: 0 14px 34px rgba(43, 212, 125, 0.55);
}
#splashPlay:active {
  transform: scale(0.96);
  box-shadow: 0 6px 18px rgba(43, 212, 125, 0.4);
}

@keyframes splashPulse {
  0%, 100% { box-shadow: 0 10px 28px rgba(43, 212, 125, 0.45); }
  50%      { box-shadow: 0 10px 40px rgba(43, 212, 125, 0.7); }
}

@media (prefers-reduced-motion: reduce) {
  .splash-phone,
  #splashPlay {
    animation: none;
  }
}

/* ------------------------------------------------------------
   2) BOTÃO FULLSCREEN — alterna tela cheia. Mobile + desktop.
   Canto superior direito, sem cobrir a players bar.
   Touch-friendly (>=44px). Escondido se browser não suporta.
   ------------------------------------------------------------ */
#fullscreenBtn {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  z-index: 1600; /* acima da players bar pra sempre clicável */
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  border-radius: 12px;
  background: var(--ohud-bg);
  border: 1px solid var(--ohud-stroke);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--ohud-emerald);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

#fullscreenBtn:hover {
  background: rgba(13, 27, 42, 0.92);
  box-shadow: 0 6px 18px rgba(43, 212, 125, 0.25);
}

#fullscreenBtn:active {
  transform: scale(0.92);
}

#fullscreenBtn svg {
  width: 22px;
  height: 22px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* alterna os dois ícones (expandir / contrair) via classe no botão */
#fullscreenBtn .fs-icon-exit {
  display: none;
}
#fullscreenBtn.is-fullscreen .fs-icon-enter {
  display: none;
}
#fullscreenBtn.is-fullscreen .fs-icon-exit {
  display: block;
}

/* se o JS detectar que não há suporte, esconde de vez */
#fullscreenBtn.fs-unsupported {
  display: none !important;
}

/* ============================================================
   MOBILE PORTRAIT — botão FULLSCREEN no canto superior direito
   colidia com o card do Player 2 e com o overlay nativo "Anon 👥".
   Solução: no celular o botão DESCE pra logo abaixo do card do
   Player 2 (top ~58px), ainda colado à direita, num ponto livre
   da mesa (área da tabela/rail). Mantém 44px (touch) e z alto.
   Desktop (largura > 500px) permanece no canto superior direito.
   ============================================================ */
@media (max-width: 500px), (orientation: portrait) and (max-width: 820px) {
  #fullscreenBtn {
    top: calc(58px + env(safe-area-inset-top));
    right: calc(8px + env(safe-area-inset-right));
    bottom: auto;
    left: auto;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    z-index: 1700; /* acima da players bar (1500) e do lobby (1450) */
  }
}

/* ============================================================
   TELA DE LOADING (#splashScreen.is-loader) — finge carregar o jogo
   com barra de progresso + celular girando (retrato->paisagem) e setas.
   Substitui o antigo botao JOGAR. Some sozinha (fade via .is-hiding).
   ============================================================ */
#splashScreen.is-loader { gap: clamp(18px, 4vh, 32px); }

/* bloco do celular girando + setas */
.ld-rotate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 4vw, 22px);
}
.ld-arrow {
  font-size: clamp(20px, 6vw, 30px);
  color: var(--ohud-emerald);
  opacity: 0.85;
  animation: ldArrowPulse 1.8s ease-in-out infinite;
}
.ld-arrow-r { animation-delay: 0.9s; }
@keyframes ldArrowPulse { 0%,100% { opacity: 0.25; } 50% { opacity: 0.95; } }

/* o celular: retangulo que gira 0 -> 90deg em loop */
.ld-phone {
  position: relative;
  width: clamp(44px, 13vw, 64px);
  height: clamp(78px, 23vw, 112px);
  border: 3px solid var(--ohud-emerald);
  border-radius: 12px;
  background: rgba(43, 212, 125, 0.08);
  transform-origin: 50% 50%;
  animation: ldPhoneRotate 1.8s cubic-bezier(.6,.05,.3,1) infinite;
  box-shadow: 0 0 18px rgba(43, 212, 125, 0.25);
}
.ld-phone .ld-cam {
  position: absolute;
  top: 6px; left: 50%; transform: translateX(-50%);
  width: 14px; height: 3px; border-radius: 3px;
  background: rgba(43, 212, 125, 0.7);
}
.ld-phone .ld-screen {
  position: absolute; inset: 9px 5px 9px;
  border-radius: 5px;
  background: linear-gradient(160deg, rgba(43,212,125,.22), rgba(43,212,125,.05));
}
@keyframes ldPhoneRotate {
  0%, 22%   { transform: rotate(0deg); }
  55%, 78%  { transform: rotate(-90deg); }
  100%      { transform: rotate(0deg); }
}

/* barra de progresso (finge carregar) */
.ld-bar {
  width: min(72vw, 320px);
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.05);
}
.ld-bar-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ohud-emerald-2), var(--ohud-emerald));
  box-shadow: 0 0 10px rgba(43, 212, 125, 0.5);
  transition: width 0.08s linear;
}

/* desktop: nao precisa girar o telefone */
#splashScreen.is-loader.is-desktop .ld-phone { animation: none; transform: none; }
#splashScreen.is-loader.is-desktop .ld-arrow { display: none; }
