:root {
    --bg-color: #0d1b2a;
    --panel-bg: rgba(255, 255, 255, 0.1);
    --slot-bg: rgba(0, 0, 0, 0.3);
    --primary: #4cc9f0;
    --accent: #f72585;
    --success: #4ade80;
    --text-color: #e0e1dd;
    --card-size: 14vmin;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: linear-gradient(135deg, #0d1b2a 0%, #1b263b 100%);
    font-family: 'Outfit', sans-serif;
    color: var(--text-color);
    overflow: hidden;
    position: relative;
}

#app-root {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* HEADER */
#ui-header {
    height: 15vmin;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4vmin;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 3vmin;
}

.header-left h1 {
    font-family: 'Comic Neue', cursive;
    font-size: 5vmin;
    margin: 0;
    color: var(--primary);
    text-shadow: 0 0 2vmin rgba(76, 201, 240, 0.5);
}

.home-btn {
    text-decoration: none;
    font-size: 5vmin;
    background: rgba(255, 255, 255, 0.1);
    width: 8vmin;
    height: 8vmin;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
    border: 2px solid transparent;
}

.home-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.2);
}

/* CONTROLS */
.header-controls {
    display: flex;
    gap: 4vmin;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5vmin;
}

.control-group label {
    font-size: 2vmin;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.toggle-switch {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 2vmin;
    padding: 0.5vmin;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 2.5vmin;
    padding: 1vmin 2vmin;
    border-radius: 1.5vmin;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: var(--primary);
    color: #0d1b2a;
    box-shadow: 0 0 2vmin rgba(76, 201, 240, 0.4);
}

/* GAME SCENE */
#game-scene {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    padding-bottom: 2vmin;
}

/* EQUATION BOARD */
#equation-board {
    display: flex;
    align-items: flex-start;
    /* Align top so radios are below slots */
    justify-content: center;
    gap: 2vmin;
    margin-bottom: 5vmin;
    padding: 4vmin;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4vmin;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.equation-part {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2vmin;
}

.slot-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    /* gap managed by radio margin-top */
}

.card-slot {
    width: var(--card-size);
    height: var(--card-size);
    background: var(--slot-bg);
    border: 0.4vmin dashed rgba(255, 255, 255, 0.2);
    border-radius: 2vmin;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 6vmin;
    font-weight: 800;
    color: var(--text-color);
    transition: all 0.3s;
}

.card-slot.filled {
    border-style: solid;
    border-color: var(--primary);
    background: rgba(76, 201, 240, 0.1);
    color: var(--primary);
    text-shadow: 0 0 2vmin rgba(76, 201, 240, 0.5);
}

.card-slot.target {
    border-color: var(--accent);
    background: rgba(247, 37, 133, 0.1);
    animation: pulseBorder 2s infinite;
}

@keyframes pulseBorder {
    0% {
        box-shadow: 0 0 0 0 rgba(247, 37, 133, 0.4);
    }

    70% {
        box-shadow: 0 0 0 2vmin rgba(247, 37, 133, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(247, 37, 133, 0);
    }
}

.target-radio {
    appearance: none;
    width: 4vmin;
    height: 4vmin;
    border: 0.4vmin solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    background: transparent;

    /* Static Positioning (Stacked) */
    position: relative;
    /* Default flow */
    bottom: auto;
    left: auto;
    transform: none;
    margin-top: 1vmin;
    /* Explicit gap */
    z-index: 1;
    background-color: transparent;
    /* Revert background */
    box-shadow: none;
}

.target-radio:checked {
    background-color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 2vmin var(--accent);
    transform: scale(1.2);
}

.equation-sign {
    font-size: 8vmin;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2vmin;
    /* Approx vertically center relative to slot */
}

/* RACK */
#options-rack {
    display: flex;
    gap: 3vmin;
    padding: 2vmin 4vmin;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3vmin;
    min-width: 60vmin;
    min-height: calc(var(--card-size) + 4vmin);
    justify-content: center;
    align-items: center;
}

.number-card {
    width: var(--card-size);
    height: var(--card-size);
    background: white;
    border-radius: 2vmin;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 6vmin;
    font-weight: 800;
    color: #0d1b2a;
    box-shadow: 0 1vmin 2vmin rgba(0, 0, 0, 0.3);
    cursor: grab;
    transition: transform 0.1s;
    z-index: 10;
}

.number-card:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.number-card.dragging {
    position: fixed;
    z-index: 1000;
    box-shadow: 0 2vmin 4vmin rgba(0, 0, 0, 0.5);
    pointer-events: none;
    /* Let events pass through to drop zones */
}

/* OVERLAY */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 27, 42, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
}

.overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.overlay-content {
    text-align: center;
}

.overlay-content h2 {
    font-size: 8vmin;
    margin-bottom: 4vmin;
    color: var(--primary);
    text-shadow: 0 0 4vmin rgba(76, 201, 240, 0.5);
}

.primary-btn {
    font-size: 4vmin;
    padding: 2vmin 6vmin;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 2vmin;
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 0 3vmin rgba(247, 37, 133, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.primary-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 5vmin rgba(247, 37, 133, 0.6);
}

/* Responsive Overrides */
@media (orientation: portrait) {
    #ui-header {
        flex-direction: column;
        height: auto;
        padding: 2vmin;
        gap: 2vmin;
    }

    .header-controls {
        width: 100%;
        justify-content: center;
    }

    #equation-board {
        flex-direction: column;
        align-items: center;
        gap: 1vmin;
        padding: 2vmin;
    }

    .equation-sign {
        margin: 0;
        transform: rotate(90deg);
        /* Optional: vertical math? No, standard is usually horizontal still better for logic flow, but if vertical stacking: a + b = c */
        font-size: 6vmin;
    }

    /* Let's try to keep horizontal layout on mobile portrait if possible, or scale down */
    #equation-board {
        flex-direction: column;
        gap: 3vmin;
    }


}

/* Specific fix for Mobile Landscape (Short screens) */
@media (max-height: 500px) and (orientation: landscape) {
    #ui-header {
        height: 12vmin;
        /* Compact header */
        padding: 0 2vmin;
    }

    .header-left h1 {
        font-size: 6vmin;
    }

    .home-btn {
        width: 10vmin;
        height: 10vmin;
        font-size: 6vmin;
    }

    #equation-board {
        margin-bottom: 2vmin;
        /* Reduce gap */
        padding: 2vmin 4vmin;
    }

    /* .card-slot modifications not needed for now */

    #options-rack {
        min-height: auto;
        padding: 1vmin;
    }
}