body {
    background: radial-gradient(ellipse at 60% 20%, #3a1c71 0%, #d76d77 40%, #ffaf7b 100%),
                radial-gradient(ellipse at 80% 80%, #231557 0%, #44107a 60%, #ff1361 100%),
                #120024;
    background-blend-mode: screen, lighten, normal;
    font-family: 'Segoe UI', Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-width: 100vw;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: hidden;
    /* Add twinkling stars */
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 0;
    background: url('data:image/svg+xml;utf8,<svg width="100%25" height="100%25" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="10" cy="10" r="0.5" fill="white" opacity="0.7"/><circle cx="20" cy="80" r="0.6" fill="white" opacity="0.5"/><circle cx="80" cy="30" r="0.7" fill="white" opacity="0.8"/><circle cx="50" cy="50" r="0.8" fill="white" opacity="0.6"/><circle cx="70" cy="70" r="0.5" fill="white" opacity="0.7"/><circle cx="90" cy="20" r="0.4" fill="white" opacity="0.4"/></svg>');
    background-size: 200px 200px;
    animation: twinkle 6s linear infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.cell {
    box-shadow: 0 0 16px 4px #fff2, 0 0 32px 8px #fff1;
    border: 1px solid #fff3;
    transition: box-shadow 0.2s, border 0.2s;
}
.cell:not(.empty) {
    filter: drop-shadow(0 0 6px #fff8) brightness(1.15) saturate(1.2);
}

.container {
    max-width: 100vw;
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    background: rgba(255,255,255,0.9);
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
    padding: 0;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    min-width: 100vw;
    justify-content: center;
}
.game-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    margin-top: 10px;
}
.game-header-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 2vw;
    margin: 0 0 10px 0;
    width: 100vw;
    max-width: 100vw;
    min-width: 320px;
    padding: 0 2vw;
    box-sizing: border-box;
}
.game-title {
    font-size: clamp(1.1rem, 3vw, 2.2rem);
    color: #4e54c8;
    font-weight: bold;
    margin: 0 1vw;
    letter-spacing: 1px;
}
.info-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
}
.score-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: #222;
    font-weight: 600;
}
.score-group {
    display: flex;
    flex-direction: row;
    gap: 1vw;
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: #222;
    font-weight: 600;
    align-items: center;
}
.score-label {
    padding: 0 0.2vw;
}
.menu-wrap {
    position: relative;
}
#menu-btn {
    background: linear-gradient(90deg, #232526 0%, #414345 100%);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 1.2rem;
    cursor: pointer;
    margin-right: 0.5vw;
    z-index: 21;
    position: relative;
    min-width: 32px;
    min-height: 32px;
    height: 32px;
    width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px #0005;
    transition: background 0.18s, box-shadow 0.18s;
}
#menu-btn:active, #menu-btn:focus {
    background: linear-gradient(90deg, #a18cd1 0%, #fbc2eb 100%);
    color: #232526;
    box-shadow: 0 4px 20px #a18cd1cc;
}

@media (max-width: 700px), (max-height: 700px) {
    #menu-btn {
        display: none !important;
    }
}

