/* Modern CSS Custom Properties */
:root {
    /* Color System - Simplified for better mobile performance */
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --modern-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --glass-gradient: rgba(255,255,255,0.08);
    --card-gradient: rgba(255,255,255,0.9);
    --glass-effect: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow-glass: 0 4px 16px 0 rgba(31, 38, 135, 0.25);
    --backdrop-blur: blur(4px);
    
    /* Neutral Colors */
    --white: #ffffff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-500: #64748b;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    
    /* Semantic Colors */
    --fish-primary: #dc2626;
    --fish-secondary: #b91c1c;
    --boat-primary: #059669;
    --boat-secondary: #047857;
    --player1-color: #e53e3e;
    --player2-color: #3182ce;
    
    /* Spacing Scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-12: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1.5rem;
    --radius-2xl: 2rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
}

/* Modern Reset */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Enhanced performance optimizations for mobile devices */
body:not(.game-visible) .fish-line,
body:not(.game-visible) .boat-line,
body:not(.game-visible) .containerGlow {
    animation-play-state: paused;
}

/* Comprehensive GPU acceleration and containment for mobile performance */
.game-piece,
.dice,
.roll-button,
.player-card,
.mobile-dice,
.mobile-roll-button,
.game-board,
.modal-content,
.notification-area,
.mobile-menu-content {
    will-change: transform;
    transform: translateZ(0);
    contain: layout style paint;
}

/* Reduce animations on low-end devices */
@media (max-width: 480px) {
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.15s !important;
    }
}

/* Webview optimizations for mobile app deployment */
@supports (-webkit-touch-callout: none) {
    /* iOS Webview optimizations */
    body {
        -webkit-user-select: none;
        -webkit-tap-highlight-color: rgba(0,0,0,0);
        -webkit-touch-callout: none;
        -webkit-text-size-adjust: none;
    }
}

/* Android Webview optimizations */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .game-board,
    .square,
    .game-piece {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000px;
        perspective: 1000px;
    }
}

/* Prevent visual instability and ensure consistent rendering */
.game-header,
.game-container,
.game-board {
    isolation: isolate;
    contain: layout style paint;
}

/* Fix potential z-index stacking issues in webviews */
.game-header {
    position: relative;
    z-index: 1;
}

.game-board {
    position: relative;
    z-index: 2;
}

.game-piece {
    position: absolute;
    z-index: 150;
}

/* Optimize for reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .game-container,
    .containerGlow,
    .activePlayerPulse,
    .finishGlow,
    .shine,
    .bounce,
    .gradientShift {
        animation: none !important;
    }
}

/* Smooth scrolling for modern browsers */
html {
    scroll-behavior: smooth;
}

/* Prefers reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

body {
    font-family: var(--font-sans);
    background: var(--modern-gradient);
    background-attachment: fixed;
    min-height: 100vh;
    padding: var(--space-6);
    color: var(--gray-800);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    position: relative;
    overflow-x: hidden;
    scroll-behavior: smooth;
    /* Improved mobile scrolling */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

/* Simplified gradient animation for mobile performance */
@media (min-width: 769px) {
    body {
        background-size: 400% 400%;
        animation: gradientShift 30s ease infinite;
    }
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.game-container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--card-gradient);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-glass);
    overflow: hidden;
    border: 1px solid var(--glass-border);
    position: relative;
    /* Reduce backdrop-filter for mobile performance */
    backdrop-filter: var(--backdrop-blur);
}

/* Container glow only on desktop for better mobile performance */
@media (min-width: 769px) {
    .game-container {
        animation: containerGlow 8s ease-in-out infinite alternate;
    }
}

@keyframes containerGlow {
    0% { 
        box-shadow: var(--shadow-glass);
        transform: translateY(0px);
    }
    100% { 
        box-shadow: var(--shadow-xl), 0 0 40px rgba(255, 255, 255, 0.1);
        transform: translateY(-2px);
    }
}

/* Header */
.game-header {
    background: var(--modern-gradient);
    color: var(--white);
    text-align: center;
    padding: var(--space-8);
    position: relative;
    overflow: hidden;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    box-shadow: var(--shadow-glass);
    backdrop-filter: var(--backdrop-blur);
}

/* Header shine effect disabled to prevent visual blipping */
.game-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255,255,255,0.15), transparent);
    transform: rotate(45deg);
    /* Animation removed to prevent header blipping/shaking */
    /* animation: shine 4s infinite ease-in-out; */
}

/* Header shine animation only on desktop and only on hover for better UX */
@media (min-width: 769px) {
    .game-header:hover::before {
        animation: shine 2s ease-in-out;
    }
}

.game-header h1 {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    margin-bottom: var(--space-1);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    position: relative;
    z-index: 2;
    letter-spacing: -0.025em;
}

.game-subtitle {
    font-size: var(--font-size-lg);
    opacity: 0.95;
    font-weight: 500;
    position: relative;
    z-index: 2;
}

/* Mobile hamburger menu button */
.mobile-menu-button {
    display: none;
    position: absolute;
    right: var(--space-4);
    top: var(--space-4);
    background: var(--glass-gradient);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border);
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    cursor: pointer;
    flex-direction: column;
    gap: var(--space-1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    box-shadow: var(--shadow-glass);
}

.mobile-menu-button:hover {
    background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0.1));
    transform: scale(1.05);
    box-shadow: var(--shadow-glass), 0 0 20px rgba(255,255,255,0.3);
}

.hamburger-line {
    width: 20px;
    height: 3px;
    background: #2d3748;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.mobile-menu-button.active .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-button.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.mobile-menu-button.active .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile menu overlay - optimized for performance */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    will-change: opacity;
}

.mobile-menu-content {
    position: absolute;
    right: 20px;
    top: 80px;
    background: white;
    border-radius: 15px;
    min-width: 200px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    animation: slideInRight 0.25s ease-out;
    transform: translateZ(0);
    will-change: transform, opacity;
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #e2e8f0;
}

.mobile-menu-header h3 {
    margin: 0;
    color: #2d3748;
    font-size: 1.1em;
}

.mobile-menu-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: #718096;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.mobile-menu-close:hover {
    background: #f7fafc;
}

.mobile-menu-items {
    padding: 10px 0;
}

.mobile-menu-item {
    width: 100%;
    padding: 15px 20px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    color: #2d3748;
    transition: all 0.2s ease;
    border-radius: 0;
}

.mobile-menu-item:hover {
    background: #f7fafc;
}

.mobile-menu-item.danger {
    color: #e53e3e;
}

