:root {
    --bg: #060010;
    --bg-secondary: #0f0a1f;
    --bg-card: #1a1430;
    --text: #e8eaed;
    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --border: rgba(139, 92, 246, 0.3);
    --border-subtle: rgba(255, 255, 255, 0.05);
    --danger: #ef476f;
    --success: #22c55e;
    --muted: #9ca3af;
}

* { box-sizing: border-box; }

html {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

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

/* ========== SCROLLBAR PERSONALIZADO ========== */
/* Para navegadores basados en WebKit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--accent), #7c3aed);
    border-radius: 10px;
    border: 2px solid rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--accent-hover), var(--accent));
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.5);
}

::-webkit-scrollbar-thumb:active {
    background: var(--accent);
}

/* Para Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--accent) rgba(0, 0, 0, 0.2);
}

body {
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Noto Sans, "Apple Color Emoji", "Segoe UI Emoji";
    background: radial-gradient(1200px 800px at 20% -10%, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0) 60%),
                radial-gradient(1200px 800px at 120% 10%, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0) 60%),
                var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    height: 100%;
    overflow: hidden;
    gap: 12px;
}

#pageTitle {
    font-size: 2rem;
    letter-spacing: 2px;
    margin: 0;
    font-weight: 900;
}

/* Título más grande en PC */
@media (min-width: 769px) {
    #pageTitle {
        font-size: 3rem;
        letter-spacing: 4px;
    }
}

.accent { color: var(--accent); }

/* Efecto Fuzzy Text */
.fuzzy-title {
    position: relative;
    color: #fff;
    animation: fuzzy 1.5s infinite;
    filter: blur(0);
}

@keyframes fuzzy {
    0% {
        text-shadow: 
            2px 0 0 rgba(255, 0, 0, 0.7),
            -2px 0 0 rgba(0, 255, 255, 0.7),
            0 0 20px rgba(139, 92, 246, 0.5);
        filter: blur(0.5px);
    }
    20% {
        text-shadow: 
            -2px 0 0 rgba(255, 0, 0, 0.8),
            2px 0 0 rgba(0, 255, 255, 0.8),
            0 0 25px rgba(139, 92, 246, 0.6);
        filter: blur(0.8px);
    }
    40% {
        text-shadow: 
            3px 0 0 rgba(255, 0, 0, 0.6),
            -3px 0 0 rgba(0, 255, 255, 0.6),
            0 0 15px rgba(139, 92, 246, 0.4);
        filter: blur(0.3px);
    }
    60% {
        text-shadow: 
            -1px 0 0 rgba(255, 0, 0, 0.9),
            1px 0 0 rgba(0, 255, 255, 0.9),
            0 0 30px rgba(139, 92, 246, 0.7);
        filter: blur(1px);
    }
    80% {
        text-shadow: 
            2px 0 0 rgba(255, 0, 0, 0.7),
            -2px 0 0 rgba(0, 255, 255, 0.7),
            0 0 20px rgba(139, 92, 246, 0.5);
        filter: blur(0.6px);
    }
    100% {
        text-shadow: 
            2px 0 0 rgba(255, 0, 0, 0.7),
            -2px 0 0 rgba(0, 255, 255, 0.7),
            0 0 20px rgba(139, 92, 246, 0.5);
        filter: blur(0.5px);
    }
}

#lobby, #waiting, #game, #admin {
    width: 100%;
    max-width: 720px;
    background: linear-gradient(180deg, rgba(139, 92, 246, 0.05), rgba(139, 92, 246, 0.02));
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 10px 40px rgba(139, 92, 246, 0.15), inset 0 1px 0 rgba(139, 92, 246, 0.1);
    backdrop-filter: blur(12px);
    overflow-y: auto;
    max-height: calc(100vh - 80px);
}

#waiting {
    padding: 10px;
    overflow-y: visible;
    overflow-x: hidden;
    max-width: 1100px;
    text-align: center;
}

#waitingPlayersList {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin: 0;
}

