/* ==========================================================================
   JELLY MATCH - 3D JELLY CARD MATCHING GAME STYLES (DYNAMIC SCREEN FIT)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&family=Outfit:wght@400;600;800&display=swap');

:root {
  --bg-gradient: linear-gradient(135deg, #1b0a2a 0%, #32104d 40%, #170d38 100%);
  --glass-bg: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.18);
  --glass-shadow: 0 10px 35px rgba(0, 0, 0, 0.5);
  --accent-gold: #ffd15c;
  --accent-pink: #ff3b7b;
  --accent-cyan: #00dfd8;
  --text-color: #ffffff;
  --font-family: 'Fredoka', 'Outfit', sans-serif;

  --card-size: min(80px, 10.5vh, 14.5vw);
  --grid-gap: min(7px, 1.1vh);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  background: var(--bg-gradient);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 4px 0;
}

/* Background animated decorative blur shapes */
.bg-decor {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
  animation: floatBg 16s infinite alternate ease-in-out;
}

.bg-decor-1 {
  width: 300px;
  height: 300px;
  background: #ff3b7b;
  top: -60px;
  left: -60px;
}

.bg-decor-2 {
  width: 320px;
  height: 320px;
  background: #7928ca;
  bottom: -80px;
  right: -60px;
  animation-delay: -6s;
}

@keyframes floatBg {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, 30px) scale(1.15); }
  100% { transform: translate(-30px, 20px) scale(0.9); }
}

/* Particle Canvas Overlay */
#particle-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 99;
}

/* App Container */
.game-container {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  max-width: 580px;
  width: 95%;
  max-height: 98vh;
  height: auto;
}

/* Header HUD */
.hud-header {
  width: 100%;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 16px;
  padding: min(6px, 1vh) min(14px, 2vw);
  margin-bottom: min(6px, 1vh);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hud-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-label {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 600;
}

.hud-value {
  font-size: min(1.1rem, 2.5vh);
  font-weight: 700;
  color: var(--accent-gold);
  text-shadow: 0 2px 8px rgba(255, 209, 92, 0.4);
}

.streak-badge {
  background: linear-gradient(135deg, #ff3b7b, #ff758c);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(255, 59, 123, 0.4);
  transition: transform 0.2s ease;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition: transform 0.2s ease, background 0.2s ease;
}

.btn-icon:hover {
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.25);
}

/* Power-ups Toolbar */
.powerup-bar {
  display: flex;
  gap: 8px;
  margin-bottom: min(6px, 1vh);
}

.btn-powerup {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 4px 12px;
  color: white;
  font-family: var(--font-family);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.btn-powerup:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.04);
  background: rgba(255, 255, 255, 0.2);
}

.btn-powerup:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 3D Card Grid Board */
.board-wrapper {
  position: relative;
  background: rgba(18, 10, 36, 0.65);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 14px 45px rgba(0, 0, 0, 0.6), inset 0 0 20px rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  padding: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.grid-board {
  display: grid;
  gap: var(--grid-gap);
  perspective: 1000px;
}

/* Card 3D Flip Container */
.card-slot {
  width: var(--card-size);
  height: var(--card-size);
  position: relative;
  cursor: pointer;
  perspective: 1000px;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-radius: 14px;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.35);
}

.card-slot:hover .card-inner:not(.flipped):not(.matched) {
  transform: translateY(-3px) scale(1.05);
}

.card-inner.flipped,
.card-inner.matched {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* Card Back (Glossy Jelly Pattern) */
.card-back {
  background: radial-gradient(circle at 35% 35%, #9d36ff, #430b7a);
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 3px 6px rgba(255, 255, 255, 0.6);
  position: relative;
  overflow: hidden;
  transform: rotateY(0deg);
  z-index: 1;
  opacity: 1;
  visibility: visible;
}

.card-back::before {
  content: '🍬';
  font-size: calc(var(--card-size) * 0.4);
}

.card-back::after {
  content: '';
  position: absolute;
  top: 12%;
  left: 15%;
  width: 35%;
  height: 25%;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  transform: rotate(-30deg);
  pointer-events: none;
}

/* Card Front (Jelly Fruit Face) */
.card-front {
  background: linear-gradient(135deg, #2b144d 0%, #160a30 100%);
  border: 2px solid rgba(255, 255, 255, 0.3);
  transform: rotateY(180deg);
  box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.1);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  z-index: 2;
}

/* Explicit Visibility Toggles */
.card-inner:not(.flipped):not(.matched) .card-front {
  opacity: 0;
  visibility: hidden;
}

.card-inner.flipped .card-back,
.card-inner.matched .card-back {
  opacity: 0;
  visibility: hidden;
}

.card-inner.flipped .card-front,
.card-inner.matched .card-front {
  opacity: 1;
  visibility: visible;
}

.card-front svg {
  width: 84%;
  height: 84%;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.4));
}

/* Matched Jelly Card Effect */
.card-inner.matched .card-front {
  background: linear-gradient(135deg, #0d3d3a 0%, #062422 100%);
  border-color: #00dfd8;
  box-shadow: 0 0 16px rgba(0, 223, 216, 0.7);
}

/* Modals & Overlays */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 4, 25, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: rgba(32, 16, 56, 0.92);
  border: 2px solid var(--glass-border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  border-radius: 22px;
  width: 90%;
  max-width: 380px;
  padding: 20px 16px;
  text-align: center;
  transform: scale(0.85) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-card {
  transform: scale(1) translateY(0);
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, #ffd15c, #ff3b7b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.modal-subtitle {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 14px;
}

.btn-primary {
  background: linear-gradient(135deg, #ff3b7b 0%, #d80056 100%);
  border: none;
  color: white;
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 700;
  padding: 8px 24px;
  border-radius: 22px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 59, 123, 0.5);
  margin: 4px 4px;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 18px;
  border-radius: 22px;
  cursor: pointer;
  margin: 4px 4px;
}

.diff-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.diff-card {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 10px 6px;
  cursor: pointer;
}

.diff-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent-gold);
}

.diff-desc {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
}

/* Ad Banner Area */
.ad-banner {
    width: 90%;
    max-width: 600px;
    height: 90px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    margin: 10px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.ad-label {
    position: absolute;
    color: rgba(255,255,255,0.6);
    font-size: 0.9rem;
    pointer-events: none;
}
.ad-bottom { margin-top: auto; margin-bottom: 20px; }
