/* Chess Switch PWA - Mobile-First Styles */

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

html, body {
    height: 100%;
    overflow: hidden; /* Prevent scrolling on mobile */
    font-family: 'Roboto Mono', 'Courier New', monospace;
    user-select: none; /* Prevent text selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: manipulation; /* Optimize touch interactions */
}

body {
    background: #1a1a1a;
    color: #ffffff;
    display: flex;
    flex-direction: column;
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}


/* Main Chess Switch Layout - Vertical - Full Height */
.chess-switch {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

/* Switch Sides (Top/Bottom halves) - Minimalist */
.switch-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease;
    border: none;
    outline: none;
    touch-action: manipulation;
}

/* Black Side (Top) - Minimalist - Rotated for top player */
.switch-black {
    background: #000000;
    color: #ffffff;
    transform: rotate(180deg);
}

/* White Side (Bottom) - Minimalist */
.switch-white {
    background: #ffffff;
    color: #000000;
}

/* Active State - Minimalist */
.switch-side.active {
    filter: brightness(0.9);
}

.switch-black.active {
    transform: rotate(180deg) scale(0.98);
}

.switch-white.active {
    transform: scale(0.98);
}

/* Hover/Focus States - Minimalist */
.switch-side:hover {
    filter: brightness(1.05);
}

.switch-side:focus {
    outline: 2px solid #666666;
    outline-offset: -2px;
}

.switch-black:active {
    transform: rotate(180deg) scale(0.96);
}

.switch-white:active {
    transform: scale(0.96);
}

/* Timer Display */
.timer-display {
    font-size: clamp(44px, 12vw, 140px);
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.02em;
    transition: all 0.15s ease;
    font-variant-numeric: tabular-nums; /* Monospace numbers */
}

/* Timer Animation on Switch */
.timer-display.highlight {
    transform: scale(1.06);
    animation: timerPulse 0.12s ease;
}

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

/* Player Labels */
.player-label {
    font-size: clamp(14px, 3vw, 24px);
    font-weight: 600;
    margin-top: 20px;
    letter-spacing: 0.1em;
    opacity: 0.8;
}

/* Central Hinge - Thin Line Separator */
.switch-hinge {
    width: 100%;
    height: 4px;
    background: #666666;
    position: relative;
    z-index: 10;
}

/* Circular Control Buttons - Overlaying the Line */
.control-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: clamp(36px, 6vw, 48px);
    height: clamp(36px, 6vw, 48px);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    color: #333333;
    font-size: clamp(16px, 3vw, 20px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    touch-action: manipulation;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 20;
}

/* Individual Button Positioning */
#settingsBtn {
    left: 50%;
    transform: translate(-150%, -50%);
}

#pauseResumeBtn {
    left: 50%;
    transform: translate(-50%, -50%);
}

#resetBtn {
    left: 50%;
    transform: translate(50%, -50%);
}

.control-btn:hover,
.control-btn:focus {
    background: rgba(255, 255, 255, 1);
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Individual Button Hover States */
#settingsBtn:hover,
#settingsBtn:focus {
    transform: translate(-150%, -50%) scale(1.1);
}

#pauseResumeBtn:hover,
#pauseResumeBtn:focus {
    transform: translate(-50%, -50%) scale(1.1);
}

#resetBtn:hover,
#resetBtn:focus {
    transform: translate(50%, -50%) scale(1.1);
}

/* Individual Button Active States */
#settingsBtn:active {
    transform: translate(-150%, -50%) scale(0.95);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

#pauseResumeBtn:active {
    transform: translate(-50%, -50%) scale(0.95);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

#resetBtn:active {
    transform: translate(50%, -50%) scale(0.95);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* Flag Overlay (Game End) - Minimalist */
.flag-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.flag-overlay.show {
    display: flex;
}

.flag-text {
    font-size: clamp(32px, 8vw, 80px);
    font-weight: 600;
    color: #ffffff;
    letter-spacing: 0.1em;
}

