/* 9-Hole Golf - Global Styles */

:root {
    --primary-color: #2c5530;
    --secondary-color: #8fb339;
    --accent-color: #d4a574;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --success-color: #28a745;
    --text-primary: #333;
    --text-secondary: #666;
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --border-color: #dee2e6;
    --shadow: rgba(0, 0, 0, 0.1);

    /* Responsive card sizes */
    --card-width: clamp(50px, 8vw, 70px);
    --card-height: clamp(70px, 11vw, 100px);
    --player-card-width: clamp(60px, 10vw, 85px);
    --player-card-height: clamp(85px, 13vw, 120px);

    /* Touch-friendly sizes */
    --min-touch-target: 44px;
    --button-padding: clamp(8px, 2vw, 12px);
    --font-size-base: clamp(14px, 2.5vw, 16px);
    --font-size-large: clamp(18px, 3vw, 24px);
    --font-size-xl: clamp(24px, 4vw, 32px);
}

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

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    margin: 0;
    padding: 0;

    /* Mobile optimizations */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;

    /* Prevent text selection on mobile */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Re-enable text selection for inputs */
input, textarea {
    -webkit-user-select: text;
    -khtml-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

#game-container {
    width: 100vw;
    height: 100vh;
    height: -webkit-fill-available; /* iOS Safari fix */
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;

    /* Mobile performance optimizations */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000px;
    perspective: 1000px;
}

/* Ensure canvas fills container */
#game-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
}

/* Mobile viewport optimizations */
@media screen and (max-width: 768px) {
    html, body {
        /* Prevent pull-to-refresh on mobile */
        overscroll-behavior: none;
        overflow: hidden;
        /* Improve scrolling performance */
        -webkit-overflow-scrolling: touch;
        /* Ensure full viewport */
        width: 100vw;
        height: 100vh;
        height: -webkit-fill-available; /* iOS Safari fix */
        margin: 0;
        padding: 0;
        position: fixed;
        top: 0;
        left: 0;
    }

    #game-container {
        /* Ensure full screen on mobile */
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: -webkit-fill-available; /* iOS Safari fix */
    }

    #game-container canvas {
        width: 100vw !important;
        height: 100vh !important;
        height: -webkit-fill-available !important; /* iOS Safari fix */
        max-width: 100vw !important;
        max-height: 100vh !important;
    }

    /* Optimize text rendering on mobile */
    * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    html, body {
        height: -webkit-fill-available;
    }
    
    #game-container {
        height: -webkit-fill-available;
    }
    
    #game-container canvas {
        height: -webkit-fill-available !important;
    }
}

/* Performance Optimizations */
* {
    /* GPU acceleration for smooth animations */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000px;
    perspective: 1000;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Low-performance device optimizations */
@media (max-width: 480px) and (-webkit-min-device-pixel-ratio: 1) {
    /* Reduce shadow complexity on low-end devices */
    .game-button {
        box-shadow: 0 2px 4px var(--shadow);
    }

    .game-button:hover {
        box-shadow: 0 2px 4px var(--shadow);
    }

    /* Simplify gradients on low-end devices */
    .game-button {
        background: var(--primary-color);
    }

    .game-button.secondary {
        background: #6c757d;
    }

    .game-button.danger {
        background: var(--danger-color);
    }

/* Button Styles - Touch Optimized */
.game-button {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: var(--button-padding);
    border-radius: 8px;
    font-size: var(--font-size-base);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px var(--shadow);
    min-width: var(--min-touch-target);
    min-height: var(--min-touch-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.game-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px var(--shadow);
}

.game-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px var(--shadow);
}

.game-button:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.game-button.secondary {
    background: linear-gradient(135deg, #6c757d, #adb5bd);
}

.game-button.danger {
    background: linear-gradient(135deg, var(--danger-color), #ff6b6b);
}

.game-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    pointer-events: none;
}

/* Mobile-specific button adjustments */
@media (hover: none) and (pointer: coarse) {
    .game-button {
        padding: calc(var(--button-padding) * 1.2);
        min-height: calc(var(--min-touch-target) * 1.1);
        font-size: calc(var(--font-size-base) * 1.1);
    }

    .game-button:hover {
        transform: none;
    }

    .game-button:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* Input Styles - Mobile Optimized */
.game-input {
    padding: var(--button-padding);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: var(--font-size-base);
    transition: border-color 0.3s ease;
    background-color: white;
    min-width: clamp(150px, 25vw, 200px);
    min-height: var(--min-touch-target);
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.game-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 85, 48, 0.1);
}

/* Mobile input optimizations */
@media (max-width: 768px) {
    .game-input {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: calc(var(--min-touch-target) * 1.1);
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-title {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 16px;
    color: var(--primary-color);
}

.modal-text {
    margin-bottom: 16px;
    line-height: 1.6;
}

/* Card Styles (for DOM elements) */
.card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 16px 0;
}

.card-slot {
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed var(--border-color);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.card-slot:hover {
    border-color: var(--primary-color);
    background-color: rgba(44, 85, 48, 0.05);
}

.card-slot.selected {
    border-color: var(--accent-color);
    background-color: rgba(212, 167, 116, 0.1);
}

/* Player Grid Styles */
.player-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 16px;
}

.player-name {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.player-score {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --card-width: 50px;
        --card-height: 70px;
        --player-card-width: 60px;
        --player-card-height: 85px;
    }

    .game-button {
        padding: 10px 20px;
        font-size: 14px;
        min-width: 100px;
    }

    .game-input {
        min-width: 150px;
        font-size: 14px;
    }

    .modal-content {
        padding: 20px;
        margin: 20px;
    }
}

@media (max-width: 480px) {
    :root {
        --card-width: 40px;
        --card-height: 55px;
        --player-card-width: 50px;
        --player-card-height: 70px;
    }

    .game-button {
        padding: 8px 16px;
        font-size: 12px;
        min-width: 80px;
    }

    .game-input {
        min-width: 120px;
        font-size: 14px;
    }
}

/* Loading Spinner */
.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Playing Card Styles */
.playing-card {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.card-back {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    border: 2px solid #0f3460;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.card-back::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: radial-gradient(circle, #e94560 0%, #e94560 40%, transparent 70%);
    box-shadow: 0 0 15px rgba(233, 69, 96, 0.4);
}

.card-back::after {
    content: '♠';
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 14px;
    color: #e94560;
    opacity: 0.7;
    font-weight: bold;
}

.card-front {
    background: white;
    border: 1px solid #ddd;
}

.card-front.suit-hearts .card-corner,
.card-front.suit-diamonds .card-corner {
    color: #e74c3c;
}

.card-front.suit-clubs .card-corner,
.card-front.suit-spades .card-corner {
    color: #2c3e50;
}

/* Utility Classes */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }

.hidden { display: none; }
.flex { display: flex; }
.flex-column { flex-direction: column; }
.justify-center { justify-content: center; }
.align-center { align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }