:root {
    --bg-color: #0d1321;
    --panel-bg: rgba(20, 28, 48, 0.8);
    --primary: #00ffcc;
    --secondary: #ff007f;
    --text: #ffffff;
    --board-border: #00ffcc;
    
    --p1-color: #ff3366;
    --p2-color: #33ccff;
    --p3-color: #ccff33;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    user-select: none;
}

body {
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(0, 255, 204, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(255, 0, 127, 0.1) 0%, transparent 40%);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    display: flex;
    width: 100%;
    max-width: 1200px;
    height: 95vh;
    gap: 20px;
    padding: 20px;
}

/* SIDE PANEL */
#scoreboard {
    width: 250px;
    background: var(--panel-bg);
    border: 1px solid rgba(0, 255, 204, 0.3);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.back-btn {
    color: #8fa3c2;
    text-decoration: none;
    font-weight: 700;
    margin-bottom: 20px;
    display: inline-block;
    transition: color 0.2s;
}

.back-btn:hover { color: var(--primary); }

#scoreboard h2 {
    color: var(--primary);
    margin-bottom: 15px;
    font-size: 1.5rem;
    text-shadow: 0 0 10px rgba(0, 255, 204, 0.5);
    text-align: center;
}

#players-list {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.player-card {
    background: rgba(0,0,0,0.3);
    border-radius: 12px;
    padding: 15px;
    border-left: 5px solid gray;
    transition: all 0.3s ease;
}

.player-card.active {
    background: rgba(255,255,255,0.1);
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255,255,255,0.1);
}

.player-name {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 5px;
}

.player-pos {
    font-size: 0.9rem;
    color: #a0aabf;
}

#dice-container {
    text-align: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.dice {
    font-size: 5rem;
    margin-bottom: 15px;
    text-shadow: 0 0 20px rgba(255,255,255,0.3);
    /* Basic animation classes added via JS */
}

/* MAIN AREA */
#board-area {
    flex-grow: 1;
    position: relative;
    background: var(--panel-bg);
    border: 1px solid rgba(0, 255, 204, 0.3);
    border-radius: 20px;
    box-shadow: 0 0 40px rgba(0, 255, 204, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 10px;
    z-index: 10;
}

.board-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    width: 100%;
    /* To keep it square but guarantee it never overflows the container's height: */
    max-width: 80vh; 
    max-height: 80vh;
    aspect-ratio: 1/1;
    background: rgba(0,0,0,0.5);
    border: 2px solid var(--board-border);
    position: relative;
}

.player-token {
    /* Set up transition for smooth gliding */
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
}

/* LADDER ANIMATION: Jump and glow */
@keyframes ladderJump {
    0% { transform: scale(1) translateY(0); }
    30% { transform: scale(1.5) translateY(-20px); filter: brightness(2); }
    100% { transform: scale(1) translateY(0); }
}

.anim-ladder {
    animation: ladderJump 0.5s ease infinite alternate;
    z-index: 100 !important;
}

/* SNAKE ANIMATION: Dizzy spin and shrink */
@keyframes snakeSpin {
    0% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(0.5) rotate(180deg); filter: grayscale(1); }
    100% { transform: scale(1) rotate(360deg); }
}

.anim-snake {
    animation: snakeSpin 0.4s linear infinite;
    z-index: 100 !important;
}

/* FAIL ANIMATION: Shake and dim */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px) rotate(-5deg); }
    75% { transform: translateX(10px) rotate(5deg); }
}

.anim-fail {
    animation: shake 0.2s ease 3;
    filter: grayscale(0.8) contrast(0.5);
}

/* Funny floating text for reactions */
@keyframes floatUp {
    0% { opacity: 0; transform: translate(-50%, 0); }
    10% { opacity: 1; }
    80% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -60px); }
}

.reaction-text {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.8rem; /* Slightly larger */
    font-weight: 900;
    pointer-events: none;
    white-space: nowrap;
    animation: floatUp 2.5s ease-out forwards;
    z-index: 200;
    text-shadow: 0 0 10px rgba(0,0,0,0.5); /* Better contrast */
}

.board-cell {
    border: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    font-weight: 700;
    color: rgba(255,255,255,0.3);
    font-size: clamp(0.8rem, 2vw, 1.5rem);
}

/* OVERLAYS */
.overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(13, 19, 33, 0.98);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
    overflow-y: auto;
}

#overlay-start {
    justify-content: flex-start;
    padding-top: 5vh;
}

/* Ensure the content inside can be scrolled if it exceeds the height */
#overlay-start > * {
    flex-shrink: 0;
}

.hidden { display: none !important; }

#overlay-start h1 {
    font-size: 4rem;
    font-weight: 900;
    margin-bottom: 20px;
    text-align: center;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.setup-section {
    margin-bottom: 30px;
    width: 100%;
    max-width: 400px;
}

.setup-section h3 {
    margin-bottom: 15px;
    color: var(--primary);
}

.name-input, .styled-select {
    width: 100%;
    padding: 15px;
    margin-bottom: 10px;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 10px;
    color: white;
    font-size: 1.1rem;
    outline: none;
}

.name-input:focus, .styled-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(0, 255, 204, 0.3);
}

.styled-select {
    appearance: none;
    cursor: pointer;
}

.action-btn {
    padding: 15px 30px;
    font-size: 1.2rem;
    font-weight: 900;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    background: linear-gradient(90deg, var(--primary), #0099ff);
    color: #000;
    text-transform: uppercase;
    box-shadow: 0 0 20px rgba(0, 255, 204, 0.4);
    transition: all 0.2s;
}

.action-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(0, 255, 204, 0.6);
}

.main-btn {
    font-size: 1.5rem;
    padding: 20px 50px;
    margin-top: 20px;
    margin-bottom: 50px; /* Safe space for mobile bars */
}

/* MATH PROBLEM OVERLAY */
#turn-indicator {
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--primary);
}

.timer-bar-container {
    width: 80%;
    max-width: 500px;
    height: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 5px;
    margin-bottom: 40px;
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: var(--primary);
    transition: width 1s linear, background-color 0.3s;
}

.problem-display {
    font-size: 5rem;
    font-weight: 900;
    margin-bottom: 50px;
    text-shadow: 0 0 20px rgba(255,255,255,0.5);
}

.answers-container {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.answer-btn {
    padding: 20px 40px;
    font-size: 2rem;
    font-weight: 700;
    background: rgba(255,255,255,0.1);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 15px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 120px;
}

.answer-btn:hover {
    background: rgba(255,255,255,0.2);
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(0, 255, 204, 0.3);
}

/* RESPONSIVE */
@media (max-width: 900px) {
    #game-container {
        flex-direction: column;
        height: auto;
    }
    #scoreboard {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
    }
    #players-list {
        flex-direction: row;
        width: 100%;
        margin-top: 10px;
    }
    .player-card { flex: 1; }
    #overlay-start h1 { font-size: 2.5rem; }
    .problem-display { font-size: 3.5rem; }
}
