/* ═══════════════════════════════════════════════════════════════════
   SNAKE ELEMENTAL
   ═══════════════════════════════════════════════════════════════════ */

/* ── Canvas base ── */
#snakeCanvas {
  display: block;
  width: min(280px, calc(100vw - 28px));
  height: min(280px, calc(100vw - 28px));
  border-radius: 10px;
  border: 1px solid rgba(167,139,250,.2);
  box-shadow: 0 0 24px rgba(100,200,100,.1), inset 0 0 40px rgba(0,0,0,.4);
  touch-action: none;
  cursor: none;
}

/* ── D-pad (mobile only) ── */
.snake-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 6px 0 2px;
}

.snake-dpad-row {
  display: flex;
  gap: 2px;
}

.snake-dpad-btn {
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  color: #a78bfa;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s, transform .1s;
  user-select: none;
}

.snake-dpad-btn:active {
  background: rgba(167,139,250,.25);
  transform: scale(.92);
}

.snake-dpad-btn.snake-dpad-center {
  background: transparent;
  border-color: transparent;
  pointer-events: none;
  color: transparent;
}

/* ── Botão fechar dentro do d-pad (mobile) — canto sup. esq. longe das setas ── */
/* ── Header do modal com título + botão fechar no topo ── */
.mini-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 2px;
}
.mini-modal-header .mini-title {
  margin-bottom: 0;
}
.mini-modal-close-btn {
  background: rgba(231,76,60,.10);
  border: 1px solid rgba(231,76,60,.3);
  border-radius: 6px;
  color: #e74c3c;
  font-family: 'Cinzel', serif;
  font-size: 7px;
  letter-spacing: 1px;
  padding: 5px 10px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.mini-modal-close-btn:active {
  background: rgba(231,76,60,.25);
}

/* ── Record animation ── */
.snake-record-ov {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: snake-rec-bg .25s ease forwards;
}

@keyframes snake-rec-bg {
  from { background: transparent; }
  to   { background: rgba(4,3,10,.8); }
}

.snake-record-ring {
  position: absolute;
  top: 50%; left: 50%;
  border-radius: 50%;
  border: 2px solid rgba(251,191,36,.7);
  animation: snake-rec-ring .6s ease .05s both;
}

@keyframes snake-rec-ring {
  0%   { width:20px;  height:20px;  margin:-10px 0 0 -10px; opacity:.9; }
  100% { width:280px; height:280px; margin:-140px 0 0 -140px; opacity:0; }
}

.snake-record-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(14px, 4vw, 22px);
  font-weight: bold;
  letter-spacing: 4px;
  color: #fbbf24;
  text-shadow: 0 0 20px #fbbf24, 0 0 48px rgba(251,191,36,.5);
  animation: snake-rec-title .45s cubic-bezier(.175,.885,.32,1.275) .1s both;
}

@keyframes snake-rec-title {
  from { opacity:0; transform:scale(.25); }
  to   { opacity:1; transform:scale(1); }
}

.snake-record-score {
  font-family: 'Cinzel', serif;
  font-size: clamp(12px, 3.5vw, 18px);
  color: #86efac;
  letter-spacing: 3px;
  margin-top: 8px;
  animation: snake-rec-score .35s ease .42s both;
}

@keyframes snake-rec-score {
  from { opacity:0; transform:translateY(10px); }
  to   { opacity:1; transform:translateY(0); }
}

.snake-record-star {
  position: absolute;
  top: 50%; left: 50%;
  font-size: 15px;
  animation: snake-rec-star .75s ease both;
}

@keyframes snake-rec-star {
  0%   { opacity:0; transform:translate(-50%,-50%) translate(0,0) scale(.4); }
  25%  { opacity:1; }
  100% { opacity:0; transform:translate(-50%,-50%) translate(var(--sx),var(--sy)) scale(1.4) rotate(200deg); }
}

/* ── Ranking panel ── */
.snake-ranking-panel {
  flex-direction: column;
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  background: rgba(10,8,24,.85);
  border: 1px solid rgba(167,139,250,.18);
  border-radius: 8px;
  padding: 6px 4px;
  margin: 4px 0 2px;
  gap: 2px;
}

.snake-rank-title {
  font-family: 'Cinzel', serif;
  font-size: 8px;
  color: var(--gold, #fbbf24);
  letter-spacing: 3px;
  text-align: center;
  padding: 2px 0 4px;
  border-bottom: 1px solid rgba(167,139,250,.12);
  margin-bottom: 2px;
}

.snake-rank-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(255,255,255,.02);
}

.snake-rank-meu {
  background: rgba(167,139,250,.12);
  border: 1px solid rgba(167,139,250,.25);
}

.snake-rank-pos {
  font-family: 'Cinzel', serif;
  font-size: 10px;
  color: var(--gold, #fbbf24);
  min-width: 22px;
  text-align: center;
}

.snake-rank-nome {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  color: var(--text, #e2e8f0);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.snake-rank-pts {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  color: #86efac;
  white-space: nowrap;
}

.snake-rank-loading {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  color: var(--muted, #64748b);
  text-align: center;
  padding: 8px;
}

/* ── Score ── */
#snakeScore {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: #86efac;
  letter-spacing: 2px;
  margin: 4px 0 0;
}

/* ── Desktop: overlay fixo centrado ── */
@media (min-width: 769px) {
  #snakeModal {
    position: fixed !important;
    inset: 0 !important;
    z-index: 500 !important;
    border-radius: 0 !important;
    background: rgba(4,3,10,.97) !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 14px 20px !important;
    max-height: 100vh;
    overflow-y: auto;
    box-sizing: border-box;
  }

  #snakeCanvas {
    /* ~10% menor: 260px cap, offset aumentado para dar folga aos elementos */
    width:  min(260px, calc(100vh - 240px)) !important;
    height: min(260px, calc(100vh - 240px)) !important;
  }

  /* D-pad desnecessário no desktop — teclado/WASD disponível */
  .snake-dpad { display: none !important; }

  #snakeModal .mini-title  { font-size: 12px !important; letter-spacing: 4px; margin-bottom: 0; }
  #snakeModal .mini-info   { font-size: 9px !important; }
  #snakeModal #snakeScore  { font-size: 12px !important; }
  #snakeModal .mini-result-box  { font-size: 12px !important; }
  #snakeModal .mini-reward-txt  { font-size: 10px !important; }
  #snakeModal .mini-btns   { margin-top: 2px; gap: 8px; }
  #snakeModal .mini-btn    { font-size: 9px !important; padding: 8px 20px !important; }

  /* Backdrop escuro atrás do painel de ranking */
  .snake-ranking-backdrop {
    position: fixed;
    inset: 0;
    z-index: 509;
    background: rgba(4,3,10,.75);
    cursor: pointer;
  }

  /* Ranking panel: overlay sobre o canvas no desktop */
  #snakeRankingPanel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(320px, 80vw);
    max-height: 60vh;
    z-index: 510;
    margin: 0;
  }

  /* Dica de teclado */
  #snakeModal::after {
    content: '↑ ↓ ← →  ou  W A S D';
    font-family: 'Cinzel', serif;
    font-size: 8px;
    color: rgba(255,255,255,.2);
    letter-spacing: 2px;
    margin-top: -2px;
  }
}