#gameContainer {
    display: none !important;
    height: calc(100vh - 40px);
    justify-content: center;
    align-items: center;
}

#gameContainer[style*="display: flex"],
#gameContainer[style*="display: block"] {
    display: flex !important;
    justify-content: center;
    align-items: center;
}

@media (max-width: 768px) {
    #gameContainer {
        display: none !important;
    }
    
    #gameContainer[style*="display: flex"],
    #gameContainer[style*="display: block"] {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 60px !important;
        row-gap: 8px !important;
        height: 100vh !important;
        height: 100dvh !important;
        min-height: auto;
        justify-content: center !important;
        align-items: center !important;
        align-content: center !important;
        padding: 0 8px !important;
        margin: 0 !important;
    }
    
    #game {
        order: -1 !important;
        max-height: none !important;
        height: auto !important;
        width: 100% !important;
        flex: 0 1 auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    #game > * {
        margin-bottom: 4px !important;
    }
    
    #game .row {
        margin-top: 4px !important;
        margin-bottom: 0 !important;
    }
    
    #game #inputError {
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    #myStickman,
    #turnStickman {
        order: 999 !important;
        margin: 0 !important;
        padding-top: 0 !important;
    }
}

#game {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#chat {
    width: 100%;
    flex: 1;
    min-height: 0;
    border: 1px solid var(--border);
    background: rgba(0,0,0,0.2);
    overflow-y: auto;
    padding: 12px;
    border-radius: 12px;
}

#hud {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 8px 0 6px;
}

#hud .pill {
    background: rgba(255,255,255,0.08);
}

.row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 8px 0;
}

.grow { flex: 1; }
.muted { color: var(--muted); font-size: .92em; }

#error {
    color: var(--danger);
    min-height: 1.2em;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(139, 92, 246, 0.05);
    color: var(--text);
    outline: none;
    transition: all 0.3s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.1);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

/* Ocultar las flechas del input number */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background:
      linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02)),
      rgba(255,255,255,0.04);
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23e7e9f7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108,92,231,0.25);
}

select:hover { filter: brightness(1.05); }
input:disabled, select:disabled { opacity: .6; cursor: not-allowed; }

button {
    padding: 10px 14px;
    font-size: .98rem;
    border-radius: 10px;
    border: 1px solid var(--accent);
    background: linear-gradient(180deg, var(--accent), #7c3aed);
    color: white;
    cursor: pointer;
    transition: transform .05s ease, filter .2s ease, box-shadow .2s ease;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

button:hover { 
    filter: brightness(1.1); 
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
}
button:active { transform: translateY(1px); }

.btn-secondary {
    background: rgba(255,255,255,0.06);
    color: var(--text);
}

.btn-selected {
    filter: brightness(1.12);
    box-shadow: 0 0 0 3px rgba(34,211,238,0.25) inset;
}

.badge, .pill {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border);
    font-size: .85rem;
}

/* Chat bubbles */
#chat .msg {
    display: flex;
    gap: 8px;
    align-items: baseline;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 10px;
    margin: 6px 0;
}

#chat .msg b {
    color: var(--accent);
    font-weight: 700;
}

#chat .msg.system {
    background: rgba(255,255,255,0.02);
    color: var(--muted);
}

/* Players list */
#playersList {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.9rem;
}

.chip .avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(180deg, #2dd4bf, #0ea5e9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: .8rem;
}

/* Stickman canvas */
#myStickmanCanvas,
#turnStickmanCanvas {
    background: transparent;
    border-radius: 8px;
}

#myStickman,
#turnStickman {
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.00));
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.04);
    backdrop-filter: blur(6px);
}

/* Modal */
.backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    width: 520px;
    max-width: 92vw;
    background: linear-gradient(180deg, #1a1430, #0f0a1f);
    color: var(--text);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,.8);
    padding: 18px;
    border: 2px solid var(--accent);
}

.modal h3 {
    margin: 0 0 12px 0;
    font-weight: 700;
    font-size: 1.5rem;
    text-align: center;
    color: #fff;
}

