/* Global Styles */
body {
    font-family: 'Inter', sans-serif;
    background: #111827 url('../img/bg.png') center center / cover no-repeat fixed;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    position: relative;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Prevent zoom on double tap and pull-to-refresh on mobile */
    touch-action: manipulation;
    overscroll-behavior: contain;
}

/* Home Screen (same background as game - uses body bg) */
.home-screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    /* Transparent so body bg.png shows through */
    background: transparent;
}

.home-screen.hidden {
    display: none !important;
}

.home-top-bar {
    position: absolute;
    top: 0.5rem;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.5rem;
    z-index: 10;
}

/* WoodButton: shared circular skeuomorphic blue theme (home screen + game HUD) */
.wood-btn {
    font-family: 'Inter', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
    padding: 0;
    border-radius: 50%;
    border: 2px solid #DBEAFE;
    background: radial-gradient(ellipse 120% 120% at 0% 0%, #60A5FA 0%, #3B82F6 50%, #2563EB 100%);
    box-shadow:
        inset 0 0 0 3px transparent,
        inset 0 0 0 4.5px rgba(147, 197, 253, 0.5),
        0 4px 8px rgba(0, 0, 0, 0.5),
        0 6px 12px -2px rgba(0, 0, 0, 0.2);
}

.wood-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(ellipse 120% 120% at 0% 0%, transparent 0%, rgba(0, 0, 0, 0.1) 100%);
}

.wood-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(0deg, transparent 0, transparent 3px, rgba(37, 99, 235, 0.2) 3px, rgba(37, 99, 235, 0.2) 4px),
        radial-gradient(circle at 25% 35%, rgba(37, 99, 235, 0.2) 0, transparent 15%),
        radial-gradient(circle at 72% 58%, rgba(37, 99, 235, 0.21) 0, transparent 12%),
        radial-gradient(circle at 45% 78%, rgba(37, 99, 235, 0.17) 0, transparent 10%);
    opacity: 0.9;
}

.wood-btn:hover {
    transform: translateY(-1px);
    box-shadow:
        inset 0 0 0 3px transparent,
        inset 0 0 0 4.5px rgba(147, 197, 253, 0.5),
        0 5px 10px rgba(0, 0, 0, 0.5),
        0 7px 14px -2px rgba(0, 0, 0, 0.25);
}

.wood-btn:active,
.wood-btn.touch-active {
    transform: translateY(2px);
    box-shadow:
        inset 0 0 0 3px transparent,
        inset 0 0 0 4.5px rgba(147, 197, 253, 0.5),
        0 6px 8px rgba(0, 0, 0, 0.5),
        0 8px 12px -2px rgba(0, 0, 0, 0.2);
}

.wood-btn--sm {
    width: 2.25rem;
    height: 2.25rem;
    min-width: 2.25rem;
    min-height: 2.25rem;
}

.wood-btn--sm .wood-btn-icon {
    width: 1rem;
    height: 1rem;
}

/* Home screen top buttons: WoodButton, small */
.home-top-btn {
    margin: 0;
}

.home-top-btn .wood-btn-icon {
    width: 1rem;
    height: 1rem;
    color: #FFFFFF;
    position: relative;
    z-index: 1;
}

.home-top-left {
    margin-left: 0.5rem;
}

.home-top-right {
    margin-right: 0.5rem;
}

.home-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2.5rem;
    padding: 2rem;
}

.home-logo-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
}

.home-logo {
    max-width: min(280px, 75vw);
    max-height: clamp(80px, 20vw, 140px);
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
}

/* Home level card – 3D gem style, large, white border, no black shadow */
.home-level-card {
    --level-card-size: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.75rem 3.5rem;
    min-width: 170px;
    position: relative;
    overflow: hidden;
    border-radius: calc(var(--level-card-size) * 0.16);
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
    background-color: #3B82F6;
    border: 2px solid #ffffff;
    outline: none;
    box-shadow: 0 2px 8px 1px rgba(59, 130, 246, 0.25);
}

.home-level-card:focus {
    outline: none;
}

.home-level-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: calc(var(--level-card-size) * 0.16);
    pointer-events: none;
    background: radial-gradient(ellipse 120% 120% at 0% 0%, rgba(95, 150, 255, 1) 0%, #3B82F6 60%, rgba(45, 98, 191, 1) 100%);
}

.home-level-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 4px 12px 2px rgba(59, 130, 246, 0.35);
}

.home-level-card:active {
    transform: translateY(-2px) scale(1.01);
}

.home-level-label {
    position: relative;
    z-index: 3;
    font-size: 0.85rem;
    font-weight: 800;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.home-level-value {
    position: relative;
    z-index: 3;
    font-size: clamp(2.25rem, 6vw, 3.5rem);
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    line-height: 1;
}

/* Hide game UI when home screen is active */
body.home-active .game-container,
body.home-active .left-controls,
body.home-active .right-controls,
body.home-active .moves-top-center {
    display: none !important;
}

/* How to Play popup - compact width */
.how-to-play-popup {
    max-width: min(420px, 90%);
}

/* Game Container – center board + palette in viewport */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    padding: 2rem;
    gap: 1.5rem;
    position: relative;
    z-index: 1;
    box-sizing: border-box;
}

/* Left Side Controls */
.left-controls {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
}

/* Right Side Controls */
.right-controls {
    position: fixed;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
}

/* Moves – top-center of screen */
.moves-top-center {
    position: fixed;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

/* Moves, Reset and Sound Row (reset + sound only) */
.moves-reset-sound-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Home and Level Row – level very close to home */
.home-level-row {
    display: flex;
    align-items: center;
    gap: 0.06rem;
}

/* Level Display – CAPS, same font size, "LEVEL 1" together, no background */
.level-display {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    height: 3.5rem;
    min-height: 3.5rem;
    background: transparent;
}

.level-display .level-text {
    font-size: 1.5rem;
    font-weight: 800;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    white-space: nowrap;
}

/* Moves Display – top-center, tap-finger icon, white background, tight horizontal padding */
.moves-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0 0.4rem;
    height: 3.5rem;
    min-height: 3.5rem;
    background: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
}

.moves-display .moves-icon {
    width: 1.25rem;
    height: 1.25rem;
    color: #1f2937;
    flex-shrink: 0;
}

.moves-display .hud-value,
.moves-display .hud-separator {
    color: #1f2937;
    text-shadow: none;
    -webkit-text-fill-color: #1f2937;
    background: none;
    background-clip: unset;
}