@media (max-width: 700px), (max-height: 700px) {
    #menu-btn {
        padding: 2px 10px;
        height: 28px;
        width: 32px;
        font-size: 1.1rem;
    }
}
.menu-content {
    background: linear-gradient(135deg, #232526 0%, #414345 100%);
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 24px 0 #0008, 0 1.5px 0 #fff2 inset;
    padding: 16px 0 8px 0;
    min-width: 140px;
    border: 1.5px solid #fff2;
    z-index: 20;
    position: absolute;
    top: 48px;
    left: 0;
    animation: menuFadeIn 0.25s;
    display: none;
}
.menu-content:not(.hidden) { display: block; }
.menu-content a {
    display: block;
    color: #fff;
    text-decoration: none;
    padding: 10px 28px 10px 20px;
    font-size: 1.07rem;
    border-radius: 6px;
    margin: 2px 8px;
    transition: background 0.18s, color 0.18s;
    background: transparent;
}
.menu-content a:hover, .menu-content a:focus {
    background: linear-gradient(90deg, #a18cd1 0%, #fbc2eb 100%);
    color: #232526;
}
@keyframes menuFadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
#start-btn {
    background: linear-gradient(90deg, #43cea2 0%, #185a9d 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 24px;
    font-size: clamp(1rem, 2vw, 1.2rem);
    cursor: pointer;
    margin-left: 0.5vw;
    transition: background 0.2s;
}
#start-btn:hover {
    background: linear-gradient(90deg, #185a9d 0%, #43cea2 100%);
}
h1 {
    color: #4e54c8;
    margin: 0;
    font-size: clamp(1.1rem, 3vw, 2.2rem);
}
#game-board {
    display: grid;
    grid-template-rows: repeat(20, 1fr);
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
    background: #222;
    border: 4px solid #4e54c8;
    border-radius: 8px;
    margin: 0 auto 12px auto;
    width: min(90vw, 70vh, 370px);
    height: calc(min(90vw, 70vh, 370px) * 2);
    max-width: 370px;
    max-height: 740px;
    aspect-ratio: 10/20;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    touch-action: manipulation;
}
.cell.empty {
    background: transparent;
    box-shadow: none;
}
/* Ghost piece styling */
.cell.ghost {
    background: rgba(255,255,255,0.4);
    box-shadow: none;
}
.popup {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.3s;
}
.popup.hidden {
    display: none;
}
.popup-content {
    background: #fff;
    padding: 32px 40px;
    border-radius: 16px;
    box-shadow: 0 4px 32px rgba(0,0,0,0.18);
    text-align: center;
    font-size: 1.2em;
    color: #444;
    min-width: 220px;
}
#close-popup {
    margin-top: 18px;
    padding: 8px 32px;
    background: linear-gradient(90deg, #43cea2 0%, #185a9d 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    transition: background 0.2s;
}
#close-popup:hover {
    background: linear-gradient(90deg, #185a9d 0%, #43cea2 100%);
}
.explode {
    animation: explode 0.5s ease forwards;
}
@keyframes explode {
    0% { transform: scale(1); box-shadow: 0 0 8px 2px #fff; }
    60% { transform: scale(1.5) rotate(10deg); box-shadow: 0 0 32px 16px #fff; opacity: 0.7; }
    100% { transform: scale(0); opacity: 0; }
}
.mobile-controls {
    display: none !important;
}
.mobile-controls button {
    background: linear-gradient(90deg, #43cea2 0%, #185a9d 100%);
    color: #fff;
    border: none;
    border-radius: 16px;
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.10);
    margin: 0 2vw;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mobile-controls button:active {
    background: linear-gradient(90deg, #185a9d 0%, #43cea2 100%);
    transform: scale(0.96);
}
.mobile-header {
    width: 100vw;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 2vw;
    padding: 4px 4vw 0 4vw;
    box-sizing: border-box;
    min-height: 36px;
    position: relative;
    z-index: 10;
}
.mobile-header .game-title {
    font-size: clamp(1.1rem, 3vw, 2.2rem);
    color: #4e54c8;
    font-weight: bold;
    margin: 0 1vw;
    letter-spacing: 1px;
}
.mobile-header #menu-btn {
    background: #4e54c8;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px 14px;
    font-size: 1.2rem;
    cursor: pointer;
    margin-right: 0.5vw;
    z-index: 21;
    position: relative;
}
.mobile-header .score-group {
    display: flex;
    flex-direction: row;
    gap: 2vw;
    font-size: clamp(1rem, 3vw, 1.2rem);
    color: #222;
    font-weight: 600;
    align-items: center;
}
#next-block {
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e7f0fa;
    border-radius: 8px;
    border: 1px solid #b3b3b3;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    position: relative;
    overflow: hidden;
}
#next-block-inner {
    display: inline-block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.icon-score {
    font-size: 1.2em;
    color: #e67e22;
    margin-right: 2px;
}
.icon-best {
    font-size: 1.2em;
    color: #f1c40f;
    margin-right: 2px;
}
.restart-btn {
    background: linear-gradient(90deg, #43cea2 0%, #185a9d 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 28px;
    font-size: 1.1rem;
    font-weight: bold;
    margin-top: 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.10);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
.restart-btn:hover {
    background: linear-gradient(90deg, #185a9d 0%, #43cea2 100%);
    transform: scale(0.97);
}
/* ----------- DESKTOP CSS ----------- */
.desktop-header {
    width: 100vw;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 2vw;
    padding: 8px 4vw 0 4vw;
    box-sizing: border-box;
    min-height: 36px;
    position: relative;
    z-index: 10;
}
.desktop-header .game-title {
    font-size: clamp(1.2rem, 2vw, 2.3rem);
    color: #4e54c8;
    font-weight: bold;
    margin: 0 1vw;
    letter-spacing: 1px;
}
.desktop-header #menu-btn-desktop {
    background: #4e54c8;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 8px 18px;
    font-size: 1.2rem;
    cursor: pointer;
    margin-right: 0.5vw;
    z-index: 21;
    position: relative;
}
.desktop-header .score-group {
    display: flex;
    flex-direction: row;
    gap: 2vw;
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    color: #222;
    font-weight: 600;
    align-items: center;
}
.desktop-instructions {
    width: 100vw;
    text-align: center;
    font-size: 1.05rem;
    color: #444;
    margin-bottom: 8px;
    margin-top: 4px;
    letter-spacing: 1px;
}
.kbd {
    display: inline-block;
    padding: 2px 8px;
    margin: 0 2px;
    border-radius: 4px;
    background: #f1f1f1;
    border: 1px solid #bbb;
    font-family: monospace;
    font-size: 1rem;
    color: #222;
}
/* Hide desktop-header and instructions on mobile */
@media (max-width: 700px), (max-height: 700px) {
    .desktop-header, .desktop-instructions { display: none !important; }
}
/* Hide mobile-header on desktop */
@media (min-width: 701px) and (min-height: 701px) {
    .mobile-header { display: none !important; }
}
@media (min-width: 701px) and (min-height: 701px) {
    .mobile-header { display: none; }
}
@media (max-width: 600px), (max-height: 700px) {
    .container {
        padding: 0;
        border-radius: 8px;
    }
    .game-header {
        gap: 2vw;
    }
    .info-group {
        flex-direction: column;
        gap: 10px;
    }
    #game-board {
        width: 98vw;
        height: min(calc(98vw * 2), 78vh);
        max-width: 98vw;
        max-height: 78vh;
        min-height: 220px;
        margin-bottom: 2vh;
        aspect-ratio: 10/20;
        border-width: 2px;
    }
    h1 {
        font-size: clamp(1rem, 5vw, 1.3rem);
    }
    .score-wrap {
        font-size: clamp(0.95rem, 3vw, 1.1rem);
    }
    #start-btn {
        font-size: clamp(0.95rem, 3vw, 1.1rem);
        padding: 7px 16px;
    }
}
@media (max-width: 700px), (max-height: 700px) {
    .mobile-header { display: flex; }
    .game-header-row { display: none !important; }
    .score-group {
        gap: 3vw;
        font-size: clamp(0.95rem, 3vw, 1.1rem);
    }
    #start-btn {
        font-size: clamp(0.95rem, 3vw, 1.1rem);
        padding: 7px 16px;
    }
    #menu-btn {
        font-size: 1.4rem;
        padding: 7px 16px;
    }
    #game-board {
        margin-bottom: 2vh;
    }
    .mobile-header {
        padding-bottom: 1vh;
    }
    .mobile-controls {
        display: none !important;
    }
}

