/* All existing styles remain the same */
:root {
    --bg: #0b0e1a;
    --bg-dark: #060812;
    --accent: #00ff9d;
    --accent2: #00d4ff;
    --accent3: #7c9eff;
    --text: #e0f0ff;
    --text-dim: #a3bffa;
    --card: rgba(20, 25, 45, 0.65);
    --glow: 0 0 20px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --color-red: #ff4444;
    --color-blue: #44aaff;
    --color-green: #44ff44;
    --color-yellow: #ffdd44;
    --color-purple: #aa44ff;
    --color-orange: #ff8844;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(145deg, var(--bg-dark) 0%, var(--bg) 100%);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
}

/* Navigation styles (same as before) */
.navbar-desktop {
    position: fixed;
    inset: 0 0 auto 0;
    padding: 0.9rem 5vw;
    background: rgba(8, 12, 30, 0.98);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 255, 157, 0.16);
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

@media (max-width: 1024px) {
    .navbar-desktop {
        display: none;
    }
}

.logo {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1.4rem, 5vw, 1.8rem);
    font-weight: 800;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.nav-links {
    display: flex;
    gap: clamp(1rem, 3vw, 1.8rem);
    align-items: center;
}

.nav-links a {
    color: var(--text-dim);
    text-decoration: none;
    font-weight: 500;
    font-size: clamp(0.8rem, 3vw, 0.95rem);
    transition: all 0.22s;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent);
}

.btn-small {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #0b1121 !important;
    padding: 0.4rem 1rem;
    border-radius: 50vmax;
    font-weight: 700;
}

/* Sidebar */
.sidebar-toggle {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1100;
    background: var(--card);
    border: 1px solid var(--accent2);
    color: var(--accent2);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
}

@media (max-width: 1024px) {
    .sidebar-toggle {
        display: flex;
    }
}

.admin-sidebar {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    transform: translateX(-120%);
    opacity: 0;
    width: 260px;
    background: rgba(8, 12, 24, 0.98);
    backdrop-filter: blur(16px);
    border: 1px solid var(--accent2);
    border-radius: 2rem;
    padding: 1.5rem 0.8rem;
    transition: transform 0.3s, opacity 0.2s;
    z-index: 2000;
}

@media (max-width: 1024px) {
    .admin-sidebar {
        display: block;
    }
}

.admin-sidebar.open {
    transform: translateX(0);
    opacity: 1;
}

.sidebar-logo {
    font-family: 'Orbitron', monospace;
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(90deg, var(--accent2), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    padding: 0 0.5rem 1.2rem;
    border-bottom: 1px solid var(--accent2);
    margin-bottom: 1.2rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.7rem 1rem;
    color: var(--text-dim);
    text-decoration: none;
    border-radius: 2rem;
}

.sidebar-nav a i {
    width: 1.5rem;
    color: var(--accent2);
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(0, 212, 255, 0.15);
    color: var(--accent2);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(0, 255, 157, 0.1);
    margin-top: 1.5rem;
}

.sidebar-footer .signup-link {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #0b1121;
    padding: 0.7rem 1rem;
    border-radius: 2rem;
    text-align: center;
    display: block;
    font-weight: 700;
    text-decoration: none;
}

.sidebar-footer .logout-link {
    background: linear-gradient(90deg, rgba(225, 62, 62, 0.81), red);
    color: white;
    padding: 0.7rem 1rem;
    border-radius: 2rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 700;
    text-decoration: none;
    margin-top: 0.5rem;
}

.main-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

@media (min-width: 1025px) {
    .main-container {
        padding-top: 80px;
    }
}

@media (max-width: 1024px) {
    .main-container {
        padding-top: 0.5rem;
    }
}

.back-home {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-dim);
    text-decoration: none;
    margin: 1rem 0;
    font-size: 0.9rem;
}

@media (max-width: 1024px) {
    .back-home {
        margin-left: 3.5rem;
    }
}

.back-home:hover {
    color: var(--accent);
    transform: translateX(-5px);
}

/* Game Header */
.game-header {
    text-align: center;
    padding: 1rem;
}

