:root {
    --bg-dark: #0a0a0c;
    --bg-panel: rgba(20, 20, 25, 0.7);
    --accent-primary: #00f2ff;
    --accent-secondary: #7000ff;
    --text-main: #e0e0e0;
    --text-muted: #888899;
    --glass-border: rgba(255, 255, 255, 0.1);
    --neon-shadow: 0 0 15px rgba(0, 242, 255, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Background Stars */
.stars-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: radial-gradient(circle at center, #1b2735 0%, #090a0f 100%);
}

.star {
    position: absolute;
    background: white;
    border-radius: 50%;
    opacity: 0.5;
    animation: twinkle var(--duration) infinite ease-in-out;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* Layout */
header {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 10;
}

.logo {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 2px;
}

.glitch-text {
    position: relative;
    color: var(--accent-primary);
    text-shadow: var(--neon-shadow);
}

.stats {
    display: flex;
    gap: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-item .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.stat-item .value {
    font-size: 1.2rem;
    font-weight: 800;
    color: #fff;
}

.header-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.3s, transform 0.2s;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    color: var(--accent-primary);
    transform: scale(1.1);
}

.icon-btn svg {
    filter: drop-shadow(0 0 5px currentColor);
}

.shuffle-btn {
    background: none;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.shuffle-btn:hover {
    background: var(--accent-primary);
    color: var(--bg-dark);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.5);
    transform: rotate(180deg);
}

/* Main Container */
#content-layout {
    flex: 1;
    display: flex;
    overflow: hidden;
}

#game-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 2rem;
    position: relative;
    overflow-y: auto;
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loader-circle {
    width: 60px;
    height: 60px;
    border: 3px solid transparent;
    border-top-color: var(--accent-primary);
    border-bottom-color: var(--accent-secondary);
    border-radius: 50%;
    animation: rotate 1.5s linear infinite;
}

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

#game-canvas-wrapper {
    width: 100%;
    max-width: 800px;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: fadeIn 0.6s ease-out;
}

.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

#game-ui {
    margin-bottom: 2rem;
    text-align: center;
}

#game-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

#game-desc {
    color: var(--text-muted);
    font-size: 0.9rem;
}

#canvas-area {
    width: 100%;
    min-height: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    overflow: hidden;
}

#sidebar {
    width: 250px;
    background: rgba(10, 10, 12, 0.4);
    backdrop-filter: blur(10px);
    border-left: 1px solid var(--glass-border);
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    overflow-y: auto;
    z-index: 5;
    transition: all 0.8s cubic-bezier(0.19, 1, 0.22, 1);
}

#sidebar.ad-hidden {
    width: 0;
    padding: 0;
    opacity: 0;
    border-left: none;
    pointer-events: none;
}

#footer-ad-bar {
    transition: all 0.8s ease;
    max-height: 500px;
    overflow: hidden;
    background: rgba(10, 10, 12, 0.6);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--glass-border);
    padding: 1rem 0;
    text-align: center;
    position: relative;
    z-index: 10;
}

#footer-ad-bar.ad-hidden {
    max-height: 50px; /* Keep a bit for credits or hide completely */
    padding: 0.5rem 0;
}

#footer-ad-bar.ad-hidden .ad-container {
    display: none;
}

.google-ad-banner {
    position: relative;
    width: 100%;
    max-width: 970px;
    margin: 0 auto;
    min-height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.google-ad-banner .ad-label {
    top: -20px;
}

.close-ad-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 24px;
    height: 24px;
    background: #ff0055;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 10px rgba(255, 0, 85, 0.5);
    transition: opacity 0.3s;
}

.close-ad-btn.hidden {
    display: none;
}

#leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    padding: 5px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}

.leaderboard-name {
    color: var(--text-main);
}

.leaderboard-score {
    color: var(--accent-primary);
    font-weight: 700;
}

.sidebar-ad {
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--glass-border);
    padding: 1rem;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 400px;
}

.sidebar-info {
    padding: 1rem;
    background: var(--bg-panel);
    border-radius: 10px;
    border: 1px solid var(--glass-border);
}

.sidebar-info h3 {
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    color: var(--accent-primary);
}

