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

/* Screen reader only content */
.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;
}

/* Skip link for keyboard navigation */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #000;
    color: #fff;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 1000;
    transition: top 0.3s;
    font-weight: bold;
    border: 2px solid transparent;
}

.skip-link:focus {
    top: 6px;
    outline: 3px solid #ffbf47;
    outline-offset: 2px;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
}

.container {
    max-width: 1200px;
    width: 100%;
    height: 100vh;
    padding: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    text-align: center;
    margin-bottom: 15px;
    color: white;
    flex-shrink: 0;
}

header h1 {
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.2rem;
    opacity: 0.9;
}

main {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.screen {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    overflow-y: auto;
}

.hidden {
    display: none !important;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 8px;
    min-width: 120px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
    transform: translateY(-2px);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
    transform: translateY(-2px);
}

/* Loading Screen */
.loading-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loading-content h2 {
    color: #333;
    margin: 0;
    font-size: 2rem;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading-status {
    color: #666;
    font-size: 1.1rem;
    margin: 0;
}

/* Main Menu */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.menu-buttons .btn {
    font-size: 1.3rem;
    padding: 18px 36px;
    min-width: 200px;
}

/* Host Screen */
.game-info {
    text-align: center;
    margin-bottom: 30px;
}

.game-id-large {
    font-size: 2.5rem;
    font-weight: bold;
    color: #667eea;
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
    letter-spacing: 0.2em;
    border: 2px solid #667eea;
}

.status {
    font-size: 1.1rem;
    color: #6c757d;
    margin-top: 15px;
}

/* Join Screen */
.join-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
}

.join-form label {
    font-size: 1.1rem;
    color: #333;
}

.join-form input {
    padding: 12px;
    font-size: 1.2rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    width: 250px;
    text-align: center;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.join-form input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 12px;
    border-radius: 8px;
    margin-top: 15px;
    border: 1px solid #f5c6cb;
}

/* Game Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.game-info span {
    margin-right: 20px;
    font-weight: 600;
}

.game-status {
    display: flex;
    align-items: center;
    gap: 15px;
}

.check-indicator {
    color: #dc3545;
    font-weight: bold;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.game-actions {
    display: flex;
    gap: 10px;
}

.game-content {
    display: flex;
    padding: 20px;
    gap: 30px;
}

.chess-board-container {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 20px;
    background: #333;
    border-radius: 8px;
    max-width: 520px;
    max-height: 520px;
    margin: 0 auto;
}

.chess-board {
    width: 480px;
    height: 480px;
    border: 2px solid #333;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    background: white;
    border-radius: 4px;
}

.chess-square {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.chess-square:nth-child(odd) {
    background: #f0d9b5;
}

.chess-square:nth-child(even) {
    background: #b58863;
}

.chess-square.light {
    background: #f0d9b5;
}

.chess-square.dark {
    background: #b58863;
}

.chess-square.selected {
    background: #7b68ee !important;
    box-shadow: inset 0 0 0 3px #4169e1;
}

.chess-square.valid-move {
    background: #90ee90 !important;
}

.chess-square.valid-move::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: #228b22;
    border-radius: 50%;
    opacity: 0.7;
}

.chess-square.capture-move {
    background: #ffb6c1 !important;
}

.chess-square.capture-move::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid #dc143c;
    border-radius: 50%;
    opacity: 0.7;
}

.chess-piece {
    font-size: 2.5rem;
    user-select: none;
    transition: transform 0.2s ease;
}

.chess-piece:hover {
    transform: scale(1.1);
}

.game-sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.move-history h3 {
    margin-bottom: 15px;
    color: #333;
}

.move-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.move-item {
    padding: 8px;
    background: white;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
}

.connection-status {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
}

.connection-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
}

.indicator-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #28a745;
    animation: pulse-dot 2s infinite;
}

.connection-indicator.disconnected .indicator-dot {
    background: #dc3545;
}

.connection-indicator.reconnecting .indicator-dot {
    background: #ffc107;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.indicator-text {
    font-weight: 600;
}

/* Game End Screen */
.game-end-content {
    text-align: center;
}

.game-end-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: #333;
}

.game-end-content p {
    font-size: 1.2rem;
    color: #666;
    margin-bottom: 30px;
}

.game-end-actions {
    display: flex;
    gap: 20px;
    justify-content: center;
}

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

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    margin-bottom: 15px;
    color: #333;
}

.modal-content p {
    margin-bottom: 20px;
    color: #666;
}

.promotion-pieces {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.promotion-piece {
    width: 60px;
    height: 60px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    font-size: 2rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.promotion-piece:hover {
    border-color: #667eea;
    background: #f8f9ff;
    transform: scale(1.05);
}

/* Practice mode styles */
.practice-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 30px;
}

.practice-option {
    text-align: center;
}

.practice-option button {
    width: 100%;
    margin-bottom: 10px;
}

.practice-option p {
    font-size: 0.9rem;
    color: #666;
    margin: 0;
}

.ai-difficulty {
    margin-bottom: 30px;
    text-align: center;
}

.ai-difficulty label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
    color: #333;
}

