/* =========================================================
   VARIÁVEIS DE TEMA (MODO ESCURO PADRÃO / MODO CLARO)
   ========================================================= */
:root {
  --bg-page: #000000;
  --bg-surface: #0c0f14;
  --bg-surface-elevated: #141923;
  --border-color: #1f2937;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-green: #00a859;
  --accent-green-hover: #00c96b;
  --accent-cyan: #00d2ff;
  --accent-gold: #ffd700;
  --shadow-stage: 0 0 35px rgba(0, 210, 255, 0.25), 0 0 12px rgba(0, 168, 89, 0.2);
}

html[data-theme="light"] {
  --bg-page: #ffffff;
  --bg-surface: #f1f5f9;
  --bg-surface-elevated: #e2e8f0;
  --border-color: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent-green: #008f4c;
  --accent-green-hover: #00a859;
  --accent-cyan: #0284c7;
  --accent-gold: #d97706;
  --shadow-stage: 0 12px 32px rgba(15, 23, 42, 0.18);
}

/* =========================================================
   RESET E BASE RESPONSIVA
   ========================================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: background-color 0.35s ease, color 0.35s ease;
  overflow-x: hidden;
}

/* =========================================================
   TÍTULO ANIMADO NO TOPO
   ========================================================= */
.top-header {
  width: 100%;
  text-align: center;
  padding: 20px 16px 10px;
}

.game-title {
  font-size: clamp(1.6rem, 4vw, 2.75rem);
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(90deg, #ffd700, #00d2ff, #00a859, #ffd700);
  background-size: 250% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: titleShine 4.5s linear infinite, titleFloat 3s ease-in-out infinite;
  filter: drop-shadow(0 2px 10px rgba(0, 210, 255, 0.35));
}

.pac-icon {
  -webkit-text-fill-color: #ffd700;
  display: inline-block;
  animation: chompIcon 0.6s alternate infinite;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

@keyframes titleShine {
  to { background-position: 250% center; }
}

@keyframes titleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes chompIcon {
  from { transform: scale(1) rotate(0deg); }
  to { transform: scale(1.15) rotate(-8deg); }
}

/* =========================================================
   CONTAINER PRINCIPAL E BOTÕES ANIMADOS
   ========================================================= */
.main-container {
  width: 100%;
  max-width: 780px;
  padding: 10px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.control-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 12px 16px;
  border-radius: 14px;
}

.difficulty-selector,
.action-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.25s ease, background-color 0.25s ease, border-color 0.25s ease;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.btn::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  transition: left 0.45s ease;
}

.btn:hover:not(:disabled)::after {
  left: 140%;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--accent-cyan);
  box-shadow: 0 4px 14px rgba(0, 210, 255, 0.25);
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-diff.active {
  background: linear-gradient(135deg, var(--accent-cyan), #0077ff);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 0 14px rgba(0, 210, 255, 0.45);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-green), #007a40);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(0, 168, 89, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-green-hover), var(--accent-green));
  box-shadow: 0 6px 20px rgba(0, 168, 89, 0.55);
}

.btn-icon {
  padding: 9px 12px;
  font-size: 1.05rem;
}

.btn-lg {
  padding: 13px 28px;
  font-size: 1.05rem;
  letter-spacing: 0.8px;
}

/* =========================================================
   HUD / PLACAR EM TEMPO REAL
   ========================================================= */
.hud-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.hud-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hud-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.8px;
}

.hud-value {
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.accent-green { color: var(--accent-green); }
.accent-cyan { color: var(--accent-cyan); }

/* =========================================================
   ÁREA DO JOGO NÍTIDA E MODO FULLSCREEN
   ========================================================= */
.game-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.game-stage:fullscreen {
  background: #000000;
  padding: 16px;
  justify-content: center;
}

.game-stage:fullscreen .canvas-wrapper {
  max-width: min(82vh, 92vw);
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 28 / 31;
  border-radius: 16px;
  overflow: hidden;
  background: #04070d;
  border: 2px solid var(--accent-cyan);
  box-shadow: var(--shadow-stage);
}

canvas#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Sobreposições (Menu e Pausa) */
.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 13, 0.84);
  backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.game-overlay.active {
  display: flex;
}

.overlay-box {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent-cyan);
  border-radius: 16px;
  padding: 26px 22px;
  max-width: 380px;
  text-align: center;
  color: #ffffff;
  box-shadow: 0 0 30px rgba(0, 210, 255, 0.3);
  animation: popIn 0.3s ease;
}

