/* --- Race Page Container & Board --- */
.race-page {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-dark);
}

.board-container { 
    display: flex; 
    flex-direction: column; 
    align-items: flex-start; 
    padding: 40px; 
    gap: 20px; 
    background-color: var(--bg-dark); 

    transform: scale(1.3);
    transform-origin: center center;
}

.board-grid {
    /* 1. Change this variable to scale the entire board! */
    --square-size: 10vmin; /* Increased from 7vmin */

    display: grid;
    /* grid-template-columns and rows will be overridden dynamically by JavaScript,
       but we use var(--square-size) when setting inline styles in JS. */
    gap: 0.6vmin;
    padding: 2.5vmin;
    background: #222;
    border-radius: var(--radius-md);
    border: 2px solid #444;
    position: relative;
}

.square {
    width: 100%; 
    height: 100%; 
    border-radius: 4px;
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: calc(var(--square-size, 10vmin) * 0.20); 
    font-weight: bold; 
    color: black;
    text-align: center; 
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
    /* Essential for positioning tokens within squares */
    position: relative;
    box-sizing: border-box;
}

/* --- Double-sized Special Tile Rules --- */
.square.start {
    background-color: #3498db !important; /* Light blue */
    color: red;
    font-size: calc(var(--square-size, 10vmin) * 0.24);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
    z-index: 2;
}

.square.finish {
    background-color: #ffffff !important; /* White (Exclusive) */
    color: #222 !important;               /* Dark text for visibility on white */
    font-size: calc(var(--square-size, 10vmin) * 0.24);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.3);
    border: 2px solid #ccc;
    z-index: 2;
}

/* Ensure tokens adjust cleanly inside larger squares */
.square.start .token-container,
.square.finish .token-container {
    padding: 4px;
    gap: 4px;
}

/* Standard tile cycling pattern (excludes white so finish remains unique) */
.square:not(.start):not(.finish):nth-child(5n+1) { background-color: #2980b9; color: white; }
.square:not(.start):not(.finish):nth-child(5n+2) { background-color: #e74c3c; color: white; }
.square:not(.start):not(.finish):nth-child(5n+3) { background-color: #9b59b6; color: white; }
.square:not(.start):not(.finish):nth-child(5n+4) { background-color: #f1c40f; color: black; }
.square:not(.start):not(.finish):nth-child(5n)   { background-color: #2ecc71; color: white; }

/* --- Token Container --- */
.token-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    padding: 2px;
    gap: 2px;
    box-sizing: border-box;
    pointer-events: none; /* Allows clicks to pass through to underlying board tiles */
    z-index: 5;
}

/* --- Base Player Token --- */
.player-token {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    /* Scalable dimensions matching square size with safety bounds */
    width: clamp(24px, calc(var(--square-size, 10vmin) * 0.38), 48px);
    height: clamp(24px, calc(var(--square-size, 10vmin) * 0.38), 48px);
    font-size: clamp(0.55rem, calc(var(--square-size, 10vmin) * 0.14), 0.85rem);

    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);

    font-weight: bold;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    
    user-select: none;
    pointer-events: auto; /* Restores hover/interaction for the token itself */
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease;
    z-index: 10;
}

/* Hover Effect */
.player-token:hover {
    transform: scale(1.18) translateY(-2px);
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.6);
    z-index: 20;
}

/* --- Token Graphic Container (Text/Icon/Image Wrapper) --- */
.token-graphic {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 50%;
}

/* Racer image artwork inside token */
.token-graphic img.racer-img {
    width: 85%;
    height: 85%;
    object-fit: contain;
    border-radius: 50%;
}

/* --- Optional Player Name Tooltip Badge --- */
.player-token .token-label {
    position: absolute;
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.6rem;
    line-height: 1;
    background: rgba(0, 0, 0, 0.82);
    color: #ffffff;
    padding: 2px 5px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* --- Active Turn Pulse Animation --- */
@keyframes tokenPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.12);
        box-shadow: 0 0 12px var(--token-color, #ff0);
    }
    100% {
        transform: scale(1);
    }
}

.player-token.active-turn {
    animation: tokenPulse 1.2s infinite ease-in-out;
}

/* Center Controls Overlay inside the track loop */
.center-controls {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1vmin;
    z-index: 100;
    pointer-events: auto;
}

/* --- Die Styling --- */
.die {
    font-size: calc(var(--square-size, 10vmin) * 0.6);
    line-height: 1;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s ease, filter 0.2s ease;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.4));
}

.die:hover:not(.disabled) {
    transform: scale(1.15) rotate(5deg);
}

.die.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(100%);
}

/* Rolling Animation */
@keyframes rollDie {
    0%   { transform: rotate(0deg) scale(1); }
    25%  { transform: rotate(180deg) scale(1.3); }
    50%  { transform: rotate(360deg) scale(0.8); }
    75%  { transform: rotate(540deg) scale(1.2); }
    100% { transform: rotate(720deg) scale(1); }
}

.die.rolling {
    animation: rollDie 0.8s infinite ease-in-out;
    pointer-events: none;
}


.die {
    width: var(--square-size, 10vmin);
    height: var(--square-size, 10vmin);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s ease, filter 0.2s ease;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.4));
}

.die-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.die-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

/* --- Super Button Styling --- */
.super-btn {
    padding: 0.4em 0.9em;
    font-size: calc(var(--square-size, 10vmin) * 0.22);
    font-weight: 900;
    font-family: inherit;
    letter-spacing: 1px;
    color: #ffffff;
    background: linear-gradient(135deg, #ff007f, #7928ca);
    border: 2px solid #ffffff;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(255, 0, 127, 0.5);
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.super-btn:hover:not(.disabled) {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 0, 127, 0.8);
}

.super-btn.disabled {
    opacity: 0.3;
    filter: grayscale(80%);
    cursor: not-allowed;
    animation: none !important;
}

/* Bouncing Attention Animation for Super Ability */
@keyframes superBounce {
    0%, 100% {
        transform: translateY(0) scale(1);
        box-shadow: 0 4px 15px rgba(255, 0, 127, 0.5);
    }
    30% {
        transform: translateY(-12px) scale(1.12);
        box-shadow: 0 12px 25px rgba(255, 0, 127, 0.9);
    }
    50% {
        transform: translateY(0) scale(0.95);
    }
    70% {
        transform: translateY(-5px) scale(1.04);
    }
}

.super-btn.bouncing {
    animation: superBounce 1.2s infinite cubic-bezier(0.28, 0.84, 0.42, 1);
}