.ai-difficulty select {
    padding: 8px 15px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    background: white;
}

/* AI controls */
.ai-controls {
    display: flex;
    gap: 10px;
    margin-left: 15px;
}

.ai-controls .btn {
    padding: 8px 15px;
    font-size: 0.9rem;
}

/* Chat interface */
.chat-section {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    height: 300px;
    display: flex;
    flex-direction: column;
}

.chat-section h3 {
    margin-bottom: 15px;
    color: #333;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: white;
    border-radius: 5px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-message {
    padding: 8px 10px;
    border-radius: 8px;
    max-width: 80%;
    word-wrap: break-word;
}

.chat-message.own-message {
    align-self: flex-end;
    background: #667eea;
    color: white;
}

.chat-message.other-message {
    align-self: flex-start;
    background: #e9ecef;
    color: #333;
}

.chat-sender {
    font-weight: bold;
    font-size: 0.8rem;
}

.chat-message.own-message .chat-sender {
    color: rgba(255, 255, 255, 0.9);
}

.chat-message.other-message .chat-sender {
    color: #666;
}

.chat-text {
    font-size: 0.9rem;
}

.chat-input {
    display: flex;
    gap: 10px;
}

.chat-input input {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 0.9rem;
}

.chat-input input:focus {
    outline: none;
    border-color: #667eea;
}

.btn-sm {
    padding: 8px 15px;
    font-size: 0.9rem;
}

.btn-info {
    background: #17a2b8;
    color: white;
}

.btn-info:hover {
    background: #138496;
    transform: translateY(-2px);
}

.btn-warning {
    background: #ffc107;
    color: #212529;
}

.btn-warning:hover {
    background: #e0a800;
    transform: translateY(-2px);
}

/* Resume game section */
.resume-section {
    margin-bottom: 30px;
    padding: 20px;
    background: #e8f5e8;
    border-radius: 10px;
    border: 2px solid #28a745;
    text-align: center;
}

.resume-info {
    margin: 10px 0 0 0;
    font-size: 0.9rem;
    color: #155724;
    font-weight: 500;
}

.btn-success {
    background: linear-gradient(145deg, #28a745, #20c997);
    color: white;
    border: none;
    font-weight: 600;
}

.btn-success:hover {
    background: linear-gradient(145deg, #218838, #1e7e34);
    transform: translateY(-2px);
}

/* Mobile chat overlay */
.mobile-chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-chat-overlay.show {
    opacity: 1;
    visibility: visible;
}

.mobile-chat-card {
    background: white;
    border-radius: 15px 15px 0 0;
    width: 100%;
    max-width: 500px;
    height: 60vh;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.2);
}

.mobile-chat-overlay.show .mobile-chat-card {
    transform: translateY(0);
}

.mobile-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #ddd;
    background: #f8f9fa;
    border-radius: 15px 15px 0 0;
}

.mobile-chat-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #333;
}

.mobile-chat-header .btn {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    line-height: 1;
    padding: 0;
    min-width: auto;
}

.mobile-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mobile-chat-input {
    padding: 15px;
    border-top: 1px solid #ddd;
    display: flex;
    gap: 10px;
    background: #f8f9fa;
}

.mobile-chat-input input {
    flex: 1;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
}

.mobile-chat-input input:focus {
    border-color: #667eea;
}

.mobile-chat-input .btn {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 1rem;
    min-width: 80px;
}

/* Mobile-only and desktop-only utilities */
.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

