/* Styles for the Indian Snakes and Ladders game */

/* Reset and basic styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* Game container - DEF-0021: responsive width/height */
#game-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: auto;
    margin: 0 auto;
    padding: 16px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    display: grid;
    grid-template-columns: 100px 1fr 180px;
    grid-template-rows: auto;
    gap: 16px;
    box-sizing: border-box;
    align-items: start;
}

/* Loading overlay (created by JS) */
#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    color: #555;
    z-index: 1000;
}

/* Board - DEF-0026: responsive board size */
#game-board {
    position: relative;
    width: 100%;
    max-width: 380px;
    aspect-ratio: 1 / 1;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 8px;
    overflow: hidden;
}

/* Tokens */
.game-token {
    position: absolute;
    pointer-events: none;
    transition: left 250ms linear, top 250ms linear, transform 250ms linear;
    z-index: 10; /* Ensure tokens appear above board cells */
}

.game-token.move-to-board {
    transition: transform 1.5s ease-in-out, left 250ms linear, top 250ms linear;
    transform: scale(1.2);
}

.game-token.return-to-staging {
    animation: bounce 0.4s ease-out;
}

/* Dice - DEF-0023: proper positioning context */
#dice-container {
    width: 60px;
    height: 60px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    align-self: center;
    margin-top: 15px;
    flex: 0 0 60px;
    min-height: 60px;
    position: relative; /* Enable absolute positioning for children if needed */
}

/* Player info panel - DEF-0022: fixed positioning with flex layout */
#player-info {
    position: relative; /* Changed from absolute to relative for flex flow */
    background: rgba(0,0,0,0.6);
    color: #fff;
    padding: 12px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-width: 200px;
    height: auto;
    flex: 0 0 auto;
}

/* Player info items */
#player-info > div {
    text-align: center;
    min-width: 60px;
    margin: 8px 0;
}

#player-info div div div:first-child {
    width: 24px;
    height: 24px;
    margin: 0 auto 4px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

#player-info div div div:nth-child(2) {
    display: block;
    font-weight: bold;
    font-size: 1rem;
}

#player-info div div div:nth-child(3) {
    display: block;
    font-size: 0.85rem;
    opacity: 0.9;
}

/* Highlight active player - DEF-0025: fixed selector (div not span) */
#player-info > div.active-player {
    border: 2px solid #ffeb3b;
    border-radius: 6px;
    padding: 4px;
    background: rgba(255, 235, 59, 0.2);
}

#player-info > div.active-player > div:nth-child(2) {
    color: #ffeb3b;
}

/* Roll button */
#roll-button {
    display: block;
    margin: 25px auto;
    padding: 12px 30px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #fff;
    background: #4caf50;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

#roll-button:hover:not(:disabled) {
    background: #43a047;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

#roll-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Extra roll state */
#roll-button.extra-roll {
    background: #ff9800;
}

#roll-button.extra-roll:hover {
    background: #fb8c00;
}

/* Responsive adjustments for tablets and small laptops */
@media (max-width: 1200px) {
    #game-container {
        grid-template-columns: 80px 1fr 250px;
    }
}

@media (max-width: 900px) {
    #game-container {
        grid-template-columns: 60px 1fr 200px;
    }
    
    #left-title-panel .title-main {
        font-size: 1.2rem;
    }
    
    #left-title-panel .title-sub {
        font-size: 0.8rem;
    }
    
    #right-commentary-panel #commentary-content {
        font-size: 0.75rem;
        padding: 8px;
    }
}

/* ============================================================================
   MOBILE VIEWPORT POLISH (PRD-C)
   Target: 390x844 (iPhone 14/15/16), 360x800 (Android), 414x896 (iPhone Plus/Max)
   Stack vertically: Title → Board → Commentary
   Board fits viewport width, no horizontal scroll, readable size
   ============================================================================ */

