@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

:root {
    --bg-color: #120f18;
    --neon-green: #39ff14;
    --neon-pink: #ff00ff;
    --neon-blue: #00ffff;
    --error-red: #ff3333;
    --text-glow: 0 0 5px var(--neon-green), 0 0 10px var(--neon-green);
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--neon-green);
    font-family: 'VT323', monospace;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* BACKGROUND EFFECTS (Optimized) */
.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.15) 50%),
        linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    background-size: 100% 3px, 3px 100%;
    pointer-events: none;
    z-index: 999;
}

.swirl-bg {
    /* Optimization: Removed complex radial gradient for smoother performance */
    background: repeating-conic-gradient(from 0deg, #120f18 0deg, #1b1625 10deg, #120f18 20deg);
    animation: pulseBg 10s ease-in-out infinite alternate;
}

.fixed-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
}

@keyframes pulseBg {
    0% {
        filter: hue-rotate(0deg);
    }

    100% {
        filter: hue-rotate(20deg);
    }
}

@keyframes floatGuide {

    0%,
    100% {
        transform: translateY(0);
        box-shadow: 0 0 10px var(--neon-blue);
    }

    50% {
        transform: translateY(-3px);
        box-shadow: 0 0 20px var(--neon-blue), 0 0 10px var(--neon-pink);
    }
}

#btn-guide {
    animation: floatGuide 2s ease-in-out infinite;
}

#btn-guide:hover {
    background: var(--neon-blue);
    color: #000;
}

@keyframes shakeRed {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
        background-color: rgba(255, 0, 0, 0.1);
    }

    10% {
        transform: translate(-1px, -2px) rotate(-1deg);
    }

    20% {
        transform: translate(-3px, 0px) rotate(1deg);
        background-color: rgba(255, 0, 0, 0.2);
    }

    30% {
        transform: translate(3px, 2px) rotate(0deg);
    }

    40% {
        transform: translate(1px, -1px) rotate(1deg);
    }

    50% {
        transform: translate(-1px, 2px) rotate(-1deg);
        background-color: rgba(255, 0, 0, 0.2);
    }

    60% {
        transform: translate(-3px, 1px) rotate(0deg);
    }

    70% {
        transform: translate(3px, 1px) rotate(-1deg);
    }

    80% {
        transform: translate(-1px, -1px) rotate(1deg);
    }

    90% {
        transform: translate(1px, 2px) rotate(0deg);
    }

    100% {
        transform: translate(1px, -2px) rotate(-1deg);
        background-color: transparent;
    }
}

.shake-red {
    animation: shakeRed 0.5s;
    border: 2px solid red !important;
}

/* TYPOGRAPHY */
h1.balatro-title {
    font-size: 5rem;
    color: var(--neon-green);
    text-shadow: 3px 3px 0 var(--neon-pink), -2px -2px 0 var(--neon-blue), 0 0 20px var(--neon-green);
    margin: 0 0 40px 0;
    letter-spacing: 5px;
    animation: floatTitle 3s ease-in-out infinite;
    transform: perspective(500px) rotateX(10deg);
    text-align: center;
}

@keyframes floatTitle {

    0%,
    100% {
        transform: perspective(500px) rotateX(10deg) translateY(0);
    }

    50% {
        transform: perspective(500px) rotateX(5deg) translateY(-10px);
    }
}

/* AUDIO & VOLUME WIDGET */
#audio-controls {
    position: fixed;
    top: 20px;
    right: 50px;
    /* Moved inwards from 20px */
    display: flex;
    gap: 15px;
    align-items: flex-end;
    z-index: 1020;
}

#volume-widget {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    cursor: pointer;
}

.vol-label {
    font-size: 0.8rem;
    color: var(--neon-green);
    margin-right: 2px;
}

.vol-bars {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 30px;
}

.vol-bar {
    width: 6px;
    background: #333;
    cursor: pointer;
    transition: background 0.1s, height 0.1s, opacity 0.1s;
    border-radius: 1px;
}

.vol-off {
    height: 30%;
    margin-right: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--error-red);
    font-size: 0.8rem;
    font-weight: bold;
    width: 12px;
    /* Bigger target */
}

/* Manual Staggering */
.vol-bar:not(.vol-off):nth-child(2) {
    height: 30%;
}

.vol-bar:not(.vol-off):nth-child(3) {
    height: 37%;
}

.vol-bar:not(.vol-off):nth-child(4) {
    height: 44%;
}

.vol-bar:not(.vol-off):nth-child(5) {
    height: 51%;
}

.vol-bar:not(.vol-off):nth-child(6) {
    height: 58%;
}

.vol-bar:not(.vol-off):nth-child(7) {
    height: 65%;
}

