:root {
    --bg-dark: #020205;
    --card-bg: rgba(4, 4, 10, 0.95);
    --border-color: rgba(0, 243, 255, 0.3);
    --neon-purple: #bd00ff;
    --neon-pink: #ff0055;
    --neon-cyan: #00f3ff;
    --neon-green: #39ff14;
    --neon-yellow: #ffe600;
    --text-color: #f0f5ff;
    --text-muted: #626e85;
    --font-pixel: 'Press Start 2P', monospace;
    --font-sans: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
}

body {
    background-color: var(--bg-dark);
    color: var(--text-color);
    font-family: var(--font-sans);
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: radial-gradient(circle at center, #0a0816 0%, #010103 100%);
    touch-action: none;
}

/* Portrait locked cabinet style game container */
#game-container {
    position: relative;
    /* Explicit dimensions derived from viewport limits to lock exactly 9:16 aspect ratio and prevent 0-height collapse */
    width: min(95vw, 530px, calc(94vh * 10.5 / 16));
    width: min(95vw, 530px, calc(94dvh * 10.5 / 16));
    height: calc(min(95vw, 530px, calc(94vh * 10.5 / 16)) * 16 / 10.5);
    height: calc(min(95vw, 530px, calc(94dvh * 10.5 / 16)) * 16 / 10.5);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 0 35px rgba(189, 0, 255, 0.25),
                0 0 70px rgba(0, 243, 255, 0.15),
                inset 0 0 30px rgba(0, 243, 255, 0.3);
    border: 3px solid rgba(0, 243, 255, 0.4);
    touch-action: none;
    background-color: #010103;
}

/* Authentic CRT scanline and glass raster filter overlay */
#game-container::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Horizontal scanlines + subtle RGB color shift mask */
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.22) 50%), 
                linear-gradient(90deg, rgba(255, 0, 85, 0.05), rgba(0, 243, 255, 0.02), rgba(189, 0, 255, 0.05));
    background-size: 100% 4px, 8px 100%;
    z-index: 99;
    pointer-events: none;
    opacity: 0.65;
    mix-blend-mode: overlay;
    border-radius: inherit;
}

#game-container:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
}
#game-container:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#canvas-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Heads Up Display (HUD) - Tailored for 9:16 layout */
#hud {
    position: absolute;
    top: 12px;
    left: 0;
    width: 100%;
    padding: 0 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr) auto;
    gap: 4px;
    pointer-events: none;
    z-index: 10;
}

.hud-item {
    background: rgba(4, 4, 14, 0.72);
    border: 1px solid rgba(0, 243, 255, 0.4);
    border-radius: 8px;
    padding: 6px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.65), inset 0 0 10px rgba(0, 243, 255, 0.1);
    min-width: 0; /* allows shrinking */
}

.hud-btn {
    padding: 4px 8px;
    cursor: pointer;
    color: var(--text-muted);
    pointer-events: auto;
    transition: all 0.2s ease;
    border: 1px solid rgba(189, 0, 255, 0.3);
}

.hud-btn:hover {
    background: rgba(189, 0, 255, 0.2);
    border-color: var(--neon-purple);
    color: #fff;
    box-shadow: 0 0 10px rgba(189, 0, 255, 0.4);
}

.hud-btn:active {
    transform: scale(0.92);
}

.hud-label {
    font-family: var(--font-pixel);
    font-size: 5.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
    letter-spacing: 0.5px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 95%;
    text-align: center;
}

.hud-value {
    font-family: var(--font-pixel);
    font-size: 9px;
    color: #fff;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 95%;
    text-align: center;
}

#score-val {
    color: var(--neon-cyan);
    text-shadow: 0 0 6px rgba(0, 243, 255, 0.5);
}

#level-val {
    color: var(--neon-purple);
    text-shadow: 0 0 6px rgba(189, 0, 255, 0.5);
}

#lives-val {
    color: var(--neon-pink);
    text-shadow: 0 0 5px rgba(255, 0, 85, 0.5);
    letter-spacing: 0.5px;
    font-size: 8px;
}

#highscore-val {
    color: var(--neon-yellow);
    text-shadow: 0 0 6px rgba(255, 230, 0, 0.4);
}