.info-item {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.highlight {
    color: #fff;
    font-weight: 600;
}

.google-ad-vertical {
    display: flex;
    justify-content: center;
    width: 100%;
    min-height: 250px;
}

/* Ad Popup */
.ad-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.4s ease;
}

.ad-popup-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
}

.ad-popup-content {
    background: #111;
    padding: 3rem 2rem 2rem;
    border-radius: 20px;
    border: 2px solid var(--accent-secondary);
    box-shadow: 0 0 50px rgba(112, 0, 255, 0.3);
    position: relative;
    text-align: center;
    max-width: 400px;
}

.google-ad-popup-box {
    margin: 1.5rem 0;
    background: #000;
    width: 300px;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-popup-content p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: #fff;
}

.ad-label {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-dark);
    padding: 0 10px;
    font-size: 0.6rem;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.key {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--glass-border);
    color: #fff;
}

/* Game Specific Styles */
canvas {
    max-width: 100%;
}

/* Sudoku Grid */
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    width: 300px;
    margin: 0 auto;
}

.sudoku-cell {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
    color: #fff;
}

.sudoku-cell:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sudoku-cell.fixed {
    color: var(--accent-primary);
    cursor: default;
}

.sudoku-cell.focused {
    border-color: var(--accent-primary);
    box-shadow: inset 0 0 10px rgba(0, 242, 255, 0.2);
}

/* Message Styles */
.game-over-msg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 2rem;
    border-radius: 15px;
    border: 1px solid var(--accent-primary);
    text-align: center;
    z-index: 100;
    max-width: 90%;
    width: 320px;
    max-height: 95%;
    overflow-y: auto;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-over-msg div {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--bg-dark);
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    font-weight: 800;
    cursor: pointer;
    margin-top: 1rem;
    transition: transform 0.2s;
    touch-action: manipulation;
    pointer-events: auto;
    position: relative;
    z-index: 1000;
}

@keyframes pulse-bgm {
    from { filter: brightness(1) drop-shadow(0 0 10px rgba(0, 242, 255, 0.5)); transform: scale(0.95); }
    to { filter: brightness(1.5) drop-shadow(0 0 30px rgba(0, 242, 255, 1)); transform: scale(1.05); }
}

/* Responsive Media Queries */
@media (max-width: 900px) {
    #content-layout {
        flex-direction: column;
        overflow-y: auto;
    }
    
    #sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--glass-border);
        padding: 1rem;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
    }
    
    .sidebar-ad {
        min-height: auto;
        width: 100%;
        margin-bottom: 1rem;
        padding: 1rem 0;
    }
    
    .google-ad-vertical {
        min-height: 100px; /* For mobile banners */
    }
    
    .sidebar-info {
        flex: 1;
        min-width: 250px;
        margin: 0.5rem;
    }
}

@media (max-width: 600px) {
    header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        padding: 1rem;
    }
    
    .stats {
        width: 100%;
        justify-content: center;
    }
    
    #game-canvas-wrapper {
        padding: 1rem;
        border-radius: 10px;
    }
    
    #game-title {
        font-size: 1.5rem;
    }

    #canvas-area {
        min-height: 350px;
    }
    
    .game-over-msg {
        padding: 1.5rem;
        width: 95%;
    }
    .game-over-msg p {
        margin: 0.5rem 0 !important;
        font-size: 0.9rem;
    }
    .btn-primary {
        padding: 0.6rem 1rem;
        margin-top: 0.5rem;
    }
    
    .sudoku-grid {
        width: 100%;
        max-width: 300px;
    }
    
    .sudoku-cell {
        width: 100%;
        height: auto;
        aspect-ratio: 1/1;
        font-size: 1.2rem;
    }
    
    canvas {
        width: 100% !important;
        height: auto !important;
    }
}

#mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 2rem;
    user-select: none;
}

.dpad-row {
    display: flex;
    gap: 10px;
}

.dpad-btn {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
    border-radius: 12px;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.1s;
}

.dpad-btn:active {
    background: var(--accent-primary);
    color: var(--bg-dark);
    transform: scale(0.9);
}

.dpad-btn.action {
    border-color: var(--accent-secondary);
    color: var(--accent-secondary);
}

.dpad-btn.action:active {
    background: var(--accent-secondary);
    color: #fff;
}

@media (max-width: 600px) {
    #mobile-controls {
        display: flex;
    }
}
