/* ─────────────────────────────────────────────
   CANDY CRUSH  –  candy.css
   ───────────────────────────────────────────── */

:root {
    --bg-deep:    #0f0a1e;
    --bg-mid:     #1a0f35;
    --panel:      #1e1040;
    --border:     #6d28d9;
    --border-hi:  #a855f7;
    --accent:     #f472b6;
    --gold:       #fbbf24;
    --teal:       #2dd4bf;
    --cell-size:  52px;
    --gap:        3px;
    --radius:     10px;
    --font-head:  'Fredoka One', cursive;
    --font-body:  'Nunito', sans-serif;
    --transition: 0.15s ease;
}

/* ── Reset & base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    min-height: 100vh;
    background: var(--bg-deep);
    background-image:
        radial-gradient(ellipse 60% 50% at 15% 15%, #2d0764 0%, transparent 55%),
        radial-gradient(ellipse 50% 60% at 85% 85%, #0f2460 0%, transparent 55%),
        radial-gradient(ellipse 40% 40% at 50% 50%, #1a0f35 0%, transparent 70%);
    font-family: var(--font-body);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-x: hidden;
}

/* ── Background particles ─────────────────────── */
.particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}
.particle {
    position: absolute;
    opacity: 0.18;
    animation: particleFloat linear infinite;
    will-change: transform;
}
/* FIX: was translate(150vh) — particles flew sideways. Fixed to translateY. */
@keyframes particleFloat {
    from { transform: translateY(105vh) rotate(0deg); opacity: 0.18; }
    to   { transform: translateY(-8vh)  rotate(360deg); opacity: 0; }
}

/* FIX: was .Game-wrapper (capital G) — selector never matched. Fixed casing. */
.game-wrapper {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    max-width: 540px;
}

/* ── Title ────────────────────────────────────── */
.game-title {
    font-family: var(--font-head);
    font-size: clamp(2rem, 7vw, 3.2rem);
    letter-spacing: 2px;
    background: linear-gradient(135deg, #f472b6 0%, #a855f7 50%, #fbbf24 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 18px rgba(168,85,247,0.6));
    animation: titlePulse 3s ease-in-out infinite;
    line-height: 1.1;
}
@keyframes titlePulse {
    0%, 100% { filter: drop-shadow(0 0 18px rgba(168,85,247,0.6)); }
    50%       { filter: drop-shadow(0 0 32px rgba(244,114,182,1));  }
}

/* ── Stats bar ────────────────────────────────── */
/* FIX: was Stats-bar (missing dot) — rule never applied. Fixed to .stats-bar. */
.stats-bar {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
}
.stat-box {
    flex: 1;
    max-width: 130px;
    background: var(--panel);
    border: 2px solid var(--border);
    border-radius: 14px;
    padding: 8px 12px;
    text-align: center;
    box-shadow: 0 0 18px rgba(109,40,217,0.3), inset 0 1px 0 rgba(255,255,255,0.08);
    transition: box-shadow var(--transition);
}
.level-box {
    border-color: var(--gold);
    box-shadow: 0 0 18px rgba(251,191,36,0.25), inset 0 1px 0 rgba(255,255,255,0.08);
}
.stat-label {
    display: block;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 2px;
    color: var(--border-hi);
    margin-bottom: 2px;
}
.level-box .stat-label { color: var(--gold); }
.stat-value {
    font-family: var(--font-head);
    font-size: 1.75rem;
    color: #fff;
    line-height: 1;
    transition: transform 0.15s, color 0.15s;
    display: block;
}
.stat-value.bump {
    transform: scale(1.3);
    color: var(--gold);
}

/* ── Progress bar ─────────────────────────────── */
.progress-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}
.progress-bar {
    width: 100%;
    height: 10px;
    background: rgba(255,255,255,0.08);
    border-radius: 99px;
    overflow: hidden;
    border: 1px solid rgba(109,40,217,0.4);
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #a855f7, #f472b6, #fbbf24);
    border-radius: 99px;
    transition: width 0.5s cubic-bezier(0.34,1.56,0.64,1);
    box-shadow: 0 0 8px rgba(244,114,182,0.7);
}
.progress-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
}

/* ── Board glow wrapper ───────────────────────── */
.board-glow-wrap {
    background: var(--panel);
    border: 3px solid var(--border);
    border-radius: 20px;
    padding: 10px;
    box-shadow:
        0 0 40px rgba(109,40,217,0.45),
        0 0 80px rgba(109,40,217,0.15),
        inset 0 1px 0 rgba(255,255,255,0.07);
    position: relative;
    animation: boardBreath 4s ease-in-out infinite;
}
@keyframes boardBreath {
    0%, 100% { box-shadow: 0 0 40px rgba(109,40,217,0.45), 0 0 80px rgba(109,40,217,0.15), inset 0 1px 0 rgba(255,255,255,0.07); }
    50%       { box-shadow: 0 0 55px rgba(168,85,247,0.65), 0 0 100px rgba(168,85,247,0.25), inset 0 1px 0 rgba(255,255,255,0.07); }
}

/* ── Board grid ───────────────────────────────── */
#board {
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    grid-template-rows:    repeat(9, var(--cell-size));
    gap: var(--gap);
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0,0,0,0.35);
}

/* ── Candy tiles ──────────────────────────────── */
#board img {
    width:  var(--cell-size);
    height: var(--cell-size);
    cursor: grab;
    border-radius: var(--radius);
    background: rgba(255,255,255,0.04);
    transition: transform var(--transition), filter var(--transition), box-shadow var(--transition);
    object-fit: contain;
    padding: 4px;
    animation: candyAppear 0.35s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes candyAppear {
    from { transform: scale(0) rotate(-20deg); opacity: 0; }
    to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}