.overlay-box h2 {
  font-size: 1.45rem;
  color: #ffd700;
  margin-bottom: 10px;
}

.overlay-box p {
  font-size: 0.92rem;
  color: #cbd5e1;
  line-height: 1.5;
  margin-bottom: 18px;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

/* Controles Touch Mobile */
.mobile-controls {
  display: none;
  margin-top: 14px;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.dpad-middle {
  display: flex;
  gap: 14px;
}

.dpad-btn {
  width: 60px;
  height: 54px;
  border-radius: 14px;
  border: 1px solid var(--accent-cyan);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-size: 1.35rem;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.dpad-btn:active {
  background: var(--accent-cyan);
  color: #000000;
  transform: scale(0.94);
}

/* =========================================================
   SEÇÃO DE PLACAR E RANKING (JSON)
   ========================================================= */
.ranking-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ranking-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.ranking-header h2 {
  font-size: 1.15rem;
  font-weight: 800;
}

.ranking-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 168, 89, 0.16);
  color: var(--accent-green);
  border: 1px solid rgba(0, 168, 89, 0.4);
}

.score-form {
  display: grid;
  grid-template-columns: 1fr 140px auto;
  gap: 10px;
  align-items: end;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.input-group label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.input-group input {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
  user-select: text !important;
}

.input-group input:focus {
  border-color: var(--accent-cyan);
}

.score-readonly input {
  font-weight: 800;
  color: var(--accent-green);
  text-align: center;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.ranking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.ranking-table th,
.ranking-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.ranking-table th {
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.ranking-table tbody tr:hover {
  background: rgba(0, 210, 255, 0.06);
}

.rank-medal {
  font-weight: 800;
}

.loading-row {
  text-align: center !important;
  color: var(--text-secondary);
}

/* =========================================================
   RODAPÉ ANIMADO EDCELL-TECH
   ========================================================= */
.edcell-footer {
  width: 100%;
  padding: 18px 16px 26px;
  text-align: center;
  margin-top: auto;
}

.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 22px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--accent-green);
  font-size: 0.92rem;
  box-shadow: 0 0 18px rgba(0, 168, 89, 0.25);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  animation: footerGlow 3s ease-in-out infinite;
}

.footer-link strong {
  color: var(--accent-green);
  letter-spacing: 0.6px;
}

.footer-link:hover {
  transform: translateY(-3px) scale(1.02);
  border-color: var(--accent-cyan);
  box-shadow: 0 6px 24px rgba(0, 210, 255, 0.4);
}

.footer-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
  animation: pulseDot 1.5s infinite;
}

.footer-arrow {
  color: var(--accent-cyan);
  font-weight: bold;
  transition: transform 0.25s ease;
}

.footer-link:hover .footer-arrow {
  transform: translateX(4px);
}

@keyframes footerGlow {
  0%, 100% { box-shadow: 0 0 14px rgba(0, 168, 89, 0.25); }
  50% { box-shadow: 0 0 24px rgba(0, 210, 255, 0.4); }
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}

/* =========================================================
   RESPONSIVIDADE (MOBILE / TABLET)
   ========================================================= */
@media (max-width: 768px) {
  .control-bar {
    justify-content: center;
  }

  .hud-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .score-form {
    grid-template-columns: 1fr;
  }

  .mobile-controls {
    display: flex;
  }
}