/* ========================================
   LUDO MASTER - MOBILE OPTIMIZED CSS v3.0
   CRITICAL FIXES FOR MOBILE LAYOUT
   ======================================== */

/* CSS Custom Properties */
:root {
    /* Color Palette */
    --bg-primary: #1a0e2e;
    --bg-secondary: #2d1b69;
    --board-bg: #2C1E3A;
    --board-surface: #3A2A4A;
    --board-border: #5A4A6A;
    --board-path: #4A3A5A;
    
    /* Player Colors */
    --color-red: #FF5252;
    --color-blue: #448AFF;
    --color-yellow: #FFD740;
    --color-green: #69F0AE;
    
    /* UI Colors */
    --ui-accent: #FFD700;
    --ui-hover: rgba(255, 255, 255, 0.1);
    --ui-active: rgba(255, 255, 255, 0.2);
    --text-primary: #FFFFFF;
    --text-secondary: #E0E0E0;
    
    /* Elevations */
    --elevation-1: 0 2px 4px rgba(0,0,0,0.1);
    --elevation-2: 0 4px 8px rgba(0,0,0,0.15);
    --elevation-3: 0 8px 16px rgba(0,0,0,0.2);
    --elevation-4: 0 12px 24px rgba(0,0,0,0.25);
    
    /* Animations */
    --transition-speed: 0.3s;
    --animation-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Global Reset & Base Styles */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    position: relative;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent iOS bounce scrolling */
body {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Focus Styles for Accessibility */
:focus {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* Screen Management */
.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    will-change: opacity;
}

.screen.active {
    display: flex;
    opacity: 1;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* Loading Screen */
#loadingScreen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.loading-content {
    text-align: center;
}

.loading-dice {
    width: 80px;
    height: 80px;
    margin: 0 auto 2rem;
    perspective: 1000px;
}

.loading-face {
    width: 100%;
    height: 100%;
    background: linear-gradient(145deg, var(--ui-accent), #FFB300);
    border-radius: 12px;
    animation: loadingRotate 2s infinite linear;
    transform-style: preserve-3d;
}

@keyframes loadingRotate {
    0% { transform: rotateX(0) rotateY(0); }
    100% { transform: rotateX(360deg) rotateY(360deg); }
}

.loading-text {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.loading-bar {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto;
}

.loading-progress {
    height: 100%;
    background: var(--ui-accent);
    border-radius: 2px;
    animation: loadingProgress 2s ease-in-out;
}

@keyframes loadingProgress {
    0% { width: 0%; }
    100% { width: 100%; }
}

/* Intro Screen */
#introScreen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    overflow-y: auto;
    background: linear-gradient(135deg, #0a0a0a 0%, #2e0e0e 100%);
}

.intro-container {
    text-align: center;
    max-width: 800px;
    width: 100%;
    animation: slideUp 0.8s ease;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.game-header {
    margin-bottom: 2rem;
}

.title-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1rem;
}

.game-title {
    font-size: clamp(2.5rem, 8vw, 5rem);
    font-weight: 800;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, var(--ui-accent), #FFF);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.2); }
}

.tagline {
    font-size: 1.25rem;
    opacity: 0.9;
    color: var(--text-secondary);
}

/* Logo Dice Animation */
.logo-dice-container {
    width: 80px;
    height: 80px;
    perspective: 1000px;
}

.logo-dice {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    animation: logoSpin 8s infinite linear;
}

@keyframes logoSpin {
    0% { transform: rotateX(0deg) rotateY(0deg); }
    100% { transform: rotateX(360deg) rotateY(360deg); }
}

.logo-dice-face {
    position: absolute;
    width: 80px;
    height: 80px;
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    border: 3px solid var(--ui-accent);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    backface-visibility: hidden;
}

.logo-dice-face.logo-face-1 { transform: rotateY(0deg) translateZ(40px); }
.logo-dice-face.logo-face-2 { transform: rotateY(90deg) translateZ(40px); }
.logo-dice-face.logo-face-3 { transform: rotateY(180deg) translateZ(40px); }
.logo-dice-face.logo-face-4 { transform: rotateY(-90deg) translateZ(40px); }
.logo-dice-face.logo-face-5 { transform: rotateX(90deg) translateZ(40px); }
.logo-dice-face.logo-face-6 { transform: rotateX(-90deg) translateZ(40px); }

.logo-dot {
    width: 16px;
    height: 16px;
    background: var(--bg-primary);
    border-radius: 50%;
    position: absolute;
    box-shadow: inset 0 -2px 4px rgba(0,0,0,0.3);
}

/* Dot positioning for logo dice */
.logo-dice-face .dot.center { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.logo-dice-face .dot.top-left { top: 20%; left: 20%; }
.logo-dice-face .dot.bottom-right { bottom: 20%; right: 20%; }
.logo-dice-face .dot.top-right { top: 20%; right: 20%; }
.logo-dice-face .dot.bottom-left { bottom: 20%; left: 20%; }
.logo-dice-face .dot.middle-left { top: 50%; left: 20%; transform: translateY(-50%); }
.logo-dice-face .dot.middle-right { top: 50%; right: 20%; transform: translateY(-50%); }

/* Player Setup */
.player-setup {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 2rem;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    box-shadow: var(--elevation-4);
}

.setup-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.setup-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Player Configuration */
.player-config {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.player-slot {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    transition: all var(--transition-speed) ease;
}

.player-slot:hover {
    background: rgba(255, 255, 255, 0.06);
    transform: translateY(-2px);
}

.color-badge {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid white;
    flex-shrink: 0;
    box-shadow: var(--elevation-2);
    transition: transform var(--transition-speed) ease;
}

.player-slot:hover .color-badge {
    transform: rotate(360deg) scale(1.1);
}

.color-badge.red { background: var(--color-red); }
.color-badge.blue { background: var(--color-blue); }
.color-badge.yellow { background: var(--color-yellow); }
.color-badge.green { background: var(--color-green); }

/* Form Controls */
.player-type,
.player-name {
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.5rem;
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    transition: all var(--transition-speed) ease;
}

.player-type {
    min-width: 100px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1.2em;
    padding-right: 2rem;
}

.player-name {
    flex: 1;
}

.player-type:hover,
.player-name:hover {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
}

.player-type:focus,
.player-name:focus {
    outline: none;
    border-color: var(--ui-accent);
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.2);
}

.player-name::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.player-name:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Game Options */
.game-options {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.option-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: opacity var(--transition-speed) ease;
}

.option-item:hover {
    opacity: 0.8;
}

.option-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Buttons */
.start-game-btn,
.tutorial-btn {
    background: linear-gradient(135deg, var(--color-green), #45a049);
    border: none;
    border-radius: 50px;
    padding: 1rem 3rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    box-shadow: var(--elevation-3);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.start-game-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.start-game-btn:hover::before {
    width: 300px;
    height: 300px;
}

.start-game-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--elevation-4), 0 10px 30px rgba(105, 240, 174, 0.3);
}

.start-game-btn:active {
    transform: translateY(0);
}

.tutorial-btn {
    background: linear-gradient(135deg, var(--color-blue), #2979FF);
    margin-top: 1rem;
    padding: 0.75rem 2rem;
    font-size: 1rem;
}

/* Game Screen - DESKTOP */
#gameScreen {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: linear-gradient(135deg, #1a0e2e 0%, #2d1b69 100%);
}

/* Game HUD - DESKTOP */
.game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    height: 60px;
    z-index: 100;
}

.hud-left,
.hud-right {
    display: flex;
    gap: 0.5rem;
}

.hud-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    color: white;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    font-size: 1.2rem;
}

.hud-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.hud-btn:active {
    transform: translateY(0);
}

/* Turn Indicator */
.turn-indicator {
    text-align: center;
}

.turn-message {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 0.5rem 1.5rem;
    display: inline-block;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.turn-player {
    font-size: 1.1rem;
    font-weight: 600;
    display: block;
}

.turn-hint {
    font-size: 0.8rem;
    opacity: 0.8;
}

/* Board Container - DESKTOP */
.board-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 1rem;
    background: transparent;
}

.game-board-wrapper {
    position: relative;
    display: inline-block;
}

/* Game Board Canvas - DESKTOP */
#gameBoard {
    background: var(--board-bg);
    border-radius: 16px;
    box-shadow: var(--elevation-4), 0 20px 40px rgba(0, 0, 0, 0.3);
    border: 3px solid var(--board-border);
    width: 600px;
    height: 600px;
    max-width: min(90vw, 90vh);
    max-height: min(90vw, 90vh);
}

/* Token Container */
.token-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Game Tokens */
.game-token {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(45deg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
    pointer-events: all;
    transition: all var(--transition-speed) var(--animation-bounce);
    border: 2px solid rgba(255, 255, 255, 0.3);
    will-change: transform;
}

.game-token span {
    transform: rotate(-45deg);
    color: white;
    font-weight: 700;
    font-size: 14px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.game-token.red { background: linear-gradient(135deg, var(--color-red), #FF1744); }
.game-token.blue { background: linear-gradient(135deg, var(--color-blue), #2962FF); }
.game-token.yellow { background: linear-gradient(135deg, var(--color-yellow), #FFC400); }
.game-token.green { background: linear-gradient(135deg, var(--color-green), #00E676); }

.game-token.movable {
    animation: tokenPulse 1s infinite;
    cursor: pointer;
}

@keyframes tokenPulse {
    0%, 100% { 
        transform: rotate(45deg) scale(1); 
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
    }
    50% { 
        transform: rotate(45deg) scale(1.2); 
        box-shadow: 0 5px 20px rgba(255, 215, 0, 0.6);
    }
}

.game-token.moving {
    pointer-events: none;
    z-index: 100;
    animation: tokenBounce 0.2s ease;
}

@keyframes tokenBounce {
    0%, 100% { transform: rotate(45deg) scale(1) translateY(0); }
    50% { transform: rotate(45deg) scale(1.1) translateY(-10px); }
}

.game-token.finished {
    animation: tokenCelebrate 1s ease infinite;
}

@keyframes tokenCelebrate {
    0%, 100% { transform: rotate(45deg) scale(1) rotateZ(0deg); }
    25% { transform: rotate(45deg) scale(1.1) rotateZ(-5deg); }
    75% { transform: rotate(45deg) scale(1.1) rotateZ(5deg); }
}

/* Dice Container - DESKTOP */
.dice-container {
    position: absolute;
    left: 2rem;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    perspective: 1000px;
    z-index: 100;
    background: var(--board-bg);
    padding: 1rem;
    border-radius: 12px;
    border: 3px solid var(--board-border);
    box-shadow: var(--elevation-4);
    transition: all var(--transition-speed) ease;
}

.dice-container:hover {
    transform: translateY(-50%) scale(1.05);
}

.dice-container.can-roll {
    animation: diceGlow 2s ease-in-out infinite;
}

@keyframes diceGlow {
    0%, 100% { 
        box-shadow: var(--elevation-4), 0 0 20px rgba(255, 215, 0, 0.5);
        border-color: var(--ui-accent);
    }
    50% { 
        box-shadow: var(--elevation-4), 0 0 30px rgba(255, 215, 0, 0.7);
        border-color: var(--ui-accent);
    }
}

/* 3D Dice */
.dice {
    width: 50px;
    height: 50px;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-20deg) rotateY(-20deg);
    transition: transform 0.6s var(--animation-bounce);
}

.dice.rolling {
    animation: diceRoll 1s cubic-bezier(0.17, 0.67, 0.83, 0.67);
}

@keyframes diceRoll {
    0% { transform: rotateX(0) rotateY(0) rotateZ(0); }
    100% { transform: rotateX(720deg) rotateY(720deg) rotateZ(360deg); }
}

.dice-face {
    position: absolute;
    width: 50px;
    height: 50px;
    background: linear-gradient(145deg, #fff, #f0f0f0);
    border: 2px solid var(--board-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
    backface-visibility: hidden;
}

.dice-face.face-1 { transform: rotateY(0deg) translateZ(25px); }
.dice-face.face-2 { transform: rotateY(90deg) translateZ(25px); }
.dice-face.face-3 { transform: rotateY(180deg) translateZ(25px); }
.dice-face.face-4 { transform: rotateY(-90deg) translateZ(25px); }
.dice-face.face-5 { transform: rotateX(90deg) translateZ(25px); }
.dice-face.face-6 { transform: rotateX(-90deg) translateZ(25px); }

.dot {
    width: 10px;
    height: 10px;
    background: #333;
    border-radius: 50%;
    position: absolute;
    box-shadow: inset 0 -1px 2px rgba(0,0,0,0.3);
}

/* Dice dot positioning */
.face-1 .dot.center { top: 50%; left: 50%; transform: translate(-50%, -50%); }

.face-2 .dot.top-left { top: 25%; left: 25%; }
.face-2 .dot.bottom-right { bottom: 25%; right: 25%; }

.face-3 .dot.top-left { top: 20%; left: 20%; }
.face-3 .dot.center { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.face-3 .dot.bottom-right { bottom: 20%; right: 20%; }

.face-4 .dot.top-left { top: 25%; left: 25%; }
.face-4 .dot.top-right { top: 25%; right: 25%; }
.face-4 .dot.bottom-left { bottom: 25%; left: 25%; }
.face-4 .dot.bottom-right { bottom: 25%; right: 25%; }

.face-5 .dot.top-left { top: 20%; left: 20%; }
.face-5 .dot.top-right { top: 20%; right: 20%; }
.face-5 .dot.center { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.face-5 .dot.bottom-left { bottom: 20%; left: 20%; }
.face-5 .dot.bottom-right { bottom: 20%; right: 20%; }

.face-6 .dot.top-left { top: 20%; left: 20%; }
.face-6 .dot.top-right { top: 20%; right: 20%; }
.face-6 .dot.middle-left { top: 50%; left: 20%; transform: translateY(-50%); }
.face-6 .dot.middle-right { top: 50%; right: 20%; transform: translateY(-50%); }
.face-6 .dot.bottom-left { bottom: 20%; left: 20%; }
.face-6 .dot.bottom-right { bottom: 20%; right: 20%; }

.dice-value {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    background: var(--board-bg);
    padding: 0.25rem 0.75rem;
    border-radius: 16px;
    border: 2px solid var(--board-border);
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.dice-value.show {
    opacity: 1;
    animation: diceValuePop 0.5s ease;
}

@keyframes diceValuePop {
    0% { transform: translateX(-50%) scale(0); }
    50% { transform: translateX(-50%) scale(1.3); }
    100% { transform: translateX(-50%) scale(1); }
}

/* Player Cards - DESKTOP */
.player-cards {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.player-card {
    position: absolute;
    background: var(--board-surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid var(--board-border);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--elevation-3);
    transition: all var(--transition-speed) ease;
    pointer-events: all;
}

.player-card.active {
    transform: scale(1.1);
    box-shadow: var(--elevation-4), 0 0 20px rgba(255, 215, 0, 0.3);
    border-color: var(--ui-accent);
    animation: cardPulse 2s ease-in-out infinite;
}

@keyframes cardPulse {
    0%, 100% { transform: scale(1.1); }
    50% { transform: scale(1.15); }
}

.player-card.winner {
    animation: winnerCelebrate 1s ease infinite;
}

@keyframes winnerCelebrate {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-5deg); }
    75% { transform: scale(1.1) rotate(5deg); }
}

.player-card.top-left { top: 5rem; left: 2rem; }
.player-card.top-right { top: 5rem; right: 2rem; }
.player-card.bottom-left { bottom: 2rem; left: 2rem; }
.player-card.bottom-right { bottom: 2rem; right: 2rem; }

.player-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    border: 2px solid white;
}

.player-info {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.player-score {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--board-surface);
    border: 2px solid var(--board-border);
    border-radius: 20px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalSlideIn 0.5s var(--animation-bounce);
}

@keyframes modalSlideIn {
    from { transform: scale(0.8) translateY(30px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    transition: transform var(--transition-speed) ease;
}

.modal-close:hover {
    transform: rotate(90deg);
}

.modal h2 {
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.tutorial-section {
    margin-bottom: 1.5rem;
}

.tutorial-section h3 {
    margin-bottom: 0.5rem;
    color: var(--ui-accent);
}

.tutorial-section ul {
    list-style: none;
    padding-left: 1rem;
}

.tutorial-section li {
    margin-bottom: 0.5rem;
    padding-left: 1.5rem;
    position: relative;
}

.tutorial-section li::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--ui-accent);
}

.modal-btn {
    background: linear-gradient(135deg, var(--color-blue), #2979FF);
    border: none;
    border-radius: 25px;
    padding: 0.75rem 2rem;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    margin-top: 1rem;
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(41, 121, 255, 0.3);
}

/* Settings Modal */
.settings-content {
    margin: 1.5rem 0;
}

.setting-item {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.setting-item label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.setting-item input[type="range"] {
    width: 150px;
    cursor: pointer;
}

.setting-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Victory Overlay */
.victory-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.victory-overlay.show {
    display: flex;
    opacity: 1;
}

.victory-content {
    background: var(--board-surface);
    border: 3px solid var(--ui-accent);
    border-radius: 24px;
    padding: 3rem;
    text-align: center;
    max-width: 500px;
    animation: victoryBounce 0.8s var(--animation-bounce);
}

@keyframes victoryBounce {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.victory-title {
    font-size: 2.5rem;
    color: var(--ui-accent);
    margin-bottom: 1rem;
    animation: victoryGlow 2s ease-in-out infinite;
}

@keyframes victoryGlow {
    0%, 100% { text-shadow: 0 0 20px rgba(255, 215, 0, 0.5); }
    50% { text-shadow: 0 0 30px rgba(255, 215, 0, 0.8); }
}

.victory-message {
    font-size: 1.5rem;
    margin-bottom: 2rem;
}

.victory-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ui-accent);
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.victory-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.victory-btn {
    background: linear-gradient(135deg, var(--color-green), #45a049);
    border: none;
    border-radius: 25px;
    padding: 0.75rem 2rem;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
}

.victory-btn.secondary {
    background: linear-gradient(135deg, #666, #444);
}

.victory-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Floating Dice Decorations */
.floating-dice {
    position: absolute;
    width: 50px;
    height: 50px;
    opacity: 0.1;
    pointer-events: none;
}

.floating-dice::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0.1));
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    animation: floatDice 20s infinite ease-in-out;
}

@keyframes floatDice {
    0%, 100% { transform: rotate(0deg) translateY(0); }
    25% { transform: rotate(90deg) translateY(-20px); }
    50% { transform: rotate(180deg) translateY(0); }
    75% { transform: rotate(270deg) translateY(20px); }
}

.dice-1 { top: 10%; left: 5%; animation-delay: 0s; }
.dice-2 { top: 20%; right: 8%; animation-delay: 5s; }
.dice-3 { bottom: 15%; left: 10%; animation-delay: 10s; }
.dice-4 { bottom: 25%; right: 5%; animation-delay: 15s; }

/* Game Messages */
.game-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--board-bg);
    color: white;
    padding: 1rem 2rem;
    border-radius: 12px;
    border: 2px solid var(--board-border);
    font-size: 1.2rem;
    z-index: 1000;
    animation: messageSlide 2s ease;
    box-shadow: var(--elevation-4);
}

@keyframes messageSlide {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}

/* ============================================ */
/* CRITICAL MOBILE STYLES - COMPLETE OVERHAUL  */
/* ============================================ */

@media only screen and (max-width: 768px) {
    /* Reset body for mobile */
    body {
        height: 100vh;
        height: 100dvh;
        position: fixed;
        overflow: hidden;
    }
    
    /* Intro screen mobile */
    #introScreen {
        padding: 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        height: 100vh;
        height: 100dvh;
    }
    
    .intro-container {
        padding: 1rem 0;
    }
    
    .title-wrapper {
        flex-direction: column;
        gap: 1rem;
    }
    
    .game-title {
        font-size: 2.5rem;
    }
    
    .tagline {
        font-size: 1rem;
    }
    
    .logo-dice-container {
        width: 60px;
        height: 60px;
    }
    
    .logo-dice-face {
        width: 60px;
        height: 60px;
    }
    
    .logo-dice-face.logo-face-1 { transform: rotateY(0deg) translateZ(30px); }
    .logo-dice-face.logo-face-2 { transform: rotateY(90deg) translateZ(30px); }
    .logo-dice-face.logo-face-3 { transform: rotateY(180deg) translateZ(30px); }
    .logo-dice-face.logo-face-4 { transform: rotateY(-90deg) translateZ(30px); }
    .logo-dice-face.logo-face-5 { transform: rotateX(90deg) translateZ(30px); }
    .logo-dice-face.logo-face-6 { transform: rotateX(-90deg) translateZ(30px); }
    
    .logo-dot {
        width: 12px;
        height: 12px;
    }
    
    .player-setup {
        padding: 1.5rem;
        border-radius: 16px;
    }
    
    .setup-title {
        font-size: 1.5rem;
    }
    
    .setup-subtitle {
        font-size: 0.9rem;
        margin-bottom: 1.5rem;
    }
    
    .player-config {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .player-slot {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .color-badge {
        width: 32px;
        height: 32px;
    }
    
    .player-type,
    .player-name {
        font-size: 0.85rem;
        padding: 0.4rem;
    }
    
    .game-options {
        flex-direction: column;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }
    
    .start-game-btn {
        padding: 0.8rem 2rem;
        font-size: 1rem;
    }
    
    .tutorial-btn {
        padding: 0.6rem 1.5rem;
        font-size: 0.9rem;
    }
    
    /* CRITICAL: Game Screen Mobile Layout Fix */
    #gameScreen {
        display: flex;
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }
    
    /* Mobile HUD */
    .game-hud {
        padding: 0.5rem;
        height: 50px;
        flex-shrink: 0;
    }
    
    .hud-btn {
        padding: 0.4rem 0.5rem;
        font-size: 1rem;
    }
    
    .turn-message {
        padding: 0.3rem 0.8rem;
    }
    
    .turn-player {
        font-size: 0.9rem;
    }
    
    .turn-hint {
        display: none;
    }
    
    /* CRITICAL: Mobile Board Container Fix */
    .board-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0.5rem;
        position: relative;
        overflow: hidden;
    }
    
    .game-board-wrapper {
        position: relative;
        width: 100%;
        max-width: calc(100vw - 1rem);
        aspect-ratio: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* CRITICAL: Mobile Board Canvas Fix */
    #gameBoard {
        width: 100%;
        height: 100%;
        max-width: min(calc(100vw - 1rem), calc(100vh - 200px));
        max-height: min(calc(100vw - 1rem), calc(100vh - 200px));
        aspect-ratio: 1;
        border-radius: 12px;
    }
    
    /* CRITICAL: Mobile Dice Positioning Fix */
    .dice-container {
        position: fixed !important;
        bottom: 100px !important;
        left: 50% !important;
        top: auto !important;
        transform: translateX(-50%) !important;
        z-index: 500 !important;
        padding: 0.75rem;
        background: rgba(44, 30, 58, 0.98);
        border: 2px solid var(--ui-accent);
    }
    
    .dice-container:active {
        transform: translateX(-50%) scale(0.95) !important;
    }
    
    .dice {
        width: 40px;
        height: 40px;
    }
    
    .dice-face {
        width: 40px;
        height: 40px;
    }
    
    .dice-face.face-1 { transform: rotateY(0deg) translateZ(20px); }
    .dice-face.face-2 { transform: rotateY(90deg) translateZ(20px); }
    .dice-face.face-3 { transform: rotateY(180deg) translateZ(20px); }
    .dice-face.face-4 { transform: rotateY(-90deg) translateZ(20px); }
    .dice-face.face-5 { transform: rotateX(90deg) translateZ(20px); }
    .dice-face.face-6 { transform: rotateX(-90deg) translateZ(20px); }
    
    .dot {
        width: 8px;
        height: 8px;
    }
    
    .dice-value {
        font-size: 1.1rem;
        top: -35px;
    }
    
    /* CRITICAL: Mobile Player Cards Fix */
    .player-cards {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        height: auto !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.3rem !important;
        padding: 0.3rem !important;
        pointer-events: all !important;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        z-index: 200;
    }
    
    .player-card {
        position: relative !important;
        inset: auto !important;
        padding: 0.4rem !important;
        border-radius: 8px;
        margin: 0 !important;
        transform: none !important;
    }
    
    .player-card.active {
        transform: scale(1.05) !important;
        border-color: var(--ui-accent);
    }
    
    .player-avatar {
        width: 24px;
        height: 24px;
        font-size: 0.8rem;
    }
    
    .player-name {
        font-size: 0.75rem;
    }
    
    .player-score {
        font-size: 0.65rem;
    }
    
    /* Mobile tokens */
    .game-token {
        width: 24px;
        height: 24px;
    }
    
    .game-token span {
        font-size: 11px;
    }
    
    /* Enlarge touch targets */
    .game-token::before {
        content: '';
        position: absolute;
        top: -10px;
        left: -10px;
        right: -10px;
        bottom: -10px;
        z-index: -1;
    }
    
    /* Mobile modals */
    .modal-content {
        padding: 1.5rem;
        margin: 1rem;
        max-width: calc(100vw - 2rem);
    }
    
    .modal h2 {
        font-size: 1.5rem;
    }
    
    /* Mobile victory */
    .victory-content {
        padding: 2rem 1.5rem;
        margin: 1rem;
    }
    
    .victory-title {
        font-size: 2rem;
    }
    
    .victory-message {
        font-size: 1.2rem;
    }
    
    .victory-stats {
        gap: 2rem;
    }
    
    .stat-value {
        font-size: 1.2rem;
    }
    
    .stat-label {
        font-size: 0.8rem;
    }
    
    .victory-btn {
        padding: 0.6rem 1.5rem;
        font-size: 0.9rem;
    }
    
    /* Mobile message */
    .game-message {
        font-size: 1rem;
        padding: 0.75rem 1.5rem;
        top: 40%;
    }
    
    /* Hide decorations on mobile */
    .floating-dice {
        display: none !important;
    }
}

/* Extra small devices */
@media only screen and (max-width: 360px) {
    .game-title {
        font-size: 2rem;
    }
    
    .player-setup {
        padding: 1rem;
    }
    
    .setup-title {
        font-size: 1.3rem;
    }
    
    /* Even smaller board for tiny screens */
    #gameBoard {
        max-width: min(calc(100vw - 0.5rem), calc(100vh - 180px));
        max-height: min(calc(100vw - 0.5rem), calc(100vh - 180px));
    }
    
    .dice-container {
        padding: 0.6rem;
        bottom: 95px !important;
    }
    
    .dice {
        width: 35px;
        height: 35px;
    }
    
    .dice-face {
        width: 35px;
        height: 35px;
    }
    
    .dice-face.face-1 { transform: rotateY(0deg) translateZ(17.5px); }
    .dice-face.face-2 { transform: rotateY(90deg) translateZ(17.5px); }
    .dice-face.face-3 { transform: rotateY(180deg) translateZ(17.5px); }
    .dice-face.face-4 { transform: rotateY(-90deg) translateZ(17.5px); }
    .dice-face.face-5 { transform: rotateX(90deg) translateZ(17.5px); }
    .dice-face.face-6 { transform: rotateX(-90deg) translateZ(17.5px); }
    
    .dot {
        width: 7px;
        height: 7px;
    }
    
    .game-token {
        width: 22px;
        height: 22px;
    }
    
    .game-token span {
        font-size: 10px;
    }
}

/* Landscape orientation fix */
@media only screen and (max-width: 768px) and (orientation: landscape) {
    .game-hud {
        padding: 0.3rem 0.5rem;
        height: 45px;
    }
    
    #gameBoard {
        max-width: min(calc(100vh - 150px), calc(100vw - 2rem));
        max-height: min(calc(100vh - 150px), calc(100vw - 2rem));
    }
    
    .player-cards {
        grid-template-columns: repeat(4, 1fr) !important;
        padding: 0.2rem !important;
    }
    
    .player-card {
        padding: 0.3rem !important;
    }
    
    .dice-container {
        right: 1rem !important;
        left: auto !important;
        bottom: 50% !important;
        transform: translateY(50%) !important;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    body {
        /* Prevent elastic scrolling */
        position: fixed;
        overflow: hidden;
    }
    
    #gameScreen {
        /* Use safe area insets */
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .player-cards {
        /* Account for iOS home indicator */
        padding-bottom: max(0.3rem, env(safe-area-inset-bottom));
    }
}

/* Accessibility - High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --board-border: #FFF;
        --text-primary: #FFF;
        --text-secondary: #CCC;
    }
    
    .game-token {
        border-width: 3px;
    }
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}