.mobile-menu-item.danger:hover {
    background: #fed7d7;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Game content layout */
.game-content {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 30px;
    padding: 30px;
}

/* Game info panel */
.game-info {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.players-info {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.player-card {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-6);
    background: var(--glass-gradient);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-glass);
}

.player-card.active {
    background: linear-gradient(135deg, rgba(255,247,237,0.9), rgba(254,215,170,0.8));
    border: 1px solid rgba(251, 146, 60, 0.5);
    transform: scale(1.02);
    box-shadow: var(--shadow-glass), 0 0 15px rgba(251, 146, 60, 0.2);
}

/* Active player pulse only on desktop */
@media (min-width: 769px) {
    .player-card.active {
        animation: activePlayerPulse 4s ease-in-out infinite alternate;
    }
}

@keyframes activePlayerPulse {
    0% { 
        box-shadow: var(--shadow-glass), 0 0 25px rgba(251, 146, 60, 0.3);
        transform: scale(1.02);
    }
    100% { 
        box-shadow: var(--shadow-glass), 0 0 35px rgba(251, 146, 60, 0.5);
        transform: scale(1.03);
    }
}

.player-token {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

.player1-token {
    background: radial-gradient(circle, #e53e3e, #c53030);
}

.player2-token {
    background: radial-gradient(circle, #3182ce, #2c5282);
}

.player-details h3 {
    font-size: 1.1em;
    margin-bottom: 5px;
    color: #2d3748;
}

.player-name {
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
    padding: 2px 6px;
}

.player-name:hover {
    background: rgba(66, 153, 225, 0.1);
    color: #3182ce;
    transform: scale(1.02);
}

.player-details p {
    font-size: 0.9em;
    color: #718096;
    margin: 2px 0;
}

/* Game controls */
.game-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.turn-indicator {
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    color: #2d3748;
    padding: 10px;
    background: #e2e8f0;
    border-radius: 8px;
}

.dice-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    background: var(--glass-gradient);
    padding: var(--space-8);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-glass);
    border: 1px solid var(--glass-border);
}

/* Backdrop-filter only on desktop for performance */
@media (min-width: 769px) {
    .dice-area {
        backdrop-filter: var(--backdrop-blur);
    }
}

.dice-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.dice {
    font-size: 4em;
    cursor: pointer;
    padding: var(--space-6);
    background: var(--glass-gradient);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-glass);
    transition: all 0.2s ease;
    border: 1px solid var(--glass-border);
    position: relative;
    overflow: hidden;
}

/* Enhanced dice effects only on desktop */
@media (min-width: 769px) {
    .dice {
        backdrop-filter: var(--backdrop-blur);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

.dice::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
    transition: var(--transition-slow);
}

.dice:hover {
    transform: scale(1.05) rotate(2deg);
    box-shadow: var(--shadow-xl);
    border-color: var(--gray-300);
}

.dice:hover::before {
    left: 100%;
}

.dice.rolling {
    animation: diceRoll 0.6s ease-in-out infinite;
}

@keyframes diceRoll {
    0%, 100% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(90deg) scale(1.1); }
    50% { transform: rotate(180deg) scale(1); }
    75% { transform: rotate(270deg) scale(1.1); }
}

.dice-value {
    font-size: 1.1em;
    font-weight: bold;
    color: #4a5568;
}

.roll-button {
    background: linear-gradient(135deg, #10b981, #059669);
    color: var(--white);
    border: none;
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-2xl);
    font-size: var(--font-size-lg);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-normal);
    box-shadow: var(--shadow-lg), 0 0 20px rgba(16, 185, 129, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-sans);
    position: relative;
    overflow: hidden;
}

.roll-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: var(--transition-slow);
}