/* Phones in portrait: up to 480px wide (covers 390, 414, 430) */
@media (max-width: 480px) {
    /* Container: switch to vertical flex, full viewport width, no max-width constraint */
    #game-container {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 8px !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        gap: 8px !important;
        min-height: 100vh !important;
        box-sizing: border-box !important;
        align-items: stretch !important;
    }

    /* Title panel: horizontal text, compact height, full width */
    #left-title-panel {
        order: 0 !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        padding: 8px 12px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        background: #f8f9fa !important;
        border-radius: 8px !important;
    }

    #left-title-panel .title-content {
        writing-mode: horizontal-tb !important;
        transform: none !important;
        text-orientation: mixed !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 100% !important;
    }

    #left-title-panel .title-main {
        font-size: 1.1rem !important;
        font-weight: bold !important;
        margin-bottom: 2px !important;
        letter-spacing: 0.3px !important;
    }

    #left-title-panel .title-sub {
        font-size: 0.75rem !important;
        color: #666 !important;
        font-style: italic !important;
    }

    /* Board container: full width, centered, no fixed width from JS */
    #game-board-container {
        order: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 4px !important;
        box-sizing: border-box !important;
        position: relative !important;
    }

    /* Board: fill viewport width (minus padding), square aspect ratio */
    #game-board {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        aspect-ratio: 1 / 1 !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 12px rgba(0,0,0,0.15) !important;
    }

    /* Staging area: full width, responsive height */
    #staging-area {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 44px !important; /* touch target size */
        display: flex !important;
        justify-content: space-around !important;
        align-items: center !important;
        padding: 4px 8px !important;
        box-sizing: border-box !important;
        background: rgba(0,0,0,0.05) !important;
        border-radius: 8px !important;
    }

    /* Right column wrapper (holds dice + commentary): full width, at bottom */
    #right-column-wrapper {
        order: 2 !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
    }

    /* Dice container: centered, touch-friendly */
    #dice-container {
        width: 56px !important;
        height: 56px !important;
        min-height: 56px !important;
        flex: 0 0 56px !important;
        margin: 0 auto !important;
        position: static !important;
        border-radius: 10px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2) !important;
    }

    /* Commentary panel: scrollable, fixed max-height, at bottom */
    #right-commentary-panel {
        width: 100% !important;
        max-width: 100% !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: 35vh !important; /* ~300px on 844px viewport */
        display: flex !important;
        flex-direction: column !important;
        border-radius: 8px !important;
        overflow: hidden !important;
        background: #f8f9fa !important;
        border: 1px solid #eee !important;
    }

    #right-commentary-panel #commentary-content {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        padding: 10px 12px !important;
        font-family: 'Courier New', monospace !important;
        font-size: 0.8rem !important;
        line-height: 1.5 !important;
        -webkit-overflow-scrolling: touch !important; /* momentum scrolling on iOS */
    }

    /* Scrollbar styling for mobile */
    #right-commentary-panel #commentary-content::-webkit-scrollbar {
        width: 6px !important;
    }

    #right-commentary-panel #commentary-content::-webkit-scrollbar-track {
        background: transparent !important;
    }

    #right-commentary-panel #commentary-content::-webkit-scrollbar-thumb {
        background: #c1c1c1 !important;
        border-radius: 3px !important;
    }

    /* Token elements: ensure they scale with board */
    .game-token {
        /* Token sizing is handled by JS sizeTokens(), but ensure they're above board */
        z-index: 20 !important;
    }

    /* Cell text: readable on mobile */
    .cell {
        font-size: 35% !important; /* smaller than desktop 50% for density */
    }

    /* Footer: compact */
    #app-footer {
        margin: 8px auto 0 !important;
        max-width: 100% !important;
        padding: 8px 0 !important;
        height: auto !important;
        line-height: 1.4 !important;
        font-size: 12px !important;
    }
}

/* Small phones: 360px and below (e.g., older Android) */
@media (max-width: 360px) {
    #game-container {
        padding: 6px !important;
        gap: 6px !important;
    }

    #left-title-panel {
        padding: 6px 10px !important;
    }

    #left-title-panel .title-main {
        font-size: 1rem !important;
    }

    #left-title-panel .title-sub {
        font-size: 0.7rem !important;
    }

    #game-board-container {
        gap: 6px !important;
    }

    #dice-container {
        width: 52px !important;
        height: 52px !important;
        min-height: 52px !important;
        flex: 0 0 52px !important;
    }

    #right-commentary-panel {
        max-height: 30vh !important;
    }

    #right-commentary-panel #commentary-content {
        font-size: 0.75rem !important;
        padding: 8px 10px !important;
    }

    .cell {
        font-size: 30% !important;
    }
}

