:root {
    --bg-deep: #0b0d1f;
    --bg-panel: rgba(20, 23, 56, 0.85);
    --accent-purple: #a855f7;
    --accent-pink: #ec4899;
    --accent-gold: #fbbf24;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --star-white: #f8fafc;
    --font-main: 'Nunito', sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-main);
    background: var(--bg-deep);
    color: var(--star-white);
}

body {
    position: relative;
}

#game-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.game-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    padding: 16px;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1100px;
    padding: 14px 18px;
    background: var(--bg-panel);
    border: 2px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    margin-bottom: 14px;
}

.question-box {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.question-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-gold);
    letter-spacing: 1px;
}

#question-text {
    font-size: 1.1rem;
    font-weight: 900;
}

.game-level {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-purple);
    letter-spacing: 1px;
}

.score-box {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.score-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-gold);
    letter-spacing: 1px;
}

.star-charge {
    display: flex;
    gap: 4px;
}

.charge-star {
    width: 18px;
    height: 18px;
    background: var(--accent-gold);
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    opacity: 0.2;
    transition: opacity 0.3s ease;
}

.charge-star.lit {
    opacity: 1;
    box-shadow: 0 0 12px var(--accent-gold);
}

.score-text {
    font-size: 0.9rem;
    font-weight: 700;
}

.play-area {
    flex: 1;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 14px 0;
}

.play-area .order-slots,
.play-area .asteroid-tray,
.play-area .message {
    margin-bottom: 0;
}

/* Number route */
.order-route {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 840px;
}

.route-rocket,
.route-planet {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    object-fit: contain;
}

.route-rocket {
    z-index: 5;
    transform: rotate(45deg);
    filter: drop-shadow(0 0 12px rgba(78, 205, 196, 0.55));
}

.route-planet {
    filter: drop-shadow(0 0 14px rgba(168, 85, 247, 0.6));
}

.route-rocket.launching {
    animation: flyRoute 1.1s cubic-bezier(0.3, 0.7, 0.35, 1) forwards;
}

@keyframes flyRoute {
    0% {
        transform: translate(0, 0) rotate(45deg) scale(1);
        opacity: 1;
    }
    45% {
        transform: translate(var(--rocket-mid-x), var(--rocket-mid-y)) rotate(70deg) scale(1.15);
        opacity: 1;
    }
    100% {
        transform: translate(var(--rocket-x), var(--rocket-y)) rotate(45deg) scale(0.65);
        opacity: 0.2;
    }
}

/* Order slots */
.order-slots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    width: auto;
    max-width: 700px;
    min-height: 110px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    margin-bottom: 14px;
}

.order-slot {
    flex: 1 1 0;
    min-width: 0;
    max-width: 70px;
    width: 70px;
    height: 90px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 900;
    transition: all 0.2s ease;
}

.order-slot > .asteroid {
    width: 100%;
    height: 100%;
    min-width: 0;
}

.order-slot.hovered {
    background: rgba(168, 85, 247, 0.25);
    border-color: var(--accent-purple);
    transform: scale(1.05);
}

.order-slot.correct {
    border-color: var(--accent-green);
    background: rgba(34, 197, 94, 0.15);
}

.order-slot.wrong {
    border-color: var(--accent-red);
    background: rgba(239, 68, 68, 0.15);
}

/* Asteroid tray */
.asteroid-tray {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 14px;
    width: 100%;
    max-width: 700px;
    min-height: 110px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    margin-bottom: 14px;
}

.asteroid {
    width: 70px;
    height: 90px;
    border-radius: 16px;
    background: radial-gradient(circle at 30% 30%, #d8b4fe, #7e22ce);
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 900;
    color: white;
    cursor: grab;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease;
    position: relative;
    z-index: 2;
    touch-action: none;
    overflow: hidden;
}

.asteroid::before {
    content: '';
    position: absolute;
    inset: 8px;
    background: url('../icons/asteroid.svg') center / contain no-repeat;
    opacity: 0.22;
    pointer-events: none;
}

.asteroid span {
    position: relative;
    z-index: 1;
    text-shadow: 0 2px 5px rgba(26, 10, 46, 0.8);
}

.asteroid:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.asteroid.dragging {
    opacity: 1;
    z-index: 100;
    cursor: grabbing;
    transform: scale(1.06);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5), 0 0 22px rgba(168, 85, 247, 0.5);
}

.asteroid-placeholder {
    flex: 0 0 auto;
    border: 2px dashed rgba(168, 85, 247, 0.35);
    border-radius: 16px;
    background: rgba(168, 85, 247, 0.06);
}

/* Message */
.message {
    min-height: 32px;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    color: var(--accent-gold);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 10px;
}

/* Burst particles */
.burst-particle {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-gold);
    pointer-events: none;
    z-index: 999;
}

