/* === Basestil === */
:root {
  --bg1: #061a3a;
  --bg2: #0a2a5f;
  --panel: #f7f9ff;
  --panel-text: #0a0f1e;
  --accent: #3b82f6;
  --good: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 20px 50px rgba(0,0,0,.35);
  --radius-xl: 1.25rem;
  --radius-lg: 0.9rem;
  --radius-md: 0.65rem;
  --cell-size: clamp(42px, 5.5vw, 72px);
  --gap: clamp(6px, 0.9vw, 12px);
  --transition-fast: 120ms ease;
  --transition: 220ms cubic-bezier(.2,.8,.2,1);
}

[hidden]{display:none !important;}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Nunito", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  color: white;
  background: radial-gradient(1200px 800px at 20% 10%, #0d2b61 0%, #061a3a 45%, #03132a 100%),
              linear-gradient(180deg, var(--bg2) 0%, var(--bg1) 100%);
  background-attachment: fixed;
}

/* Header / Footer */
.site-header, .site-footer {
  width: min(1200px, 92vw);
  margin: 24px auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.site-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
}
.site-header h1 {
  margin: 0;
  font-size: clamp(26px, 3.6vw, 44px);
  letter-spacing: 0.5px;
  text-shadow: 0 10px 30px rgba(0,0,0,.35);
  justify-self: center;
}
.site-footer { opacity: .8; justify-content: center; }

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  background: rgba(255,255,255,.08);
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(6px);
}
.score-wrap { font-weight: 800; font-size: clamp(16px, 2.2vw, 20px); }
.hud { display: flex; gap: 14px; opacity: .95; }
.hud strong { color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,.35); }
.btn {
  cursor: pointer; border: none; border-radius: 999px; padding: 10px 16px;
  font-weight: 800; background: white; color: #0a0f1e;
  box-shadow: 0 8px 24px rgba(0,0,0,.25), inset 0 -3px 0 rgba(0,0,0,.15);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), filter var(--transition-fast);
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.02); }
.btn:active { transform: translateY(0); box-shadow: 0 4px 14px rgba(0,0,0,.25), inset 0 -1px 0 rgba(0,0,0,.15); }
.btn-ghost { background: transparent; color: white; border: 1px dashed rgba(255,255,255,.5); }

/* Scene */
.stage { width: 100%; display: grid; place-items: center; padding: 24px 0 60px; }
.game-card {
  display: inline-block;
  background: transparent;
  color: var(--panel-text);
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0 auto;
}
.top-bar { 
  display:flex; 
  align-items:center; 
  gap: 12px; 
  margin-top: 4px;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}