.vol-bar:not(.vol-off):nth-child(8) {
    height: 72%;
}

.vol-bar:not(.vol-off):nth-child(9) {
    height: 79%;
}

.vol-bar:not(.vol-off):nth-child(10) {
    height: 86%;
}

.vol-bar:not(.vol-off):nth-child(11) {
    height: 100%;
}

.vol-bar.active {
    background: var(--neon-green);
    box-shadow: 0 0 5px var(--neon-green);
}

.vol-bar:hover {
    background: #fff;
}

/* LAYOUT & CONTAINERS */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    padding: 20px;
    height: 100vh;
    overflow-y: hidden;
    /* Prevent body scroll */
}

.screen.active {
    display: flex;
}

.game-layout {
    flex-direction: row;
    justify-content: center;
    gap: 20px;
    align-items: flex-start;
    padding-top: 60px;
}

/* RESPONSIVE DESIGN */
/* LOGIN FLEX FIXES */
.join-actions {
    display: flex;
    gap: 10px;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    /* Allow wrap on very small screens */
}

@media (max-width: 900px) {

    /* MOBILE VOLUME & UI FIX */
    #volume-widget {
        display: none !important;
    }

    #mobile-vol-controls {
        display: flex !important;
        align-items: center;
        /* Position at bottom right to avoid header overlap */
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 2000;
        background: rgba(0, 0, 0, 0.8);
        border: 1px solid var(--neon-blue);
        border-radius: 4px;
        padding: 5px;
    }

    #mobile-vol-display {
        color: var(--neon-blue);
        font-family: 'VT323', monospace;
    }

    h1.balatro-title {
        font-size: 3.5rem;
    }

    .game-layout {
        flex-direction: column;
        align-items: center;
        padding-top: 10px;
        justify-content: flex-start;
        height: 100vh;
    }

    /* Fixed Header for Mobile */
    .game-header {
        flex-wrap: wrap;
        font-size: 0.9rem;
        gap: 5px;
        justify-content: center;
        width: 100%;
        margin-bottom: 5px;
    }

    .game-header button {
        padding: 5px 10px;
        font-size: 0.9rem;
    }

    #room-display,
    #deck-info {
        font-size: 0.9rem;
    }

    .game-main {
        width: 100%;
        order: 1;
        flex: 1;
        overflow-y: hidden;
        /* Prevent main scroll */
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    /* Better Bottom Bar */
    .game-sidebar {
        width: 100% !important;
        height: 25vh !important;
        /* Taller for chat */
        order: 2;
        border-left: none !important;
        border-top: 2px solid var(--neon-green);
        padding-left: 0 !important;
        padding: 10px;
        flex-direction: column !important;
        /* Stack msgs and input */
        gap: 5px;
        background: #000;
        z-index: 100;
    }

    /* CARD SIZING FIX */
    .card-container {
        margin: 5px 0;
        min-height: auto;
        transform: none;
        /* remove scale */
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        /* Prevent vertical stretching */
        gap: 5px;
    }

    .card {
        width: 22%;
        /* Fluid width */
        height: auto;
        aspect-ratio: 2.5 / 3.5;
        max-width: 70px;
        /* Cap it so it doesn't get huge */
    }

    .controls-container {
        width: 98%;
        gap: 5px;
    }

    .control-btn {
        font-size: 1.5rem;
        padding: 5px 0;
    }

    /* Fixed Chat Input for Mobile */
    .chat-input-row {
        flex-direction: row !important;
        justify-content: space-between;
        width: 100%;
        gap: 5px;
        height: 40px;
    }

    #chat-messages {
        flex: 1;
        border-bottom: 1px dashed #333;
        width: 100%;
        font-size: 0.8rem;
        margin-bottom: 5px;
    }

    .game-sidebar h3 {
        display: none;
    }

    #chat-input {
        flex: 1;
        font-size: 1rem;
        width: auto;
        /* Let flex handle it */
    }

    #btn-chat-send {
        width: 50px;
    }

    /* Login Mobile Tweaks */
    .join-actions {
        flex-direction: column;
        align-items: center;
    }

    .join-actions input {
        width: 100%;
    }

    .join-actions button {
        width: 100%;
    }
}

@media (max-width: 400px) {
    .card {
        width: 65px;
        height: 91px;
    }

    h1.balatro-title {
        font-size: 3rem;
    }
}


/* LOGIN PANEL */
.login-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: rgba(0, 0, 0, 0.8);
    padding: 30px;
    border: 2px solid var(--neon-pink);
    border-radius: 15px;
    box-shadow: 0 0 30px rgba(255, 0, 255, 0.2);
    align-items: center;
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.8;
    margin-top: 10px;
    color: var(--error-red);
    text-shadow: 0 0 5px var(--error-red);
    text-align: center;
}