/* Check button */
.check-btn {
    padding: 12px 32px;
    border-radius: 28px;
    border: 2px solid rgba(34, 197, 94, 0.6);
    background: rgba(34, 197, 94, 0.25);
    font-family: var(--font-main);
    font-size: 1.2rem;
    font-weight: 900;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.check-btn:hover {
    background: rgba(34, 197, 94, 0.4);
    transform: scale(1.08);
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(11, 13, 31, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: rgba(20, 23, 56, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 24px;
    padding: 32px 28px;
    text-align: center;
    max-width: 520px;
    width: calc(100% - 32px);
    box-shadow: 0 0 40px rgba(168, 85, 247, 0.3);
    max-height: 92vh;
    overflow-y: auto;
}

.overlay-asteroid {
    width: 80px;
    height: 80px;
    margin-bottom: 15px;
    filter: drop-shadow(0 0 20px rgba(168, 85, 247, 0.5));
}

.overlay-content h1 {
    font-size: 2.2rem;
    font-weight: 900;
    margin: 0 0 12px;
    color: var(--accent-gold);
}

.game-desc {
    font-size: 1rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 20px;
}

.choose-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-gold);
    margin-bottom: 12px;
}

.difficulty-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.diff-btn {
    padding: 14px 22px;
    border-radius: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-weight: 900;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 110px;
}

.diff-btn:hover {
    transform: scale(1.08);
    background: rgba(255, 255, 255, 0.15);
}

.diff-btn span {
    display: block;
    font-size: 0.8rem;
    font-weight: 400;
    opacity: 0.8;
}

.win-rocket {
    margin: 20px 0;
    animation: launch 2s ease-in-out infinite;
}

.win-rocket img {
    width: 80px;
    height: 80px;
}

@keyframes launch {
    0%, 100% { transform: translateY(6px) rotate(-10deg); }
    50% { transform: translateY(-20px) rotate(-10deg); }
}

.launch-btn {
    padding: 12px 28px;
    border-radius: 24px;
    border: none;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
    font-family: var(--font-main);
    font-size: 1.1rem;
    font-weight: 900;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    margin-right: 10px;
}

.launch-btn:hover {
    transform: scale(1.08);
}

.home-btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: 24px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
    transition: all 0.2s ease;
}

.home-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Exit button */
.exit-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 50;
    padding: 8px 16px;
    border-radius: 24px;
    background: rgba(10, 10, 30, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.15);
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 700;
    color: white;
    letter-spacing: 0.5px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.exit-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.08);
}

/* Responsive */
@media (max-width: 600px) {
    .game-header {
        padding: 10px 14px;
        gap: 12px;
    }

    .question-box {
        min-width: 0;
    }

    #question-text {
        font-size: 0.9rem;
        line-height: 1.25;
    }

    .score-box {
        flex: 0 0 auto;
        gap: 3px;
    }

    .score-label {
        font-size: 0.62rem;
    }

    .star-charge {
        gap: 2px;
    }

    .charge-star {
        width: 11px;
        height: 11px;
    }

    .score-text {
        font-size: 0.8rem;
    }

    .play-area {
        gap: 18px;
        padding: 12px 0;
    }

    .order-route {
        display: block;
    }

    .route-rocket,
    .route-planet {
        position: absolute;
        top: -22px;
        width: 32px;
        height: 32px;
    }

    .route-rocket {
        left: 8px;
    }

    .route-planet {
        right: 8px;
    }

    .order-route .order-slots {
        width: 100%;
    }

    .order-slots,
    .asteroid-tray {
        gap: 8px;
        min-height: 90px;
    }

    .order-slots {
        gap: 5px;
        padding: 10px;
    }

    .order-slot,
    .asteroid {
        width: 52px;
        height: 72px;
        font-size: 1.2rem;
    }

    .exit-btn {
        bottom: 12px;
        right: 12px;
        padding: 6px 12px;
        font-size: 0.85rem;
    }
}

@media (max-width: 360px) {
    .score-label {
        font-size: 0.58rem;
    }

    .star-charge {
        gap: 1px;
    }

    .charge-star {
        width: 9px;
        height: 9px;
    }

    .order-slot,
    .asteroid {
        width: 44px;
        height: 62px;
        font-size: 1rem;
    }
}

/* Short landscape screens (Nest Hub, landscape phones, small tablets) */
@media (max-height: 640px) {
    .game-container {
        padding: 8px;
    }

    .game-header {
        padding: 8px 14px;
        margin-bottom: 8px;
    }

    .play-area {
        gap: 8px;
        padding: 8px 0 44px;
    }

    .message {
        margin-bottom: 6px;
        min-height: 22px;
        font-size: 0.95rem;
    }
}