.progress {
  flex: none;
  width: calc(8 * var(--cell-size) + 7 * var(--gap));
  height: 24px; 
  background: #dfe9ff; 
  border-radius: 999px; 
  overflow: hidden;
  border: 1px solid #cbdafc; 
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7);
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, #22c55e, #f59e0b, #ef4444);
  transition: width 200ms linear;
}
.combo {
  min-width: 52px; text-align: center; font-weight: 900;
  background: #111827; color: #fff; border-radius: 12px; padding: 6px 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

/* Board */
.board {
  --size: 8;
  display: grid;
  grid-template-columns: repeat(var(--size), var(--cell-size));
  grid-template-rows: repeat(var(--size), var(--cell-size));
  gap: var(--gap);
  justify-content: center;
  align-content: center;
  padding: clamp(1px, 0.1vw, 1px);
  background: #d1ddf5;
  border-radius: var(--radius-lg);
  border: 1px solid #c2d0ec;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.8), inset 0 -2px 20px rgba(3,24,79,.08);
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

/* Fullscreen board styling */
.board.fullscreen {
  --cell-size: min(8vh, 8vw);
  --gap: min(1vh, 1vw);
  width: 100vw;
  height: 100vh;
  margin: 0;
  border-radius: 0;
  border: none;
  box-shadow: none;
  background: #d1ddf5;
  display: grid;
  place-items: center;
}

.board.fullscreen .particles {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

/* Fullscreen UI overlay */
.fullscreen-ui {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1001;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  padding: 0;
  pointer-events: none;
}

.board.fullscreen .fullscreen-ui {
  display: flex !important;
}

.fullscreen-stats {
  display: flex;
  gap: 40px;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.fullscreen-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  padding: 16px 24px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.fullscreen-label {
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.fullscreen-value {
  color: white;
  font-size: 24px;
  font-weight: 900;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.fullscreen-progress-container {
  padding: 20px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
}

.fullscreen-progress {
  width: 100%;
  max-width: 800px;
  height: 20px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.3);
  margin: 0 auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.fullscreen-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #f59e0b, #ef4444);
  transition: width 200ms linear;
  border-radius: 999px;
}

/* Tips section */
.tips {
  margin-top: 4px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  font-size: 0.85em;
  line-height: 1.3;
  border: 1px solid rgba(0, 0, 0, 0.1);
  width: calc(8 * var(--cell-size) + 7 * var(--gap));
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.tips p {
  margin: 0;
}

/* Particles */
.particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.particle {
  position: absolute; font-size: 18px; opacity: 0; transform: translate(-50%, -50%) scale(.6);
  animation: burst 900ms ease-out forwards;
}
@keyframes burst {
  0% { opacity: 1; transform: translate(-50%,-50%) scale(.6); }
  70% { opacity: .9; transform: translate(-50%,-50%) scale(1.6) rotate(12deg); }
  100% { opacity: 0; transform: translate(-50%,-140%) scale(0.8) rotate(-10deg); }
}

/* Cell */
.cell {
  display: grid; place-items: center;
  font-size: calc(var(--cell-size) * 0.55);
  user-select: none; cursor: pointer;
  border-radius: 22%;
  background: white;
  border: 1px solid rgba(10,15,30,.08);
  box-shadow: 0 6px 16px rgba(7, 23, 66, 0.15), inset 0 -3px 0 rgba(0,0,0,.06);
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
  position: relative;
}

/* Smooth swap animation */
.cell.swapping {
  transition: transform 250ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  z-index: 10;
}

/* Emoji-specific background colors - more solid */
.cell.emoji-skull { 
  background: linear-gradient(135deg, #4b5563, #374151);
  border-color: #6b7280;
  color: white;
}
.cell.emoji-happy { 
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-color: #d97706;
  color: #451a03;
}
.cell.emoji-monkey { 
  background: linear-gradient(135deg, #ea580c, #dc2626);
  border-color: #b91c1c;
  color: white;
}
.cell.emoji-cool { 
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #1d4ed8;
  color: white;
}
.cell.emoji-crazy { 
  background: linear-gradient(135deg, #a855f7, #9333ea);
  border-color: #7c3aed;
  color: white;
}
.cell.emoji-love { 
  background: linear-gradient(135deg, #ec4899, #db2777);
  border-color: #be185d;
  color: white;
}
.cell.emoji-laugh { 
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-color: #15803d;
  color: white;
}
.cell.emoji-party { 
  background: linear-gradient(135deg, #fb923c, #f97316);
  border-color: #ea580c;
  color: white;
}
.cell:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(7, 23, 66, 0.2); }
.cell:active { transform: translateY(0); }

.cell.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  filter: drop-shadow(0 0 12px rgba(59,130,246,.45));
}

/* Hint styling */
.cell.hint {
  animation: hintPulse 1s infinite ease-in-out;
  outline: 2px solid #fbbf24;
  outline-offset: -2px;
  filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.6));
}

/* Powerup emojis - replace original emoji entirely */
.cell.power-row::after {
  content: "💣"; 
  position: absolute; 
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.2em; 
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  animation: powerupShake 2s infinite ease-in-out;
  z-index: 2;
}
.cell.power-col::after {
  content: "⚡"; 
  position: absolute; 
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.2em; 
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  animation: powerupShake 2s infinite ease-in-out;
  z-index: 2;
}
.cell.power-cross::after {
  content: "💥"; 
  position: absolute; 
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.2em; 
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  animation: powerupShake 2s infinite ease-in-out;
  z-index: 2;
}
.cell.power-color::after {
  content: "🌈"; 
  position: absolute; 
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.2em; 
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  animation: powerupShake 2s infinite ease-in-out;
  z-index: 2;
}

/* Powerup cells get special background - more solid */
.cell.power-row, .cell.power-col, .cell.power-cross, .cell.power-color {
  background: linear-gradient(135deg, #1e40af, #1e3a8a);
  border-color: #2563eb;
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
  color: white;
}

/* Match / Floating score */
.cell.match { animation: popOut 380ms ease forwards; }
.floating {
  position:absolute; color:#111827; font-weight:900; pointer-events:none;
  transform: translate(-50%, -40%); opacity:0;
  animation: floatUp 800ms ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -10%); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -110%); }
}
@keyframes popOut {
  0% { transform: scale(1); opacity: 1; }
  70% { transform: scale(1.25); opacity: .6; }
  100% { transform: scale(.2); opacity: 0; }
}

/* Invalid swap shake */
.shake { animation: shake 180ms ease-in-out 0s 2 alternate; }
@keyframes shake { from { transform: translateX(-3px); } to { transform: translateX(3px); } }

/* Powerup shake animation */
@keyframes powerupShake {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.1) rotate(-2deg); }
  75% { transform: scale(1.1) rotate(2deg); }
}

/* Hint pulse animation */
@keyframes hintPulse {
  0%, 100% { 
    outline-color: rgba(251, 191, 36, 0.8);
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.6));
  }
  50% { 
    outline-color: rgba(251, 191, 36, 0.3);
    filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.3));
  }
}