/* Mobile-first responsive design */
@media (max-width: 480px) {
    /* Show mobile-only elements */
    .mobile-only {
        display: block;
    }
    
    /* Hide desktop-only elements */
    .desktop-only {
        display: none;
    }
    
    /* Hide desktop chat on mobile */
    .game-sidebar .chat-section {
        display: none !important;
    }
    
    /* Full viewport usage on mobile */
    body {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
        overflow: hidden;
    }
    
    .container {
        padding: 5px;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
    }
    
    header {
        margin-bottom: 10px;
        padding: 5px;
    }
    
    header h1 {
        font-size: 1.5rem;
        margin-bottom: 2px;
    }
    
    header p {
        font-size: 0.9rem;
    }
    
    .screen {
        padding: 10px;
        overflow-y: auto;
        flex: 1;
    }
    
    /* Menu buttons stack vertically on mobile */
    .menu-buttons {
        display: flex;
        flex-direction: column;
        gap: 15px;
        width: 100%;
    }
    
    .btn {
        width: 100%;
        padding: 15px;
        font-size: 1.1rem;
        min-height: 50px;
    }
    
    /* Resume section mobile optimization */
    .resume-section {
        margin-bottom: 20px;
        padding: 15px;
    }
    
    /* Practice options mobile layout */
    .practice-options {
        gap: 15px;
    }
    
    .practice-option button {
        padding: 15px;
        font-size: 1rem;
    }
    
    /* Game screen mobile layout */
    .game-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
        padding: 10px;
    }
    
    .game-info {
        flex-direction: column;
        gap: 5px;
    }
    
    .game-actions {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }
    
    .game-actions .btn {
        flex: 1;
        min-width: 120px;
    }
    
    /* Chess board mobile optimization */
    .chess-board-container {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-bottom: 20px;
        padding: 15px;
        background: #333;
        border-radius: 8px;
        max-width: min(90vw, 390px);
        margin: 0 auto 20px auto;
    }
    
    .chess-board {
        width: min(90vw, 360px);
        height: min(90vw, 360px);
        margin: 0;
        background: white;
        border-radius: 4px;
    }
    
    .chess-square {
        width: calc(min(90vw, 360px) / 8);
        height: calc(min(90vw, 360px) / 8);
        font-size: clamp(1.2rem, 4vw, 2rem);
    }
    
    /* Game content mobile layout */
    .game-content {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }
    
    .game-sidebar {
        width: 100%;
        max-width: min(90vw, 400px);
        order: 2;
    }
    
    /* Chat mobile optimization */
    .chat-section {
        height: 200px;
        margin-bottom: 15px;
    }
    
    .chat-messages {
        font-size: 0.85rem;
    }
    
    .chat-input {
        flex-direction: row;
        gap: 8px;
    }
    
    .chat-input input {
        flex: 1;
        font-size: 1rem;
        padding: 12px;
    }
    
    .chat-input .btn {
        width: auto;
        min-width: 60px;
        padding: 12px 15px;
    }
    
    /* Move history mobile */
    .move-history {
        height: 150px;
        margin-bottom: 15px;
    }
    
    /* Form inputs mobile */
    input[type="text"], select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
        width: 100%;
    }
    
    /* Modal mobile optimization */
    .modal-content {
        margin: 10px;
        padding: 20px;
        max-width: calc(100vw - 20px);
    }
    
    .promotion-pieces {
        gap: 10px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .promotion-piece {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }
}

/* Tablet responsive design */
@media (min-width: 481px) and (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2.2rem;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 1rem;
    }
    
    .chess-board-container {
        padding: 18px;
        background: #333;
        border-radius: 8px;
        max-width: min(70vw, 436px);
        margin: 0 auto;
    }
    
    .chess-board {
        width: min(70vw, 400px);
        height: min(70vw, 400px);
        background: white;
        border-radius: 4px;
    }
    
    .chess-square {
        width: calc(min(70vw, 400px) / 8);
        height: calc(min(70vw, 400px) / 8);
        font-size: 1.8rem;
    }
    
    .game-content {
        flex-direction: column;
        align-items: center;
    }
    
    .game-sidebar {
        width: 100%;
        max-width: 500px;
    }
    
    .chat-section {
        height: 250px;
    }
}

/* Large screens */
@media (min-width: 1200px) {
    .container {
        max-width: 1400px;
    }
    
    .game-content {
        gap: 40px;
    }
    
    .chess-board {
        width: 480px;
        height: 480px;
    }
    
    .chess-square {
        width: 60px;
        height: 60px;
        font-size: 3rem;
    }
}/
* Enhanced accessibility focus indicators */
button:focus,
input:focus,
select:focus,
.chess-board:focus {
    outline: 3px solid #ffbf47;
    outline-offset: 2px;
}

/* Ensure sufficient color contrast for all text */
.status,
.resume-info,
.practice-option p {
    color: #333;
    font-weight: 500;
}

/* Better focus for chess board squares */
.chess-square:focus {
    outline: 3px solid #ffbf47;
    outline-offset: -2px;
    z-index: 10;
}

/* Improved promotion piece focus */
.promotion-piece:focus {
    outline: 3px solid #ffbf47;
    outline-offset: 2px;
    transform: scale(1.1);
}

/* Screen reader only text for better context */
.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;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
    
    .chess-square {
        border: 1px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}/* Ad
ditional accessibility improvements */
/* Ensure all interactive elements have minimum touch target size */
button,
input,
select,
.chess-square {
    min-height: 44px;
    min-width: 44px;
}

/* Better error message styling */
.error-message {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 12px;
    margin: 8px 0;
}

.error-message:focus {
    outline: 3px solid #ffbf47;
    outline-offset: 2px;
}

/* Improved modal accessibility */
.modal {
    background: rgba(0, 0, 0, 0.8);
}

.modal-content {
    background: white;
    border-radius: 8px;
    padding: 24px;
    max-width: 500px;
    margin: 50px auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Better fieldset styling */
fieldset {
    border: 2px solid #ddd;
    border-radius: 4px;
    padding: 16px;
    margin: 8px 0;
}

legend {
    padding: 0 8px;
    font-weight: bold;
}

/* Improved loading spinner accessibility */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Better connection indicator */
.connection-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
}

.indicator-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #28a745;
}

.connection-indicator.disconnected .indicator-dot {
    background: #dc3545;
}

/* Ensure proper spacing for screen readers */
.sr-only + * {
    margin-top: 0;
}