* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --accent: #ffce47;
  --accent-2: #ff7b54;
  --panel: rgba(13, 18, 38, 0.75);
  --panel-border: rgba(255, 255, 255, 0.12);
  --field-w: 800px;
  --field-h: 600px;
}

html, body {
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100dvh;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 20% 20%, #1b2a6b 0%, transparent 45%),
    radial-gradient(circle at 80% 30%, #6b1b5e 0%, transparent 50%),
    linear-gradient(160deg, #0b1026 0%, #131a3a 55%, #05060f 100%);
  color: #f4f6ff;
  touch-action: manipulation;
}

/* Layout em tela cheia: HUD no topo, campo preenchendo o resto.
   O ranking é um painel lateral fixo (desktop) / selo no canto (mobile). */
.game-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  height: 100dvh;
  padding: 10px;
}

/* ===================== HUD ===================== */
.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px 16px;
  backdrop-filter: blur(6px);
}

.hud-item { display: flex; flex-direction: column; gap: 2px; }

.hud-label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #9aa6d4;
}

.hud-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

#difficulty {
  background: #1a2348;
  color: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  cursor: pointer;
}

.sound-btn {
  background: #1a2348;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-size: 20px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s;
}
.sound-btn:hover { background: #26316a; transform: scale(1.05); }
.sound-btn.off { opacity: 0.55; font-size: 14px; }
#musicToggle { margin-left: auto; }
.hud-home { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* ===================== CAMPO ===================== */
/* O frame ocupa a célula do grid; o campo (800x600) é escalado por GSAP via
   fitBoard() para caber na largura disponível (mobile). */
.field-frame {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
.field {
  position: relative;
  width: var(--field-w);
  height: var(--field-h);
  border-radius: 18px;
  overflow: hidden;
  cursor: crosshair;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  border: 1px solid var(--panel-border);
  background:
    linear-gradient(180deg, #10193f 0%, #1b2a6b 60%, #2a1850 100%);
  user-select: none;
  touch-action: none;
}

/* Cenário */
.moon {
  position: absolute;
  top: 8%;
  right: 12%;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 38%, #fff6d6, #ffe9a8);
  box-shadow: 0 0 50px 12px rgba(255, 246, 214, 0.45);
}

.stars { position: absolute; inset: 0; pointer-events: none; }
.star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: #cfe0ff;
  border-radius: 50%;
}

.hills {
  position: absolute;
  left: 0; right: 0; bottom: 70px;
  height: 160px;
  background: rgba(20, 30, 70, 0.7);
  clip-path: polygon(0 100%, 0 55%, 18% 18%, 36% 60%, 55% 10%, 75% 55%, 100% 25%, 100% 100%);
}

.floor {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 70px;
  background: linear-gradient(180deg, #2f8f4e 0%, #1c5a31 100%);
  border-top: 3px solid rgba(255, 255, 255, 0.18);
}

/* Sombra da bola */
.shadow {
  position: absolute;
  left: 0; top: 0;
  width: 76px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.38);
  filter: blur(2px);
  pointer-events: none;
}

/* ===================== BOLA ===================== */
.ball {
  position: absolute;
  left: 0; top: 0;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 30%, #ffb347 0%, #ff7b1c 60%, #c8530a 100%);
  box-shadow: inset -8px -8px 16px rgba(120, 40, 0, 0.45),
              0 6px 14px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
/* costuras estilo basquete */
.ball::before,
.ball::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(60, 20, 0, 0.55);
}
.ball::before {
  border-left: none; border-right: none;
  transform: scaleX(0.45);
}
.ball::after {
  border-top: none; border-bottom: none;
  transform: scaleY(0.45);
}
.ball-shine {
  position: absolute;
  top: 16%; left: 18%;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  filter: blur(1px);
}

/* ===================== PASSARINHO ===================== */
.bird {
  position: absolute;
  left: 0; top: 0;
  width: 56px;
  height: 44px;
  cursor: pointer;
  z-index: 4;
  --bird-a: #2a6fd6;
  --bird-b: #6fb1ff;
}
.bird.angry { --bird-a: #c0392b; --bird-b: #ff7a6e; }

.bird > div { position: absolute; }

.bird-body {
  width: 36px; height: 28px;
  left: 8px; top: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--bird-b), var(--bird-a));
}
.bird-belly {
  width: 22px; height: 16px;
  left: 16px; top: 18px;
  border-radius: 50%;
  background: #dceaff;
}
.bird.angry .bird-belly { background: #ffd2cc; }

.bird-head {
  width: 20px; height: 20px;
  left: 30px; top: 4px;
  border-radius: 50%;
  background: var(--bird-a);
}
.bird-eye {
  width: 7px; height: 7px;
  left: 9px; top: 4px;
  border-radius: 50%;
  background: #fff;
}
.bird-eye::after {
  content: ""; position: absolute;
  width: 3px; height: 3px; left: 2px; top: 2px;
  border-radius: 50%; background: #111;
}
.bird-brow {
  width: 10px; height: 3px;
  left: 4px; top: 1px;
  background: #5a1a14;
  border-radius: 2px;
  transform: rotate(20deg);
  opacity: 0;
}
.bird.angry .bird-brow { opacity: 1; }

.bird-beak {
  width: 0; height: 0;
  left: 18px; top: 7px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 11px solid #ffb01f;
}
.bird-wing, .bird-wing-back {
  width: 28px; height: 16px;
  border-radius: 50%;
  background: var(--bird-a);
  transform-origin: 30% 50%;
}
.bird-wing { left: 6px; top: 12px; background: #4f95ff; }
.bird.angry .bird-wing { background: #ff6b5e; }
.bird-wing-back { left: 4px; top: 8px; opacity: 0.85; }

.bird-tail {
  width: 0; height: 0;
  left: -10px; top: 12px;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-right: 16px solid var(--bird-a);
}
.bird-anger {
  left: 36px; top: -14px;
  font-size: 16px;
  opacity: 0;
}
.bird.angry .bird-anger { opacity: 1; }

/* ===================== EFEITOS ===================== */
.fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.particle {
  position: absolute;
  border-radius: 50%;
  will-change: transform, opacity;
}
.click-marker {
  position: absolute;
  width: 10px; height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: #ff2b2b;
  box-shadow: 0 0 0 2px rgba(255, 43, 43, 0.5);
}
.float-text {
  position: absolute;
  font-weight: 800;
  font-size: 26px;
  color: #7CFC00;
  text-shadow: 0 0 6px rgba(0,0,0,0.7);
  transform: translate(-50%, -50%);
}

/* ===================== OVERLAYS ===================== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  background: rgba(5, 8, 22, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10;
}
.overlay.hidden { display: none; }
#startOverlay { pointer-events: none; }

/* ===================== TELA DE GAME OVER (fora do campo) ===================== */
/* Overlay de tela cheia: fundo escuro cobrindo tudo e um card ENCOSTADO NO TOPO,
   bem longe da base, onde o jogador estava martelando a bola. */
.screen-over {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5, 8, 22, 0.82);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: flex-start;          /* card no topo */
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 16px;
  overflow-y: auto;
}
.screen-over.hidden { display: none; }
.over-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.over-card h1 {
  font-size: 34px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.over-card p { font-size: 16px; color: #d7ddf5; }
/* Trava os botões por um instante: cliques de "martelada" no momento do game
   over não acionam Salvar/Jogar sem querer. */
.screen-over.lock .name-row,
.screen-over.lock .play-again,
.screen-over.lock .ovl-home { pointer-events: none; opacity: 0.55; }

.overlay h1 {
  font-size: 44px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 4px 24px rgba(255, 123, 84, 0.25);
}
.overlay p { font-size: 17px; line-height: 1.5; color: #d7ddf5; }
.overlay .hint { font-size: 14px; color: #9aa6d4; }

.name-row { display: flex; gap: 10px; margin-top: 6px; }
#playerName {
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: #11183a;
  color: #fff;
  font-size: 18px;
  outline: none;
}
#playerName:focus { border-color: var(--accent); }

.overlay button,
.over-card button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 14px 22px;
  font-size: 18px;
  font-weight: 700;
  color: #1a1300;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: transform 0.1s ease, filter 0.2s;
}
.overlay button:hover, .over-card button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.play-again { margin-top: 6px; }

/* ===================== RANKING ===================== */
/* Painel flutuante à direita (desktop); aparece só na tela inicial. */
.ranking {
  position: fixed;
  top: 76px;
  right: 16px;
  width: 260px;
  max-height: calc(100dvh - 96px);
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
}
.ranking h2 { font-size: 18px; margin-bottom: 12px; }

#rankList { list-style: none; counter-reset: rank; flex: 1; overflow-y: auto; }
#rankList li {
  counter-increment: rank;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
}
#rankList li::before {
  content: counter(rank);
  font-weight: 700;
  color: var(--accent);
  min-width: 18px;
}
#rankList li .rk-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#rankList li .rk-clicks { font-variant-numeric: tabular-nums; color: #ffce47; font-size: 12px; }
#rankList li .rk-time { font-variant-numeric: tabular-nums; color: #b7c0ea; }
#rankList li:nth-child(1)::before { color: #ffd84d; }
#rankList li:nth-child(2)::before { color: #cfd6e6; }
#rankList li:nth-child(3)::before { color: #e09b5a; }
#rankList li.empty { justify-content: center; color: #6f7aa6; font-style: italic; }
#rankList li.empty::before { content: ""; min-width: 0; }

.back-link {
  margin-top: 10px;
  display: block;
  text-align: center;
  background: transparent;
  border: 1px solid var(--panel-border);
  color: #9aa6d4;
  border-radius: 9px;
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
.back-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

/* Seletor de dificuldade na TELA INICIAL (não na HUD). O #startOverlay tem
   pointer-events:none (para o toque "atravessar" até a bola), então reativamos
   o clique só nos controles. */
.start-controls {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 4px 0 2px;
  pointer-events: auto;
}
.start-controls label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: #9aa6d4;
}
.start-controls select { font-size: 15px; padding: 8px 10px; pointer-events: auto; }

/* Ranking aparece SOMENTE antes de iniciar (estado "ready") */
body[data-state="playing"] .ranking,
body[data-state="over"] .ranking { display: none !important; }

/* Game over: botões mais fáceis de tocar */
.play-again { width: 100%; padding: 12px; font-size: 16px; }
#saveScore { white-space: nowrap; }
#playerName { text-transform: uppercase; }
.ovl-home { display: inline-block; margin-top: 8px; color: #9aa6d4; font-size: 14px; text-decoration: none; }
.ovl-home:hover { color: #fff; }
.float-text.neg { color: #ff5a5a; }

/* Pássaros da revoada (distração que cruza a tela) */
.flock-bird {
  position: absolute;
  left: 0; top: 0;
  font-size: 26px;
  line-height: 1;
  z-index: 8;
  cursor: pointer;
  user-select: none;
  will-change: transform;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
}
.rank-total { font-size: 11px; color: #6f7aa6; text-align: center; margin-top: 6px; }

/* ===================== MOBILE (reformulado) ===================== */
@media (max-width: 820px) {
  .game-wrapper {
    gap: 4px;
    padding: calc(env(safe-area-inset-top, 0px) + 4px) 4px 4px;
  }

  /* HUD enxuta: barra fina translúcida */
  .hud {
    flex: 0 0 auto;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 10px;
    flex-wrap: nowrap;
    overflow-x: auto;
  }
  .hud-label { display: none; }
  .hud-value { font-size: 18px; }
  #difficulty { font-size: 12px; padding: 4px 6px; }
  .sound-btn { width: 38px; height: 38px; font-size: 16px; }

  /* Campo preenche todo o espaço entre a HUD e a base (vertical no celular) */
  .field-frame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
  }

  /* Ranking: selo discreto no canto superior direito (só os online) */
  .ranking {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 54px);
    right: 8px;
    z-index: 40;
    width: auto;
    min-width: 96px;
    max-width: 46vw;
    padding: 5px 8px;
    border-radius: 10px;
    background: rgba(5, 8, 22, 0.6);
    backdrop-filter: blur(4px);
  }
  .ranking h2 { font-size: 10px; letter-spacing: 0.5px; margin-bottom: 3px; opacity: 0.8; }
  #rankList { overflow: visible; }
  #rankList li {
    padding: 1px 3px;
    margin-bottom: 1px;
    font-size: 11px;
    background: transparent;
  }
  #rankList li::before { min-width: 12px; }
  #rankList li { gap: 5px; }
  #rankList li .rk-clicks { font-size: 11px; }      /* mostra as rebatidas (👆) */
  .back-link { display: none; }
  .rank-total { font-size: 10px; }

  /* Game over: card largo, campos e botões BEM grandes (fáceis de tocar) */
  .over-card { max-width: none; gap: 14px; padding: 18px; }
  .over-card h1 { font-size: 30px; }
  .name-row { width: 100%; flex-direction: column; gap: 12px; }
  #playerName { width: 100%; min-width: 0; font-size: 22px; padding: 18px; text-align: center; }
  #saveScore { width: 100%; font-size: 20px; padding: 18px; }
  .play-again { width: 100%; font-size: 20px; padding: 18px; }
  .ovl-home { font-size: 16px; padding: 6px; }
}
