* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 12px;
    background-color: #050510;
    color: #fff;
    font-family: 'Press Start 2P', cursive;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

/* CRT Scanline Effect */
body::before {
    content: " ";
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 10;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
}

.game-container {
    text-align: center;
    position: relative;
    border: 4px solid #00f3ff;
    padding: clamp(10px, 2vh, 20px);
    padding-top: clamp(32px, 6vh, 46px);
    width: min(960px, 100%);
    box-shadow: 0 0 20px #00f3ff, inset 0 0 20px rgba(0, 243, 255, 0.2);
    background: rgba(0, 20, 25, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1;
}

.game-title {
    font-size: 32px;
    margin-bottom: 20px;
    color: #fff;
    text-shadow: 
        0 0 5px #00f3ff,
        0 0 10px #00f3ff,
        0 0 20px #00f3ff;
    letter-spacing: 4px;
    text-transform: uppercase;
}

.character-select {
    width: 88%;
    margin: 0 auto 16px auto;
    border: 1px solid rgba(124, 255, 248, 0.35);
    background: rgba(6, 20, 34, 0.75);
    padding: 14px 12px 12px 12px;
    box-shadow: inset 0 0 18px rgba(0, 243, 255, 0.12);
}

.character-select.is-hidden {
    display: none;
}

.character-select-title {
    font-size: 13px;
    color: #bdf8ff;
    margin: 0 0 8px 0;
    letter-spacing: 1px;
}

.character-select-note {
    margin: 0 0 10px 0;
    font-size: 8px;
    color: #89cad8;
    line-height: 1.7;
}

.character-options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.character-option {
    appearance: none;
    border: 1px solid rgba(168, 215, 223, 0.35);
    background: rgba(8, 18, 32, 0.8);
    color: #d8f4ff;
    padding: 6px 4px;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    font-family: 'Press Start 2P', cursive;
}

.character-option:hover {
    transform: translateY(-2px);
    border-color: rgba(124, 255, 248, 0.8);
    box-shadow: 0 0 10px rgba(124, 255, 248, 0.3);
}

.character-option.is-selected {
    border-color: #7cfff8;
    box-shadow: 0 0 12px rgba(124, 255, 248, 0.35), inset 0 0 8px rgba(124, 255, 248, 0.15);
}

.character-thumb {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: contain;
    background: radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.02));
    border: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 6px;
}

.character-name {
    display: block;
    font-size: 7px;
    line-height: 1.4;
    min-height: 20px;
}

.character-traits {
    display: block;
    font-size: 6px;
    line-height: 1.5;
    color: #8fc1cb;
    min-height: 18px;
}

.start-match-btn {
    appearance: none;
    border: 1px solid #7cfff8;
    background: rgba(0, 243, 255, 0.12);
    color: #dfffff;
    font-family: 'Press Start 2P', cursive;
    font-size: 9px;
    padding: 8px 12px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.start-match-btn:hover {
    transform: translateY(-1px);
    background: rgba(0, 243, 255, 0.2);
    box-shadow: 0 0 10px rgba(124, 255, 248, 0.32);
}

.score-board {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    width: 88%;
    margin: 0 auto 20px auto;
}

.score-card {
    flex: 1;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 12, 24, 0.6);
    padding: 10px 12px;
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.05);
}

.score-name {
    display: block;
    margin-bottom: 8px;
    font-size: 10px;
    letter-spacing: 1px;
    color: #a9d7df;
}

#player-score,
#computer-score {
    font-size: 34px;
    text-shadow: 0 0 10px currentColor;
}

#player-score {
    color: #00f3ff; /* Neon Cyan */
}

#computer-score {
    color: #ff0055; /* Neon Red */
}

.phase-board {
    width: 88%;
    margin: 0 auto 14px auto;
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #89cad8;
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.2);
}

#phase-label {
    color: #7de7ff;
}

#rally-count {
    color: #ffc57a;
}

.record-board {
    width: 88%;
    margin: 0 auto 12px auto;
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: #8ec3cf;
    line-height: 1.4;
}

canvas {
    background-color: #0a0a14;
    border: 2px solid #333;
    display: block;
    margin: 0 auto;
    width: min(100%, 800px);
    height: auto;
    aspect-ratio: 8 / 5;
    box-shadow: 
        inset 0 0 50px rgba(0,0,0,0.8), 
        0 0 15px rgba(0, 243, 255, 0.3);
    cursor: none; /* Hide default cursor */
}

.controls {
    margin-top: 15px;
    font-size: 11px;
    color: #888;
    text-shadow: 0 0 2px #fff;
    line-height: 1.6;
}

.game-meta {
    position: absolute;
    top: max(8px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 8px;
    color: rgba(161, 204, 214, 0.78);
    line-height: 1.35;
    text-align: right;
    z-index: 12;
}

.back-link {
    position: absolute;
    top: max(8px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    color: rgba(184, 215, 220, 0.82);
    text-decoration: none;
    font-size: 8px;
    letter-spacing: 0.02em;
    transition: color 0.3s, opacity 0.3s;
    z-index: 12;
}

.back-link:hover {
    color: #00f3ff;
    text-shadow: 0 0 8px #00f3ff;
    opacity: 1;
}

/* Response for smaller screens */
@media (max-width: 900px) {
    body {
        padding: 0;
        min-height: 100dvh;
        overflow: hidden;
        align-items: stretch;
    }

    .game-container {
        padding: calc(30px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
        border-width: 0;
        width: 100vw;
        min-height: 100dvh;
        border-radius: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    canvas {
        width: 100%;
        height: auto;
        max-height: 48dvh;
    }
    .game-title {
        font-size: 20px;
    }
    .score-board {
        width: 100%;
        gap: 8px;
    }
    .score-name {
        font-size: 8px;
    }
    #player-score,
    #computer-score {
        font-size: 22px;
    }
    .phase-board {
        width: 100%;
        font-size: 8px;
    }
    .record-board {
        width: 100%;
        font-size: 7px;
        margin-bottom: 10px;
    }
    .character-select {
        width: 100%;
    }
    .character-options {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .character-name {
        min-height: 0;
    }
    .character-traits {
        min-height: 0;
    }
}

@media (max-height: 760px) {
    body {
        padding: 8px;
    }
    .game-title {
        font-size: 20px;
        margin-bottom: 10px;
    }
    .score-board {
        margin-bottom: 10px;
    }
    .phase-board {
        margin-bottom: 8px;
    }
    .controls {
        margin-top: 10px;
        font-size: 9px;
    }
    .game-meta {
        font-size: 7px;
    }
    .back-link {
        font-size: 7px;
    }
}

@media (max-height: 640px) {
    .game-title {
        font-size: 16px;
        letter-spacing: 2px;
    }
    #player-score,
    #computer-score {
        font-size: 18px;
    }
    .score-name,
    .phase-board {
        font-size: 7px;
    }
    .record-board {
        flex-direction: column;
        align-items: center;
        gap: 3px;
    }
    .game-meta {
        gap: 1px;
    }
}

@media (max-width: 900px) {
    body {
        padding: 0;
    }
}
