:root {
    --primary-color: #6c5ce7;
    --secondary-color: #a29bfe;
    --accent-color: #fd79a8;
    --bg-color: #dfe6e9;
    --board-bg: #ffffff;
    --text-color: #2d3436;
    --font-main: 'Poppins', sans-serif;
    --cell-size: 60px;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.app-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    margin-bottom: 30px;
    text-align: center;
}

h1 {
    font-weight: 700;
    color: var(--primary-color);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.1);
}

/* Setup Section */
.setup-container {
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    text-align: center;
    max-width: 500px;
    width: 100%;
}

.input-group {
    margin: 20px 0;
}

input {
    padding: 10px;
    font-size: 1.2rem;
    border: 2px solid var(--secondary-color);
    border-radius: 8px;
    width: 80px;
    text-align: center;
}

.primary-btn {
    padding: 12px 24px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
}

.primary-btn:hover {
    transform: translateY(-2px);
    background-color: #5849be;
}

/* Game Section */
.hidden {
    display: none !important;
}

.game-layout {
    display: flex;
    gap: 40px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Board Styling */
.board-container {
    background: white;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
}

.board {
    display: grid;
    grid-template-columns: repeat(10, var(--cell-size));
    grid-template-rows: repeat(10, var(--cell-size));
    gap: 2px;
    border: 4px solid #2d3436;
    background: #2d3436;
    position: relative;
    transition: filter 0.3s;
}

#board-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through if needed */
    z-index: 5; /* Above cells (0), below tokens (10) */
}