/* Animación trail para el título */
.pressure-letter {
    display: inline-block;
    color: #fff;
    font-weight: 900;
    animation: letterBounce 0.6s ease backwards;
    position: relative;
    will-change: filter;
}

.pressure-letter:nth-child(1) { animation-delay: 0.05s; }
.pressure-letter:nth-child(2) { animation-delay: 0.1s; }
.pressure-letter:nth-child(3) { animation-delay: 0.15s; }
.pressure-letter:nth-child(4) { animation-delay: 0.2s; }
.pressure-letter:nth-child(5) { animation-delay: 0.25s; }
.pressure-letter:nth-child(6) { animation-delay: 0.3s; }
.pressure-letter:nth-child(7) { animation-delay: 0.35s; }
.pressure-letter:nth-child(8) { animation-delay: 0.4s; }

#titleImpostor {
    letter-spacing: 8px;
    font-weight: 900;
    cursor: default;
}

@keyframes letterBounce {
    0% {
        opacity: 0;
        transform: translateY(-30px) scale(0.3);
    }
    50% {
        transform: translateY(5px) scale(1.1);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ========== RESPONSIVE MOBILE ========== */

/* Tablets y pantallas medianas */
@media (max-width: 1000px) {
    #waiting {
        max-width: 720px;
    }
    
    #waitingMainGrid {
        grid-template-columns: 1fr !important;
    }
    
    #adminSidePanel {
        margin-top: 8px;
    }
}

/* Móviles - Ajustes generales */
@media (max-width: 768px) {
    html {
        height: 100vh;
        height: 100dvh;
    }
    
    body {
        padding: 8px;
        gap: 8px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Pantalla de bienvenida responsive */
    #welcomeScreen {
        width: 100%;
        min-height: 100%;
    }
    
    #titleImpostor {
        font-size: 12vw !important;
        top: 45% !important;
    }
    
    #welcomeScreen > div {
        bottom: 15% !important;
        width: calc(100% - 40px) !important;
    }
    
    #pageTitle {
        font-size: 1.5rem;
        letter-spacing: 1px;
    }
    
    #lobby, #waiting, #game, #admin {
        padding: 12px;
        max-height: calc(100vh - 60px);
    }
    
    /* Botones más grandes para touch */
    button {
        padding: 12px 16px;
        font-size: 1rem;
        min-height: 44px; /* Tamaño mínimo recomendado para touch */
    }
    
    input[type="text"],
    input[type="number"],
    select {
        padding: 12px;
        font-size: 16px; /* Evita zoom en iOS */
        min-height: 44px;
    }
    
    /* Modal más pequeño */
    .modal {
        width: 90vw;
        padding: 16px;
    }
    
    /* Lobby - Grid responsive */
    #lobby > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Sala de espera */
    #waitingPlayersList {
        gap: 8px;
    }
    
    /* Chat más compacto */
    #chat .msg {
        padding: 6px 8px;
        font-size: 0.9rem;
    }
}