/* BUTTONS & INPUTS */
input {
    background: #000;
    border: 2px solid var(--neon-green);
    color: var(--neon-green);
    font-family: 'VT323', monospace;
    font-size: 2rem;
    padding: 10px;
    text-align: center;
    outline: none;
    box-shadow: 0 0 10px var(--neon-green);
    width: 350px;
    /* Widened from 250px */
    text-transform: uppercase;
    max-width: 100%;
}

button {
    font-family: 'VT323', monospace;
    font-size: 1.5rem;
    padding: 10px 20px;
    border: none;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: bold;
    transition: all 0.1s;
}

.neon-btn {
    background: transparent;
    border: 2px solid var(--neon-blue);
    color: var(--neon-blue);
    box-shadow: 0 0 10px var(--neon-blue), inset 0 0 10px var(--neon-blue);
}

.neon-btn:hover {
    background: var(--neon-blue);
    color: #000;
    box-shadow: 0 0 20px var(--neon-blue);
}

.red-btn {
    background: transparent;
    border: 2px solid var(--error-red);
    color: var(--error-red);
}

.red-btn:hover {
    background: var(--error-red);
    color: #000;
    box-shadow: 0 0 20px var(--error-red);
}

.control-btn {
    background: #000;
    color: var(--neon-blue);
    border: 2px solid var(--neon-blue);
    font-size: 1.8rem;
    padding: 10px 0;
    width: 50px;
    box-shadow: 0 0 5px var(--neon-blue);
    cursor: pointer;
    flex: 1;
}

.control-btn.action {
    color: var(--neon-pink);
    border-color: var(--neon-pink);
    box-shadow: 0 0 5px var(--neon-pink);
}

.control-btn.submit-btn {
    flex-grow: 2;
    background: rgba(255, 0, 255, 0.1);
}

/* GAME ELEMENTS */
.game-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    border-bottom: 2px solid var(--neon-pink);
    padding-bottom: 10px;
    align-items: center;
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.leaderboard {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.score-pill {
    font-size: 1rem;
    padding: 5px 10px;
    border: 1px solid #444;
    border-radius: 4px;
}

.score-pill.loser {
    border-color: var(--error-red);
    color: var(--error-red);
}

.card-container {
    display: flex;
    gap: 15px;
    justify-content: center;
    perspective: 1000px;
    margin: 20px 0;
    min-height: 200px;
}

.card {
    width: 140px;
    height: 196px;
    background-size: 100% 100%;
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s, filter 0.2s;
    image-rendering: pixelated;
    border: 1px solid #333;
    cursor: pointer;
}

.card:hover {
    transform: translateY(-10px) scale(1.05);
    z-index: 10;
    box-shadow: 0 0 15px var(--neon-green);
}

.card.used {
    filter: grayscale(100%) brightness(0.4);
    pointer-events: none;
    transform: scale(0.95);
}

.controls-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 450px;
}

.ops-row {
    display: flex;
    gap: 10px;
    /* Arcadey spacing but not too tight */
}

/* SIDEBAR & MODALS */
.game-sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
    border-left: 1px dashed var(--neon-green);
    padding-left: 20px;
}

.chat-msg {
    margin: 5px 0;
    border-bottom: 1px solid #333;
    word-wrap: break-word;
}

.chat-msg .name {
    color: var(--neon-green);
    font-weight: bold;
}

.chat-msg .content {
    color: #fff;
}

.modal-box {
    background: rgba(0, 0, 0, 0.95);
    padding: 30px;
    border: 1px solid var(--neon-blue);
    text-align: center;
    max-width: 90%;
    width: 500px;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.winner-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    /* Smaller for mobile safety */
    color: var(--neon-green);
    text-shadow: 0 0 30px #fff;
    z-index: 200;
    display: none;
    pointer-events: none;
    animation: bounce 0.5s infinite alternate;
    width: 100%;
    text-align: center;
}

@keyframes bounce {
    from {
        transform: translate(-50%, -50%) scale(1);
    }

    to {
        transform: translate(-50%, -50%) scale(1.1);
    }
}

/* ADDED UTILS & MODAL STYLES */
.small {
    font-size: 1rem !important;
    padding: 5px 10px !important;
}

.modal-box.small-modal {
    width: 400px;
    border-color: var(--neon-blue);
    padding: 20px;
}

/* Specific for Lobby Leave to separate it */
#btn-lobby-leave {
    opacity: 0.7;
    transition: opacity 0.2s;
}

#btn-lobby-leave:hover {
    opacity: 1;
}

.footer-credit {
    margin-top: 20px;
    font-size: 0.8rem;
    opacity: 0.6;
}

.footer-credit a {
    color: var(--neon-pink);
    text-decoration: none;
}