/* Reset y variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6aaa64;
    --secondary-color: #538d4e;
    --warning-color: #c9b458;
    --error-color: #787c7e;
    --dark-color: #121213;
    --light-color: #ffffff;
    --border-color: #3a3a3c;
    --bg-color: #121213;
    --text-color: #ffffff;
    --gray: #3a3a3c;
    --gray-light: #818384;
    --danger-color: #dc3545;
    --timer-warning: #ff6b6b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #1e1e1e 0%, #121213 100%);
    color: var(--text-color);
    min-height: 100vh;
    padding: 10px;
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Pantallas */
.screen {
    display: none;
    animation: fadeIn 0.3s ease-in;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 40px;
    position: relative;
}

.header h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    margin-bottom: 10px;
    color: var(--primary-color);
}

.header h2 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin-bottom: 15px;
}

.subtitle {
    color: var(--gray-light);
    font-size: clamp(0.9rem, 2vw, 1.1rem);
}

.btn-back {
    position: absolute;
    left: 0;
    top: 0;
    background: var(--gray);
    color: var(--text-color);
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.3s;
}

.btn-back:hover {
    background: var(--gray-light);
}

/* Botones */
.button-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 400px;
    margin: 0 auto;
}

.btn {
    padding: 20px 30px;
    font-size: 1.2rem;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: var(--primary-color);
    color: var(--light-color);
}

.btn-primary:hover {
    background: var(--secondary-color);
    transform: scale(1.05);
}

.btn-secondary {
    background: var(--gray);
    color: var(--light-color);
}

.btn-secondary:hover {
    background: var(--gray-light);
    transform: scale(1.05);
}

.btn-danger {
    background: var(--danger-color);
    color: var(--light-color);
}

.btn-danger:hover {
    background: #c82333;
    transform: scale(1.05);
}

.btn-large {
    width: 100%;
    padding: 18px;
    font-size: 1.1rem;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
    min-width: auto;
}

.icon {
    font-size: 1.5rem;
}

/* Formularios */
.form-container {
    max-width: 500px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.05);
    padding: 30px;
    border-radius: 16px;
    backdrop-filter: blur(10px);
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 1rem;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea {
    width: 100%;
    padding: 14px;
    background: var(--dark-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s;
}

.form-group input[type="text"]:focus,
.form-group input[type="number"]:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group textarea {
    resize: vertical;
    min-height: 150px;
    font-family: monospace;
}

.form-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 10px;
    cursor: pointer;
}

.helper-text {
    display: block;
    margin-top: 8px;
    color: var(--gray-light);
    font-size: 0.9rem;
}

/* Código de juego */
.game-code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.game-code-display strong {
    font-size: 2rem;
    color: var(--primary-color);
    letter-spacing: 3px;
    background: rgba(106, 170, 100, 0.1);
    padding: 10px 20px;
    border-radius: 8px;
}

.btn-copy {
    background: var(--gray);
    color: var(--text-color);
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s;
}

.btn-copy:hover {
    background: var(--gray-light);
}

/* QR Code Section */
.qr-section {
    background: rgba(255, 255, 255, 0.05);
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 30px;
    text-align: center;
}

.qr-section h3 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

.qr-container {
    background: white;
    padding: 20px;
    border-radius: 12px;
    display: inline-block;
    margin-bottom: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.qr-container img {
    display: block;
    max-width: 200px;
    height: auto;
}

/* Lobby */
.lobby-container {
    max-width: 600px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.05);
    padding: 30px;
    border-radius: 16px;
}

.lobby-container h3 {
    margin-bottom: 20px;
    text-align: center;
}