/* Instructions Overlay - Minimalist */
.instructions {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    padding: 16px 24px;
    border-radius: 8px;
    font-size: 16px;
    text-align: center;
    z-index: 500;
    opacity: 1;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.instructions.hidden {
    opacity: 0;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background: #ffffff;
    color: #000000;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease;
}

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

/* Modal Header */
.modal-header {
    display: flex;
    justify-content: between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eeeeee;
}

.modal-header h2 {
    flex: 1;
    font-size: 24px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666666;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: #f0f0f0;
    color: #000000;
}

/* Modal Body */
.modal-body {
    padding: 20px;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333333;
}

.setting-group input[type="number"],
.setting-group select {
    width: 100%;
    padding: 12px;
    border: 2px solid #dddddd;
    border-radius: 8px;
    font-size: 16px;
    background: #ffffff;
    transition: border-color 0.2s ease;
}

.setting-group input[type="number"]:focus,
.setting-group select:focus {
    outline: none;
    border-color: #4285f4;
}

/* Custom Checkbox */
.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
}

.checkbox-label input[type="checkbox"] {
    opacity: 0;
    position: absolute;
    width: 0;
    height: 0;
}

.checkmark {
    display: inline-block;
    width: 24px;
    height: 24px;
    background: #ffffff;
    border: 2px solid #dddddd;
    border-radius: 4px;
    margin-right: 12px;
    position: relative;
    transition: all 0.2s ease;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: #4285f4;
    border-color: #4285f4;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
}

/* Modal Footer */
.modal-footer {
    padding: 20px;
    border-top: 1px solid #eeeeee;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-primary {
    background: #4285f4;
    color: #ffffff;
}

.btn-primary:hover {
    background: #3367d6;
}

.btn-primary:active {
    transform: scale(0.98);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #ffffff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 3000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

/* Wake Lock Status */
.wake-lock-status {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 193, 7, 0.9);
    color: #000000;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    z-index: 1500;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.wake-lock-status.show {
    opacity: 1;
}

/* Responsive Design - Larger Screens */
@media (min-width: 768px) {
    .control-btn {
        width: clamp(44px, 7vw, 56px);
        height: clamp(44px, 7vw, 56px);
        font-size: clamp(18px, 3.5vw, 24px);
    }
    
    .switch-hinge {
        height: 6px;
    }
    
    /* Larger screen button positioning with wider spacing */
    #settingsBtn {
        transform: translate(-200%, -50%);
    }
    
    #resetBtn {
        transform: translate(100%, -50%);
    }
    
    /* Larger screen hover states */
    #settingsBtn:hover,
    #settingsBtn:focus {
        transform: translate(-200%, -50%) scale(1.1);
    }
    
    #resetBtn:hover,
    #resetBtn:focus {
        transform: translate(100%, -50%) scale(1.1);
    }
    
    /* Larger screen active states */
    #settingsBtn:active {
        transform: translate(-200%, -50%) scale(0.95);
    }
    
    #resetBtn:active {
        transform: translate(100%, -50%) scale(0.95);
    }
    
    .modal-content {
        max-width: 500px;
    }
}

/* Landscape Orientation - Keep Vertical Layout */
@media (orientation: landscape) and (max-height: 600px) {
    .control-btn {
        width: clamp(28px, 5vw, 36px);
        height: clamp(28px, 5vw, 36px);
        font-size: clamp(12px, 2.5vw, 16px);
    }
    
    .chess-switch {
        /* Keep vertical layout even in landscape */
        flex-direction: column;
    }
    
    .switch-hinge {
        width: 100%;
        height: 3px;
    }
    
    .timer-display {
        font-size: clamp(24px, 5vw, 50px);
    }
    
    .player-label {
        font-size: clamp(8px, 1.5vw, 14px);
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .switch-black {
        background: #000000;
        color: #ffffff;
        border: 2px solid #ffffff;
    }
    
    .switch-white {
        background: #ffffff;
        color: #000000;
        border: 2px solid #000000;
    }
    
    .control-btn {
        border: 2px solid #ffffff;
    }
}

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

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .modal-content {
        background: #2a2a2a;
        color: #ffffff;
    }
    
    .modal-header {
        border-bottom-color: #444444;
    }
    
    .modal-footer {
        border-top-color: #444444;
    }
    
    .setting-group input[type="number"],
    .setting-group select {
        background: #3a3a3a;
        color: #ffffff;
        border-color: #555555;
    }
    
    .checkmark {
        background: #3a3a3a;
        border-color: #555555;
    }
    
    .close-btn {
        color: #cccccc;
    }
    
    .close-btn:hover {
        background: #444444;
        color: #ffffff;
    }
}