/* ================================
   Fruit Frenzy - Styles
   A Tropical Match-3 Adventure
   ================================ */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --coral: #FF6B6B;
    --coral-dark: #e55a5a;
    --mango: #FFB347;
    --sunset: #FF8E72;
    --cream: #FFF8F0;
    --cream-dark: #f5f0eb;
    --teal: #20B2AA;
    --teal-dark: #1A9690;
    --purple-accent: #9B59B6;
    --gold: #FFD700;
    --shadow-color: rgba(139, 69, 19, 0.2);
    --grid-size: min(85vw, 400px);
    --cell-size: calc(var(--grid-size) / 8);
}

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

body {
    font-family: 'DM Sans', sans-serif;
    background: linear-gradient(135deg, #FF6B6B 0%, #FFB347 50%, #FF8E72 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    position: relative;
    overflow: hidden;
}

/* Animated Background */
.background-layer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 0;
}

.bubble {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    animation: float 8s ease-in-out infinite;
}

.bubble:nth-child(1) { width: 80px; height: 80px; left: 10%; top: 20%; animation-delay: 0s; }
.bubble:nth-child(2) { width: 120px; height: 120px; right: 15%; top: 60%; animation-delay: 2s; }
.bubble:nth-child(3) { width: 60px; height: 60px; left: 20%; bottom: 20%; animation-delay: 4s; }
.bubble:nth-child(4) { width: 100px; height: 100px; right: 10%; top: 15%; animation-delay: 1s; }
.bubble:nth-child(5) { width: 50px; height: 50px; left: 5%; top: 50%; animation-delay: 3s; }
.bubble:nth-child(6) { width: 70px; height: 70px; right: 25%; bottom: 15%; animation-delay: 5s; }

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.3; }
    50% { transform: translateY(-30px) rotate(180deg); opacity: 0.6; }
}