.cell {
    background: var(--board-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    position: relative;
    user-select: none;
    color: #b2bec3; /* Default number color subtle */
    flex-direction: column;
    z-index: 1;
}

/* Remove old marker styles interaction if any remains, but keep classes for logic */
.snake-start, .snake-end, .ladder-start, .ladder-end {
    /* No bg color change, we use canvas now */
    border: none !important; 
    /* Keep color text for debug or fallback? Let's hide marker content via JS or CSS */
}

/* Hide marker icons since we rely on canvas */
.marker-icon, .marker-sub {
    display: none !important;
}

/* Controls */
.controls-container {
    flex: 1;
    min-width: 300px;
    max-width: 400px;
    background: white;
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    height: fit-content;
}

.player-info {
    text-align: center;
    width: 100%;
}

.player-badge {
    margin-top: 10px;
    padding: 10px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.2rem;
    transition: background-color 0.3s;
}

.dice-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.dice {
    font-size: 4rem;
    height: 100px;
    width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 12px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
    color: #2d3436;
}

.roll-btn {
    padding: 15px 40px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(253, 121, 168, 0.4);
    transition: transform 0.1s, background-color 0.2s;
    width: 100%;
}

.roll-btn:hover {
    background-color: #e84393;
}

.roll-btn:active {
    transform: scale(0.95);
}

.roll-btn:disabled {
    background-color: #b2bec3;
    cursor: not-allowed;
    box-shadow: none;
}

.log-area {
    width: 100%;
    height: 200px;
    background: #f1f2f6;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
    font-size: 0.9rem;
    font-family: monospace;
    border: 1px solid #dfe6e9;
}

.log-area p {
    margin-bottom: 5px;
    border-bottom: 1px solid #dfe6e9;
    padding-bottom: 2px;
}

/* Player Tokens */
.player-token {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    position: absolute; /* relative to cell still works if cell is relative */
    top: 0; /* JS will set top/left */
    left: 0;
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
    z-index: 10;
    border: 2px solid white;
    transition: top 0.3s linear, left 0.3s linear; /* Smooth step movement */
}

/* Responsive Redesign - Mobile Polish */
@media (max-width: 900px) {
    body {
        padding: 0;
        height: 100vh;
        overflow: hidden; /* Prevent scroll on mobile game */
    }

    .app-container {
        padding: 0;
        max-width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    main {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%; /* Ensure it fills parent */
        overflow: hidden;
    }

    /* Hide global header only on mobile to save space */
    header {
        display: none; 
    }
    
    /* Setup container needs margin if header is gone */
    .setup-container {
        margin-top: 20%;
        padding: 20px;
    }

    /* Game Section Constraint */
    .game-container {
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
    }

    .game-layout {
        flex-direction: column;
        gap: 0;
        width: 100%;
        height: 100%;
        flex-grow: 1;
    }

    /* 1. Maximize Board */
    .board-container {
        width: 100%;
        max-width: 100%;
        padding: 10px;
        box-shadow: none;
        background: transparent;
        flex-grow: 1; /* Occupy all available vertical space */
        display: flex;
        align-items: center; /* Vertical Center */
        justify-content: center;
        min-height: 0; /* Allow shrinking if needed */
    }

    .board {
        width: 100%;
        height: auto; /* Aspect ratio handles height */
        max-height: 80vh; /* Don't overflow if screen is very short/wide */
        aspect-ratio: 1/1;
        grid-template-columns: repeat(10, 1fr);
        grid-template-rows: repeat(10, 1fr);
        border-width: 2px;
        box-shadow: 0 5px 15px rgba(0,0,0,0.2); /* Add shadow back for depth */
    }

    /* Remove fixed cell-size dependency for responsive grid */
    :root {
        --cell-size: 10vw; 
    }
    
    .cell {
        font-size: 0.7rem; 
    }

    /* 2. Compact Controls (Bottom Sheet) */
    .controls-container {
        width: 100%;
        max-width: 100%;
        padding: 15px 20px;
        background: white;
        border-radius: 20px 20px 0 0; /* Smooth top corners */
        box-shadow: 0 -5px 25px rgba(0,0,0,0.15); /* Stronger shadow */
        z-index: 100;
        flex-direction: row;
        flex-wrap: nowrap; /* Prevent wrapping */
        justify-content: space-between;
        align-items: center;
        gap: 15px;
        flex-shrink: 0; /* Don't shrink */
        padding-bottom: max(15px, env(safe-area-inset-bottom)); /* Safe area for iPhone home bar */
        margin-top: auto; /* Push to bottom */
    }
    
    .player-info {
        flex: 0 0 auto; /* Don't grow/shrink */
        width: auto; /* Override desktop 100% width */
    }
    
    .player-info h3 { display: none; }
    
    .player-badge {
        margin: 0;
        padding: 8px 16px;
        font-size: 1rem;
        border-radius: 20px;
    }

    .dice-area {
         width: auto;
         flex-direction: row;
         gap: 15px;
         flex: 1;
         justify-content: flex-end;
         align-items: center;
    }

    .dice {
        width: 45px;
        height: 45px;
        font-size: 1.8rem;
        border-radius: 8px;
        background: #f1f2f6;
        box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    }

    .roll-btn {
        width: auto;
        flex: 1;
        padding: 12px;
        font-size: 1.1rem;
        border-radius: 12px; /* Less pill-shaped, more button-y */
        white-space: nowrap;
        max-width: 150px; /* Don't get too wide */
    }

    /* 3. Hide Logs */
    .log-area { display: none; }
    
    .player-token {
        width: 8vw; /* Slightly larger tokens on mobile */
        height: 8vw;
        border: 2px solid white;
        box-shadow: 0 2px 5px rgba(0,0,0,0.4);
    }
}

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

.modal.hidden {
    opacity: 0;
    pointer-events: none;
    display: flex !important; 
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    border: 4px solid var(--primary-color);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 90%;
    width: 90%;
}

.winner-title {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.winner-display {
    font-size: 1.8rem;
    font-weight: bold;
    margin-bottom: 20px;
    padding: 10px 30px;
    border-radius: 50px;
    color: white;
    display: inline-block;
}

.restart-btn {
    font-size: 1.2rem;
    padding: 12px 30px;
    background-color: var(--accent-color);
    box-shadow: 0 8px 20px rgba(253, 121, 168, 0.5);
    border-radius: 30px;
    border: none;
    color: white;
    cursor: pointer;
    transition: transform 0.2s;
    width: 100%;
}

.restart-btn:hover {
    transform: translateY(-3px) scale(1.05);
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 480px) {
   /* Extra tweaks for very small screens if needed, 
      but the >900px logic above covers almost all mobile cases nicely now. 
   */
}