/* Undo Button Container */
.undo-button-container {
    transition: all 0.3s ease;
}

/* Reset Button - Now on Right */
.reset-button-container {
    transition: all 0.3s ease;
}

.reset-button:not(.wood-btn) {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #ef4444;
    border: none;
    border-radius: 8px;
    box-shadow: 
        0 4px 16px rgba(239, 68, 68, 0.3),
        0 2px 8px rgba(239, 68, 68, 0.2);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

.reset-button:not(.wood-btn)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.2) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.reset-button:not(.wood-btn):hover::before {
    transform: translateX(100%);
}

.reset-button:not(.wood-btn):hover {
    transform: translateY(-3px) scale(1.05);
    background: #dc2626;
    box-shadow: 
        0 8px 25px rgba(239, 68, 68, 0.4),
        0 4px 12px rgba(239, 68, 68, 0.3);
}

.reset-button:not(.wood-btn):active {
    transform: translateY(-1px) scale(1.02);
    transition: transform 0.1s ease;
}

.reset-icon {
    font-size: 1.2rem;
    position: relative;
    z-index: 1;
    transition: transform 0.3s ease;
}

.reset-button:hover .reset-icon {
    transform: rotate(180deg);
}

/* Icon-only button styles */
.undo-button.icon-only,
.reset-button.icon-only,
.sound-button.icon-only,
.solution-button.icon-only,
.home-button.icon-only {
    padding: 1rem;
    width: 3.5rem;
    height: 3.5rem;
    min-width: 3.5rem;
    min-height: 3.5rem;
    justify-content: center;
    border-radius: 8px;
}

.home-button.wood-btn.icon-only,
.undo-button.wood-btn.icon-only,
.reset-button.wood-btn.icon-only,
.sound-button.wood-btn.icon-only {
    border-radius: 50%;
}

.undo-button.icon-only .undo-icon,
.reset-button.icon-only .reset-icon,
.sound-button.icon-only .sound-icon,
.solution-button.icon-only .solution-icon,
.home-button.icon-only .home-icon {
    width: 1.5rem;
    height: 1.5rem;
    color: #ffffff;
    transition: all 0.3s ease;
}

.wood-btn.icon-only .wood-btn-icon {
    width: 1.5rem;
    height: 1.5rem;
    color: #ffffff;
    position: relative;
    z-index: 1;
}

/* Undo Button Disabled State */
.undo-button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Sound off state */
.sound-icon.sound-off {
    opacity: 0.6;
}

.sound-icon.sound-off line {
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2;
    stroke-linecap: round;
}

/* Sound Button Container */
.sound-button-container {
    transition: all 0.3s ease;
}

/* Sound Button */
.sound-button:not(.wood-btn) {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #3b82f6;
    border: none;
    border-radius: 8px;
    box-shadow: 
        0 4px 16px rgba(59, 130, 246, 0.3),
        0 2px 8px rgba(59, 130, 246, 0.2);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

.sound-button:not(.wood-btn)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.2) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.sound-button:not(.wood-btn):hover::before {
    transform: translateX(100%);
}

.sound-button:not(.wood-btn):hover {
    transform: translateY(-3px) scale(1.05);
    background: #2563eb;
    box-shadow: 
        0 8px 25px rgba(59, 130, 246, 0.4),
        0 4px 12px rgba(59, 130, 246, 0.3);
}

.sound-button:not(.wood-btn):active {
    transform: translateY(-1px) scale(1.02);
    transition: transform 0.1s ease;
}

.sound-icon {
    font-size: 1.2rem;
    position: relative;
    z-index: 1;
    transition: transform 0.3s ease;
}

.sound-button:hover .sound-icon {
    transform: scale(1.1);
}

/* Solution Button Container */
.solution-button-container {
    display: none !important; /* Hide solution button */
    transition: all 0.3s ease;
}

/* Extra Moves Button - Inside moves display */
.extra-moves-button {
    display: none; /* Hidden by default, shown when 3 moves remain */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    margin-left: 0.4rem;
    margin-right: 0;
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    min-width: 85px;
    height: calc(100% - 0.5rem);
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.extra-moves-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
    background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
}

.extra-moves-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.extra-moves-icon {
    width: 1.1rem;
    height: 1.1rem;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.extra-moves-text {
    position: relative;
    z-index: 1;
    font-size: 0.65rem;
    font-weight: 600;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    line-height: 1;
    white-space: nowrap;
}

/* Solution Button */
.solution-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #8b5cf6;
    border: none;
    border-radius: 8px;
    box-shadow: 
        0 4px 16px rgba(139, 92, 246, 0.3),
        0 2px 8px rgba(139, 92, 246, 0.2);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

.solution-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.2) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.solution-button:hover::before {
    transform: translateX(100%);
}

.solution-button:hover {
    transform: translateY(-3px) scale(1.05);
    background: #7c3aed;
    box-shadow: 
        0 8px 25px rgba(139, 92, 246, 0.4),
        0 4px 12px rgba(139, 92, 246, 0.3);
}

.solution-button:active {
    transform: translateY(-1px) scale(1.02);
    transition: transform 0.1s ease;
}

.solution-icon {
    font-size: 1.2rem;
    position: relative;
    z-index: 1;
    transition: transform 0.3s ease;
}

.solution-button:hover .solution-icon {
    transform: scale(1.1);
}

/* Home Button Container */
.home-button-container {
    transition: all 0.3s ease;
}

/* Home Button */
.home-button:not(.wood-btn) {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #22c55e;
    border: none;
    border-radius: 8px;
    box-shadow: 
        0 4px 16px rgba(34, 197, 94, 0.3),
        0 2px 8px rgba(34, 197, 94, 0.2);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

.home-button:not(.wood-btn)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.2) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.home-button:not(.wood-btn):hover::before {
    transform: translateX(100%);
}

.home-button:not(.wood-btn):hover {
    transform: translateY(-3px) scale(1.05);
    background: #16a34a;
    box-shadow: 
        0 8px 25px rgba(34, 197, 94, 0.4),
        0 4px 12px rgba(34, 197, 94, 0.3);
}

.home-button:not(.wood-btn):active {
    transform: translateY(-1px) scale(1.02);
    transition: transform 0.1s ease;
}

.home-icon {
    font-size: 1.2rem;
    position: relative;
    z-index: 1;
    transition: transform 0.3s ease;
}

.home-button:hover .home-icon {
    transform: scale(1.1);
}

