/* Reset — removes all the default spacing so we start from scratch */
* { margin: 0; padding: 0; box-sizing: border-box; }

/* Body — the whole page background, centered and dark like an arcade */
body {
    background: #111;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    font-family: 'Courier New', monospace;
    color: #fff;
    user-select: none;
    overflow: hidden;
    touch-action: none;
}

/* Game screen — the area that holds the canvas, scores, and controls */
#game-screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Game row — puts the scores and canvas side by side */
#game-row {
    display: flex;
    align-items: center;
    gap: 24px;
}

/* Side scores — the big numbers on each side of the game */
.side-score {
    font-size: 64px;
    min-width: 60px;
    text-align: center;
}

/* Canvas — the playing field where the ball bounces around */
canvas {
    border: 2px solid #444;
    display: block;
}

/* Controls text — tells you which keys to press */
#controls {
    margin-top: 16px;
    font-size: 14px;
    color: #888;
    text-align: center;
    line-height: 1.8;
}

/* Slow timer — shows a countdown when your paddle is slowed down */
#slow-timer, #player-slow-timer {
    font-size: 16px;
    min-height: 24px;
}

/* Color Picker — a popup where you type in paddle colors for local games */
#color-picker {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    color: #000;
    padding: 40px;
    border-radius: 12px;
    font-family: 'Courier New', monospace;
    z-index: 10;
    text-align: center;
}

#color-picker .columns {
    display: flex;
    gap: 60px;
    margin-top: 20px;
}

#color-picker .column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#color-picker .column label {
    font-size: 18px;
    font-weight: bold;
}

#color-picker .column input {
    font-family: 'Courier New', monospace;
    font-size: 18px;
    padding: 6px 12px;
    border: 2px solid #333;
    border-radius: 6px;
    text-align: center;
    width: 160px;
}

#color-picker .hint {
    margin-top: 20px;
    font-size: 14px;
    color: #666;
}

/* Mode Select Overlay — the main menu that covers the whole screen */
#mode-select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

/* The white box in the center of the menu and username screens */
#mode-select .box,
#username-modal .box {
    background: #fff;
    color: #000;
    padding: 50px 60px;
    border-radius: 16px;
    font-family: 'Courier New', monospace;
    text-align: center;
}

#mode-select h1,
#username-modal h1 {
    font-size: 36px;
    margin-bottom: 30px;
}

/* The big clickable buttons on the menu and username screens */
#mode-select .mode-btn,
#username-modal .mode-btn {
    display: block;
    width: 100%;
    padding: 16px 40px;
    margin-bottom: 16px;
    font-size: 22px;
    font-family: 'Courier New', monospace;
    background: #333;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

#mode-select .mode-btn:hover,
#username-modal .mode-btn:hover {
    background: #555;
}

/* The "Online Play" button gets a special green color to stand out */
#mode-select .mode-btn-online {
    background: #2a5;
}

#mode-select .mode-btn-online:hover {
    background: #3b7;
}

/* Username Modal — the popup where you type your online name */
#username-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

#username-modal input[type="text"] {
    display: block;
    width: 100%;
    padding: 14px 20px;
    margin-bottom: 12px;
    font-size: 20px;
    font-family: 'Courier New', monospace;
    border: 2px solid #333;
    border-radius: 8px;
    text-align: center;
    outline: none;
}

#username-modal input[type="text"]:focus {
    border-color: #2a5;
}

/* Online Color Modal — the popup where you pick your paddle color */
#online-color-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.selected {
    border-color: #fff;
    transform: scale(1.15);
}

#online-color-modal input[type="color"] {
    display: block;
    width: 120px;
    height: 120px;
    margin: 0 auto;
    padding: 0;
    border: 3px solid #888;
    border-radius: 12px;
    cursor: pointer;
    background: none;
}

#online-color-modal input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 4px;
}

#online-color-modal input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 8px;
}

/* Error message that shows up in red if your username is not valid */
.username-error {
    color: #c33;
    font-size: 14px;
    min-height: 20px;
    margin-bottom: 8px;
    font-family: 'Courier New', monospace;
}

/* Settings Overlay — a popup to turn music and background on or off */
#settings {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #555;
    color: #fff;
    padding: 40px;
    border-radius: 12px;
    font-family: 'Courier New', monospace;
    z-index: 10;
    text-align: center;
    min-width: 280px;
}

#settings h2 {
    margin-bottom: 24px;
    font-size: 28px;
}

/* Each setting row — label on the left, toggle switch on the right */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-size: 18px;
}

/* Toggle switch — a little slider that turns things on and off */
.toggle {
    width: 50px;
    height: 26px;
    background: #888;
    border-radius: 13px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
}

/* When the toggle is ON, it turns green */
.toggle.on {
    background: #4caf50;
}

/* The white circle that slides back and forth inside the toggle */
.toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: left 0.2s;
}

.toggle.on::after {
    left: 27px;
}

#settings .hint {
    margin-top: 20px;
    font-size: 14px;
    color: #ccc;
}

/* Lobby screen — hidden by default; JavaScript shows it when you go online */
#lobby-screen {
    display: none;
}

/* Touch controls — buttons that appear on phones and tablets instead of keyboard */
#touch-controls {
    display: none;
    margin-top: 12px;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Each touch button — styled to look nice and be easy to tap */
.touch-btn {
    padding: 12px 20px;
    font-size: 16px;
    font-family: 'Courier New', monospace;
    background: #333;
    color: #fff;
    border: 2px solid #666;
    border-radius: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

.touch-btn:active, .touch-btn.active {
    background: #555;
    border-color: #aaa;
}

/* Special "slow" button — has an orange color to look different */
.touch-btn-slow {
    background: #553300;
    border-color: #ff8800;
}

.touch-btn-slow:active, .touch-btn-slow.active {
    background: #774400;
    border-color: #ffaa33;
}

/* Touch device overrides — when you're on a phone or tablet with a touchscreen */
/* "pointer: coarse" means "this device uses a finger, not a mouse" */
@media (pointer: coarse) {
    #touch-controls {
        display: flex;
    }
    #controls {
        display: none !important;
    }
    .side-score {
        font-size: 36px;
        min-width: 40px;
    }
    #game-row {
        gap: 8px;
    }
}

/* Small screen overrides — makes things smaller so they fit on tiny phones */
@media (max-width: 600px) {
    .side-score {
        font-size: 28px;
    }
    .touch-btn {
        padding: 8px 14px;
        font-size: 14px;
    }
    #color-picker .columns {
        flex-direction: column;
        gap: 20px;
    }
    .mode-btn {
        padding: 12px 24px !important;
    }
}