/* Móviles - Vista de juego responsive */
@media (max-width: 768px) {
    /* Contenedor de stickmen debajo del chat - LADO A LADO */
    #myStickman,
    #turnStickman {
        flex: 0 0 auto !important;
        width: 48% !important;
        max-width: 160px;
        padding: 12px;
        display: flex !important;
        flex-direction: column !important;
    }
    
    #myStickman {
        margin-right: 0;
    }
    
    /* Canvas más pequeños */
    #myStickmanCanvas,
    #turnStickmanCanvas {
        width: 100px !important;
        height: 140px !important;
    }
    
    /* HUD más compacto */
    #hud {
        gap: 4px;
        margin: 6px 0;
    }
    
    #hud .pill {
        font-size: 0.75rem;
        padding: 3px 6px;
    }
    
    /* Lista de jugadores más compacta */
    #playersList {
        gap: 4px;
        margin-bottom: 8px;
    }
    
    .chip {
        font-size: 0.8rem;
        padding: 3px 6px;
    }
    
    .chip .avatar {
        width: 18px;
        height: 18px;
        font-size: 0.7rem;
    }
    
    /* Chat más pequeño en móvil */
    #chat {
        min-height: 200px;
        max-height: 35vh;
        padding: 8px;
    }
    
    /* Input de pista */
    .row {
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 8px;
    }
    
    #pistaInput {
        width: 100%;
        flex: 1 1 100%;
        margin-bottom: 0;
    }
    
    #sendBtn,
    #skipTurnBtn {
        flex: 1 1 calc(50% - 4px);
        min-width: calc(50% - 4px);
        max-width: calc(50% - 4px);
        padding: 12px 8px;
        font-size: 0.95rem;
        white-space: nowrap;
    }
    
    /* Asegurar que los botones se vean */
    #sendBtn {
        display: inline-block !important;
    }
    
    #skipTurnBtn[style*="display: none"] {
        display: none !important;
    }
    
    #skipTurnBtn:not([style*="display: none"]) {
        display: inline-block !important;
    }
}

/* Móviles pequeños (< 480px) */
@media (max-width: 480px) {
    #pageTitle {
        font-size: 1.2rem;
    }
    
    body {
        padding: 4px;
    }
    
    #lobby, #waiting, #game, #admin {
        padding: 8px;
        border-radius: 12px;
    }
    
    /* Stickmen aún más pequeños */
    #myStickman,
    #turnStickman {
        width: 48% !important;
        max-width: 130px;
        padding: 8px;
    }
    
    #myStickman {
        margin-right: 0;
    }
    
    #myStickmanCanvas,
    #turnStickmanCanvas {
        width: 80px !important;
        height: 120px !important;
    }
    
    /* Chat más compacto */
    #chat {
        min-height: 150px;
        max-height: 30vh;
        padding: 6px;
    }
    
    #chat .msg {
        padding: 4px 6px;
        font-size: 0.85rem;
        margin: 4px 0;
    }
    
    /* Botones más visibles en móviles pequeños */
    #sendBtn,
    #skipTurnBtn {
        flex: 1 1 calc(50% - 4px);
        min-width: calc(50% - 4px);
        max-width: calc(50% - 4px);
        padding: 12px 6px;
        font-size: 0.9rem;
    }
    
    .row {
        gap: 6px;
    }
}

/* Landscape en móviles */
@media (max-width: 900px) and (orientation: landscape) {
    body {
        overflow-y: auto;
    }
    
    #gameContainer {
        flex-direction: row !important;
        height: auto !important;
    }
    
    #myStickman,
    #turnStickman {
        flex: 0 0 100px !important;
        width: 100px !important;
    }
    
    #game {
        max-height: calc(100vh - 100px);
    }
    
    #chat {
        max-height: 40vh;
    }
}

/* Editor de Avatar */
.color-btn {
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
}

.color-btn:active {
    transform: scale(0.95);
}

#avatarCanvas {
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    image-rendering: -webkit-optimize-contrast;
    image-rendering: smooth;
}

#avatarPreview {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#avatarPreview:hover {
    transform: scale(1.05);
    transition: transform 0.2s ease;
}

.tool-btn {
    transition: all 0.2s ease;
}

.tool-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

/* ========== ANUNCIOS LATERALES ========== */
#leftAdsContainer,
#rightAdsContainer {
    pointer-events: auto;
}

/* Ocultar anuncios laterales en pantallas pequeñas y medianas */
@media (max-width: 1400px) {
    #leftAdsContainer,
    #rightAdsContainer {
        display: none !important;
    }
}

/* En pantallas muy grandes, ajustar posición para no interferir */
@media (min-width: 1600px) {
    #leftAdsContainer {
        left: 20px;
    }
    
    #rightAdsContainer {
        right: 20px;
    }
}

/* Anuncio en lobby para móvil */
#lobbyMobileAd {
    display: none;
}

@media (max-width: 768px) {
    #lobbyMobileAd {
        display: block !important;
    }
}
