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

:root {
    --primary: #0088ff;
    --secondary: #00f2fe;
    --accent: #4facef;
    --danger: #ff4757;
    --dark: #071221;
    --deep-sea: #050a14;
    --glass: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glow: 0 0 15px rgba(0, 242, 254, 0.4);
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', 'Segoe UI', system-ui, sans-serif;
    background: radial-gradient(circle at center, #112d4e 0%, #050a14 100%);
    color: white;
    overflow: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" opacity="0.05"><path fill="%23ffffff" d="M0,500 C150,400 350,600 500,500 C650,400 850,600 1000,500 L1000,1000 L0,1000 Z"/></svg>');
    background-size: 200% 100%;
    animation: waves 20s linear infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes waves {
    from {
        background-position: 0 0;
    }

    to {
        background-position: -200% 0;
    }
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.hidden {
    display: none !important;
}

/* ============ TEAM SELECTION ============ */
#teamScreen .container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    padding: 40px 20px 20px;
    text-align: center;
}

.logo {
    font-size: 80px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-15px);
    }
}

#teamScreen h1,
#nameScreen h1 {
    font-size: 32px;
    font-weight: 800;
    margin: 15px 0 5px;
    background: linear-gradient(90deg, #fff, var(--secondary), #fff);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: shine 3s linear infinite;
}

@keyframes shine {
    to {
        background-position: 200% center;
    }
}

.subtitle {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 30px;
}

.team-list {
    width: 100%;
    max-width: 100%;
    max-height: 50vh;
    overflow-y: auto;
    padding: 0 10px;
}

.team-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: var(--glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 18px;
    margin-bottom: 12px;
    transition: transform 0.2s, background 0.2s;
}

.team-card:active {
    transform: scale(0.98);
    background: rgba(255, 255, 255, 0.15);
}

.team-color {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.team-info {
    flex: 1;
    text-align: left;
}

.team-name {
    font-weight: 600;
    font-size: 16px;
}

.team-members {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}

.join-btn {
    padding: 10px 22px;
    background: linear-gradient(135deg, var(--secondary), var(--accent));
    border: none;
    border-radius: 25px;
    color: var(--deep-sea);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 242, 254, 0.3);
}

.note {
    margin-top: 20px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
}

.loading {
    color: rgba(255, 255, 255, 0.5);
    padding: 20px;
}

.name-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.name-form input {
    padding: 18px 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 18px;
    text-align: center;
    outline: none;
    transition: border-color 0.3s;
}

.name-form input:focus {
    border-color: var(--secondary);
}

.name-form input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.btn-confirm {
    padding: 18px 30px;
    border: none;
    border-radius: 15px;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    color: white;
    font-size: 18px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3), var(--glow);
}

.btn-confirm:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.4), 0 0 25px rgba(0, 242, 254, 0.6);
}

.btn-confirm:active {
    transform: translateY(-1px) scale(0.98);
}

.btn-leave {
    background: rgba(140, 60, 50, 0.3);
    color: rgba(255, 180, 160, 0.9);
    border: 1px solid rgba(180, 80, 60, 0.5);
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-leave:hover {
    background: rgba(160, 70, 50, 0.4);
}

.btn-leave:active {
    background: rgba(180, 60, 50, 0.7);
    color: white;
}

/* ============ GAME SCREEN ============ */
#gameScreen {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: url('/images/bgcontroller.svg') center center / cover no-repeat;
    position: relative;
}

#gameScreen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg,
            rgba(0, 20, 40, 0.4) 0%,
            rgba(0, 30, 60, 0.2) 30%,
            rgba(0, 40, 80, 0.1) 50%,
            rgba(0, 30, 60, 0.2) 70%,
            rgba(0, 20, 40, 0.5) 100%);
    pointer-events: none;
    z-index: 0;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(180deg, rgba(0, 30, 60, 0.85), rgba(0, 20, 40, 0.75));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(0, 180, 216, 0.3);
    box-shadow: 0 4px 20px rgba(0, 50, 100, 0.4);
    z-index: 10;
    position: relative;
}

.team-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.team-badge {
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 14px;
    background: linear-gradient(135deg, rgba(180, 140, 80, 0.3), rgba(140, 100, 50, 0.4));
    border: 2px solid rgba(200, 160, 100, 0.6);
    box-shadow: 0 0 12px rgba(180, 140, 80, 0.2), inset 0 1px 0 rgba(255, 220, 150, 0.15);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color: rgba(255, 240, 200, 0.95);
}

