@font-face {
    font-family: 'C64ProMono';
    src: url('/dscene/C64_Pro_Mono-STYLE.ttf') format('truetype');
}

:root {
    --c64-black: #000000;
    --c64-white: #ffffff;
    --c64-red: #880000;
    --c64-cyan: #aeeeef;
    --c64-purple: #cc44cc;
    --c64-green: #00cc55;
    --c64-blue: #0000aa;
    --c64-yellow: #eeee77;
    --c64-orange: #dd8855;
    --c64-brown: #664400;
    --c64-light-red: #ff7777;
    --c64-dark-grey: #333333;
    --c64-grey: #777777;
    --c64-light-green: #aaff66;
    --c64-light-blue: #0088ff;
    --c64-light-grey: #bbbbbb;
    --c64-frame-blue: #7c70da;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'C64ProMono', monospace;
    text-transform: uppercase;
    user-select: none;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
    position: fixed;
    inset: 0;
    background-color: #050508;
    color: var(--c64-light-blue);
    display: flex;
    justify-content: center;
    align-items: center;
}

#monitor-container {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    background-color: var(--c64-frame-blue);
    border: 6px solid var(--c64-frame-blue);
    box-shadow: inset 0 0 50px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    overflow: hidden;
    touch-action: none;
}

#c64-header {
    width: 100%;
    background-color: var(--c64-frame-blue);
    color: #4034a0;
    text-align: center;
    font-size: 1.15rem;
    padding: 3px 0;
    letter-spacing: 1px;
    font-weight: bold;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#btn-home {
    position: absolute;
    left: 8px;
    font-size: 0.85rem;
    color: #4034a0;
    text-decoration: none;
    padding: 0 6px;
    transition: color 0.1s;
}

#btn-home:hover {
    color: var(--c64-white);
}

#c64-footer {
    width: 100%;
    background-color: var(--c64-frame-blue);
    color: #4034a0;
    text-align: center;
    font-size: 0.85rem;
    padding: 3px 0;
    letter-spacing: 1px;
    font-weight: bold;
    flex-shrink: 0;
}

/* Pantalla de bienvenida */
#welcome-screen {
    width: 100%;
    flex: 1;
    background-color: var(--c64-blue);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.welcome-box {
    text-align: center;
    max-width: 90%;
    color: var(--c64-cyan);
}

.welcome-box h1 {
    font-size: 2rem;
    color: var(--c64-light-blue);
    text-shadow: 2px 2px #000;
    margin-bottom: 10px;
}

.welcome-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--c64-yellow);
    text-shadow: 4px 4px var(--c64-black);
    margin-bottom: 5px;
    letter-spacing: 2px;
}

.welcome-subtitle {
    font-size: 1.1rem;
    color: var(--c64-white);
    margin-bottom: 25px;
    text-shadow: 2px 2px #000;
}

.instructions {
    border: 3px double var(--c64-cyan);
    padding: 15px;
    margin-bottom: 25px;
    background-color: rgba(0, 0, 0, 0.4);
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--c64-light-grey);
}

.setup-row {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 30px;
}

.menu-btn {
    background-color: var(--c64-blue);
    color: var(--c64-cyan);
    border: 3px solid var(--c64-cyan);
    padding: 8px 16px;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 4px 4px 0px #000;
}

.menu-btn.active {
    background-color: var(--c64-purple);
    color: var(--c64-white);
    border-color: var(--c64-white);
}

#btn-start-game {
    background-color: var(--c64-green);
    color: var(--c64-black);
    border: 3px solid var(--c64-white);
    padding: 12px 24px;
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 4px 4px 0px #000;
}

#btn-start-game:hover {
    background-color: var(--c64-white);
}

/* Pantalla del juego */
#game-screen {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#hud {
    width: 100%;
    background-color: var(--c64-blue);
    color: var(--c64-cyan);
    padding: 6px 12px;
    border-bottom: 4px solid var(--c64-frame-blue);
    flex-shrink: 0;
}

.hud-row {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
}

.hud-score {
    font-size: 1.4rem;
    text-shadow: 2px 2px #000;
}

#p1-name { color: var(--c64-light-red); }
#p2-name { color: var(--c64-cyan); }
#p3-name { color: var(--c64-light-green); }

#canvas-wrapper {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--c64-black);
    overflow: hidden;
}

#gameCanvas {
    display: block;
    background-color: var(--c64-grey);
    image-rendering: pixelated;
    width: 100%;
    height: 100%;
    object-fit: fill; /* Ocupa el 100% de la pantalla CRT */
    box-shadow: 0 0 30px rgba(0,0,0,0.9);
}

/* Modal Overlay Retro */
#overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
}

#overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-c64 {
    background-color: var(--c64-blue);
    border: 4px solid var(--c64-cyan);
    padding: 24px 32px;
    text-align: center;
    box-shadow: 8px 8px 0px #000;
    max-width: 90%;
}