/* Landscape phones: height-constrained, width > height */
@media (max-height: 480px) and (orientation: landscape) {
    #game-container {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        min-height: 100vh !important;
        padding: 8px !important;
        gap: 8px !important;
        align-items: flex-start !important;
    }

    #left-title-panel {
        order: 0 !important;
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: 120px !important;
        max-width: 160px !important;
        height: 100% !important;
        padding: 8px !important;
    }

    #left-title-panel .title-content {
        writing-mode: vertical-rl !important;
        text-orientation: sideways !important;
        white-space: normal !important;
    }

    #game-board-container {
        order: 1 !important;
        flex: 1 1 auto !important;
        width: auto !important;
        max-width: none !important;
        height: 100% !important;
        justify-content: center !important;
    }

    #game-board {
        width: auto !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        height: auto !important;
        aspect-ratio: 1 / 1 !important;
    }

    #staging-area {
        display: none !important; /* hide staging in landscape to save space */
    }

    #right-column-wrapper {
        order: 2 !important;
        flex: 0 0 auto !important;
        width: 180px !important;
        max-width: 180px !important;
        height: 100% !important;
        min-height: 0 !important;
    }

    #dice-container {
        margin: 8px auto !important;
    }

    #right-commentary-panel {
        max-height: none !important;
        height: calc(100% - 72px) !important; /* minus dice */
    }
}

/* Tablets in portrait: 600px - 800px */
@media (min-width: 421px) and (max-width: 768px) {
    #game-container {
        grid-template-columns: 70px 1fr 200px !important;
        padding: 12px !important;
        gap: 12px !important;
    }

    #left-title-panel .title-main {
        font-size: 1.1rem !important;
    }

    #left-title-panel .title-sub {
        font-size: 0.75rem !important;
    }

    #game-board {
        max-width: 100% !important;
    }

    #right-commentary-panel #commentary-content {
        font-size: 0.8rem !important;
        padding: 10px !important;
    }
}

/* High DPI displays: ensure crisp rendering */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #game-board {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    .game-token {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    #dice-container {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

@keyframes bounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.2); }
  60% { transform: scale(0.8); }
  100% { transform: scale(1); }
}

/* Cell borders and z-index */
.cell {
    position: relative;
    z-index: 1;
    border: 1px solid #bbb;
    font-size: 50%; /* OI-1: reduce tile numbers to 50% of default size */
}


/* Left margin title panel - Grid column 1 */
#left-title-panel {
    grid-column: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none; /* Allow clicks to pass through to game */
    height: 100%;
}

/* Game board container - Grid column 2 */
#game-board-container {
    grid-column: 2;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 4px;
    box-sizing: border-box;
    min-height: 0;
}

#left-title-panel .title-content {
    writing-mode: vertical-rl;
    text-orientation: sideways;
    text-align: center;
    transform: rotate(180deg); /* Optional: makes it read bottom-to-top instead of top-to-bottom */
    font-family: 'Arial', sans-serif;
    color: #333;
}

#left-title-panel .title-main {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

#left-title-panel .title-sub {
    font-size: 0.8rem;
    color: #666;
    font-style: italic;
}

/* Right column wrapper for commentary - Grid column 3 */
#right-column-wrapper {
    grid-column: 3;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

/* Commentary panel - DEF-0024: scrolling enabled */
#right-commentary-panel {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    /* pointer-events: none; REMOVED - DEF-0024: was preventing scrolling */
}

#right-commentary-panel #commentary-content {
    flex: 1;
    overflow-y: auto; /* Required for scrolling */
    padding: 12px;
    background-color: #f8f9fa;
    border-left: 1px solid #eee;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    min-height: 0; /* Allow shrinking */
}

#right-commentary-panel #commentary-content::-webkit-scrollbar {
    width: 8px;
}

#right-commentary-panel #commentary-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#right-commentary-panel #commentary-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

#right-commentary-panel #commentary-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Footer */
#app-footer {
    width: 100%;
    max-width: 800px;
    margin: 16px auto 0;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-top: 1px solid #ddd;
    font-size: 0; /* to remove whitespace */
}
#app-footer a {
    font-size: 14px;
    color: #0066cc;
    text-decoration: none;
}
#app-footer a:hover {
    text-decoration: underline;
}

/* Player color definitions for commentary */
.commentary-player-0 { color: #e74c3c; } /* Red */
.commentary-player-1 { color: #3498db; } /* Blue */
.commentary-player-2 { color: #2ecc71; } /* Green */
.commentary-player-3 { color: #f1c40f; } /* Yellow */