.game-header h1 {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1.8rem, 8vw, 2.5rem);
    font-weight: 900;
}

.gradient-text {
    background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent3));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* Game Stats */
.game-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
    margin: 1rem auto;
    padding: 1rem;
    background: var(--card);
    border-radius: 2rem;
    border: 1px solid rgba(0, 255, 157, 0.2);
    max-width: 900px;
}

.stat-box {
    text-align: center;
}

.stat-value {
    font-family: 'Orbitron', monospace;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--accent);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Game Grid */
.game-container {
    position: relative;
    margin: 1rem auto;
    display: flex;
    justify-content: center;
}

canvas {
    background: var(--card);
    border-radius: 1.5rem;
    border: 2px solid rgba(0, 255, 157, 0.3);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    cursor: pointer;
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin: 1rem auto;
    padding: 0.5rem;
    background: var(--card);
    border-radius: 2rem;
    max-width: 400px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(0, 255, 157, 0.3);
    border-radius: 50px;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.control-btn:hover {
    background: rgba(0, 255, 157, 0.2);
    transform: scale(1.05);
}

/* Combo Meter */
.combo-meter {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #ffd700, #ffaa00);
    color: #000;
    border-radius: 50px;
    padding: 0.5rem 1.5rem;
    font-weight: bold;
    font-size: 1rem;
    z-index: 100;
    display: none;
    white-space: nowrap;
}

.combo-meter.show {
    display: block;
    animation: comboPop 0.3s ease;
}

@keyframes comboPop {
    0% {
        transform: translateX(-50%) scale(0.8);
        opacity: 0;
    }

    100% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }
}

/* Leaderboard */
.leaderboard-section {
    background: var(--card);
    border-radius: 1.5rem;
    padding: 1.5rem;
    margin: 2rem auto;
    max-width: 800px;
    border: 1px solid rgba(0, 255, 157, 0.2);
}

.match3-rank-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.match3-rank-number {
    font-family: 'Orbitron', monospace;
    width: 40px;
    font-weight: bold;
    color: var(--accent);
}

.match3-rank-flag {
    font-size: 1.2rem;
    width: 30px;
}

.match3-rank-name {
    flex: 1;
}

.match3-rank-score {
    font-family: 'Orbitron', monospace;
    color: var(--accent2);
    font-weight: bold;
}

.match3-rank-stats {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-left: 0.5rem;
}

/* Modal */
.game-over-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: linear-gradient(135deg, #1a1f35, #0b0e1a);
    border-radius: 2rem;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--accent);
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.modal-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 2rem;
    font-weight: bold;
    cursor: pointer;
    border: none;
}

.modal-btn-primary {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #0b1121;
}

.modal-btn-secondary {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
}

/* Footer */
footer {
    padding: 2rem 5vw 1.5rem;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    color: var(--text-dim);
    border-top: 1px solid rgba(0, 255, 157, 0.1);
    font-size: 0.8rem;
    margin-top: 2rem;
    width: 100%;
    padding-bottom: calc(1.5rem + var(--safe-bottom));
}

.footer-developer {
    font-family: 'Orbitron', monospace;
    font-size: 0.9rem;
    color: #8ab4ff;
}

footer a {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.8rem;
}

footer a:hover {
    color: var(--accent);
}

@media (max-width: 930px) {
    footer {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
        gap: 0.8rem;
    }
}


body.sidebar-open {
    overflow: hidden;
}

@keyframes fadeOut {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.2);
        display: none;
    }
}

@keyframes matchPop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-3px);
    }

    75% {
        transform: translateX(3px);
    }
}

/* ============================================
   MATCH 3 BOUNCE - RESPONSIVE STYLES
   Mobile Optimization (max-width: 400px)
   ============================================ */

/* Base container adjustments */
.main-container {
    padding: 0 0.5rem;
    overflow-x: hidden;
}

/* Game Header - Mobile */
.game-header {
    padding: 0.5rem;
}

.game-header h1 {
    font-size: 1.5rem;
    line-height: 1.2;
}