.players-list {
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.player-item {
    background: var(--dark-color);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 2px solid var(--border-color);
}

.player-item.host {
    border-color: var(--primary-color);
}

.player-name {
    font-size: 1.1rem;
    font-weight: 500;
    flex: 1;
}

.player-badges {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-badge {
    background: var(--primary-color);
    color: var(--light-color);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.btn-kick {
    background: var(--danger-color);
    color: var(--light-color);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    line-height: 1;
    padding: 0;
}

.btn-kick:hover {
    background: #c82333;
    transform: scale(1.1);
}

.host-controls {
    margin: 30px 0;
    text-align: center;
}

.lobby-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

/* Pantalla de juego */
.game-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.game-info {
    font-size: 1.2rem;
    font-weight: 600;
}

.timer-container {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.timer-label {
    font-size: 1rem;
    color: var(--gray-light);
}

.timer {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    font-family: 'Courier New', monospace;
    min-width: 80px;
    text-align: center;
    background: rgba(106, 170, 100, 0.1);
    padding: 5px 15px;
    border-radius: 8px;
}

.timer.timer-warning {
    color: var(--timer-warning);
    background: rgba(255, 107, 107, 0.1);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.game-code-small {
    font-size: 1rem;
    color: var(--gray-light);
    text-align: right;
}

.game-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 1024px) {
    .game-layout {
        grid-template-columns: 2fr 1fr;
    }
}

/* Tablero de juego */
.game-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.board {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    max-width: 450px;
    margin: 0 auto;
    width: 100%;
}

.board-row {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.tile {
    width: 60px;
    height: 60px;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    text-transform: uppercase;
    background: var(--dark-color);
    border-radius: 4px;
    transition: all 0.3s;
}

.tile.filled {
    border-color: var(--gray-light);
    animation: pop 0.1s;
}

.tile.correct {
    background: var(--primary-color);
    border-color: var(--primary-color);
    animation: flip 0.6s;
}

.tile.present {
    background: var(--warning-color);
    border-color: var(--warning-color);
    animation: flip 0.6s;
}

.tile.absent {
    background: var(--error-color);
    border-color: var(--error-color);
    animation: flip 0.6s;
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

/* Teclado */
.keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 500px;
    margin: 0 auto;
}

.keyboard-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.key {
    min-width: 40px;
    height: 58px;
    background: var(--gray);
    border: none;
    border-radius: 4px;
    color: var(--text-color);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.1s;
    text-transform: uppercase;
    padding: 0 12px;
}

.key:hover:not(:disabled) {
    background: var(--gray-light);
}

.key:active:not(:disabled) {
    transform: scale(0.95);
}

.key:disabled {
    cursor: not-allowed;
}

.key.wide {
    min-width: 65px;
    font-size: 0.75rem;
}

.key.correct {
    background: var(--primary-color);
}

.key.present {
    background: var(--warning-color);
}

.key.absent {
    background: #3a3a3c;
    color: #666;
}

/* Mensaje de juego */
.game-message {
    text-align: center;
    min-height: 30px;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--primary-color);
}

/* Scoreboard */
.scoreboard-panel {
    background: rgba(255, 255, 255, 0.05);
    padding: 20px;
    border-radius: 12px;
    height: fit-content;
}

.scoreboard-panel h3 {
    margin-bottom: 20px;
    text-align: center;
}

.scoreboard {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.score-item {
    background: var(--dark-color);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid var(--border-color);
}

.player-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.player-info .name {
    font-weight: 600;
    font-size: 1rem;
}

.player-info .status {
    font-size: 0.85rem;
    color: var(--gray-light);
}

.player-score {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* Podio */
.podium-container {
    max-width: 900px;
    margin: 0 auto;
}

.podium {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 20px;
    margin-bottom: 50px;
    flex-wrap: wrap;
}

.podium-place {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 150px;
}

.podium-medal {
    font-size: 4rem;
    margin-bottom: 15px;
    animation: bounce 1s infinite;
}

.podium-player {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 10px;
    text-align: center;
}

.podium-score {
    font-size: 1.1rem;
    color: var(--gray-light);
    margin-bottom: 15px;
}

.podium-stand {
    width: 100%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--light-color);
    font-size: 2rem;
    font-weight: bold;
    padding: 20px;
    border-radius: 8px 8px 0 0;
    text-align: center;
}

.podium-place.first .podium-stand {
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.podium-place.second .podium-stand {
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
}

.podium-place.third .podium-stand {
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.full-rankings {
    background: rgba(255, 255, 255, 0.05);
    padding: 30px;
    border-radius: 12px;
    margin-bottom: 30px;
}

.full-rankings h3 {
    text-align: center;
    margin-bottom: 20px;
}

.rankings-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ranking-item {
    background: var(--dark-color);
    padding: 15px 20px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid var(--border-color);
}

.ranking-position {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    min-width: 40px;
}

.ranking-name {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 500;
}

.ranking-score {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* Loader */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--gray);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader p {
    margin-top: 20px;
    font-size: 1.2rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--dark-color);
    color: var(--text-color);
    padding: 15px 30px;
    border-radius: 8px;
    border: 2px solid var(--primary-color);
    font-size: 1rem;
    font-weight: 500;
    z-index: 1000;
    transition: bottom 0.3s;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    bottom: 30px;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .game-header {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .timer {
        font-size: 1.5rem;
    }

    .game-code-small {
        text-align: center;
    }

    .tile {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }

    .key {
        min-width: 32px;
        height: 50px;
        font-size: 0.9rem;
        padding: 0 8px;
    }

    .key.wide {
        min-width: 55px;
        font-size: 0.7rem;
    }

    .game-code-display {
        flex-direction: column;
    }

    .game-code-display strong {
        font-size: 1.5rem;
    }

    .podium {
        gap: 10px;
    }

    .podium-place {
        min-width: 120px;
    }

    .podium-medal {
        font-size: 3rem;
    }

    .form-container {
        padding: 20px;
    }

    .btn-back {
        position: static;
        margin-bottom: 20px;
        width: 100%;
    }

    .lobby-actions {
        flex-direction: column;
    }

    .qr-container img {
        max-width: 160px;
    }

    .btn-kick {
        width: 24px;
        height: 24px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .tile {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }

    .key {
        min-width: 28px;
        height: 45px;
        font-size: 0.8rem;
        padding: 0 6px;
    }

    .key.wide {
        min-width: 48px;
    }

    .keyboard-row {
        gap: 4px;
    }

    .timer {
        font-size: 1.2rem;
        min-width: 60px;
    }
}