#board img:hover {
    transform: scale(1.12) translateY(-2px);
    filter: brightness(1.25) drop-shadow(0 4px 10px rgba(168,85,247,0.6));
    z-index: 5;
    position: relative;
    background: rgba(255,255,255,0.1);
    cursor: grab;
}
#board img[src*="blank"] {
    cursor: default;
    opacity: 0;
    pointer-events: none;
}
#board img.dragging {
    opacity: 0.45;
    transform: scale(0.85);
    cursor: grabbing;
    filter: brightness(0.8);
}
#board img.highlight-hint {
    animation: hintPulse 0.6s ease-in-out 3;
}
@keyframes hintPulse {
    0%, 100% { filter: brightness(1);   box-shadow: none; }
    50%       { filter: brightness(1.5) drop-shadow(0 0 12px #fbbf24); box-shadow: inset 0 0 0 2px #fbbf24; }
}

/* Crush animation */
#board img.crush-anim {
    animation: crushPop 0.35s ease-out forwards;
}
@keyframes crushPop {
    0%   { transform: scale(1);    opacity: 1; }
    40%  { transform: scale(1.45); opacity: 0.9; filter: brightness(2); }
    100% { transform: scale(0);    opacity: 0; }
}

/* FIX: was translateY(-30deg) — degrees invalid for translate. Fixed to px. */
#board img.drop-anim {
    animation: dropBounce 0.4s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes dropBounce {
    from { transform: translateY(-30px) scale(0.7); opacity: 0; }
    to   { transform: translateY(0)     scale(1);   opacity: 1; }
}

/* Swap flash */
#board img.swap-flash {
    animation: swapFlash 0.25s ease-out;
}
@keyframes swapFlash {
    0%, 100% { filter: brightness(1); }
    50%       { filter: brightness(1.8) drop-shadow(0 0 8px #f472b6); }
}

/* Invalid swap shake */
#board img.invalid-shake {
    animation: invalidShake 0.35s ease;
}
@keyframes invalidShake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-6px); }
    40%      { transform: translateX(6px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(4px); }
}

/* ── Floating score pop label ─────────────────── */
.pop-label {
    position: fixed;
    font-family: var(--font-head);
    font-size: 15px;
    color: var(--gold);
    pointer-events: none;
    z-index: 9999;
    white-space: nowrap;
    text-shadow: 0 0 8px rgba(251,191,36,0.9);
    animation: popFloat 0.9s ease-out forwards;
}
@keyframes popFloat {
    0%   { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-55px) scale(1.4); }
}

/* ── Buttons ──────────────────────────────────── */
.btn-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}
.btn {
    font-family: var(--font-head);
    font-size: 0.95rem;
    letter-spacing: 1px;
    padding: 10px 20px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--panel);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 12px rgba(109,40,217,0.3);
}
.btn:hover {
    background: var(--border);
    box-shadow: 0 0 22px rgba(109,40,217,0.7);
    transform: translateY(-3px);
}
.btn:active { transform: translateY(0); }
.btn.sound-off {
    border-color: rgba(109,40,217,0.3);
    opacity: 0.55;
}

/* ── Combo badge ──────────────────────────────── */
.combo-badge {
    font-family: var(--font-head);
    font-size: 1.4rem;
    color: var(--accent);
    letter-spacing: 2px;
    min-height: 36px;
    text-shadow: 0 0 14px rgba(244,114,182,0.9);
    transition: opacity 0.3s;
    opacity: 0;
}
.combo-badge.visible {
    opacity: 1;
    animation: comboPop 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes comboPop {
    from { transform: scale(0.5); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

/* ── Level-up overlay ─────────────────────────── */
.level-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    /* FIX: was justify-self (not valid on flex container). Fixed to justify-content. */
    justify-content: center;
    z-index: 1000;
    background: rgba(10,5,25,0.7);
    backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.level-overlay.show {
    opacity: 1;
    pointer-events: all;
}
.level-overlay-inner {
    text-align: center;
    /* FIX: was cubic-bezier(0.34,1.56,0,64,1) — missing dot before 64. Fixed. */
    animation: levelUpBounce 0.6s cubic-bezier(0.34,1.56,0.64,1);
}
/* FIX: "to" had opacity:0 — overlay appeared then instantly vanished. Fixed to opacity:1. */
@keyframes levelUpBounce {
    from { transform: scale(0.3) rotate(-10deg); opacity: 0; }
    to   { transform: scale(1)   rotate(0deg);   opacity: 1; }
}
.level-up-emoji { font-size: 5rem; line-height: 1; }
.level-up-title {
    font-family: var(--font-head);
    font-size: 3.5rem;
    background: linear-gradient(135deg, #fbbf24, #f472b6);
    /* FIX: was --webkit- (double dash = CSS var, not vendor prefix). Fixed to -webkit-. */
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 20px rgba(251,191,36,0.8));
}
.level-up-sub {
    font-size: 1.2rem;
    font-weight: 700;
    color: rgba(255,255,255,0.75);
    margin-top: 6px;
}

/* ── Responsive ───────────────────────────────── */
@media (max-width: 520px) {
    :root { --cell-size: 38px; --gap: 2px; }
    .game-title { font-size: 1.8rem; }
    .stat-value  { font-size: 1.4rem; }
    .board-glow-wrap { padding: 7px; }
}
@media (max-width: 380px) {
    :root { --cell-size: 32px; --gap: 1px; }
}