.modal-c64 h1 {
    font-size: 2.0rem;
    color: var(--c64-yellow);
    text-shadow: 3px 3px 0px var(--c64-black);
    margin-bottom: 12px;
}

.modal-c64 p {
    font-size: 1.4rem;
    color: var(--c64-white);
    margin-bottom: 20px;
    text-shadow: 2px 2px 0px var(--c64-black);
}

.btn-container {
    display: flex;
    justify-content: center;
    gap: 12px;
}

button {
    background-color: var(--c64-cyan);
    color: var(--c64-blue);
    border: 3px solid var(--c64-white);
    padding: 10px 20px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 4px 4px 0px #000;
    transition: all 0.1s;
}

button:hover {
    background-color: var(--c64-white);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0px #000;
}

button:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px #000;
}

/* Animaciones C64 */
.blink-fast {
    animation: blinker 0.4s linear infinite;
}

.blink-slow {
    animation: blinker 1.2s linear infinite;
}

@keyframes blinker {
    50% { opacity: 0; }
}

.hidden {
    display: none !important;
}

/* Responsividad para móviles */
@media (max-width: 600px) {
    .welcome-title {
        font-size: 1.8rem;
    }
    
    .instructions {
        font-size: 0.8rem;
        padding: 8px;
    }
    
    .setup-row {
        flex-direction: column;
        gap: 10px;
        align-items: center;
    }
    
    .menu-btn {
        width: 100%;
        max-width: 260px;
    }
    
    #c64-header, #c64-footer {
        font-size: 0.75rem;
    }
    
    .hud-score {
        font-size: 1.1rem;
    }
    
    .btn-container {
        flex-direction: column;
        gap: 10px;
    }
    
    button {
        width: 100%;
    }
}

/* ─────────────────────────────────────────────
   ONLINE WEB-RTC MATCHMAKING STYLE
   ─────────────────────────────────────────── */
.mode-select-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--c64-frame-blue);
    padding-bottom: 10px;
}

.tab-btn {
    background-color: transparent;
    color: var(--c64-light-blue);
    border: none;
    box-shadow: none;
    font-size: 1.1rem;
    padding: 6px 12px;
    cursor: pointer;
}

.tab-btn:hover {
    background-color: transparent;
    color: var(--c64-white);
    transform: none;
    box-shadow: none;
}

.tab-btn.active {
    color: var(--c64-yellow);
    border-bottom: 3px solid var(--c64-yellow);
    font-weight: bold;
}

.tab-btn.disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: not-allowed;
}

.setup-container {
    animation: fadeIn 0.3s ease-out;
}

.online-box-split {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
    background-color: rgba(0,0,0,0.3);
    padding: 15px;
    border: 2px double var(--c64-cyan);
}

.online-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.online-panel h3 {
    font-size: 0.95rem;
    color: var(--c64-light-blue);
    text-shadow: 1px 1px #000;
}

.divider-v {
    width: 2px;
    background-color: var(--c64-frame-blue);
    align-self: stretch;
}

#input-room-code {
    width: 100%;
    max-width: 160px;
    background-color: var(--c64-black);
    color: var(--c64-yellow);
    border: 2px solid var(--c64-cyan);
    padding: 8px;
    font-size: 1rem;
    text-align: center;
    font-family: 'C64ProMono', monospace;
    outline: none;
}

.code-highlight {
    color: var(--c64-yellow);
    font-size: 1.4rem;
    font-weight: bold;
    letter-spacing: 2px;
    background-color: var(--c64-black);
    padding: 4px 10px;
    border: 1px solid var(--c64-yellow);
    margin-left: 5px;
    display: inline-block;
}

.status-msg {
    font-size: 0.85rem;
    color: var(--c64-light-green);
    text-align: center;
    margin-top: 8px;
}

.status-sub {
    font-size: 0.75rem;
    color: var(--c64-light-grey);
    margin-top: 4px;
    animation: blinker 1s steps(2, start) infinite;
}

.error-msg {
    color: var(--c64-light-red);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 10px;
    border: 1px solid var(--c64-red);
    padding: 6px;
    background-color: rgba(136, 0, 0, 0.2);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 600px) {
    .online-box-split {
        flex-direction: column;
        gap: 15px;
    }
    .divider-v {
        width: 100%;
        height: 2px;
    }
}

/* ─────────────────────────────────────────────
   ROTATION OVERLAY & ORIENTATION FIXES
   ─────────────────────────────────────────── */
#rotation-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: var(--c64-blue);
    z-index: 99999;
    justify-content: center;
    align-items: center;
    padding: 20px;
    text-align: center;
    box-shadow: inset 0 0 80px rgba(0,0,0,0.8);
    border: 8px solid var(--c64-frame-blue);
}

#rotation-overlay .welcome-box {
    max-width: 500px;
}

#rotation-overlay h1 {
    font-size: 1.8rem;
    color: var(--c64-light-red);
    text-shadow: 2px 2px #000;
    margin-bottom: 12px;
}