/* Theme Backgrounds */
body.theme-tropical {
    background: linear-gradient(135deg, #FF6B6B 0%, #FFB347 50%, #FF8E72 100%);
}

body.theme-berry {
    background: linear-gradient(135deg, #9B59B6 0%, #E91E63 50%, #FF5722 100%);
}

body.theme-ocean {
    background: linear-gradient(135deg, #00BCD4 0%, #2196F3 50%, #3F51B5 100%);
}

body.theme-forest {
    background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 50%, #CDDC39 100%);
}

body.theme-night {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

body.theme-night .game-container {
    background: #1e1e2e;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(255, 255, 255, 0.1);
}

body.theme-night .stat-box,
body.theme-night .cell {
    background: linear-gradient(145deg, #2a2a3e 0%, #1e1e2e 100%);
    color: #fff;
}

body.theme-night .stat-label {
    color: #888;
}

body.theme-night .game-board {
    background: linear-gradient(145deg, #151525 0%, #1a1a2e 100%);
}

/* Game Container */
.game-container {
    background: var(--cream);
    border-radius: 1.75rem;
    padding: 1.25rem;
    box-shadow:
        0 20px 60px var(--shadow-color),
        0 0 0 6px rgba(255, 255, 255, 0.3),
        inset 0 2px 0 rgba(255, 255, 255, 0.8);
    max-width: 420px;
    width: 100%;
    position: relative;
    z-index: 10;
    transition: transform 0.1s ease;
}

.game-container.shake {
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px) rotate(-1deg); }
    40% { transform: translateX(8px) rotate(1deg); }
    60% { transform: translateX(-4px) rotate(-0.5deg); }
    80% { transform: translateX(4px) rotate(0.5deg); }
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    position: relative;
}

.game-title {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 700;
    background: linear-gradient(135deg, var(--coral) 0%, var(--mango) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.title-emoji {
    font-size: 0.8em;
    animation: bounce 1s ease-in-out infinite;
    -webkit-text-fill-color: initial;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.header-buttons {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #fff 0%, var(--cream-dark) 100%);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 8px rgba(0,0,0,0.1), 0 2px 0 #e0d8d0;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 12px rgba(0,0,0,0.15), 0 3px 0 #e0d8d0;
}

.icon-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1), 0 1px 0 #e0d8d0;
}

.icon-btn.active {
    background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
    box-shadow: 0 3px 8px rgba(32, 178, 170, 0.3), 0 2px 0 var(--teal-dark);
}

/* Mode Selector */
.mode-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    background: rgba(0,0,0,0.05);
    padding: 4px;
    border-radius: 12px;
}

.mode-btn {
    flex: 1;
    padding: 0.5rem;
    border: none;
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: #888;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: white;
    color: var(--coral);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.mode-btn:hover:not(.active) {
    color: var(--coral);
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.stat-box {
    flex: 1;
    background: linear-gradient(135deg, #fff 0%, var(--cream-dark) 100%);
    border-radius: 0.875rem;
    padding: 0.6rem 0.5rem;
    text-align: center;
    box-shadow:
        0 4px 12px rgba(0,0,0,0.08),
        inset 0 -2px 0 rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
}

.stat-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 0.875rem 0.875rem 0 0;
}

.stat-box.score::before { background: linear-gradient(90deg, var(--teal), #4ECDC4); }
.stat-box.level::before { background: linear-gradient(90deg, var(--purple-accent), #D980FA); }
.stat-box.moves::before { background: linear-gradient(90deg, var(--coral), var(--mango)); }
.stat-box.timer::before { background: linear-gradient(90deg, var(--gold), #FFA500); }
.stat-box.streak::before { background: linear-gradient(90deg, #FF6B6B, #FF8E72); }
.stat-box.high-score::before { background: linear-gradient(90deg, var(--gold), var(--mango)); }

.stat-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #888;
    margin-bottom: 0.15rem;
}

.stat-value {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(1rem, 3.5vw, 1.25rem);
    font-weight: 700;
    color: var(--coral);
}

.stat-box.score .stat-value { color: var(--teal); }
.stat-box.level .stat-value { color: var(--purple-accent); }
.stat-box.timer .stat-value { color: #FFA500; }
.stat-box.streak .stat-value { color: var(--coral); }
.stat-box.high-score .stat-value { color: var(--gold); }

.stat-box.timer.warning .stat-value {
    color: var(--coral);
    animation: pulse-warning 0.5s ease-in-out infinite;
}

@keyframes pulse-warning {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Progress Bar */
.progress-container {
    margin-bottom: 0.75rem;
    background: #eee;
    border-radius: 1rem;
    height: 14px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--teal), var(--coral), var(--mango));
    background-size: 200% 100%;
    border-radius: 1rem;
    transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: shimmer 2s ease-in-out infinite;
    position: relative;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.3), transparent);
    border-radius: 1rem 1rem 0 0;
}

@keyframes shimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.progress-stars {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 2px;
    font-size: 0.7rem;
    z-index: 5;
}

.progress-stars .star {
    opacity: 0.4;
    transition: all 0.3s ease;
}

.progress-stars .star.earned {
    opacity: 1;
    animation: starPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes starPop {
    0% { transform: scale(0); }
    50% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

.star-1 { left: 33%; }
.star-2 { left: 66%; }
.star-3 { right: 4%; }

/* Game Board */
.game-board-wrapper {
    position: relative;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    background: linear-gradient(145deg, #e8e0d8 0%, #d4ccc4 100%);
    padding: 6px;
    border-radius: 1rem;
    box-shadow:
        inset 0 4px 12px rgba(0,0,0,0.15),
        0 4px 0 #c4bab0;
    position: relative;
    touch-action: none;
}

.cell {
    aspect-ratio: 1;
    background: linear-gradient(145deg, #fff 0%, var(--cream-dark) 100%);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--cell-size) * 0.6);
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.15s ease;
    box-shadow:
        0 2px 4px rgba(0,0,0,0.1),
        inset 0 1px 0 rgba(255,255,255,0.8);
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    overflow: hidden;
}

.cell:active {
    transform: scale(0.92);
}

.cell.selected {
    transform: scale(1.12);
    box-shadow:
        0 8px 20px rgba(255, 107, 107, 0.4),
        0 0 0 3px var(--coral),
        inset 0 1px 0 rgba(255,255,255,0.8);
    z-index: 10;
    animation: pulse 0.6s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 8px 20px rgba(255, 107, 107, 0.4), 0 0 0 3px var(--coral); }
    50% { box-shadow: 0 8px 25px rgba(255, 107, 107, 0.6), 0 0 0 5px var(--mango); }
}

.cell.hint {
    animation: hint 0.8s ease-in-out infinite;
}

@keyframes hint {
    0%, 100% { transform: scale(1); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
    50% { transform: scale(1.08); box-shadow: 0 4px 12px rgba(32, 178, 170, 0.4), 0 0 0 2px var(--teal); }
}

.cell.matched {
    animation: pop 0.3s ease-out forwards;
}

@keyframes pop {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.8; }
    100% { transform: scale(0); opacity: 0; }
}

.cell.dropping {
    animation: drop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes drop {
    0% { transform: translateY(-100%) scale(0.8); opacity: 0; }
    60% { transform: translateY(10%) scale(1.05); opacity: 1; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.cell.swapping {
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Special Fruit Indicators */
.cell.special-line {
    background: linear-gradient(145deg, #fff4e6 0%, #ffe4c4 100%);
}

.cell.special-line::after {
    content: '';
    position: absolute;
    inset: 2px;
    border: 2px dashed var(--mango);
    border-radius: 4px;
    animation: rotate 4s linear infinite;
}

.cell.special-bomb {
    background: linear-gradient(145deg, #ffe6e6 0%, #ffc4c4 100%);
}

.cell.special-bomb::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    border: 2px solid var(--coral);
    animation: pulse-border 1s ease-in-out infinite;
}

.cell.special-rainbow {
    background: linear-gradient(145deg,
        #ffcccc, #ffe6cc, #ffffcc, #e6ffcc, #ccffcc, #ccffe6, #ccffff, #cce6ff, #ccccff, #e6ccff);
    background-size: 400% 400%;
    animation: rainbow-shift 3s ease infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulse-border {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(0.9); opacity: 0.6; }
}

@keyframes rainbow-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* Line Clear Effect */
.line-clear-h, .line-clear-v {
    position: absolute;
    background: linear-gradient(90deg, transparent, var(--mango), white, var(--mango), transparent);
    z-index: 100;
    pointer-events: none;
}

.line-clear-h {
    height: calc(var(--cell-size) + 6px);
    width: 0;
    left: 0;
    animation: line-clear-horizontal 0.4s ease-out forwards;
}

.line-clear-v {
    width: calc(var(--cell-size) + 6px);
    height: 0;
    top: 0;
    animation: line-clear-vertical 0.4s ease-out forwards;
}

@keyframes line-clear-horizontal {
    0% { width: 0; opacity: 1; }
    100% { width: 100%; opacity: 0; }
}

@keyframes line-clear-vertical {
    0% { height: 0; opacity: 1; }
    100% { height: 100%; opacity: 0; }
}

/* Bomb Explosion Effect */
.bomb-explosion {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, white, var(--coral), transparent);
    z-index: 100;
    pointer-events: none;
    animation: explode 0.5s ease-out forwards;
}

@keyframes explode {
    0% { transform: scale(0); opacity: 1; }
    50% { opacity: 0.8; }
    100% { transform: scale(3); opacity: 0; }
}

/* Combo Display */
.combo-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Fredoka', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--coral);
    text-shadow:
        0 4px 8px var(--shadow-color),
        0 0 20px rgba(255, 107, 107, 0.5);
    pointer-events: none;
    opacity: 0;
    z-index: 100;
    white-space: nowrap;
}

.combo-display.show {
    animation: comboPopup 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes comboPopup {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    60% { transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(0.8); }
}

/* Particles */
.particle {
    position: absolute;
    pointer-events: none;
    font-size: 1.25rem;
    z-index: 50;
    animation: particleFly 0.8s ease-out forwards;
}

@keyframes particleFly {
    0% { opacity: 1; transform: translate(0, 0) scale(1) rotate(0deg); }
    100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0) rotate(360deg); }
}

/* Sparkle particles for special fruits */
.sparkle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: white;
    border-radius: 50%;
    pointer-events: none;
    animation: sparkle 0.6s ease-out forwards;
}

@keyframes sparkle {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0) translate(var(--tx), var(--ty)); }
}

/* Buttons */
.button-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.game-btn {
    flex: 1;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 0.875rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.game-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s ease;
}

.game-btn:hover::before {
    left: 100%;
}

.game-btn.primary {
    background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
    color: white;
    box-shadow:
        0 4px 15px rgba(32, 178, 170, 0.4),
        0 3px 0 var(--teal-dark);
}

.game-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow:
        0 6px 20px rgba(32, 178, 170, 0.5),
        0 5px 0 var(--teal-dark);
}

.game-btn.primary:active {
    transform: translateY(2px);
    box-shadow:
        0 2px 8px rgba(32, 178, 170, 0.4),
        0 1px 0 var(--teal-dark);
}

.game-btn.secondary {
    background: linear-gradient(135deg, #fff 0%, var(--cream-dark) 100%);
    color: var(--coral);
    box-shadow:
        0 3px 10px rgba(0,0,0,0.1),
        0 2px 0 #e0d8d0;
}

.game-btn.secondary:hover {
    transform: translateY(-2px);
    box-shadow:
        0 5px 14px rgba(0,0,0,0.15),
        0 4px 0 #e0d8d0;
}

.game-btn.secondary:active {
    transform: translateY(1px);
}

.game-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.game-btn .btn-badge {
    background: rgba(255,255,255,0.3);
    padding: 0.1rem 0.4rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 1rem;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--cream);
    border-radius: 1.75rem;
    padding: 1.75rem;
    text-align: center;
    max-width: 320px;
    width: 100%;
    transform: scale(0.8) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

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

.modal-emoji {
    font-size: 3.5rem;
    margin-bottom: 0.75rem;
    animation: modalBounce 0.6s ease-in-out infinite;
}

@keyframes modalBounce {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-10px) rotate(5deg); }
}

.modal-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--coral);
    margin-bottom: 0.4rem;
}

.modal-text {
    color: #666;
    margin-bottom: 1rem;
    line-height: 1.4;
    font-size: 0.9rem;
}

.modal-score {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--teal);
    margin: 0.75rem 0;
}

.modal-stars {
    font-size: 2rem;
    margin: 0.75rem 0;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.modal-stars .star {
    opacity: 0.3;
    transform: scale(0);
    animation: starReveal 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.modal-stars .star.earned {
    opacity: 1;
}

.modal-stars .star:nth-child(1) { animation-delay: 0.1s; }
.modal-stars .star:nth-child(2) { animation-delay: 0.2s; }
.modal-stars .star:nth-child(3) { animation-delay: 0.3s; }

@keyframes starReveal {
    0% { transform: scale(0) rotate(-180deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.modal-stats {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin: 1rem 0;
    padding: 0.75rem;
    background: rgba(0,0,0,0.03);
    border-radius: 1rem;
}

.modal-stat {
    text-align: center;
}

.modal-stat-value {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--purple-accent);
}

.modal-stat-label {
    font-size: 0.7rem;
    color: #888;
    text-transform: uppercase;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.modal-buttons .game-btn {
    width: 100%;
}

/* Score Popup */
.score-popup {
    position: fixed;
    pointer-events: none;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--mango);
    text-shadow: 0 2px 8px rgba(0,0,0,0.3), 0 0 10px rgba(255,255,255,0.5);
    z-index: 500;
    animation: scoreFloat 1s ease-out forwards;
}

@keyframes scoreFloat {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(1.2); }
}

/* Settings Panel */
.settings-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--cream);
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    z-index: 1000;
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.95);
    transform-origin: top right;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.settings-panel.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.settings-title {
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    color: var(--coral);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.settings-row:last-child {
    border-bottom: none;
}

.settings-label {
    font-size: 0.8rem;
    color: #666;
}

.toggle {
    width: 44px;
    height: 24px;
    background: #ddd;
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s ease;
}

.toggle.active {
    background: var(--teal);
}

.toggle::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle.active::after {
    transform: translateX(20px);
}

.theme-selector {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.theme-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.theme-dot:hover {
    transform: scale(1.1);
}

.theme-dot.active {
    border-color: var(--coral);
    box-shadow: 0 0 0 2px white;
}

.theme-dot.tropical { background: linear-gradient(135deg, #FF6B6B, #FFB347); }
.theme-dot.berry { background: linear-gradient(135deg, #9B59B6, #E91E63); }
.theme-dot.ocean { background: linear-gradient(135deg, #00BCD4, #2196F3); }
.theme-dot.forest { background: linear-gradient(135deg, #4CAF50, #8BC34A); }
.theme-dot.night { background: linear-gradient(135deg, #1a1a2e, #16213e); }

/* Achievement Toast */
.achievement-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: linear-gradient(135deg, var(--gold) 0%, #FFA500 100%);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 1rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 10px 30px rgba(255, 215, 0, 0.4);
    z-index: 2000;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.achievement-toast.show {
    transform: translateX(-50%) translateY(0);
}

.achievement-toast .emoji {
    font-size: 1.5rem;
}

/* ================================
   COIN DISPLAY (Header)
   ================================ */
.coin-display {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: linear-gradient(135deg, #fff 0%, var(--cream-dark) 100%);
    padding: 0.4rem 0.75rem;
    border-radius: 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    color: #666;
}

.coin-display .coin-icon {
    font-size: 1rem;
}

.coin-display .coin-value {
    min-width: 30px;
}

/* ================================
   THEME SHOP
   ================================ */
.shop-modal {
    max-width: 400px;
    max-height: 85vh;
    overflow: hidden;
    position: relative;
    padding: 1.25rem;
}

.shop-close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.1);
    color: #666;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.shop-close-btn:hover {
    background: rgba(0, 0, 0, 0.15);
    transform: scale(1.1);
}

.shop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-right: 2.5rem;
}

.shop-header .modal-title {
    margin: 0;
}

.shop-coins {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: linear-gradient(135deg, var(--gold) 0%, #FFA500 100%);
    padding: 0.35rem 0.75rem;
    border-radius: 2rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    color: white;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
}

.shop-tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
    background: rgba(0,0,0,0.05);
    padding: 4px;
    border-radius: 10px;
}

.shop-tab {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 8px;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: #888;
    transition: all 0.2s ease;
}

.shop-tab.active {
    background: white;
    color: var(--coral);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.shop-tab:hover:not(.active) {
    color: var(--coral);
}

.shop-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
    max-height: 55vh;
    overflow-y: auto;
    padding: 0.25rem;
    padding-bottom: 1rem;
}

.shop-card {
    background: linear-gradient(145deg, #fff 0%, var(--cream-dark) 100%);
    border-radius: 1rem;
    padding: 0.75rem;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease;
    position: relative;
    border: 2px solid transparent;
}

.shop-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.shop-card.active {
    border-color: var(--teal);
    background: linear-gradient(145deg, #e6fff9 0%, #d4f5f0 100%);
}

.shop-card.owned::before {
    content: '✓';
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    width: 18px;
    height: 18px;
    background: var(--teal);
    color: white;
    border-radius: 50%;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shop-card-preview {
    font-size: 1.5rem;
    line-height: 1.2;
    margin-bottom: 0.4rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.shop-card:not(.owned):not(.bundle-card):not(.coin-pack-card):not(.coin-balance-card):not(.info-card):not(.restore-card) .shop-card-preview {
    filter: grayscale(0.3) drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.shop-card-name {
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    color: #333;
    margin-bottom: 0.2rem;
}

.shop-card-desc {
    font-size: 0.65rem;
    color: #888;
    margin-bottom: 0.4rem;
    line-height: 1.2;
}

.shop-card-prices {
    display: flex;
    gap: 0.35rem;
}

.shop-card-btn {
    flex: 1;
    padding: 0.4rem 0.5rem;
    border: none;
    border-radius: 0.5rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.shop-card-btn.buy {
    background: linear-gradient(135deg, var(--coral) 0%, var(--mango) 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(255, 107, 107, 0.3);
}

.shop-card-btn.buy:hover {
    transform: scale(1.02);
}

.shop-card-btn.buy.coin-btn {
    background: linear-gradient(135deg, var(--gold) 0%, #FFA500 100%);
    box-shadow: 0 2px 6px rgba(255, 215, 0, 0.3);
}

.shop-card-btn.buy.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.shop-card-btn.buy.disabled:hover {
    transform: none;
}

.shop-card-btn.owned {
    background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
    color: #666;
}

.shop-card-btn.owned:hover {
    background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
    color: white;
}

.shop-card-btn.active {
    background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
    color: white;
    cursor: default;
}

/* Bundle Cards */
.bundle-card {
    grid-column: span 2;
    padding: 1rem;
}

.bundle-badge {
    position: absolute;
    top: -8px;
    right: 1rem;
    background: linear-gradient(135deg, var(--coral) 0%, #FF4757 100%);
    color: white;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(255, 71, 87, 0.4);
}

.bundle-themes {
    display: flex;
    justify-content: center;
    gap: 0.35rem;
    margin: 0.5rem 0;
}

.bundle-theme {
    font-size: 1.25rem;
    opacity: 0.4;
    filter: grayscale(0.5);
    transition: all 0.2s ease;
}

.bundle-theme.owned {
    opacity: 1;
    filter: none;
}

/* Coin Balance Card */
.coin-balance-card {
    grid-column: span 2;
    background: linear-gradient(135deg, var(--gold) 0%, #FFA500 100%);
    color: white;
    padding: 1rem;
}

.coin-balance-label {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-bottom: 0.25rem;
}

.coin-balance-value {
    font-family: 'Fredoka', sans-serif;
    font-size: 2rem;
    font-weight: 700;
}

.coin-balance-info {
    font-size: 0.7rem;
    opacity: 0.8;
    margin-top: 0.25rem;
}

/* Coin Pack Card */
.coin-pack-card {
    position: relative;
}

.coin-pack-card.popular {
    border-color: var(--gold);
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.3);
}

.popular-badge {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, var(--gold) 0%, #FFA500 100%);
    color: white;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 0.55rem;
    padding: 0.15rem 0.5rem;
    border-radius: 0.5rem;
    white-space: nowrap;
}

.coin-amount {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: var(--gold);
    margin-bottom: 0.5rem;
}

.coin-bonus {
    font-size: 0.7rem;
    color: var(--teal);
}

/* Info Card */
.info-card {
    grid-column: span 2;
    text-align: left;
    padding: 0.75rem 1rem;
}

.earn-info {
    margin-top: 0.5rem;
}

.earn-row {
    font-size: 0.75rem;
    color: #666;
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.earn-row:last-child {
    border-bottom: none;
}

/* Restore Card */
.restore-card {
    grid-column: span 2;
    background: linear-gradient(145deg, #f8f8f8 0%, #f0f0f0 100%);
}

/* Responsive */
@media (max-width: 400px) {
    .game-container {
        padding: 1rem;
        border-radius: 1.25rem;
    }

    .game-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .stats-bar {
        gap: 0.35rem;
    }

    .stat-box {
        padding: 0.4rem 0.25rem;
        border-radius: 0.75rem;
    }

    .stat-label {
        font-size: 0.55rem;
    }

    .stat-value {
        font-size: 0.95rem;
    }

    .game-board {
        gap: 2px;
        padding: 5px;
        border-radius: 0.875rem;
    }

    .cell {
        border-radius: 4px;
        font-size: calc(var(--cell-size) * 0.55);
    }

    .button-row {
        gap: 0.35rem;
    }

    .game-btn {
        padding: 0.65rem 0.75rem;
        font-size: 0.8rem;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
}

@media (max-width: 350px) {
    body {
        padding: 0.5rem;
    }

    .game-container {
        padding: 0.75rem;
    }

    .mode-selector {
        flex-wrap: wrap;
    }

    .mode-btn {
        font-size: 0.65rem;
        padding: 0.4rem;
    }
}

/* Touch device optimizations */
@media (hover: none) {
    .cell:hover {
        transform: none;
    }

    .game-btn:hover {
        transform: none;
    }

    .game-btn:hover::before {
        left: -100%;
    }

    .icon-btn:hover {
        transform: none;
    }
}

/* Landscape mobile */
@media (max-height: 600px) and (orientation: landscape) {
    body {
        padding: 0.5rem;
    }

    .game-container {
        padding: 0.75rem;
        max-width: 380px;
    }

    .game-header {
        margin-bottom: 0.5rem;
    }

    .stats-bar {
        margin-bottom: 0.5rem;
    }

    .progress-container {
        height: 10px;
        margin-bottom: 0.5rem;
    }

    .button-row {
        margin-top: 0.5rem;
    }
}

/* Autosave indicator */
.autosave-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-family: 'DM Sans', sans-serif;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 100;
}

.autosave-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

.autosave-indicator .spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* More Games Promo */
.more-games-promo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    max-width: 420px;
    margin: 1rem auto 0;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.85) 100%);
    border-radius: 1rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    text-decoration: none;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.more-games-promo:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0,0,0,0.12);
    border-color: var(--teal);
}

.promo-label {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.promo-game {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.promo-icon {
    font-size: 1.5rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.promo-name {
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    color: #333;
}

.promo-desc {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.7rem;
    color: #888;
    display: none;
}

.promo-arrow {
    font-size: 1.1rem;
    color: var(--teal);
    transition: transform 0.2s ease;
}

.more-games-promo:hover .promo-arrow {
    transform: translateX(3px);
}

@media (min-width: 500px) {
    .promo-desc {
        display: inline;
    }

    .promo-game {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.1rem;
    }

    .promo-icon {
        position: absolute;
        left: 1rem;
    }

    .more-games-promo {
        padding-left: 3.5rem;
        position: relative;
    }
}

@media (max-width: 400px) {
    .more-games-promo {
        margin: 0.75rem 1rem 0;
        padding: 0.6rem 0.75rem;
        gap: 0.5rem;
    }

    .promo-label {
        font-size: 0.55rem;
    }

    .promo-name {
        font-size: 0.85rem;
    }

    .promo-icon {
        font-size: 1.25rem;
    }
}

/* Footer */
.game-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.75rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
}

.game-footer a {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    transition: color 0.2s;
}

.game-footer a:hover {
    color: white;
    text-decoration: underline;
}

.footer-divider {
    opacity: 0.5;
}