.score-display {
    flex: 1;
    text-align: center;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.score-label {
    font-size: 10px;
    font-weight: 600;
    color: rgba(255, 220, 180, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-size: 26px;
    font-weight: 900;
    background: linear-gradient(135deg, #ffd700, #daa520, #f0c060);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    filter: drop-shadow(0 0 8px rgba(218, 165, 32, 0.5));
    animation: scoreGlow 3s ease-in-out infinite;
}

@keyframes scoreGlow {

    0%,
    100% {
        filter: drop-shadow(0 0 8px rgba(218, 165, 32, 0.5));
    }

    50% {
        filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.7));
    }
}

.game-status {
    padding: 6px 14px;
    background: linear-gradient(135deg, rgba(100, 80, 50, 0.4), rgba(70, 50, 30, 0.5));
    border: 1px solid rgba(180, 140, 80, 0.4);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: rgba(255, 220, 180, 0.85);
}

.game-status.playing {
    background: linear-gradient(135deg, rgba(60, 160, 100, 0.6), rgba(40, 120, 70, 0.7));
    color: rgba(220, 255, 230, 0.95);
    border-color: rgba(100, 200, 130, 0.7);
    box-shadow: 0 0 15px rgba(60, 160, 100, 0.4), 0 0 30px rgba(80, 200, 120, 0.2);
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {

    0%,
    100% {
        box-shadow: 0 0 15px rgba(60, 160, 100, 0.4), 0 0 30px rgba(80, 200, 120, 0.2);
    }

    50% {
        box-shadow: 0 0 20px rgba(80, 200, 120, 0.6), 0 0 40px rgba(100, 220, 140, 0.3);
    }
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Game Area - container for canvas and overlay controls */
.game-area {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    background-image: url('/images/bgcontroller.svg');
    background-color: #5eb8e6;
    /* Use cover to ensure full coverage, always show bottom part (sea) */
    background-size: cover;
    background-position: center bottom;
    background-repeat: no-repeat;
    transition: background-image 0.5s ease;
}

/* Storm background */
.game-area.storm-active {
    background-image: url('/images/bgStormcontroller.svg');
}

/* Controls Overlay - sits on top of canvas */
.controls-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 20px 25px;
    padding-bottom: 30px;
    z-index: 100;
    pointer-events: none;
}

.controls-overlay>* {
    pointer-events: auto;
}

.controls-left,
.controls-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.control-btn {
    width: 80px;
    height: 80px;
    font-size: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: white;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.control-btn.steer {
    width: 95px;
    height: 95px;
    background: transparent;
    border: none;
    /* Removed border */
    box-shadow: none;
    background-size: 80% 80%;
    background-position: center;
    background-repeat: no-repeat;
}

.steer-left {
    background-image: url('/images/trai.svg') !important;
}

.steer-right {
    background-image: url('/images/phai.svg') !important;
}

.control-btn.speed {
    width: 95px;
    height: 95px;
    background-size: 80% 80%;
}

.control-btn.gas {
    background: transparent;
    border: none;
    /* Removed border */
    box-shadow: none;
    background-image: url('/images/tangtoc.svg') !important;
    background-size: 80% 80%;
    background-position: center;
    background-repeat: no-repeat;
}

.control-btn.brake {
    background: transparent;
    border: none;
    /* Removed border */
    box-shadow: none;
    background-image: url('/images/giamtoc.svg') !important;
    background-size: 80% 80%;
    background-position: center;
    background-repeat: no-repeat;
}

.control-btn:active,
.control-btn.active {
    transform: scale(1.15);
    /* Scale up when pressed */
    background: transparent !important;
}

.control-btn.steer:active,
.control-btn.steer.active {
    border: none;
    box-shadow: none;
}

.steer-left:active,
.steer-left.active {
    background-image: url('/images/trai.svg') !important;
}

.steer-right:active,
.steer-right.active {
    background-image: url('/images/phai.svg') !important;
}

.control-btn.gas:active,
.control-btn.gas.active {
    background: transparent !important;
    background-image: url('/images/tangtoc.svg') !important;
    background-size: 80% 80%;
    background-position: center;
    background-repeat: no-repeat;
    border: none;
    box-shadow: 0 0 15px rgba(100, 255, 180, 0.2);
}

.control-btn.brake:active,
.control-btn.brake.active {
    background: transparent !important;
    background-image: url('/images/giamtoc.svg') !important;
    background-size: 80% 80%;
    background-position: center;
    background-repeat: no-repeat;
    border: none;
    box-shadow: 0 0 15px rgba(255, 150, 130, 0.2);
}

/* ============ RESULT SCREEN ============ */
#resultScreen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, #1a3c5a 0%, #050a14 100%);
}

.result-content {
    text-align: center;
    padding: 30px;
    max-width: 500px;
    width: 100%;
}

.result-content h1 {
    font-size: 42px;
    font-weight: 800;
    margin-bottom: 40px;
    background: linear-gradient(180deg, #fff 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
}

.result-scores {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 40px;
}

.result-item {
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.result-label {
    display: block;
    font-size: 12px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    font-weight: 700;
}

.result-value {
    font-size: 32px;
    font-weight: 800;
    color: white;
}

.waiting-rank {
    font-size: 18px;
    color: rgba(0, 242, 254, 0.6);
    font-weight: 600;
    letter-spacing: 1px;
}

.ranking-result h2 {
    font-size: 20px;
    margin-bottom: 25px;
    color: white;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.team-rank-display {
    background: linear-gradient(135deg, #00f2fe, #4facef);
    padding: 40px 60px;
    border-radius: 30px;
    display: inline-block;
    box-shadow: 0 0 40px rgba(0, 242, 254, 0.3), inset 0 0 20px rgba(255, 255, 255, 0.3);
    border: 2px solid white;
}

.team-rank-display .rank-number {
    display: block;
    font-size: 80px;
    font-weight: 900;
    color: var(--deep-sea);
    line-height: 1;
}

.team-rank-display .rank-score {
    display: block;
    font-size: 16px;
    margin-top: 10px;
    font-weight: 700;
    color: rgba(5, 10, 20, 0.8);
}

.player-rank-display {
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 25px;
    margin-top: 30px;
    text-align: center;
}

.player-rank-display h3 {
    font-size: 14px;
    margin-bottom: 15px;
    color: var(--accent);
    text-transform: uppercase;
    font-weight: 700;
}

.player-rank-display .rank-number {
    font-size: 48px;
    font-weight: 900;
    color: #ffd700;
}

.player-rank-display .rank-info {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 5px;
}

/* ============ EVENT OVERLAY ============ */
.event-overlay {
    position: fixed;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    padding: 12px 25px;
    background: rgba(5, 10, 20, 0.8);
    backdrop-filter: blur(15px);
    border: 1px solid var(--secondary);
    border-radius: 30px;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    color: #fff;
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.3);
    animation: eventSlide 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.score-overlay {
    position: fixed;
    top: 150px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    padding: 8px 20px;
    background: rgba(0, 40, 40, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid var(--accent);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    color: var(--secondary);
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.2);
    animation: scoreSlide 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes eventSlide {
    0% {
        transform: translateX(-50%) translateY(-30px) scale(0.9);
        opacity: 0;
    }

    100% {
        transform: translateX(-50%) translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes scoreSlide {
    0% {
        transform: translateX(-50%) translateY(-20px) scale(0.8);
        opacity: 0;
    }

    100% {
        transform: translateX(-50%) translateY(0) scale(1);
        opacity: 1;
    }
}

/* ============ COUNTDOWN OVERLAY ============ */
.countdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 10, 20, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(15px);
}

.countdown-number {
    font-size: 180px;
    font-weight: 900;
    background: linear-gradient(180deg, #fff 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    filter: drop-shadow(0 0 30px rgba(0, 242, 254, 0.6));
    animation: countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse {

    0%,
    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 30px rgba(0, 242, 254, 0.6));
    }

    50% {
        transform: scale(1.15);
        filter: drop-shadow(0 0 50px rgba(0, 242, 254, 0.9));
    }
}

/* ============ SPEEDOMETER GAUGE ============ */
.game-header {
    position: relative;
}

.speedometer {
    width: 100px;
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-left: auto;
    margin-right: 10px;
}

.speedometer.hidden {
    display: none;
}

.speedometer-svg {
    width: 100%;
    height: 50px;
}

.speedometer-bg {
    fill: none;
    stroke: rgba(255, 150, 100, 0.2);
    stroke-width: 8;
    stroke-linecap: round;
}

.speedometer-fill {
    fill: none;
    stroke: #ff8c42;
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 126;
    stroke-dashoffset: 126;
    transition: stroke-dashoffset 0.1s ease-out, stroke 0.3s ease;
}

.speedometer-fill.high-speed {
    stroke: #ff4444;
    filter: drop-shadow(0 0 8px #ff4444);
}

.speedometer-needle {
    stroke: #fff;
    stroke-width: 2.5;
    stroke-linecap: round;
    transform-origin: 50px 55px;
    transition: transform 0.1s ease-out;
}

.speedometer-center {
    fill: #ff6b35;
    filter: drop-shadow(0 0 4px rgba(255, 107, 53, 0.6));
}

.speedometer-text {
    font-size: 14px;
    font-weight: 700;
    color: #ff8c42;
    text-align: center;
    margin-top: -2px;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

.speedometer-text.high-speed {
    color: #ff4444;
    text-shadow: 0 0 10px #ff4444;
}