.roll-button:hover {
    background: linear-gradient(135deg, #059669, #10b981);
    transform: translateY(-2px) scale(1.02);
    box-shadow: var(--shadow-xl), 0 0 30px rgba(16, 185, 129, 0.5);
}

.roll-button:hover::before {
    left: 100%;
}

.roll-button:active {
    transform: translateY(0px) scale(0.98);
    transition: var(--transition-fast);
}

.roll-button:disabled {
    background: var(--gray-400);
    cursor: not-allowed;
    transform: none;
    box-shadow: var(--shadow-sm);
}

.roll-button:disabled::before {
    display: none;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-secondary {
    background: linear-gradient(135deg, #4299e1, #3182ce);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #3182ce, #4299e1);
    transform: translateY(-2px);
}

#clear-stats {
    background: linear-gradient(135deg, #f56565, #e53e3e);
}

#clear-stats:hover {
    background: linear-gradient(135deg, #e53e3e, #f56565);
    transform: translateY(-2px);
}

/* Board container */
.board-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

/* Mobile dice area - hidden by default */
.mobile-dice-area {
    display: none;
    background: var(--glass-gradient);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border);
    padding: var(--space-6);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-glass);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.mobile-turn-info {
    background: linear-gradient(135deg, #fff3e0, #ffe0b2);
    padding: 8px 16px;
    border-radius: 20px;
    margin-bottom: 10px;
    border: 2px solid #ff9800;
    box-shadow: 0 3px 8px rgba(255, 152, 0, 0.2);
}

.mobile-turn-info span {
    font-size: 1.1em;
    font-weight: bold;
    color: #e65100;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
}

.mobile-dice-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.mobile-dice {
    font-size: 3.5em;
    padding: var(--space-4);
    background: var(--glass-gradient);
    backdrop-filter: var(--backdrop-blur);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-glass);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin: var(--space-2) 0;
}

.mobile-dice:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 30px rgba(0,0,0,0.2);
}

.mobile-dice.rolling {
    animation: diceRoll 0.6s ease-in-out infinite;
}

.mobile-dice-value {
    font-size: 1.1em;
    font-weight: bold;
    color: #4a5568;
}

.mobile-roll-button {
    background: linear-gradient(135deg, #48bb78, #38a169);
    color: white;
    border: none;
    padding: 18px 40px;
    border-radius: 30px;
    font-size: 1.2em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 20px rgba(72, 187, 120, 0.4);
    width: 100%;
    max-width: 250px;
}

.mobile-roll-button:hover {
    background: linear-gradient(135deg, #38a169, #48bb78);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(72, 187, 120, 0.5);
}

.mobile-roll-button:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 3px;
    background: var(--glass-gradient);
    border: 1px solid var(--glass-border);
    padding: var(--space-6);
    border-radius: var(--radius-2xl);
    width: 600px;
    height: 600px;
    position: relative;
    box-shadow: var(--shadow-glass);
    /* Optimize grid for mobile performance */
    contain: layout style paint;
}

/* Enhanced board effects only on desktop */
@media (min-width: 769px) {
    .game-board {
        backdrop-filter: var(--backdrop-blur);
        box-shadow: var(--shadow-glass), 0 0 0 1px rgba(255,255,255,0.1);
    }
}

.square {
    background: rgba(255,255,255,0.85);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 18px;
    color: #1a202c;
    position: relative;
    transition: transform 0.2s ease;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.9);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    font-family: 'Arial Black', 'Helvetica', sans-serif;
    contain: layout style paint;
}

/* Enhanced square effects only on desktop */
@media (min-width: 769px) {
    .square {
        background: linear-gradient(135deg, rgba(255,255,255,0.9), rgba(248,250,252,0.8));
        backdrop-filter: blur(4px);
        transition: all 0.3s ease;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    }
}

.square:hover {
    background: #f7fafc;
    transform: scale(1.02);
}

.square.start {
    background: linear-gradient(135deg, #48bb78, #38a169);
    color: white;
    font-weight: bold;
}

.square.finish {
    background: linear-gradient(135deg, #ed8936, #dd6b20);
    color: white;
    font-weight: bold;
    position: relative;
    overflow: hidden;
    /* Mobile-friendly subtle glow effect */
    box-shadow: 0 0 4px rgba(237, 137, 54, 0.4);
    border: 2px solid rgba(255, 193, 7, 0.6);
}

/* Enhanced finish square effects on desktop */
@media (min-width: 769px) {
    .square.finish {
        animation: finishGlow 3s ease-in-out infinite;
        box-shadow: 0 0 8px rgba(237, 137, 54, 0.6);
    }
}

/* Mobile-optimized finish square animation */
@media (max-width: 768px) {
    .square.finish {
        animation: mobileFinishPulse 2s ease-in-out infinite alternate;
    }
}

/* Mobile finish animation - subtle pulse effect */
@keyframes mobileFinishPulse {
    0% { 
        box-shadow: 0 0 4px rgba(237, 137, 54, 0.4);
        border-color: rgba(255, 193, 7, 0.6);
        transform: scale(1);
    }
    100% { 
        box-shadow: 0 0 8px rgba(237, 137, 54, 0.7);
        border-color: rgba(255, 193, 7, 0.9);
        transform: scale(1.02);
    }
}

.square.finish::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    /* Shine animation only on desktop to prevent mobile blipping */
}

/* Desktop shine effect for finish square */
@media (min-width: 769px) {
    .square.finish::before {
        animation: shine 3s infinite;
    }
}

@keyframes finishGlow {
    0%, 100% { box-shadow: 0 0 8px rgba(237, 137, 54, 0.6), inset 0 0 8px rgba(255, 255, 255, 0.2); }
    50% { box-shadow: 0 0 20px rgba(237, 137, 54, 0.9), inset 0 0 12px rgba(255, 255, 255, 0.3); }
}

@keyframes shine {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    50% { transform: translateX(100%) translateY(100%) rotate(45deg); }
    100% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
}

/* Fish and boat visual elements spanning multiple cells */
.fish-container, .boat-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

.fish-path, .boat-path {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.fish-line {
    fill: none;
    stroke: #dc2626;
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 0.8;
    stroke-dasharray: 6, 3;
}

/* Fish swim animation only on desktop */
@media (min-width: 769px) {
    .fish-line {
        stroke-width: 4;
        filter: drop-shadow(1px 1px 3px rgba(220,38,38,0.4));
        animation: fishSwim 3s ease-in-out infinite;
    }
}

@keyframes fishSwim {
    0%, 100% { stroke-dashoffset: 0; }
    50% { stroke-dashoffset: 12; }
}

.boat-line {
    fill: none;
    stroke: #92400e;
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 0.85;
}

/* Enhanced boat line effects only on desktop */
@media (min-width: 769px) {
    .boat-line {
        stroke-width: 4;
        filter: drop-shadow(1px 1px 3px rgba(146,64,14,0.4));
    }
}

.boat-rung {
    fill: none;
    stroke: #92400e;
    stroke-width: 2;
    stroke-linecap: round;
    opacity: 0.8;
    filter: drop-shadow(1px 1px 2px rgba(146,64,14,0.3));
}

.fish-head, .fish-tail, .boat-bottom, .boat-top {
    position: absolute;
    font-size: 24px;
    transform: translate(-50%, -50%);
    z-index: 60;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    padding: 6px;
    border: 2px solid transparent;
    contain: layout style paint;
}

/* Bounce animation and enhanced effects only on desktop */
@media (min-width: 769px) {
    .fish-head, .fish-tail, .boat-bottom, .boat-top {
        text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
        animation: bounce 3s ease-in-out infinite;
    }
}

.fish-head {
    font-size: 28px;
    background: linear-gradient(135deg, #fee2e2, #fecaca);
    border-color: #dc2626;
}

.fish-tail {
    font-size: 22px;
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    border-color: #3b82f6;
}

.boat-bottom {
    font-size: 26px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-color: #f59e0b;
}

.boat-top {
    font-size: 28px;
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    border-color: #10b981;
}

.fish-head, .fish-tail {
    filter: drop-shadow(1px 1px 3px rgba(229, 62, 62, 0.5));
}

.boat-bottom, .boat-top {
    filter: drop-shadow(1px 1px 3px rgba(139, 69, 19, 0.5));
}

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

/* Disable animations for distant fish/boat elements */
.fish-head.no-animation, .fish-tail.no-animation, 
.boat-bottom.no-animation, .boat-top.no-animation {
    animation: none !important;
}

/* Player pieces - optimized for accurate positioning */
.game-piece {
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 3px solid white;
    z-index: 150; /* Higher than fish/boats */
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4), 0 0 0 2px rgba(255,255,255,0.9);
    animation: playerGlow 3s ease-in-out infinite alternate;
    /* Ensure consistent positioning across devices */
    left: 0;
    top: 0;
    pointer-events: none;
    /* Better mobile rendering */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Mobile-specific optimizations for player pieces */
@media (max-width: 768px) {
    .game-piece {
        /* Slightly smaller on mobile for better fit */
        width: 22px;
        height: 22px;
        border-width: 2px;
        /* Faster animation on mobile */
        transition: all 0.3s ease;
        /* Reduced glow effect on mobile */
        box-shadow: 0 2px 8px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.8);
    }
    
    /* Disable player glow animation on mobile for better performance */
    .game-piece {
        animation: none;
    }
}

.game-piece.player1 {
    background: radial-gradient(circle, #e53e3e, #c53030);
    border-color: #fed7d7;
}

.game-piece.player2 {
    background: radial-gradient(circle, #3182ce, #2c5282);
    border-color: #bee3f8;
}

.game-piece.moving {
    animation: simplePieceMove 0.6s ease-in-out;
    z-index: 160;
    transform: scale(1.3);
    box-shadow: 0 8px 24px rgba(0,0,0,0.6), 0 0 0 4px rgba(255,255,255,1);
}

@keyframes playerGlow {
    0% { box-shadow: 0 4px 12px rgba(0,0,0,0.4), 0 0 0 2px rgba(255,255,255,0.9); }
    100% { box-shadow: 0 6px 16px rgba(0,0,0,0.6), 0 0 0 3px rgba(255,255,255,1); }
}

@keyframes simplePieceMove {
    0%, 100% { transform: scale(1.3); }
    50% { transform: scale(1.5); }
}

/* Game status */
.game-status {
    background: var(--glass-gradient);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: var(--space-6);
    text-align: center;
    font-weight: 500;
    box-shadow: var(--shadow-glass);
}

.game-status.winner {
    background: linear-gradient(135deg, rgba(254,215,215,0.9), rgba(254,178,178,0.8));
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #c53030;
    font-weight: bold;
    animation: celebrate 1s ease-in-out infinite;
    box-shadow: var(--shadow-glass), 0 0 30px rgba(239, 68, 68, 0.3);
}

/* Notification area - optimized for mobile performance */
.notification-area {
    background: rgba(254,243,199,0.95);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-lg);
    padding: 15px;
    text-align: center;
    animation: slideDown 0.3s ease-out;
    transform: translateZ(0);
}

/* Enhanced notification effects only on desktop */
@media (min-width: 769px) {
    .notification-area {
        background: linear-gradient(135deg, rgba(254,243,199,0.9), rgba(252,211,77,0.8));
        backdrop-filter: var(--backdrop-blur);
        animation: slideDown 0.5s ease-out;
    }
}

.notification-content {
    font-weight: 600;
    color: #92400e;
    font-size: 1.1em;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* History Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 16px 32px rgba(0,0,0,0.25);
    animation: slideUp 0.25s ease-out;
    transform: translateZ(0);
    will-change: transform, opacity;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    background: linear-gradient(135deg, #4CAF50, #2E7D32);
    color: white;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5em;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 2em;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
}

.modal-body {
    padding: 25px;
    max-height: 60vh;
    overflow-y: auto;
}

.history-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
}

.tab-button {
    background: none;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    font-weight: 600;
    color: #718096;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
}

.tab-button.active {
    color: #4CAF50;
    border-bottom-color: #4CAF50;
}

.tab-button:hover {
    color: #4CAF50;
}

.tab-content h3 {
    margin: 0 0 15px 0;
    color: #2d3748;
}

.move-history {
    max-height: 300px;
    overflow-y: auto;
    padding: 10px;
    background: #f7fafc;
    border-radius: 8px;
}

.move-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: white;
    border-radius: 6px;
    border-left: 4px solid #4CAF50;
}

.move-item.special {
    border-left-color: #f59e0b;
    background: #fffbeb;
}

.move-details {
    flex-grow: 1;
}

.move-player {
    font-weight: bold;
    color: #2d3748;
}

.move-action {
    font-size: 0.9em;
    color: #4a5568;
    margin-top: 2px;
}

.move-result {
    font-size: 0.9em;
    font-weight: 600;
    color: #4CAF50;
}

.no-moves {
    text-align: center;
    color: #718096;
    font-style: italic;
    padding: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: #f7fafc;
    border-radius: 8px;
    border-left: 4px solid #4CAF50;
}

.stat-label {
    font-weight: 600;
    color: #2d3748;
}

.stat-value {
    font-size: 1.5em;
    font-weight: bold;
    color: #4CAF50;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Custom Modal Styles */
.confirmation-modal, .input-modal {
    max-width: 400px;
    background: linear-gradient(135deg, #ffffff, #f8fafc);
    border: 3px solid #4CAF50;
}

.confirmation-buttons, .input-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.btn-confirm {
    background: linear-gradient(135deg, #48bb78, #38a169);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.3);
}

.btn-confirm:hover {
    background: linear-gradient(135deg, #38a169, #48bb78);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(72, 187, 120, 0.4);
}

.btn-cancel {
    background: linear-gradient(135deg, #f56565, #e53e3e);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(245, 101, 101, 0.3);
}

.btn-cancel:hover {
    background: linear-gradient(135deg, #e53e3e, #f56565);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(245, 101, 101, 0.4);
}

.custom-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1em;
    margin: 15px 0;
    transition: all 0.3s ease;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.custom-input:focus {
    outline: none;
    border-color: #4CAF50;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

#confirmation-message, #input-message {
    font-size: 1.1em;
    color: #2d3748;
    text-align: center;
    line-height: 1.6;
}

/* Bottom info */
.bottom-info {
    background: linear-gradient(135deg, #e6fffa, #b2f5ea);
    padding: 15px 20px;
    border-top: 2px solid #38b2ac;
    text-align: center;
}

.bottom-info p {
    margin: 5px 0;
    color: #2d3748;
    font-size: 1em;
}

.bottom-info strong {
    color: #1a202c;
}

/* Instructions */
.instructions {
    background: #f7fafc;
    padding: 20px;
    border-top: 1px solid #e2e8f0;
}

.instructions h3 {
    color: #2d3748;
    margin-bottom: 10px;
}

.instructions ul {
    list-style: none;
    padding: 0;
}

.instructions li {
    margin: 8px 0;
    padding-left: 5px;
    color: #4a5568;
}

/* Enhanced responsive design with mobile performance optimizations */
@media (max-width: 768px) {
    body {
        /* Disable background animation on mobile */
        animation: none;
        background: var(--primary-gradient);
        /* Webview performance optimizations */
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeSpeed;
    }
    
    .game-content {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px;
        display: flex;
        flex-direction: column;
        /* Optimize rendering */
        contain: layout style paint;
    }
    
    /* Reduce backdrop-filter usage on mobile */
    .game-container {
        backdrop-filter: none;
    }
    
    /* Simplify glass effects */
    .game-info,
    .mobile-dice-area {
        backdrop-filter: none;
        background: rgba(255, 255, 255, 0.9);
    }
    
    .game-board {
        width: 100%;
        max-width: 500px;
        height: auto;
        aspect-ratio: 1;
        padding: 8px;
        order: 1; /* Board comes first */
    }
    
    .board-container {
        order: 1;
        gap: 10px;
    }
    
    .players-info {
        order: 2; /* Players info after board */
        gap: 8px;
        margin: 10px 0;
    }
    
    .square {
        font-size: 16px;
        font-weight: 900;
        border-width: 3px;
        text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.9);
        border-radius: 10px;
    }
    
    .game-header h1 {
        font-size: 2em;
    }
    
    .players-info {
        flex-direction: row;
        justify-content: space-around;
        gap: 10px;
    }
    
    .player-card {
        padding: 12px;
        margin: 0;
        flex: 1;
        max-width: none;
    }
    
    /* Hide desktop elements, show mobile elements */
    .dice-area {
        display: none !important;
    }
    
    .action-buttons {
        display: none !important;
    }
    
    .turn-indicator {
        display: none !important;
    }
    
    .mobile-dice-area {
        display: block !important;
    }
    
    .mobile-menu-button {
        display: flex !important;
    }
    
    .board-container {
        gap: 15px;
    }
    
    .fish-head, .fish-tail, .boat-bottom, .boat-top {
        font-size: 16px;
        padding: 3px;
    }
    
    .game-status {
        padding: 12px;
        font-size: 0.95em;
        margin: 10px 0 0 0;
        border-radius: 10px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 2px;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        overflow-x: hidden;
        /* Aggressive optimization for low-end devices */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Disable all non-essential animations on small screens */
    *, *::before, *::after {
        animation-duration: 0.1s !important;
        transition-duration: 0.1s !important;
    }
    
    .game-content {
        padding: 4px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        gap: 6px;
    }
    
    .game-board {
        max-width: 360px;
        padding: 4px;
        flex-shrink: 0;
    }
    
    .board-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        order: 2; /* Board after players */
        flex-shrink: 0;
    }
    
    .square {
        font-size: 14px;
        font-weight: 900;
        border-width: 3px;
        border-radius: 8px;
        text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.9);
        box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
        min-height: 32px;
        min-width: 32px;
    }
    
    .game-header h1 {
        font-size: 1.4em;
        margin: 2px 0 6px 0;
    }
    
    .game-header {
        padding: 8px 15px;
    }
    
    .game-subtitle {
        font-size: 0.9em;
        margin: 0;
    }
    
    .players-info {
        order: 1; /* Show players at top */
        margin: 0;
        flex-shrink: 0;
    }
    
    .player-card {
        padding: 8px;
        margin: 2px;
    }
    
    .dice {
        font-size: 4.5em;
        padding: 15px;
    }
    
    .roll-button {
        font-size: 1.1em;
        padding: 16px 30px;
    }
    
    .mobile-dice {
        font-size: 2.8em;
        padding: 8px;
        border-radius: 12px;
        margin: 4px 0;
    }
    
    .mobile-dice-area {
        padding: 10px;
        border-radius: 12px;
        order: 3; /* Dice after board */
        flex-shrink: 0;
        margin-top: 8px;
    }
    
    .mobile-turn-info {
        padding: 6px 12px;
        margin-bottom: 8px;
        border-radius: 16px;
    }
    
    .game-status {
        padding: 8px;
        font-size: 0.85em;
        order: 4; /* Status after dice */
        margin: 4px 0 0 0;
        border-radius: 8px;
        line-height: 1.3;
    }
    
    .notification-area {
        order: 5;
        margin: 4px 0 0 0;
        padding: 8px;
        border-radius: 8px;
    }
    
    .fish-head, .fish-tail, .boat-bottom, .boat-top {
        font-size: 14px;
        padding: 2px;
    }
    
    .fish-line, .boat-line {
        stroke-width: 3;
    }
    
    .boat-rung {
        stroke-width: 1.5;
    }
}

/* Footer */
.game-footer {
    background: linear-gradient(135deg, rgba(255,255,255,0.95), rgba(248,250,252,0.9));
    backdrop-filter: var(--backdrop-blur);
    border: 2px solid rgba(102, 126, 234, 0.2);
    color: var(--gray-700);
    text-align: center;
    padding: 12px 16px;
    margin: 16px auto 0 auto;
    border-top: 3px solid #667eea;
    max-width: 600px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(102, 126, 234, 0.1);
}

.footer-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.footer-content p {
    margin: 0;
    font-size: 0.85em;
    font-weight: 600;
    color: var(--gray-700);
}

.footer-content a {
    color: #667eea;
    text-decoration: none;
    font-weight: 700;
    transition: all var(--transition-fast);
}

.footer-content a:hover {
    color: #764ba2;
    text-decoration: underline;
    text-shadow: 0 0 8px rgba(102, 126, 234, 0.3);
}

/* Social Links */
.social-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.social-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    border: 1.5px solid rgba(102, 126, 234, 0.3);
    border-radius: var(--radius-md);
    color: #667eea;
    transition: all var(--transition-normal);
    text-decoration: none;
    backdrop-filter: var(--backdrop-blur);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.social-links a:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.2));
    color: #764ba2;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md), 0 0 8px rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.5);
    text-decoration: none;
}

.social-links svg {
    width: 16px;
    height: 16px;
    transition: transform var(--transition-fast);
}

.social-links a:hover svg {
    transform: scale(1.1);
}

/* Mobile footer adjustments */
@media (max-width: 768px) {
    .game-footer {
        padding: 10px 12px;
        margin-top: 12px;
        max-width: 95%;
    }
    
    .footer-content {
        gap: 6px;
    }
    
    .footer-content p {
        font-size: 0.8em;
    }
    
    .social-links {
        gap: 6px;
    }
    
    .social-links a {
        width: 28px;
        height: 28px;
    }
    
    .social-links svg {
        width: 14px;
        height: 14px;
    }
}

@media (max-width: 480px) {
    .game-footer {
        padding: 8px 10px;
        margin-top: 8px;
        border-radius: var(--radius-md);
    }
    
    .footer-content {
        gap: 4px;
    }
    
    .footer-content p {
        font-size: 0.75em;
    }
    
    .social-links {
        gap: 4px;
    }
    
    .social-links a {
        width: 24px;
        height: 24px;
    }
    
    .social-links svg {
        width: 12px;
        height: 12px;
    }
}

/* Offline Status Indicator */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #fed7d7, #feb2b2);
    color: #c53030;
    text-align: center;
    padding: 8px;
    font-weight: bold;
    font-size: 0.9em;
    z-index: 10000;
    border-bottom: 2px solid #e53e3e;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    animation: slideDownOffline 0.3s ease-out;
}

@keyframes slideDownOffline {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Adjust layout when offline indicator is shown */
@media (max-width: 768px) {
    .offline-indicator {
        font-size: 0.8em;
        padding: 6px;
    }
}

@media (max-width: 480px) {
    .offline-indicator {
        font-size: 0.75em;
        padding: 5px;
    }
}