* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ADA: visually hidden but accessible to screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#app {
    width: 100%;
    max-width: 500px;
    padding: 20px;
}

.screen {
    display: none;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 30px;
    text-align: center;
    animation: fadeIn 0.3s ease-in;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h1 {
    font-size: 3em;
    margin-bottom: 10px;
    background: linear-gradient(45deg, #3498db, #e74c3c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h2 {
    font-size: 2em;
    margin-bottom: 20px;
    color: #333;
}

.game-description {
    font-size: 1.1em;
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.game-options {
    margin-bottom: 25px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
}

.option-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1em;
    color: #333;
    cursor: pointer;
}

.option-text {
    user-select: none;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.menu-btn {
    background: linear-gradient(45deg, #667eea, #764ba2);
    border: none;
    border-radius: 15px;
    padding: 20px;
    color: white;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.menu-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.menu-btn:active {
    transform: translateY(0);
}

.menu-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.menu-btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

.btn-title {
    font-weight: bold;
    font-size: 1.2em;
}

.btn-subtitle {
    font-size: 0.9em;
    opacity: 0.8;
}

.control-btn {
    background: #ecf0f1;
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    color: #333;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
}

.control-btn:hover {
    background: #bdc3c7;
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.control-btn:disabled:hover {
    background: #ecf0f1;
}

.game-header {
    margin-bottom: 20px;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.current-player {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1em;
    font-weight: bold;
}

.player-indicator {
    width: 30px;
    height: 8px;
    border-radius: 4px;
}

.player-indicator.horizontal {
    background: #3498db;
}

.player-indicator.vertical {
    background: #e74c3c;
    width: 8px;
    height: 30px;
}

.game-controls {
    display: flex;
    gap: 10px;
}

.game-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    position: relative;
}

#game-canvas {
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    max-width: 100%;
    height: auto;
}

.in-game-over-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(2px);
    z-index: 2;
}

.in-game-over-overlay.visible {
    display: flex;
}

#in-game-winner-display {
    font-size: 1.1em;
    margin: 12px 0;
    padding: 14px;
    border-radius: 10px;
    background: #f8f9fa;
}

.game-footer {
    margin-top: 20px;
}

.legend {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    color: #666;
}

.legend-symbol {
    width: 20px;
    height: 4px;
    border-radius: 2px;
}

.legend-symbol.horizontal {
    background: #3498db;
}

.legend-symbol.vertical {
    background: #e74c3c;
    width: 4px;
    height: 20px;
}

.legend-symbol.plus {
    background: #9b59b6;
    position: relative;
}

.legend-symbol.plus::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 20px;
    background: #9b59b6;
    border-radius: 2px;
}

.remote-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 30px 0;
}

.join-room {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#room-code {
    padding: 15px;
    border: 2px solid #ecf0f1;
    border-radius: 10px;
    font-size: 1.1em;
    text-align: center;
    letter-spacing: 3px;
    text-transform: uppercase;
}

#room-code:focus {
    outline: none;
    border-color: #3498db;
}

.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.settings-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.play-again-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

#play-again-status {
    font-size: 1.1em;
    margin: 20px 0;
    color: #666;
}

#play-again-timer {
    font-size: 1em;
    margin: 15px 0;
    color: #e74c3c;
    font-weight: bold;
}

#winner-display {
    font-size: 1.2em;
    margin: 20px 0;
    padding: 20px;
    border-radius: 10px;
    background: #f8f9fa;
}

/* How to Play button (secondary, on main menu) */
.how-to-play-btn {
    background: none;
    border: 1px solid rgba(0, 0, 0, 0.2);
    color: #666;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 8px 24px;
    border-radius: 8px;
    margin-top: 4px;
    transition: background 0.15s, color 0.15s;
}

.how-to-play-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #333;
}

/* Tutorial / How to Play screen */
.tutorial-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin: 10px 0 20px;
}

.tutorial-canvas-wrapper {
    display: grid;
    grid-template-columns: 52px auto 52px;
    align-items: center;
    gap: 10px;
}

.tutorial-nav-btn {
    height: 80px;
    background: none;
    border: 2px solid #ccc;
    border-radius: 12px;
    font-size: 2.8rem;
    line-height: 1;
    color: #999;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.tutorial-nav-btn:hover {
    border-color: #9B59B6;
    color: #9B59B6;
}

.tutorial-step-label {
    font-size: 1rem;
    font-weight: 700;
    color: #9B59B6;
    margin: 0;
    min-height: 1.3em;
    text-align: center;
}

#tutorial-canvas {
    border-radius: 12px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.18);
    background: #fff;
    max-width: 100%;
}

.tutorial-step-text {
    font-size: 0.9rem;
    color: #444;
    text-align: center;
    max-width: 280px;
    margin: 0;
    min-height: 3.2em;
    line-height: 1.55;
}

.tutorial-dots {
    display: flex;
    gap: 7px;
    justify-content: center;
}

.tutorial-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    transition: background 0.3s;
}

.tutorial-dot.active {
    background: #9B59B6;
}

/* Site footer */
#site-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 6px 0;
    font-size: 0.72rem;
    background: rgba(0, 0, 0, 0.55);
    color: rgba(255, 255, 255, 0.55);
    z-index: 100;
}

#site-footer a {
    color: rgba(255, 255, 255, 0.55);
    text-decoration: none;
}

#site-footer a:hover {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: underline;
}

/* Mobile Optimizations */
@media (max-width: 600px) {
    #app {
        padding: 10px;
    }
    
    .screen {
        padding: 20px;
    }
    
    h1 {
        font-size: 2.5em;
    }
    
    .game-info {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    #game-canvas {
        width: 100%;
        max-width: 350px;
    }
    
    .legend {
        justify-content: center;
        gap: 10px;
    }
}

@media (max-height: 700px) {
    .screen {
        padding: 15px;
    }
    
    h1 {
        font-size: 2em;
        margin-bottom: 15px;
    }
    
    .game-description {
        margin-bottom: 20px;
    }
}

/* Touch-friendly sizing */
@media (pointer: coarse) {
    .menu-btn {
        min-height: 60px;
    }
    
    .control-btn {
        min-height: 50px;
        padding: 12px 24px;
    }
}