/* Overlays and Cards */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(2, 2, 6, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.card {
    background: var(--card-bg);
    border: 2px solid var(--neon-cyan);
    border-radius: 16px;
    padding: 16px 14px;
    width: 92%;
    max-height: 96%;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 243, 255, 0.15), 
                inset 0 0 10px rgba(0, 243, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: cardPulse 4s infinite alternate;
}

/* Custom scrollbar for cards if controls content overflows on very small heights */
.card::-webkit-scrollbar {
    width: 4px;
}
.card::-webkit-scrollbar-thumb {
    background: rgba(0, 243, 255, 0.2);
    border-radius: 2px;
}

.border-red {
    border-color: var(--neon-pink);
    box-shadow: 0 0 30px rgba(255, 0, 85, 0.2), 
                inset 0 0 10px rgba(255, 0, 85, 0.1);
    animation: cardPulseRed 4s infinite alternate;
}

@keyframes cardPulse {
    0% { border-color: rgba(0, 243, 255, 0.35); box-shadow: 0 0 20px rgba(0, 243, 255, 0.1); }
    100% { border-color: rgba(0, 243, 255, 0.75); box-shadow: 0 0 35px rgba(0, 243, 255, 0.25); }
}

@keyframes cardPulseRed {
    0% { border-color: rgba(255, 0, 85, 0.35); box-shadow: 0 0 20px rgba(255, 0, 85, 0.1); }
    100% { border-color: rgba(255, 0, 85, 0.75); box-shadow: 0 0 35px rgba(255, 0, 85, 0.25); }
}

.logo {
    font-family: var(--font-pixel);
    font-size: 19px;
    letter-spacing: 1.5px;
    color: #fff;
    background: linear-gradient(to right, var(--neon-cyan), var(--neon-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 8px rgba(0, 243, 255, 0.45));
    text-shadow: none;
}

.gameover-title {
    font-family: var(--font-pixel);
    font-size: 18px;
    color: var(--neon-pink);
    filter: drop-shadow(0 0 6px rgba(255, 0, 85, 0.5));
    letter-spacing: 1px;
}

.tagline {
    font-size: 8px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 2px;
}

.story-box {
    background: rgba(0, 243, 255, 0.02);
    border: 1px solid rgba(0, 243, 255, 0.15);
    border-radius: 8px;
    padding: 10px 8px;
    font-size: 10.5px;
    line-height: 1.45;
    color: #c2cbd6;
    text-align: left;
    box-shadow: inset 0 0 10px rgba(0, 243, 255, 0.03);
}

.controls-card {
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    text-align: left;
    line-height: 1.35;
}

.controls-card p {
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.key {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-bottom: 2px solid rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    padding: 1px 5px;
    font-weight: bold;
    color: #fff;
    font-family: monospace;
    font-size: 10px;
}

.btn {
    background: linear-gradient(135deg, var(--neon-purple) 0%, var(--neon-pink) 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-family: var(--font-sans);
    font-weight: bold;
    font-size: 13px;
    padding: 10px 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 0 10px rgba(189, 0, 255, 0.25);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 15px rgba(189, 0, 255, 0.5), 0 0 8px rgba(0, 243, 255, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn-restart {
    background: linear-gradient(135deg, var(--neon-pink) 0%, #ff5e00 100%);
    box-shadow: 0 0 10px rgba(255, 0, 85, 0.3);
}

.btn-restart:hover {
    box-shadow: 0 0 15px rgba(255, 0, 85, 0.5);
}

.btn-share {
    background: linear-gradient(135deg, var(--neon-cyan) 0%, var(--neon-purple) 100%);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.25);
}

.btn-share:hover {
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.5);
}

.btn-back {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    box-shadow: none;
    text-decoration: none;
    display: inline-block;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.gameover-desc {
    font-size: 11.5px;
    color: var(--text-muted);
}

.scores-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.score-card {
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 11px;
}

.score-card span {
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 8px;
    letter-spacing: 0.5px;
}

.score-card strong {
    font-family: var(--font-pixel);
    font-size: 13px;
    color: var(--neon-cyan);
    text-shadow: 0 0 8px rgba(0, 243, 255, 0.35);
}

#card-final-best strong {
    color: var(--neon-yellow);
    text-shadow: 0 0 8px rgba(255, 230, 0, 0.35);
}

.stats-footer {
    font-size: 9px;
    color: var(--text-muted);
}

/* Custom UI Indicator for Active Power-up */
#powerup-hud {
    position: absolute;
    top: 54px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(4, 4, 10, 0.85);
    border: 1px solid rgba(57, 255, 20, 0.3);
    border-radius: 6px;
    padding: 6px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    z-index: 10;
    width: 170px;
    backdrop-filter: blur(6px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#powerup-hud.active {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#powerup-hud.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
}

.powerup-text {
    font-family: var(--font-pixel);
    font-size: 7px;
    color: var(--neon-green);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
    text-align: center;
}

.powerup-bar-container {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

#powerup-bar {
    width: 100%;
    height: 100%;
    background: var(--neon-green);
    box-shadow: 0 0 5px var(--neon-green);
    transition: width 0.1s linear;
}

/* Screen orientations fallbacks: center cabinet on large screens */
@media (min-width: 768px) {
    #game-container {
        border-radius: 20px;
        border-width: 3px;
    }
}

/* Serve Prompt styling */
#serve-prompt {
    position: absolute;
    bottom: 24%;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-pixel);
    font-size: 8px;
    color: var(--neon-cyan);
    text-shadow: 0 0 6px var(--neon-cyan);
    pointer-events: none;
    z-index: 10;
    text-align: center;
    white-space: nowrap;
    animation: textBlink 1.2s infinite alternate;
}

#serve-prompt.hidden {
    display: none !important;
}

@keyframes textBlink {
    0% { opacity: 0.25; }
    100% { opacity: 1.0; }
}

/* Mobile Plunger Button */
#mobile-plunger {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--neon-pink) 0%, var(--neon-purple) 100%);
    border: 2px solid var(--neon-cyan);
    color: #fff;
    font-family: var(--font-pixel);
    font-size: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(255, 0, 85, 0.4);
    cursor: pointer;
    z-index: 15;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    user-select: none;
    -webkit-user-select: none;
}

#mobile-plunger:active {
    transform: scale(0.9);
    box-shadow: 0 0 5px rgba(255, 0, 85, 0.2);
}

#mobile-plunger.hidden {
    display: none !important;
}