/* Powerup effect animations */
@keyframes explode {
  0% { 
    opacity: 1; 
    transform: translate(-50%, -50%) scale(1); 
  }
  100% { 
    opacity: 0; 
    transform: translate(calc(-50% + var(--end-x)), calc(-50% + var(--end-y))) scale(0.3); 
  }
}

@keyframes lightning {
  0% { 
    opacity: 0; 
    transform: translate(-50%, -50%) scale(0.5); 
    filter: brightness(1);
  }
  50% { 
    opacity: 1; 
    transform: translate(-50%, -50%) scale(1.5); 
    filter: brightness(2) drop-shadow(0 0 20px #ffff00);
  }
  100% { 
    opacity: 0; 
    transform: translate(-50%, -50%) scale(0.8); 
    filter: brightness(1);
  }
}

@keyframes crossExplode {
  0% { 
    opacity: 1; 
    transform: translate(-50%, -50%) scale(0.8); 
  }
  100% { 
    opacity: 0; 
    transform: translate(calc(-50% + var(--end-x)), calc(-50% + var(--end-y))) scale(0.4); 
  }
}

@keyframes rainbow {
  0% { 
    opacity: 0; 
    transform: translate(-50%, -50%) scale(0.5) rotate(0deg); 
    filter: hue-rotate(0deg);
  }
  50% { 
    opacity: 1; 
    transform: translate(-50%, -50%) scale(1.2) rotate(180deg); 
    filter: hue-rotate(180deg) brightness(1.5);
  }
  100% { 
    opacity: 0; 
    transform: translate(-50%, -50%) scale(0.8) rotate(360deg); 
    filter: hue-rotate(360deg);
  }
}

/* Tables */
.tables-wrap {
  width:min(980px, 92vw);
  display: grid; gap: 16px;
  margin-top: 16px;
}
.table-card {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  color: #e6eeff;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.table-card.outlined {
  background: transparent;
  border: 2px solid #ffffff;
  color: #ffffff;
}
.table { width:100%; border-collapse: collapse; }
.table th, .table td {
  border-bottom: 1px solid rgba(255,255,255,.18);
  padding: 8px 10px;
  text-align: left;
}
.placeholder-text { opacity: .9; padding: 8px 4px; }

/* Modal */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,16,.6); backdrop-filter: blur(3px);
}
.modal {
  width: min(520px, 92vw);
  background: linear-gradient(180deg, #ffffff, #f7f9ff);
  color: #111827; border-radius: var(--radius-xl);
  box-shadow: var(--shadow); padding: 18px 20px;
  border: 1px solid rgba(255,255,255,.45);
}
.modal h3 { margin: 0 0 8px; }
.modal-actions { display:flex; gap:10px; justify-content:flex-end; }

/* Responsive */
@media (max-width: 520px) {
  :root { --cell-size: 44px; }
  .controls { gap: 10px; }
}