.hud-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.hud-value {
    font-size: 1.1rem;
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    background: linear-gradient(135deg, #ffffff 0%, #f1f5f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hud-separator {
    font-size: 1.1rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}


/* Game Board – centered in game container */
.game-board {
    display: grid;
    gap: 1.5px; /* Grid spacing: 1.5px between tiles (cross-axis and main-axis) */
    width: 100%;
    max-width: 320px;
    padding: clamp(8px, 2vw, 14px); /* Responsive padding: 8px (small), 10px (medium), 12px (large), 14px (tablet) */
    background: transparent;
    border-radius: 24px; /* Game Board Border Radius: 24px */
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    /* Keep the tile grid centered inside the board even when tiles shrink */
    justify-content: center;
    align-content: center;
}


/* Grid size classes for different levels */
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-8 { grid-template-columns: repeat(8, 1fr); }
.grid-11 { grid-template-columns: repeat(11, 1fr); }
.grid-14 { grid-template-columns: repeat(14, 1fr); }
.grid-17 { grid-template-columns: repeat(17, 1fr); }
.grid-20 { grid-template-columns: repeat(20, 1fr); }

/* Cell Styles - 3D Gem/Glass Effect */
.cell {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease; /* Swipe effect: 300ms duration */
    /* Keep tiles perfectly square: height = width */
    aspect-ratio: 1 / 1;
    /* Border radius: 8% of cell size - calculated via CSS variable */
    border-radius: calc(var(--cell-size, 50px) * 0.08);
    /* Clip to match border radius */
    clip-path: inset(0 round calc(var(--cell-size, 50px) * 0.08));
    /* Initial state for escape animation */
    opacity: 1;
    transform: scale(1);
}

/* Color change animation: 300ms duration */
@keyframes colorChange {
    0% {
        clip-path: inset(0 100% 0 0 round calc(var(--cell-size, 50px) * 0.08));
    }
    100% {
        clip-path: inset(0 0 0 0 round calc(var(--cell-size, 50px) * 0.08));
    }
}

.cell.color-changing {
    animation: colorChange 0.3s ease-in-out;
}

/* Base background color */
.cell-red { background-color: #EF4444; }
.cell-blue { background-color: #3B82F6; }
.cell-green { background-color: #30D158; }
.cell-yellow { background-color: #FFD60A; }
.cell-orange { background-color: #FF9F0A; }
.cell-pink { background-color: #EC4899; }

/* Permanently escaped tile: keep its grid position but make it invisible and non-interactive */
.cell-escaped {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

/* Radial gradient overlay (top-left to bottom-right) */
/* Type: RadialGradient, Center: topLeft, Radius: 1.2 */
/* Colors: 20% lighter at stop 0.0, base color at stop 0.6, 25% darker at stop 1.0 */
.cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: calc(var(--cell-size, 50px) * 0.08);
    pointer-events: none;
}

/* Helper functions for lighten/darken colors */
.cell-red::before {
    /* 20% lighter: #EF4444 -> rgba(255, 95, 95), base: #EF4444, 25% darker: rgba(191, 52, 52) */
    background: radial-gradient(ellipse 120% 120% at 0% 0%, rgba(255, 95, 95, 1) 0%, #EF4444 60%, rgba(191, 52, 52, 1) 100%);
}

.cell-blue::before {
    /* 20% lighter: #3B82F6 -> rgba(95, 150, 255), base: #3B82F6, 25% darker: rgba(45, 98, 191) */
    background: radial-gradient(ellipse 120% 120% at 0% 0%, rgba(95, 150, 255, 1) 0%, #3B82F6 60%, rgba(45, 98, 191, 1) 100%);
}

.cell-green::before {
    /* 20% lighter: #30D158 -> rgba(95, 225, 120), base: #30D158, 25% darker: rgba(36, 157, 66) */
    background: radial-gradient(ellipse 120% 120% at 0% 0%, rgba(95, 225, 120, 1) 0%, #30D158 60%, rgba(36, 157, 66, 1) 100%);
}

.cell-yellow::before {
    /* 20% lighter: #FFD60A -> rgba(255, 230, 50), base: #FFD60A, 25% darker: rgba(191, 160, 7) */
    background: radial-gradient(ellipse 120% 120% at 0% 0%, rgba(255, 230, 50, 1) 0%, #FFD60A 60%, rgba(191, 160, 7, 1) 100%);
}

.cell-orange::before {
    /* 20% lighter: #FF9F0A -> rgba(255, 175, 50), base: #FF9F0A, 25% darker: rgba(191, 119, 7) */
    background: radial-gradient(ellipse 120% 120% at 0% 0%, rgba(255, 175, 50, 1) 0%, #FF9F0A 60%, rgba(191, 119, 7, 1) 100%);
}

.cell-pink::before {
    /* 20% lighter: #EC4899 -> rgba(255, 95, 170), base: #EC4899, 25% darker: rgba(177, 54, 115) */
    background: radial-gradient(ellipse 120% 120% at 0% 0%, rgba(255, 95, 170, 1) 0%, #EC4899 60%, rgba(177, 54, 115, 1) 100%);
}

/* White border with 30% opacity, 1.5px width */
.cell::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    border-radius: calc(var(--cell-size, 50px) * 0.08);
    pointer-events: none;
    z-index: 2;
}

/* Shadow Layer 1 - Deep Shadow: black 50% opacity, 10px blur, offset 4% of cell size */
/* Shadow Layer 2 - Medium Shadow: black 30% opacity, 8px blur, -1px spread, offset 2% of cell size */
/* Shadow Layer 3 - Inner Glow: tile color 30% opacity, 8px blur, 1px spread, offset (0, 2px) */
.cell-red {
    box-shadow: 
        /* Layer 1: Deep Shadow */
        calc(var(--cell-size, 50px) * 0.04) calc(var(--cell-size, 50px) * 0.04) 10px 0 rgba(0, 0, 0, 0.5),
        /* Layer 2: Medium Shadow */
        calc(var(--cell-size, 50px) * 0.02) calc(var(--cell-size, 50px) * 0.02) 8px -1px rgba(0, 0, 0, 0.3),
        /* Layer 3: Inner Glow */
        0 2px 8px 1px rgba(239, 68, 68, 0.3);
}

.cell-blue {
    box-shadow: 
        calc(var(--cell-size, 50px) * 0.04) calc(var(--cell-size, 50px) * 0.04) 10px 0 rgba(0, 0, 0, 0.5),
        calc(var(--cell-size, 50px) * 0.02) calc(var(--cell-size, 50px) * 0.02) 8px -1px rgba(0, 0, 0, 0.3),
        0 2px 8px 1px rgba(59, 130, 246, 0.3);
}

.cell-green {
    box-shadow: 
        calc(var(--cell-size, 50px) * 0.04) calc(var(--cell-size, 50px) * 0.04) 10px 0 rgba(0, 0, 0, 0.5),
        calc(var(--cell-size, 50px) * 0.02) calc(var(--cell-size, 50px) * 0.02) 8px -1px rgba(0, 0, 0, 0.3),
        0 2px 8px 1px rgba(48, 209, 88, 0.3);
}

.cell-yellow {
    box-shadow: 
        calc(var(--cell-size, 50px) * 0.04) calc(var(--cell-size, 50px) * 0.04) 10px 0 rgba(0, 0, 0, 0.5),
        calc(var(--cell-size, 50px) * 0.02) calc(var(--cell-size, 50px) * 0.02) 8px -1px rgba(0, 0, 0, 0.3),
        0 2px 8px 1px rgba(255, 214, 10, 0.3);
}

.cell-orange {
    box-shadow: 
        calc(var(--cell-size, 50px) * 0.04) calc(var(--cell-size, 50px) * 0.04) 10px 0 rgba(0, 0, 0, 0.5),
        calc(var(--cell-size, 50px) * 0.02) calc(var(--cell-size, 50px) * 0.02) 8px -1px rgba(0, 0, 0, 0.3),
        0 2px 8px 1px rgba(255, 159, 10, 0.3);
}

.cell-pink {
    box-shadow: 
        calc(var(--cell-size, 50px) * 0.04) calc(var(--cell-size, 50px) * 0.04) 10px 0 rgba(0, 0, 0, 0.5),
        calc(var(--cell-size, 50px) * 0.02) calc(var(--cell-size, 50px) * 0.02) 8px -1px rgba(0, 0, 0, 0.3),
        0 2px 8px 1px rgba(236, 72, 153, 0.3);
}

/* Mahjong Icon - 55% of cell size, centered, white, bold */
.mahjong-icon {
    position: relative;
    z-index: 3;
    font-size: calc(var(--cell-size, 50px) * 0.55); /* 55% of cell size */
    font-weight: bold;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.mahjong-icon svg {
    width: calc(var(--cell-size, 50px) * 0.55);
    height: calc(var(--cell-size, 50px) * 0.55);
}

/* Escape animation: Tiles fade out and scale down when "escaping" (500ms duration) */
/* Stagger delay: (row + col) * 30ms (passed via --escape-delay) */
.cell.escape {
    animation: escapeTile 0.5s ease-in-out forwards;
    animation-delay: var(--escape-delay, 0ms);
    will-change: opacity, transform;
    transform-origin: center center;
    /* Override transition during escape animation */
    transition: none;
    /* Force hardware acceleration */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    perspective: 1000px;
    -webkit-perspective: 1000px;
}

/* Make the white border fade out in perfect sync with the tile */
.cell.escape::after {
    animation: escapeTile 0.5s ease-in-out forwards;
    animation-delay: var(--escape-delay, 0ms);
}

@keyframes escapeTile {
    0% {
        opacity: 1;
        transform: scale(1) translateZ(0);
    }
    100% {
        opacity: 0;
        transform: scale(0) translateZ(0);
    }
}

.cell:hover {
    transform: scale(1.05);
}

/* Color Palette Container – centered below board */
.color-palette {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(6px, 1.5vw, 10px); /* Spacing: 6-10px between color buttons */
    padding: clamp(12px, 2.5vw, 20px); /* Responsive padding: 12-20px */
    background: transparent; /* Transparent background */
    border: 2px solid white; /* White border, 2px width */
    border-radius: 20px; /* Border radius: 20px */
    opacity: 1;
    pointer-events: auto;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible;
    margin: 0 auto;
    flex-shrink: 0;
}

.color-palette.disabled {
    opacity: 0.3;
    pointer-events: none;
    transform: scale(0.9);
    filter: grayscale(0.5);
}

/* Color Button Styles - 3D Gem/Glass Effect */
.color-button {
    width: clamp(40px, 5vw, 48px); /* Responsive size: 40-48px */
    height: clamp(40px, 5vw, 48px);
    aspect-ratio: 1 / 1; /* Maintain circular shape */
    border-radius: 50%; /* Circular shape */
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* Base background colors */
.button-red { background-color: #EF4444; }
.button-blue { background-color: #3B82F6; }
.button-green { background-color: #30D158; }
.button-yellow { background-color: #FFD60A; }
.button-orange { background-color: #FF9F0A; }
.button-pink { background-color: #EC4899; }

/* 3D effect: Same radial gradient as tiles */
.color-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    pointer-events: none;
}

/* Radial gradient (top-left to bottom-right) */
.button-red::before {
    background: radial-gradient(ellipse at 20% 20%, rgba(255, 95, 95, 1) 0%, #EF4444 60%, rgba(191, 52, 52, 1) 100%);
}

.button-blue::before {
    background: radial-gradient(ellipse at 20% 20%, rgba(95, 150, 255, 1) 0%, #3B82F6 60%, rgba(45, 98, 191, 1) 100%);
}

.button-green::before {
    background: radial-gradient(ellipse at 20% 20%, rgba(95, 225, 120, 1) 0%, #30D158 60%, rgba(36, 157, 66, 1) 100%);
}

.button-yellow::before {
    background: radial-gradient(ellipse at 20% 20%, rgba(255, 230, 50, 1) 0%, #FFD60A 60%, rgba(191, 160, 7, 1) 100%);
}

.button-orange::before {
    background: radial-gradient(ellipse at 20% 20%, rgba(255, 175, 50, 1) 0%, #FF9F0A 60%, rgba(191, 119, 7, 1) 100%);
}

.button-pink::before {
    background: radial-gradient(ellipse at 20% 20%, rgba(255, 95, 170, 1) 0%, #EC4899 60%, rgba(177, 54, 115, 1) 100%);
}

/* Highlights */
.color-button::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    pointer-events: none;
    /* Main highlight: top-left, white at 60% opacity */
    background: radial-gradient(ellipse at 25% 25%, rgba(255, 255, 255, 0.6) 0%, transparent 50%),
                /* Secondary highlight: top-right, white at 50% opacity */
                radial-gradient(ellipse at 75% 25%, rgba(255, 255, 255, 0.5) 0%, transparent 40%);
}

/* Shadows: Similar to tiles */
.color-button {
    box-shadow: 
        /* Deep shadow: black at 50% opacity, 10px blur, offset (4% of button size) */
        0 calc(4% * 1) 10px rgba(0, 0, 0, 0.5),
        /* Medium shadow: black at 30% opacity, 8px blur */
        0 0 8px rgba(0, 0, 0, 0.3);
}

/* Inner glow: button color at 30% opacity, 8px blur */
.button-red {
    box-shadow: 
        0 calc(4% * 1) 10px rgba(0, 0, 0, 0.5),
        0 0 8px rgba(0, 0, 0, 0.3),
        inset 0 0 8px rgba(239, 68, 68, 0.3);
}

.button-blue {
    box-shadow: 
        0 calc(4% * 1) 10px rgba(0, 0, 0, 0.5),
        0 0 8px rgba(0, 0, 0, 0.3),
        inset 0 0 8px rgba(59, 130, 246, 0.3);
}

.button-green {
    box-shadow: 
        0 calc(4% * 1) 10px rgba(0, 0, 0, 0.5),
        0 0 8px rgba(0, 0, 0, 0.3),
        inset 0 0 8px rgba(48, 209, 88, 0.3);
}

.button-yellow {
    box-shadow: 
        0 calc(4% * 1) 10px rgba(0, 0, 0, 0.5),
        0 0 8px rgba(0, 0, 0, 0.3),
        inset 0 0 8px rgba(255, 214, 10, 0.3);
}

.button-orange {
    box-shadow: 
        0 calc(4% * 1) 10px rgba(0, 0, 0, 0.5),
        0 0 8px rgba(0, 0, 0, 0.3),
        inset 0 0 8px rgba(255, 159, 10, 0.3);
}

.button-pink {
    box-shadow: 
        0 calc(4% * 1) 10px rgba(0, 0, 0, 0.5),
        0 0 8px rgba(0, 0, 0, 0.3),
        inset 0 0 8px rgba(236, 72, 153, 0.3);
}

/* Border: White at 20% opacity, 1.5px width */
.color-button {
    border: 1.5px solid rgba(255, 255, 255, 0.2);
}

/* Mahjong Icon Button - Very large and prominent, white, bold */
.mahjong-icon-button {
    position: relative;
    z-index: 1;
    font-size: 1.4rem; /* Slightly smaller for better balance */
    font-weight: 800; /* Slightly lighter than tiles */
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), 0 0 6px rgba(0, 0, 0, 0.4); /* Softer shadow */
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.color-button:hover {
    transform: scale(1.15) translateY(-3px);
}

.color-button:hover::after {
    opacity: 1;
}

.color-button:active,
.color-button.touch-active {
    transform: scale(1.05) translateY(-1px);
    transition: transform 0.1s ease;
}

.color-button:focus {
    outline: none;
    box-shadow: 
        0 0 0 6px rgba(255, 255, 255, 0.3),
        0 calc(4% * 1) 10px rgba(0, 0, 0, 0.5),
        0 0 8px rgba(0, 0, 0, 0.3);
}

/* Legacy responsive adjustments - now handled in comprehensive responsive section above */

/* Pop-up Overlay */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Pop-up Container - Common Styles */
.popup-container {
    background: linear-gradient(135deg, rgba(31, 41, 55, 0.3) 0%, rgba(17, 24, 39, 0.3) 100%);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    border: 2px solid rgba(59, 130, 246, 0.6);
    box-shadow: 
        0 8px 20px rgba(0, 0, 0, 0.5);
    padding: clamp(1rem, 2.5vw, 1.5rem);
    max-width: min(500px, 90%);
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sound Settings Pop-up - Smaller width */
.sound-settings-popup {
    max-width: min(360px, 85%);
    width: 85%;
}

/* Additional responsive adjustments for smaller screens */
@media (max-width: 640px) {
    .sound-settings-popup {
        max-width: min(320px, 90%);
        width: 90%;
    }
    
    .start-popup {
        max-width: min(95%, 450px);
        width: 95%;
    }
}

/* Game Over Popup - Larger border radius */
.game-over-popup {
    border-radius: 32px;
    padding: clamp(1rem, 2.5vw, 1.5rem);
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateY(50px) scale(0.9);
    }
    to { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Start Pop-up Specific */
.start-popup {
    text-align: center;
}

/* Game Over Pop-up Specific */
.game-over-popup {
    text-align: center;
}

/* Pop-up Header */
.popup-header {
    margin-bottom: 2rem;
}

.game-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    position: relative;
}

.logo-image {
    max-width: 100%;
    height: auto;
    max-height: 120px;
    width: auto;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    transition: transform 0.3s ease;
}

.logo-image:hover {
    transform: scale(1.05);
}

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



.result-icon {
    font-size: clamp(2.5rem, 6vw, 3.75rem);
    margin-bottom: 1rem;
    animation: celebration 1s ease-in-out;
    line-height: 1;
}

@keyframes celebration {
    0% { transform: scale(0) rotate(0deg); }
    50% { transform: scale(1.2) rotate(180deg); }
    100% { transform: scale(1) rotate(360deg); }
}

.result-title {
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 0.5rem 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    text-align: center;
    letter-spacing: 0.5px;
}

.result-subtitle {
    font-size: clamp(0.875rem, 2vw, 1.125rem);
    color: #ffffff;
    margin: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    line-height: 1.5;
    text-align: center;
}

/* Pop-up Content */
.popup-content {
    margin-bottom: 2rem;
}

.section-title {
    font-size: clamp(1.125rem, 3vw, 1.375rem);
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 1rem 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-text {
    font-size: clamp(0.875rem, 2vw, 1rem);
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.6;
    margin: 0 0 2rem 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.goal-section, .how-to-play-section {
    margin-bottom: 2rem;
}

.instructions {
    display: flex;
    flex-direction: column;
    gap: clamp(0.375rem, 1.5vw, 0.625rem);
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: clamp(0.75rem, 2vw, 1rem);
    padding: clamp(0.625rem, 1.5vw, 0.875rem);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
    backdrop-filter: blur(5px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.instruction-item:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%);
    transform: translateX(5px);
}

.instruction-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(1.25rem, 3vw, 1.75rem);
    height: clamp(1.25rem, 3vw, 1.75rem);
    min-width: clamp(1.25rem, 3vw, 1.75rem);
    min-height: clamp(1.25rem, 3vw, 1.75rem);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.7) 100%);
    color: #1f2937;
    border-radius: 12px;
    font-weight: 700;
    font-size: clamp(0.625rem, 1.5vw, 0.875rem);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.instruction-text {
    color: #ffffff;
    font-size: clamp(0.75rem, 2vw, 1rem);
    font-weight: 500;
    line-height: 1.4;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Mobile-only instruction */
.mobile-only {
    display: none;
}

@media (max-width: 640px) {
    .mobile-only {
        display: flex;
    }
}

/* Stats Section */
.stats-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.5rem 1rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.stat-item:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.08) 100%);
    transform: translateY(-2px);
}

.stat-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    background: linear-gradient(135deg, #ffffff 0%, #f1f5f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Pop-up Footer */
.popup-footer {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Pop-up Buttons */
.popup-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    padding: clamp(0.75rem, 2vw, 1.125rem) clamp(0.75rem, 3vw, 1.5rem);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    font-size: clamp(0.875rem, 2vw, 1.125rem);
    font-weight: 700;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    min-height: 44px;
    min-width: 120px;
}

/* Primary Button - Blue Gradient */
.popup-button.primary {
    background: linear-gradient(135deg, #60A5FA 0%, #3B82F6 50%, #2563EB 100%);
    box-shadow: 
        0 0 12px rgba(59, 130, 246, 0.5),
        0 5px 10px rgba(0, 0, 0, 0.4),
        0 7px 15px rgba(0, 0, 0, 0.15);
}

.popup-button.primary:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 0 16px rgba(59, 130, 246, 0.6),
        0 8px 12px rgba(0, 0, 0, 0.4),
        0 10px 18px rgba(0, 0, 0, 0.2);
}

.popup-button.primary:active {
    transform: translateY(0);
}

/* Secondary Button - Gray Gradient */
.popup-button.secondary {
    background: linear-gradient(135deg, #4B5563 0%, #374151 50%, #1F2937 100%);
    box-shadow: 
        0 0 12px rgba(75, 85, 99, 0.5),
        0 5px 10px rgba(0, 0, 0, 0.4),
        0 7px 15px rgba(0, 0, 0, 0.15);
}

.popup-button.secondary:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 0 16px rgba(75, 85, 99, 0.6),
        0 8px 12px rgba(0, 0, 0, 0.4),
        0 10px 18px rgba(0, 0, 0, 0.2);
}

.popup-button.secondary:active {
    transform: translateY(0);
}

/* Home Button - Green Gradient */
.popup-button.home {
    background: linear-gradient(135deg, #22C55E 0%, #16A34A 50%, #15803D 100%);
    box-shadow: 
        0 0 12px rgba(34, 197, 94, 0.5),
        0 5px 10px rgba(0, 0, 0, 0.4),
        0 7px 15px rgba(0, 0, 0, 0.15);
}

.popup-button.home:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 0 16px rgba(34, 197, 94, 0.6),
        0 8px 12px rgba(0, 0, 0, 0.4),
        0 10px 18px rgba(0, 0, 0, 0.2);
}

.popup-button.home:active {
    transform: translateY(0);
}

.popup-button.touch-active {
    transform: translateY(0);
    transition: transform 0.1s ease;
}

.button-text {
    position: relative;
    z-index: 1;
}

/* Sound Settings Pop-up */
.sound-settings-popup {
    text-align: center;
}

.sound-control-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 1rem;
}

.sound-control-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: clamp(0.75rem, 2vw, 1.25rem);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
    backdrop-filter: blur(5px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.sound-control-item:hover {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%);
    transform: translateY(-2px);
}

.sound-control-label {
    display: flex;
    align-items: center;
    gap: clamp(0.75rem, 2vw, 1rem);
}

.sound-control-icon {
    display: none; /* Hide emoji icons */
}

.sound-control-text {
    font-size: clamp(0.875rem, 2vw, 1.125rem);
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Toggle Switch */
.sound-toggle-switch {
    position: relative;
    width: 60px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
    outline: none;
}

.sound-toggle-switch:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

.sound-toggle-switch.active {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    border-color: rgba(96, 165, 250, 0.6);
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background: #ffffff;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.sound-toggle-switch.active .toggle-slider {
    transform: translateX(28px);
    background: #ffffff;
}

.sound-toggle-switch:active .toggle-slider {
    transform: scale(0.9);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.show-flex {
    display: flex !important;
}

/* ============================================
   RESPONSIVE DESIGN - MAINTAINING ASPECT RATIOS
   ============================================ */

/* Note: aspect-ratio is already set in base styles for .cell and .color-button */
/* All responsive rules below maintain these aspect ratios */

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
    .game-container {
        padding: 0.75rem;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .game-board {
        max-width: calc(100vw - 2rem);
        padding: clamp(6px, 2vw, 8px);
        gap: 1.5px;
    }

    .color-palette {
        gap: clamp(4px, 1.2vw, 8px);
        padding: clamp(10px, 2vw, 16px);
        border-radius: 16px;
    }

    .color-button {
        width: clamp(36px, 8vw, 44px);
        height: clamp(36px, 8vw, 44px);
        min-width: 40px;
        min-height: 40px;
    }

    .left-controls,
    .right-controls {
        top: 0.4rem;
        gap: 0.4rem;
    }

    .left-controls {
        left: 0.4rem;
    }

    .right-controls {
        right: 0.4rem;
    }

    .moves-top-center {
        top: 0.4rem;
    }

    .undo-button.icon-only,
    .reset-button.icon-only,
    .sound-button.icon-only,
    .solution-button.icon-only,
    .home-button.icon-only {
        width: 2.75rem;
        height: 2.75rem;
        min-width: 2.75rem;
        min-height: 2.75rem;
        padding: 0.65rem;
    }

    .undo-button.icon-only .undo-icon,
    .reset-button.icon-only .reset-icon,
    .sound-button.icon-only .sound-icon,
    .solution-button.icon-only .solution-icon,
    .home-button.icon-only .home-icon {
        width: 0.9rem;
        height: 0.9rem;
    }

    .level-display,
    .moves-display {
        height: 2.75rem;
        min-height: 2.75rem;
        font-size: 0.7rem;
    }

    .level-display {
        padding: 0 0.15rem;
    }

    .level-display .level-text {
        font-size: 1.35rem;
    }

    .moves-display {
        padding: 0 0.3rem;
        gap: 0.3rem;
        border-radius: 8px;
    }

    .moves-display .moves-icon {
        width: 1rem;
        height: 1rem;
    }
    
    .extra-moves-button {
        min-width: 70px;
        padding: 0.4rem 0.6rem;
        gap: 0.15rem;
        margin-left: 0.3rem;
    }
    
    .extra-moves-icon {
        width: 0.9rem;
        height: 0.9rem;
    }
    
    .extra-moves-text {
        font-size: 0.5rem;
    }

    .hud-label {
        font-size: 0.6rem;
    }

    .hud-value {
        font-size: 1rem;
    }

    .popup-container {
        padding: 1.25rem;
        margin: 0.75rem;
        max-width: calc(100vw - 1.5rem);
        max-height: 90dvh;
    }

    .logo-image {
        max-height: 60px;
    }

    .result-icon {
        font-size: 2.5rem;
    }

    .result-title {
        font-size: 1.75rem;
    }

    .result-subtitle {
        font-size: 0.875rem;
    }

    .result-subtitle {
        font-size: 1rem;
    }

    .popup-button {
        width: 100%;
        min-height: 44px;
        padding: 0.875rem 1.25rem;
        font-size: 1rem;
    }

    .stats-section {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .instruction-item {
        padding: 0.75rem;
        min-height: 44px;
    }

    .cell {
        min-height: 28px;
        min-width: 28px;
    }

    .home-top-bar {
        top: 0.4rem;
        padding: 0 0.4rem;
    }

    .wood-btn--sm {
        width: 2rem;
        height: 2rem;
        min-width: 2rem;
        min-height: 2rem;
    }

    .wood-btn--sm .wood-btn-icon {
        width: 0.85rem;
        height: 0.85rem;
    }

    .home-content {
        gap: 1.75rem;
    }

    .home-logo {
        max-height: clamp(60px, 18vw, 90px);
    }

    .home-level-card {
        padding: 1.5rem 3rem;
        min-width: 150px;
    }

    .home-level-label {
        font-size: 0.8rem;
        font-weight: 800;
    }

    .home-level-value {
        font-size: 2.25rem;
    }
}

/* Mobile (≤640px) */
@media (min-width: 481px) and (max-width: 640px) {
    .game-container {
        padding: 1rem;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .game-board {
        max-width: min(320px, calc(100vw - 3rem));
        padding: clamp(8px, 2vw, 10px);
        gap: 1.5px;
    }

    .color-palette {
        gap: clamp(6px, 1.5vw, 10px);
        padding: clamp(12px, 2.5vw, 18px);
        border-radius: 18px;
    }

    .color-button {
        width: clamp(40px, 6vw, 46px);
        height: clamp(40px, 6vw, 46px);
        min-width: 44px;
        min-height: 44px;
    }

    .left-controls,
    .right-controls {
        top: 0.5rem;
        gap: 0.5rem;
    }

    .left-controls {
        left: 0.5rem;
    }

    .right-controls {
        right: 0.5rem;
    }

    .undo-button.icon-only,
    .reset-button.icon-only,
    .sound-button.icon-only,
    .solution-button.icon-only,
    .home-button.icon-only {
        width: 3rem;
        height: 3rem;
        min-width: 3rem;
        min-height: 3rem;
        padding: 0.75rem;
    }

    .undo-button.icon-only .undo-icon,
    .reset-button.icon-only .reset-icon,
    .sound-button.icon-only .sound-icon,
    .solution-button.icon-only .solution-icon,
    .home-button.icon-only .home-icon {
        width: 1rem;
        height: 1rem;
    }

    .level-display,
    .moves-display {
        height: 3rem;
        min-height: 3rem;
        font-size: 0.75rem;
    }

    .level-display {
        padding: 0 0.2rem;
    }

    .level-display .level-text {
        font-size: 1.45rem;
    }

    .moves-display {
        padding: 0 0.35rem;
        gap: 0.35rem;
        border-radius: 10px;
    }
    
    .extra-moves-button {
        margin-left: 0.35rem;
    }

    .hud-label {
        font-size: 0.65rem;
    }

    .hud-value {
        font-size: 1.05rem;
    }

    .popup-container {
        padding: 1.5rem;
        margin: 1rem;
        max-width: 90vw;
        max-height: 90dvh;
    }

    .logo-image {
        max-height: 80px;
    }

    .result-icon {
        font-size: 3rem;
    }

    .result-title {
        font-size: 2rem;
    }

    .result-subtitle {
        font-size: 1rem;
    }

    .popup-button {
        width: 100%;
        min-height: 48px;
        padding: 1rem 1.5rem;
        font-size: 1.05rem;
    }

    .stats-section {
        grid-template-columns: 1fr;
        gap: 0.875rem;
    }

    .cell {
        min-height: 32px;
        min-width: 32px;
    }
}

/* Tablet Portrait (641px-768px) */
@media (min-width: 641px) and (max-width: 768px) {
    .game-container {
        padding: 1.25rem;
    }

    .game-board {
        max-width: min(380px, calc(100vw - 4rem));
        padding: clamp(10px, 1.5vw, 12px);
        gap: 1.5px;
    }

    .color-palette {
        gap: clamp(8px, 1.5vw, 12px);
        padding: clamp(14px, 2.5vw, 20px);
        border-radius: 20px;
    }

    .color-button {
        width: clamp(42px, 5vw, 48px);
        height: clamp(42px, 5vw, 48px);
        min-width: 44px;
        min-height: 44px;
    }

    .left-controls,
    .right-controls {
        top: 0.75rem;
        gap: 0.5rem;
    }

    .undo-button.icon-only,
    .reset-button.icon-only,
    .sound-button.icon-only,
    .solution-button.icon-only,
    .home-button.icon-only {
        width: 3.25rem;
        height: 3.25rem;
        min-width: 3.25rem;
        min-height: 3.25rem;
    }

    .level-display,
    .moves-display {
        padding: 0 0.4rem;
        height: 3.25rem;
        min-height: 3.25rem;
    }

    .popup-container {
        max-width: 85vw;
        padding: 2rem;
    }

    .logo-image {
        max-height: 100px;
    }

    .result-icon {
        font-size: 3.5rem;
    }

    .result-title {
        font-size: 2.25rem;
    }

    .popup-button {
        min-width: 180px;
    }
}

/* Tablet Landscape (769px-1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .game-container {
        padding: 1.5rem;
    }

    .game-board {
        max-width: min(420px, calc(100vw - 6rem));
        padding: clamp(12px, 1.5vw, 14px);
        gap: 1.5px;
    }

    .color-palette {
        gap: clamp(8px, 1.5vw, 12px);
        padding: clamp(16px, 2.5vw, 22px);
    }

    .color-button {
        width: clamp(44px, 4.5vw, 50px);
        height: clamp(44px, 4.5vw, 50px);
    }

    .undo-button.icon-only,
    .reset-button.icon-only,
    .sound-button.icon-only,
    .solution-button.icon-only,
    .home-button.icon-only {
        width: 3.5rem;
        height: 3.5rem;
        min-width: 3.5rem;
        min-height: 3.5rem;
    }

    .level-display,
    .moves-display {
        padding: 0 0.4rem;
        height: 3.5rem;
        min-height: 3.5rem;
    }
    
    .extra-moves-button {
        margin-left: 0.4rem;
    }

    .popup-container {
        max-width: 80vw;
        padding: 2.5rem;
    }

    .logo-image {
        max-height: 110px;
    }

    .result-icon {
        font-size: 3.75rem;
    }

    .result-title {
        font-size: 2.5rem;
    }
}

/* Desktop (≥1025px) */
@media (min-width: 1025px) {
    .game-container {
        padding: 2rem;
    }

    .game-board {
        max-width: 480px;
        padding: 14px;
        gap: 1.5px;
    }

    .color-palette {
        gap: 10px;
        padding: 20px;
    }

    .color-button {
        width: 48px;
        height: 48px;
    }

    .undo-button.icon-only,
    .reset-button.icon-only,
    .sound-button.icon-only,
    .solution-button.icon-only,
    .home-button.icon-only {
        width: 3.5rem;
        height: 3.5rem;
        min-width: 3.5rem;
        min-height: 3.5rem;
    }

    .level-display,
    .moves-display {
        padding: 0 0.4rem;
        height: 3.5rem;
        min-height: 3.5rem;
    }
    
    .extra-moves-button {
        margin-left: 0.4rem;
    }

    .popup-container {
        max-width: 500px;
        padding: 2.5rem;
    }

    .logo-image {
        max-height: 120px;
    }
}

/* Landscape Mobile (orientation: landscape) */
@media (orientation: landscape) and (max-height: 600px) {
    .game-container {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
        min-height: 100vh;
        min-height: 100dvh;
        justify-content: center;
    }

    .game-board {
        max-width: min(70vh, calc(100vw - 2rem));
        margin: 0 auto;
        padding: clamp(6px, 1.5vh, 10px);
        gap: 1.5px;
    }

    .color-palette {
        flex-direction: row;
        gap: clamp(5px, 1.2vw, 8px);
        padding: clamp(10px, 2vw, 16px);
        border-radius: 18px;
    }

    .color-button {
        width: clamp(36px, 4.5vw, 44px);
        height: clamp(36px, 4.5vw, 44px);
        min-width: 40px;
        min-height: 40px;
        aspect-ratio: 1 / 1;
    }

    /* Compact HUD for landscape */
    .left-controls,
    .right-controls {
        top: 0.25rem;
        gap: 0.25rem;
    }

    .left-controls {
        left: 0.25rem;
    }

    .right-controls {
        right: 0.25rem;
    }

    .level-display,
    .moves-display {
        height: 2.5rem;
        min-height: 2.5rem;
        font-size: 0.7rem;
    }

    .level-display {
        padding: 0 0.1rem;
    }

    .level-display .level-text {
        font-size: 1.2rem;
    }

    .moves-top-center {
        top: 0.25rem;
    }

    .moves-display {
        padding: 0 0.3rem;
        gap: 0.25rem;
        border-radius: 8px;
    }

    .moves-display .moves-icon {
        width: 0.9rem;
        height: 0.9rem;
    }
    
    .extra-moves-button {
        margin-left: 0.3rem;
    }

    .hud-label {
        font-size: 0.6rem;
    }

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

    .undo-button.icon-only,
    .reset-button.icon-only,
    .sound-button.icon-only,
    .solution-button.icon-only,
    .home-button.icon-only {
        width: 2.5rem;
        height: 2.5rem;
        min-width: 2.5rem;
        min-height: 2.5rem;
        padding: 0.5rem;
        aspect-ratio: 1 / 1;
    }

    .undo-button.icon-only .undo-icon,
    .reset-button.icon-only .reset-icon,
    .sound-button.icon-only .sound-icon,
    .solution-button.icon-only .solution-icon,
    .home-button.icon-only .home-icon {
        width: 0.9rem;
        height: 0.9rem;
    }
    
    .extra-moves-button {
        min-width: 65px;
        padding: 0.35rem 0.5rem;
        gap: 0.1rem;
    }
    
    .extra-moves-icon {
        width: 0.8rem;
        height: 0.8rem;
    }
    
    .extra-moves-text {
        font-size: 0.45rem;
    }

    .home-level-row {
        gap: 0.06rem;
    }

    .moves-reset-sound-row {
        gap: 0.25rem;
    }

    /* Pop-up responsive adjustments for landscape mobile */
    .popup-container {
        padding: clamp(0.75rem, 2vh, 1.25rem);
        margin: 0.5rem;
        max-width: min(85vw, 500px);
        max-height: 90vh;
        max-height: 90dvh;
        width: 85vw;
    }

    /* Start pop-up specific adjustments */
    .start-popup {
        max-width: min(80vw, 450px);
        width: 80vw;
        max-height: 88vh;
        max-height: 88dvh;
    }

    /* Sound settings pop-up - even smaller in landscape */
    .sound-settings-popup {
        max-width: min(70vw, 320px);
        width: 70vw;
        max-height: 85vh;
        max-height: 85dvh;
        padding: clamp(0.75rem, 1.5vh, 1rem);
    }

    .popup-header {
        margin-bottom: 1rem;
    }

    .popup-content {
        margin-bottom: 1rem;
    }

    .logo-image {
        max-height: 50px;
    }

    .result-icon {
        font-size: 2rem;
    }

    .result-title {
        font-size: 1.5rem;
    }

    .result-subtitle {
        font-size: 0.875rem;
    }

    .section-title {
        font-size: 1rem;
    }

    .section-text {
        font-size: 0.875rem;
    }

    .sound-control-item {
        padding: clamp(0.5rem, 1.5vh, 0.75rem);
    }

    .sound-control-text {
        font-size: 0.875rem;
    }

    .popup-button {
        padding: clamp(0.625rem, 1.5vh, 0.875rem) clamp(1rem, 3vw, 1.25rem);
        font-size: 0.875rem;
        min-height: 40px;
    }

    .instruction-item {
        padding: clamp(0.5rem, 1.5vh, 0.75rem);
    }

    .cell {
        min-height: 24px;
        min-width: 24px;
    }
}

/* Color-specific classes are now defined above with the 3D gem effects */