/* Solar system animation background */
.solarsystem-bg {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}
.planet-orbit {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 1.5px dashed #fff3;
    animation: orbit-spin linear infinite;
}
.planet {
    position: absolute;
    border-radius: 50%;
    box-shadow: 0 0 16px 4px #fff3;
}
.solarsystem-center {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    pointer-events: none;
    width: 0; height: 0;
}
.sun {
    width: 64px; height: 64px;
    background: radial-gradient(circle at 60% 40%, #ffe066 0%, #ffb300 80%, #ff6f00 100%);
    box-shadow: 0 0 64px 32px #ffe06677, 0 0 0 8px #fff2 inset;
    border-radius: 50%;
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    border: 2.5px solid #fff7;
}
.planet1-orbit { width: 120px; height: 120px; animation-duration: 7s; }
.planet2-orbit { width: 180px; height: 180px; animation-duration: 11s; }
.planet3-orbit { width: 260px; height: 260px; animation-duration: 16s; }
.planet4-orbit { width: 340px; height: 340px; animation-duration: 22s; }
.planet1 { width: 18px; height: 18px; background: #aaf; top: 50%; left: 100%; margin-left: -9px; margin-top: -9px; }
.planet2 { width: 22px; height: 22px; background: #f8a; top: 50%; left: 100%; margin-left: -11px; margin-top: -11px; }
.planet3 { width: 26px; height: 26px; background: #8fc; top: 50%; left: 100%; margin-left: -13px; margin-top: -13px; }
.planet4 { width: 14px; height: 14px; background: #fc8; top: 50%; left: 100%; margin-left: -7px; margin-top: -7px; }
.moon-orbit {
    position: absolute;
    top: 50%; left: 50%;
    width: 38px; height: 38px;
    margin-left: -19px;
    margin-top: -19px;
    border-radius: 50%;
    border: 1px dashed #fff6;
    animation: moon-spin 2.6s linear infinite;
    z-index: 2;
}
.moon {
    position: absolute;
    width: 8px; height: 8px;
    background: #eee;
    border-radius: 50%;
    top: 50%; left: 100%;
    margin-left: -4px;
    margin-top: -4px;
    box-shadow: 0 0 8px 2px #fff9;
}
@keyframes orbit-spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}
@keyframes moon-spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Meteor animation styles */
.meteor {
    position: fixed;
    width: 32px;
    height: 8px;
    background: linear-gradient(90deg, #fff, #ffe066 60%, #fbc2eb 100%);
    border-radius: 8px;
    box-shadow: 0 0 12px 4px #ffe06699, 0 0 32px 8px #fff3;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.92;
    transition: opacity 0.2s;
    animation: meteor-fly 0.7s linear forwards;
}
@keyframes meteor-fly {
    0% { opacity: 1; }
    90% { opacity: 1; }
    100% { opacity: 0; }
}

.combo-indicator {
    position: fixed;
    top: 12vh;
    left: 50%;
    transform: translateX(-50%) scale(1);
    font-size: 2.2rem;
    font-family: 'Arial Black', Arial, sans-serif;
    color: #ffe066;
    text-shadow: 0 0 18px #fff, 0 0 36px #a18cd1, 0 2px 4px #000b;
    background: linear-gradient(90deg, #a18cd1cc 0%, #fbc2ebcc 100%);
    border-radius: 32px;
    padding: 8px 32px;
    opacity: 0;
    pointer-events: none;
    z-index: 2000;
    transition: opacity 0.28s, transform 0.32s cubic-bezier(.6,-0.28,.74,.05);
}
.combo-indicator.show {
    opacity: 1;
    transform: translateX(-50%) scale(1.16) rotate(-3deg);
    animation: combo-pop 0.7s cubic-bezier(.6,-0.28,.74,.05);
}
@keyframes combo-pop {
    0% { opacity: 0; transform: translateX(-50%) scale(0.8); }
    60% { opacity: 1; transform: translateX(-50%) scale(1.22) rotate(2deg); }
    100% { opacity: 1; transform: translateX(-50%) scale(1.16) rotate(-3deg); }
}

.pause-btn {
    background: linear-gradient(90deg, #43cea2 0%, #185a9d 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    margin: 0 4px 0 0;
    padding: 2px 7px;
    font-size: 1.08rem;
    font-weight: bold;
    box-shadow: 0 1px 4px #0002;
    cursor: pointer;
    min-width: 24px;
    min-height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s, box-shadow 0.18s, color 0.15s;
    line-height: 1.1;
}
.pause-btn:active, .pause-btn:focus {
    background: linear-gradient(90deg, #185a9d 0%, #43cea2 100%);
    color: #ffe066;
    box-shadow: 0 2px 10px #a18cd1cc;
}
@media (max-width: 700px), (max-height: 700px) {
    .pause-btn {
        font-size: 1.18rem;
        min-width: 25px;
        min-height: 22px;
        padding: 2px 7px;
        margin-right: 2px;
    }
}