#rotation-overlay .welcome-title {
    font-size: 2.0rem;
    color: var(--c64-yellow);
    text-shadow: 3px 3px var(--c64-black);
    margin-bottom: 8px;
}

#rotation-overlay .welcome-subtitle {
    font-size: 0.95rem;
    color: var(--c64-white);
    margin-bottom: 20px;
    line-height: 1.4;
}

#rotation-overlay .instructions {
    border: 3px double var(--c64-cyan);
    padding: 12px;
    background-color: rgba(0, 0, 0, 0.4);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--c64-light-grey);
}

/* Mostrar overlay de rotación si la pantalla es vertical (Portrait) en móviles o tablets */
@media (orientation: portrait) and (max-width: 1024px) {
    #rotation-overlay {
        display: flex;
    }
    #monitor-container {
        display: none !important;
    }
}

/* Optimización para Pantallas de Baja Altura (Móviles en Apaisado/Landscape) */
@media (max-height: 480px) {
    #c64-header {
        font-size: 0.9rem;
        padding: 1px 0;
    }
    #c64-footer {
        font-size: 0.75rem;
        padding: 1px 0;
    }
    
    #monitor-container {
        border-width: 3px;
    }

    #welcome-screen {
        padding: 6px 15px;
    }

    .welcome-box h1 {
        font-size: 1.1rem;
        margin-bottom: 2px;
    }

    .welcome-title {
        font-size: 1.5rem;
        margin-bottom: 2px;
        letter-spacing: 1px;
    }

    .welcome-subtitle {
        font-size: 0.8rem;
        margin-bottom: 8px;
    }

    .instructions {
        padding: 4px 10px;
        margin-bottom: 8px;
        font-size: 0.7rem;
        line-height: 1.2;
    }
    
    .mode-select-row {
        margin-bottom: 8px;
        padding-bottom: 4px;
        gap: 10px;
    }
    
    .tab-btn {
        font-size: 0.85rem;
        padding: 2px 6px;
    }

    .setup-row {
        gap: 6px;
        margin-bottom: 8px;
    }

    .menu-btn {
        padding: 4px 10px;
        font-size: 0.75rem;
        border-width: 2px;
        box-shadow: 2px 2px 0px #000;
    }

    #btn-start-game {
        padding: 6px 16px;
        font-size: 0.95rem;
        border-width: 2px;
        box-shadow: 2px 2px 0px #000;
    }
    
    .online-box-split {
        gap: 10px;
        margin-bottom: 6px;
        padding: 6px;
        border-width: 1px;
    }
    
    .online-panel h3 {
        font-size: 0.75rem;
        margin-bottom: 4px;
    }
    
    #btn-create-room, #btn-join-room {
        padding: 4px 10px;
        font-size: 0.75rem;
        border-width: 2px;
        box-shadow: 2px 2px 0px #000;
    }
    
    #input-room-code {
        padding: 4px;
        font-size: 0.8rem;
        border-width: 2px;
    }
    
    .code-highlight {
        font-size: 0.95rem;
        padding: 2px 6px;
    }
    
    .status-msg, .error-msg {
        font-size: 0.7rem;
        margin-top: 4px;
        padding: 3px;
    }
}

/* Filtros CRT retro de Nitas */
.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%, 
        rgba(0, 0, 0, 0.15) 50%
    );
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 99;
}

.crt-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        circle, 
        rgba(255, 255, 255, 0.03) 0%, 
        rgba(0, 0, 0, 0.25) 100%
    );
    pointer-events: none;
    z-index: 100;
}

/* Pantalla de Carga C64 Retro */
#c64-loader {
    position: fixed;
    inset: 0;
    background-color: #3e31a1;
    color: #7c70da;
    z-index: 999999;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'C64ProMono', monospace;
    text-transform: uppercase;
    transition: opacity 0.4s ease-out;
}

#c64-loader.loading-border {
    animation: c64BorderFlash 0.15s infinite;
}

#c64-loader .loader-content {
    background-color: #3e31a1;
    border: 32px solid #7c70da;
    width: 100%;
    height: 100%;
    padding: 30px;
    font-size: 0.95rem;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    box-sizing: border-box;
}

#c64-loader.loading-border .loader-content {
    border-color: transparent;
}

@keyframes c64BorderFlash {
    0% { background-color: #0000aa; border-color: #00cc55; }
    20% { background-color: #880000; border-color: #cc44cc; }
    40% { background-color: #777777; border-color: #eeee77; }
    60% { background-color: #dd8855; border-color: #0088ff; }
    80% { background-color: #664400; border-color: #ff7777; }
    100% { background-color: #000000; border-color: #aeeeef; }
}

#c64-loader .cursor {
    display: inline-block;
    width: 10px;
    height: 12px;
    background-color: #7c70da;
    animation: c64CursorBlink 0.5s steps(2, start) infinite;
    vertical-align: middle;
    margin-left: 2px;
}

@keyframes c64CursorBlink {
    to { visibility: hidden; }
}



