/* === 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(28px, 3.5vw, 48px);
  --gap: clamp(4px, 0.6vw, 8px);
  --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(16 * var(--cell-size) + 15 * 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: 16;
  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;
}

/* 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(16 * var(--cell-size) + 15 * 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: box-shadow var(--transition), filter var(--transition);
  position: relative;
}

/* Animation classes for smooth swapping */
.cell.swapping {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  z-index: 10;
  will-change: transform;
}

// Removed falling and landing animations to prevent glitches

// Removed land keyframes

/* Emoji-specific background colors - more vibrant and unique */
.cell.emoji-apple { 
  background: linear-gradient(135deg, #ff6b6b, #ee5a52);
  border-color: #dc2626;
  box-shadow: 0 6px 16px rgba(220, 38, 38, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
}
.cell.emoji-lemon { 
  background: linear-gradient(135deg, #ffd93d, #ffc107);
  border-color: #f59e0b;
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
}
.cell.emoji-grape { 
  background: linear-gradient(135deg, #a855f7, #9333ea);
  border-color: #7c3aed;
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
}
.cell.emoji-cherry { 
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: #b91c1c;
  box-shadow: 0 6px 16px rgba(185, 28, 28, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
}
.cell.emoji-watermelon { 
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-color: #15803d;
  box-shadow: 0 6px 16px rgba(21, 128, 61, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
}
.cell.emoji-orange { 
  background: linear-gradient(135deg, #fb923c, #ea580c);
  border-color: #c2410c;
  box-shadow: 0 6px 16px rgba(194, 65, 12, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
}
.cell.emoji-pineapple { 
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-color: #d97706;
  box-shadow: 0 6px 16px rgba(217, 119, 6, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
}
.cell.emoji-kiwi { 
  background: linear-gradient(135deg, #84cc16, #65a30d);
  border-color: #4d7c0f;
  box-shadow: 0 6px 16px rgba(77, 124, 15, 0.3), inset 0 -3px 0 rgba(0,0,0,.1);
}
.cell:hover:not(.swapping) { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(7, 23, 66, 0.2); }
.cell:active:not(.swapping) { transform: translateY(0); }

.cell.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  filter: drop-shadow(0 0 12px rgba(59,130,246,.45));
  animation: selectedPulse 1.5s ease-in-out infinite;
  transform: scale(1.05);
  z-index: 8;
}

@keyframes selectedPulse {
  0%, 100% { 
    outline-color: var(--accent);
    filter: drop-shadow(0 0 12px rgba(59,130,246,.45));
  }
  50% { 
    outline-color: rgba(59,130,246,0.7);
    filter: drop-shadow(0 0 20px rgba(59,130,246,.7));
  }
}

/* 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 */
.cell.power-row, .cell.power-col, .cell.power-cross, .cell.power-color {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(37, 99, 235, 0.3));
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.2), inset 0 -3px 0 rgba(0,0,0,.06);
}

/* Match / Floating score */
.cell.match { 
  animation: matchPop 400ms cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
  z-index: 15;
}

.floating {
  position:absolute; color:#111827; font-weight:900; pointer-events:none;
  transform: translate(-50%, -40%); opacity:0;
  animation: floatUp 1000ms ease-out forwards;
  z-index: 20;
  text-shadow: 0 0 10px rgba(255,255,255,0.8);
}

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -10%) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -20%) scale(1.1); }
  80% { opacity: 0.8; transform: translate(-50%, -80%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(0.9); }
}

@keyframes matchPop {
  0% { 
    transform: scale(1) rotate(0deg); 
    opacity: 1; 
    filter: brightness(1);
  }
  25% { 
    transform: scale(1.15) rotate(5deg); 
    opacity: 0.9; 
    filter: brightness(1.3) drop-shadow(0 0 15px rgba(255,255,255,0.6));
  }
  50% { 
    transform: scale(1.3) rotate(-3deg); 
    opacity: 0.7; 
    filter: brightness(1.5) drop-shadow(0 0 20px rgba(255,255,255,0.8));
  }
  75% { 
    transform: scale(0.8) rotate(2deg); 
    opacity: 0.4; 
    filter: brightness(1.2) drop-shadow(0 0 10px rgba(255,255,255,0.4));
  }
  100% { 
    transform: scale(0.1) rotate(0deg); 
    opacity: 0; 
    filter: brightness(1);
  }
}

/* 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; }

/* Fullscreen board styling */
.fullscreen-board {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 9999 !important;
  background: var(--bg1) !important;
  display: grid !important;
  grid-template-columns: repeat(var(--size), var(--cell-size)) !important;
  grid-template-rows: repeat(var(--size), var(--cell-size)) !important;
  gap: var(--gap) !important;
  justify-content: center !important;
  align-content: center !important;
  padding: 20px !important;
  box-sizing: border-box !important;
  /* Scale up cells for fullscreen */
  --cell-size: clamp(35px, 4.5vw, 60px) !important;
  --gap: clamp(6px, 0.8vw, 10px) !important;
}

.fullscreen-board .particles {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 1 !important;
  pointer-events: none !important;
}

.fullscreen-board .top-bar {
  position: absolute !important;
  top: 20px !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  z-index: 2 !important;
  background: rgba(0, 0, 0, 0.7) !important;
  padding: 10px 20px !important;
  border-radius: 25px !important;
  backdrop-filter: blur(10px) !important;
}

.fullscreen-board .progress {
  width: calc(16 * var(--cell-size) + 15 * var(--gap)) !important;
}

/* Exit fullscreen button */
.fullscreen-board::before {
  content: "✕" !important;
  position: fixed !important;
  top: 20px !important;
  right: 20px !important;
  z-index: 10000 !important;
  background: rgba(0, 0, 0, 0.7) !important;
  color: white !important;
  width: 40px !important;
  height: 40px !important;
  border-radius: 50% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 20px !important;
  cursor: pointer !important;
  backdrop-filter: blur(10px) !important;
  transition: background 0.2s ease !important;
}

.fullscreen-board::before:hover {
  background: rgba(0, 0, 0, 0.9) !important;
}

/* Responsive Design */
@media (max-width: 1200px) {
  :root {
    --cell-size: clamp(26px, 3vw, 42px);
    --gap: clamp(3px, 0.5vw, 7px);
  }
}

@media (max-width: 768px) {
  :root { 
    --cell-size: clamp(22px, 2.8vw, 32px);
    --gap: clamp(2px, 0.4vw, 6px);
  }
  
  .page {
    padding: 20px 8px !important;
  }
  
  .game-stats {
    gap: 15px;
    margin-bottom: 8px;
  }
  
  .stat-item {
    gap: 2px;
  }
  
  .stat-label {
    font-size: 0.7em;
  }
  
  .stat-value {
    font-size: 1em;
  }
  
  .game-controls .btn {
    padding: 8px 16px;
    font-size: 0.8em;
    min-width: 80px;
    margin: 0 4px;
  }
  
  .top100, .game-info {
    padding: 12px;
    margin-top: 8px;
  }
  
  .top100 h3, .game-info h3 {
    font-size: clamp(14px, 2vw, 18px);
    margin: 0 0 8px;
  }
}

@media (max-width: 520px) {
  :root { 
    --cell-size: clamp(18px, 2.2vw, 28px);
    --gap: clamp(1px, 0.3vw, 4px);
  }
  
  body {
    padding: 40px 6px calc(5vh + 6px) 6px !important;
  }
  
  .page {
    gap: 4px;
  }
  
  .game-stats {
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .game-controls {
    flex-direction: column;
    gap: 8px;
    align-items: center;
  }
  
  .game-controls .btn {
    width: 100%;
    max-width: 200px;
    margin: 2px 0;
  }
  
  .logo-header {
    padding: 6px 0;
  }
  
  .logo-header a {
    font-size: 1rem;
  }
  
  .page h1 {
    font-size: clamp(14px, 3.5vw, 24px);
    margin: 8px 0;
  }
}

@media (max-width: 360px) {
  :root { 
    --cell-size: clamp(16px, 2vw, 24px);
    --gap: clamp(1px, 0.2vw, 3px);
  }
  
  .game-stats {
    gap: 8px;
  }
  
  .stat-label {
    font-size: 0.6em;
  }
  
  .stat-value {
    font-size: 0.9em;
  }
  
  .top100, .game-info {
    padding: 8px;
  }
}

/* Landscape orientation for mobile */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --cell-size: clamp(16px, 2.5vh, 28px);
    --gap: clamp(1px, 0.3vh, 4px);
  }
  
  body {
    padding: 20px 8px 10px 8px !important;
  }
  
  .page {
    min-height: auto;
  }
  
  .game-stats {
    margin-bottom: 6px;
  }
  
  .top100, .game-info {
    margin-top: 6px;
    padding: 8px;
  }
  
  .top100 h3, .game-info h3 {
    font-size: 14px;
    margin: 0 0 6px;
  }
}