:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.5);
    --success-color: #4ade80;
    --error-color: #f87171;
    --font-family: 'Outfit', sans-serif;
    --palette-bg: rgba(30, 41, 59, 0.8);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#app {
    width: 100%;
    max-width: 900px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    height: 100vh;
    justify-content: space-between;
}

header {
    text-align: center;
    margin-top: 1rem;
}

h1 {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: -0.05em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-color) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 20px var(--accent-glow));
}

.subtitle {
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 2rem;
    position: relative;
}

#game-board {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0;
    width: 100%;
    min-height: 150px;
}

/* Tokens */
.card {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0.5rem 1rem;
    min-width: 60px;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    font-weight: 700;
    box-shadow: 0 5px 15px -5px rgba(0, 0, 0, 0.5);
    margin: 0 4px;
}

.token-op {
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    border-radius: 8px;
    width: 40px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    margin: 0 2px;
}

.token-op:hover {
    background: rgba(248, 113, 113, 0.2);
    border-color: var(--error-color);
    color: var(--error-color);
}

/* Drop Zone: Hidden by default, reveals on hover/drag */
.drop-zone {
    width: 20px;
    height: 90px;
    margin: 0 -5px;
    /* Slight overlap to minimize gap feeling */
    border-radius: 4px;
    border: 2px dashed transparent;
    /* Hidden border */
    background: transparent;
    /* Hidden BG */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
    position: relative;
}

/* When active dragging or hover */
.drop-zone.drag-over {
    width: 60px;
    /* Expand */
    margin: 0 5px;
    background: rgba(56, 189, 248, 0.2);
    border-color: var(--accent-color);
    border-style: dashed;
}

.drop-zone.drag-over::after {
    content: '+';
    /* Visual hint */
    color: var(--accent-color);
    font-size: 1.5rem;
    opacity: 0.8;
}


/* Operator Palette */
#operator-palette {
    display: flex;
    gap: 1rem;
    background: var(--palette-bg);
    padding: 1rem 1.5rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    margin-bottom: 2rem;
    backdrop-filter: blur(10px);
    align-items: center;
}

.separator {
    width: 2px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 0.5rem;
}

.palette-item {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    cursor: grab;
    transition: all 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.palette-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
    border-color: var(--accent-color);
}

.palette-item:active {
    cursor: grabbing;
}

/* Controls */
#controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.btn {
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    border: none;
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn.primary {
    background: var(--accent-color);
    color: #0f172a;
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Error Msg */
#error-msg {
    color: var(--error-color);
    font-weight: 500;
    background: rgba(248, 113, 113, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    margin-top: -1rem;
    animation: shake 0.5s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 3rem;
    border-radius: 24px;
    text-align: center;
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 50px var(--accent-glow);
    min-width: 400px;
}

#final-expression .katex {
    font-size: 2.5rem;
    color: var(--accent-color);
    margin-bottom: 1rem;
    display: block;
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    #app {
        padding: 1rem;
        gap: 1rem;
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    h1 {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    /* Game Board & Tokens */
    #game-board {
        gap: 2px;
        min-height: 120px;
    }

    .card {
        min-width: 40px;
        height: 60px;
        font-size: 1.5rem;
        padding: 0.25rem;
        margin: 2px;
        border-radius: 8px;
    }

    .token-op {
        width: 32px;
        height: 40px;
        font-size: 1.2rem;
        margin: 0 1px;
        border-radius: 6px;
    }

    /* Drop Zone */
    .drop-zone {
        width: 15px;
        height: 60px;
        margin: 0 -2px;
    }

    .drop-zone.drag-over {
        width: 40px;
        margin: 0 2px;
    }

    .drop-zone.drag-over::after {
        font-size: 1rem;
    }

    /* Palette */
    #operator-palette {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
        padding: 0.5rem;
        width: 100%;
        margin-bottom: 2rem;
        justify-items: center;
    }

    .palette-item {
        width: 100%;
        height: auto;
        aspect-ratio: 1;
        font-size: 2.5rem;
        border-radius: 8px;
    }

    .separator {
        display: none;
    }

    /* Controls */
    #controls {
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
    }

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    /* Modal */
    .modal-content {
        min-width: 90%;
        padding: 2rem;
        margin: 1rem;
    }

    #final-expression .katex {
        font-size: 1.5rem;
    }
}