.game-header p {
    font-size: 0.75rem;
    padding: 0 0.5rem;
}

/* Game Stats - Mobile */
.game-stats {
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 1rem;
    margin: 0.5rem auto;
    flex-wrap: wrap;
    justify-content: space-around;
}

.stat-box {
    min-width: 70px;
    flex: 1;
}

.stat-value {
    font-size: 1.2rem;
}

.stat-label {
    font-size: 0.6rem;
    letter-spacing: 0.5px;
}

/* Game Container */
.game-container {
    margin: 0.5rem auto;
    padding: 0;
}

canvas {
    width: 100%;
    height: auto;
    max-width: 400px;
    display: block;
    margin: 0 auto;
    border-radius: 1rem;
}

/* Controls - Mobile */
.controls {
    gap: 0.5rem;
    padding: 0.3rem;
    margin: 0.5rem auto;
    max-width: 280px;
}

.control-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.7rem;
    gap: 0.3rem;
}

.control-btn i {
    font-size: 0.8rem;
}

/* Leaderboard Section - Mobile */
.leaderboard-section {
    padding: 1rem;
    margin: 1rem auto;
    border-radius: 1rem;
}

.leaderboard-section h3 {
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
}

.match3-rank-item {
    gap: 0.5rem;
    padding: 0.6rem;
}

.match3-rank-number {
    width: 30px;
    font-size: 0.8rem;
}

.match3-rank-flag {
    font-size: 1rem;
    width: 24px;
}

.match3-rank-name {
    font-size: 0.75rem;
}

.match3-rank-score {
    font-size: 0.75rem;
}

.match3-rank-stats {
    font-size: 0.6rem;
    margin-left: 0.3rem;
}

/* Modal - Mobile */
.modal-content {
    padding: 1.2rem;
    width: 95%;
    max-width: 320px;
}

.modal-content h2 {
    font-size: 1.2rem;
}

.stats-grid {
    gap: 0.5rem;
    margin: 0.8rem 0;
}

.modal-buttons {
    gap: 0.8rem;
}

.modal-btn {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

/* Back Home Button */
.back-home {
    font-size: 0.75rem;
    margin: 0.5rem 0;
    padding: 0.3rem 0;
}

@media (max-width: 1024px) {
    .back-home {
        margin-left: 2rem;
    }
}

@media (max-width: 400px) {
    .back-home {
        margin-left: 1rem;
    }
}

/* Navigation - Mobile */
@media (max-width: 1024px) {
    .navbar-desktop {
        display: none;
    }

    .sidebar-toggle {
        display: flex;
    }
}

/* Fix for canvas scaling on very small screens */
@media (max-width: 350px) {
    .game-stats {
        gap: 0.3rem;
    }

    .stat-box {
        min-width: 60px;
    }

    .stat-value {
        font-size: 1rem;
    }

    .stat-label {
        font-size: 0.55rem;
    }

    .control-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.65rem;
    }

    .control-btn i {
        font-size: 0.7rem;
    }

    .match3-rank-item {
        padding: 0.5rem;
    }

    .match3-rank-number {
        width: 25px;
        font-size: 0.7rem;
    }

    .match3-rank-flag {
        font-size: 0.9rem;
        width: 20px;
    }

    .match3-rank-name {
        font-size: 0.7rem;
    }

    .match3-rank-score {
        font-size: 0.7rem;
    }
}

/* Ensure canvas maintains aspect ratio */
canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    max-width: 500px;
}

/* Touch-friendly improvements */
.control-btn,
.match3-rank-item,
.modal-btn {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
    transform: scale(0.95);
}

/* Prevent zoom on input focus (iOS) */
@media (max-width: 400px) {

    input,
    button,
    .control-btn,
    .modal-btn {
        font-size: 16px;
    }
}

/* Sidebar open state */
body.sidebar-open {
    overflow: hidden;
}

/* Footer mobile */
@media (max-width: 930px) {
    footer {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
        padding: 1rem;
        font-size: 0.7rem;
    }

    footer p {
        margin: 0;
    }

    .footer-developer {
        font-size: 0.7rem;
    }
}