* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    color: #eee;
    font-family: 'Segoe UI', system-ui, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 1s ease-in-out;
}

/* ========== 8 Orion Themes ========== */

/* Theme 0: The Void (Lvl 1-5) - Deep midnight blue, calm focus */
body.theme-0 {
    background: radial-gradient(ellipse at center, #1e293b 0%, #0f172a 70%, #020617 100%);
}

/* Theme 1: Nebula (Lvl 6-10) - Purple/pink cosmic */
body.theme-1 {
    background: radial-gradient(ellipse at top right, #581c87 0%, #3b0764 50%, #1e1b4b 100%);
}

/* Theme 2: Cyber Grid (Lvl 11-15) - Teal/green matrix */
body.theme-2 {
    background: linear-gradient(135deg, #022c22 0%, #064e3b 50%, #065f46 100%);
}

/* Theme 3: Red Giant (Lvl 16-20) - Orange/red intensity */
body.theme-3 {
    background: radial-gradient(ellipse at bottom, #7f1d1d 0%, #450a0a 70%, #1c1917 100%);
}

/* Theme 4: Deep Sea (Lvl 21-25) - Bioluminescent blue */
body.theme-4 {
    background: radial-gradient(ellipse at center, #0c4a6e 0%, #082f49 50%, #0a0f1a 100%);
}

/* Theme 5: Synthwave (Lvl 26-30) - Violet/sunset */
body.theme-5 {
    background: linear-gradient(135deg, #4c1d95 0%, #6b21a8 30%, #92400e 100%);
}

/* Theme 6: Monochrome (Lvl 31-35) - Stark black/white */
body.theme-6 {
    background: radial-gradient(ellipse at center, #27272a 0%, #18181b 50%, #09090b 100%);
}

/* Theme 7: Supernova (Lvl 36-40) - Gold/white finale */
body.theme-7 {
    background: radial-gradient(ellipse at center, #854d0e 0%, #78350f 40%, #292524 100%);
}

.game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    padding: 8px;
    gap: 6px;
}

/* Top info bar - compact horizontal */
.game-info {
    display: flex;
    flex-direction: row;
    gap: 6px;
    justify-content: center;
    flex-shrink: 0;
}

.score-panel {
    display: flex;
    flex-direction: row;
    gap: 6px;
}

.info-box {
    background: rgba(15, 15, 26, 0.6);
    border: 1px solid rgba(58, 58, 90, 0.5);
    border-radius: 6px;
    padding: 4px 10px;
    min-width: 55px;
    text-align: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.label {
    display: block;
    font-size: 9px;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 1px;
}

.value {
    display: block;
    font-size: 16px;
    font-weight: bold;
    color: #4ecdc4;
}

.next-piece {
    background: rgba(15, 15, 26, 0.6);
    border: 1px solid rgba(58, 58, 90, 0.5);
    border-radius: 6px;
    padding: 4px;
    text-align: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.next-piece .label {
    margin-bottom: 2px;
}

#nextCanvas {
    background: #0f0f1a;
    width: 50px;
    height: 50px;
}

/* Floating menu button - top right corner */
.floating-menu-btn {
    position: fixed;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    font-size: 24px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    color: #888;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    z-index: 50;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.floating-menu-btn:active {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(0.95);
}

/* Game canvas - fills available space */
.canvas-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
}

#gameCanvas {
    background: rgba(10, 10, 20, 0.7);
    border: 1px solid rgba(58, 58, 90, 0.4);
    border-radius: 6px;
    max-height: 100%;
    max-width: 100%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Touch controls - compact layout */
.controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    padding: 0 4px;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.control-btn {
    width: 52px;
    height: 44px;
    font-size: 20px;
    background: rgba(42, 42, 74, 0.7);
    border: 1px solid rgba(74, 74, 106, 0.5);
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: transform 0.1s, background 0.1s;
}

.control-btn:active {
    background: linear-gradient(180deg, #2a2a4a 0%, #3a3a5a 100%);
    transform: scale(0.95) translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.control-btn.wide {
    width: 140px;
    font-size: 14px;
    font-weight: 600;
}

/* Overlay styles */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: rgba(21, 21, 37, 0.9);
    border: 1px solid rgba(74, 74, 106, 0.5);
    border-radius: 12px;
    padding: 20px 24px;
    text-align: center;
    max-width: 90vw;
    width: 300px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.overlay-content h2 {
    font-size: 24px;
    color: #ff6b6b;
    margin-bottom: 16px;
}

.overlay-content p {
    font-size: 16px;
    margin-bottom: 12px;
    color: #aaa;
}

/* Start screen */
.start-content {
    padding: 30px 24px;
}

.game-title {
    font-size: 42px;
    font-weight: 900;
    color: #4ecdc4;
    margin-bottom: 4px;
    text-shadow: 0 0 20px rgba(78, 205, 196, 0.4);
    letter-spacing: 4px;
}

.game-subtitle {
    font-size: 14px;
    color: #888;
    margin-bottom: 20px;
}

.start-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 24px;
}

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

.stat-item .stat-label {
    display: block;
    font-size: 11px;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.stat-item .stat-value {
    font-size: 20px;
    font-weight: bold;
    color: #4ecdc4;
}

.controls-hint {
    font-size: 12px;
    color: #666;
    margin-top: 16px;
}

/* Quit screen */
.quit-score {
    font-size: 18px;
    color: #4ecdc4;
    font-weight: bold;
}

/* Game over stats */
.final-stats {
    margin-bottom: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid #2a2a4a;
}

.stat-label {
    color: #888;
    font-size: 13px;
}

.stat-value {
    color: #4ecdc4;
    font-size: 16px;
    font-weight: bold;
}

/* High score banner */
.high-score-banner {
    background: linear-gradient(135deg, #f0a000, #ff6b6b);
    color: #fff;
    padding: 10px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    margin-bottom: 12px;
    animation: pulse 1s ease-in-out infinite alternate;
}

.high-score-banner.hidden {
    display: none;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.03); }
}

/* Name input */
.name-section {
    margin-bottom: 16px;
}

.name-section label {
    display: block;
    color: #888;
    font-size: 11px;
    text-transform: uppercase;
    margin-bottom: 6px;
}

#playerName, #quitPlayerName {
    width: 100%;
    background: #0f0f1a;
    border: 2px solid #4a4a6a;
    border-radius: 6px;
    padding: 10px 12px;
    color: #fff;
    font-size: 16px;
    outline: none;
}

#playerName:focus, #quitPlayerName:focus {
    border-color: #4ecdc4;
}

#playerName::placeholder, #quitPlayerName::placeholder {
    color: #666;
}

/* Button group */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.button-group .control-btn {
    width: 100%;
    height: 44px;
    font-size: 14px;
}

.control-btn.wide {
    width: 100%;
}

.control-btn.primary {
    background: linear-gradient(180deg, #4ecdc4 0%, #3dbdb5 100%);
    border-color: #5eddd5;
    color: #0f0f1a;
    font-weight: bold;
}

.control-btn.primary:active {
    background: linear-gradient(180deg, #3dbdb5 0%, #4ecdc4 100%);
}

.control-btn.secondary {
    background: transparent;
    border-color: #4a4a6a;
    color: #888;
}

.control-btn.secondary:active {
    background: #2a2a4a;
}

/* Leaderboard */
.leaderboard-content {
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.period-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.toggle-btn {
    flex: 1;
    padding: 8px 12px;
    background: transparent;
    border: 2px solid #4a4a6a;
    border-radius: 6px;
    color: #888;
    font-size: 13px;
    cursor: pointer;
}

.toggle-btn.active {
    background: #4ecdc4;
    border-color: #4ecdc4;
    color: #0f0f1a;
    font-weight: bold;
}

.leaderboard-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 12px;
    max-height: 250px;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #2a2a4a;
}

.leaderboard-entry.highlight {
    background: rgba(78, 205, 196, 0.1);
}

.rank {
    width: 28px;
    font-weight: bold;
    color: #4ecdc4;
}

.rank.gold { color: #ffd700; }
.rank.silver { color: #c0c0c0; }
.rank.bronze { color: #cd7f32; }

.entry-name {
    flex: 1;
    font-size: 13px;
}

.entry-score {
    font-weight: bold;
    color: #4ecdc4;
    font-size: 14px;
}

.share-rank-btn {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    margin-left: 8px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.share-rank-btn:active {
    opacity: 1;
    transform: scale(0.95);
}

.loading, .no-scores {
    text-align: center;
    color: #888;
    padding: 20px;
    font-size: 14px;
}

/* Desktop: Hide touch controls, side-by-side layout */
@media (min-width: 600px) and (hover: hover) {
    .game-container {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 20px;
        padding: 20px;
    }

    .game-info {
        flex-direction: column;
        gap: 12px;
    }

    .score-panel {
        flex-direction: column;
        gap: 8px;
    }

    .info-box {
        padding: 8px 12px;
        min-width: 80px;
    }

    .label {
        font-size: 11px;
    }

    .value {
        font-size: 20px;
    }

    .next-piece {
        padding: 8px;
    }

    #nextCanvas {
        width: 70px;
        height: 70px;
    }

    .canvas-wrapper {
        flex: none;
    }

    .controls {
        display: none;
    }
}

/* Achievement Popup */
#achievementPopup {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: linear-gradient(135deg, #2a2a4a 0%, #1a1a2e 100%);
    border: 2px solid #4ecdc4;
    border-radius: 12px;
    padding: 12px 16px;
    z-index: 200;
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    box-shadow: 0 8px 32px rgba(78, 205, 196, 0.3);
}

#achievementPopup.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.achievement-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.achievement-icon {
    font-size: 32px;
    animation: bounce 0.6s ease infinite alternate;
}

@keyframes bounce {
    from { transform: scale(1); }
    to { transform: scale(1.15); }
}

.achievement-text {
    text-align: left;
}

.achievement-title {
    font-size: 14px;
    font-weight: bold;
    color: #4ecdc4;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.achievement-subtitle {
    font-size: 12px;
    color: #aaa;
    margin-top: 2px;
}

.share-btn {
    background: linear-gradient(180deg, #4ecdc4 0%, #3dbdb5 100%);
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    color: #0f0f1a;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.1s;
}

.share-btn:active {
    transform: scale(0.95);
}
