* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
    background-size: 400% 400%;
    animation: gradient 15s ease infinite;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    color: white;
}

@keyframes gradient {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes tornado {
    0% {
        transform: rotate(0deg) scale(0.5);
        opacity: 0;
    }

    50% {
        transform: rotate(180deg) scale(1.2);
        opacity: 0.8;
    }

    100% {
        transform: rotate(360deg) scale(2);
        opacity: 0;
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    }

    50% {
        box-shadow: 0 0 40px rgba(255, 0, 255, 0.8), 0 0 60px rgba(255, 0, 255, 0.6);
    }
}

/* Pantalla de Inicio */
.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a0a2e 0%, #2d1b4e 25%, #16213e 50%, #0f3460 75%, #1a0a2e 100%);
    background-size: 400% 400%;
    animation: gradient 12s ease infinite;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    cursor: pointer;
    overflow: hidden;
}

/* Bloques flotantes de fondo (estilo Tetris) */
.start-screen-bg-blocks {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.start-screen-bg-blocks::before,
.start-screen-bg-blocks::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 215, 0, 0.25);
    border-radius: 2px;
    animation: float-block 8s ease-in-out infinite;
}

.start-screen-bg-blocks::before {
    top: 38%;
    left: 35%;
    animation-delay: 0s;
}

.start-screen-bg-blocks::after {
    top: 52%;
    right: 38%;
    animation-delay: -4s;
}

@keyframes float-block {

    0%,
    100% {
        transform: translate(0, 0) rotate(0deg);
        opacity: 0.4;
    }

    33% {
        transform: translate(15px, -20px) rotate(5deg);
        opacity: 0.7;
    }

    66% {
        transform: translate(-10px, 10px) rotate(-5deg);
        opacity: 0.5;
    }
}

.start-screen-bg-blocks .bg-block {
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 215, 0, 0.35);
    border-radius: 2px;
    animation: float-block 6s ease-in-out infinite;
}

/* Posiciones más cerca del centro (aprox. 30%-70% en cada eje) y el doble de bloques */
.start-screen-bg-blocks .bg-block:nth-child(1) {
    top: 28%;
    left: 28%;
    animation-delay: 0s;
}

.start-screen-bg-blocks .bg-block:nth-child(2) {
    top: 32%;
    right: 32%;
    animation-delay: -1.5s;
    border-color: rgba(0, 240, 240, 0.4);
}

.start-screen-bg-blocks .bg-block:nth-child(3) {
    bottom: 38%;
    left: 30%;
    animation-delay: -3s;
}

.start-screen-bg-blocks .bg-block:nth-child(4) {
    bottom: 32%;
    right: 28%;
    animation-delay: -4.5s;
    border-color: rgba(255, 0, 128, 0.35);
}

.start-screen-bg-blocks .bg-block:nth-child(5) {
    top: 48%;
    left: 26%;
    animation-delay: -2s;
}

.start-screen-bg-blocks .bg-block:nth-child(6) {
    top: 36%;
    right: 30%;
    animation-delay: -5s;
}

.start-screen-bg-blocks .bg-block:nth-child(7) {
    top: 40%;
    left: 38%;
    animation-delay: -1s;
}

.start-screen-bg-blocks .bg-block:nth-child(8) {
    bottom: 36%;
    left: 36%;
    animation-delay: -3.5s;
    border-color: rgba(0, 255, 128, 0.35);
}

.start-screen-bg-blocks .bg-block:nth-child(9) {
    top: 44%;
    right: 26%;
    animation-delay: -2.5s;
}

.start-screen-bg-blocks .bg-block:nth-child(10) {
    bottom: 40%;
    right: 34%;
    animation-delay: -5.5s;
}

.start-screen-bg-blocks .bg-block:nth-child(11) {
    top: 52%;
    left: 32%;
    animation-delay: -0.5s;
    border-color: rgba(255, 200, 0, 0.4);
}

.start-screen-bg-blocks .bg-block:nth-child(12) {
    top: 34%;
    left: 42%;
    animation-delay: -4s;
}

.start-content {
    text-align: center;
    animation: fadeIn 1s ease-in;
    position: relative;
    z-index: 2;
}

.start-tagline {
    font-size: 1rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(255, 215, 0, 0.9);
    margin-bottom: 0.5rem;
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    animation: tagline-glow 3s ease-in-out infinite;
}

@keyframes tagline-glow {

    0%,
    100% {
        opacity: 0.85;
    }

    50% {
        opacity: 1;
    }
}

.title-container-start {
    margin-bottom: 1rem;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 3px solid rgba(255, 215, 0, 0.4);
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    animation: title-pulse 2s ease-in-out infinite;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#titleCanvasStart {
    max-width: 100%;
    height: auto;
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.3));
}

@keyframes title-pulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.2);
    }

    50% {
        transform: scale(1.03);
        box-shadow: 0 0 50px rgba(255, 215, 0, 0.35);
    }
}

.main-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 1.5rem;
    align-items: center;
}

.menu-btn {
    min-width: 220px;
    padding: 12px 24px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 215, 0, 0.6);
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, color 0.2s;
}

.menu-btn:hover {
    transform: scale(1.05);
    background: rgba(255, 215, 0, 0.25);
    color: #ffd700;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

.start-records {
    margin-top: 3rem;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s ease;
}

.start-records.show {
    opacity: 1;
    transform: translateY(0);
    animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.start-records h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.records-list {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 1rem;
    max-width: 400px;
    margin: 0 auto;
    backdrop-filter: blur(10px);
}

.record-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    margin: 0.3rem 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    font-size: 0.9rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Contenedor del Juego: columna = fila de juego + barra inferior */
.game-container {
    display: none;
    flex-direction: column;
    position: relative;
    padding: 10px;
    max-height: 98vh;
    width: 100%;
    max-width: min(100vw, 600px);
    margin: 0 auto;
    box-sizing: border-box;
    align-items: stretch;
}

.game-container.active {
    display: flex;
    animation: fadeIn 0.5s ease-in;
}

/* Fila superior: izquierda | centro | derecha (sin solapar el tablero) */
.game-row {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    gap: 8px;
    align-items: flex-start;
    justify-content: center;
}

/* Paneles laterales: ancho fijo para no tapar el tablero */
.side-panel {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 8px;
    width: 88px;
    min-width: 88px;
    max-width: 88px;
    flex-shrink: 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.2);
    overflow-y: auto;
    overflow-x: hidden;
}

/* Panel derecho: solo "Siguiente" */
.side-panel.next-panel {
    padding: 6px;
}

.side-panel.next-panel .next-piece-section {
    padding: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.side-panel.next-panel .next-piece-section h3 {
    margin-bottom: 4px;
    font-size: 0.75rem;
    text-align: center;
    width: 100%;
}

.side-panel.next-panel #nextCanvas {
    display: block;
    margin: 0 auto;
}

.info-section {
    margin-bottom: 14px;
}

.info-section:last-child {
    margin-bottom: 0;
}

.info-section h3 {
    font-size: 0.7rem;
    margin-bottom: 2px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    color: #ffd700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-name {
    font-size: 0.75rem;
    font-weight: bold;
    color: #4facfe;
    text-shadow: 0 0 10px rgba(79, 172, 254, 0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
    white-space: nowrap;
}

.score-value,
.level-value,
.lines-value {
    font-size: 1rem;
    font-weight: bold;
    color: #ffd700;
    text-shadow:
        0 0 10px rgba(255, 215, 0, 0.8),
        2px 2px 4px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score-value:active,
.level-value:active,
.lines-value:active {
    transform: scale(1.1);
}

/* Área de Juego (centro): ancho mínimo para que los paneles no lo tapen */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 288px;
    max-width: 100%;
    padding-bottom: 0;
}

/* Sección de título con piezas */
.tetris-title-section {
    margin-bottom: 10px;
}

.mobile-title-section {
    display: none;
    width: 100%;
    text-align: center;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.mobile-title-section #titleCanvas {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    max-width: 100%;
    height: auto;
}

.desktop-title-section {
    display: block;
}

#titleCanvas,
#titleCanvasDesktop {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

/* Mensaje de error */
.error-message {
    color: #ff4444;
    font-size: 0.9rem;
    margin: 10px 0;
    text-align: center;
    text-shadow: 0 0 5px rgba(255, 68, 68, 0.5);
}

#gameCanvas {
    background: rgba(0, 0, 0, 0.5);
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    box-shadow:
        0 0 20px rgba(255, 255, 255, 0.3),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
}

.next-piece-section {
    background: transparent;
    border-radius: 6px;
    padding: 6px;
    text-align: center;
}

.next-piece-section h3 {
    margin-bottom: 4px;
    font-size: 0.8rem;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#nextCanvas {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    display: block;
    margin: 0 auto;
}

/* Controles (barra inferior) */
.controls-info {
    font-size: 0.7rem;
    line-height: 1.4;
}

.controls-info div,
.controls-info span {
    padding: 0 6px;
    color: rgba(255, 255, 255, 0.9);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Barra inferior: controles + botones */
.bottom-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 12px;
    margin-top: 8px;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(8px);
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
    z-index: 10;
}

.bottom-bar .controls-info {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.bottom-bar .button-section {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 0;
}

/* Slots de items (power-ups) */
.item-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.item-slots.has-items {
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.item-slot {
    min-width: 80px;
    padding: 6px 10px;
    font-size: 0.7rem;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(135deg, #555, #333);
    border: 2px solid rgba(255, 215, 0, 0.5);
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.item-slot:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.5);
    background: linear-gradient(135deg, #666, #444);
}

.item-slot:disabled {
    opacity: 0.6;
    cursor: default;
    border-color: rgba(255, 255, 255, 0.2);
}

.item-slot-new {
    animation: item-slot-pulse 0.6s ease-out 3;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.9);
}

@keyframes item-slot-pulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.9);
    }

    50% {
        transform: scale(1.12);
        box-shadow: 0 0 28px rgba(255, 215, 0, 1);
    }
}

/* Notificación al obtener un item */
.item-obtained-toast {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.7);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.92), rgba(40, 20, 80, 0.92));
    border: 3px solid #ffd700;
    border-radius: 16px;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-shadow: 0 0 40px rgba(255, 215, 0, 0.5), inset 0 0 20px rgba(255, 215, 0, 0.1);
    pointer-events: none;
}

.item-obtained-toast.item-obtained-visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.item-obtained-toast .item-obtained-icon {
    font-size: 1.6rem;
    color: #ffd700;
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.8);
}

.item-obtained-toast .item-obtained-text {
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
}

.item-selection-hint {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid #ffd700;
    border-radius: 10px;
    z-index: 100;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
}

.item-selection-hint .btn-confirm-selection {
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: bold;
    color: #000;
    background: #ffd700;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.item-selection-hint .btn-confirm-selection:hover {
    background: #ffed4e;
}

/* Controles de Volumen */
.volume-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    font-size: 0.9rem;
}

.volume-controls label {
    min-width: 70px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
}

.volume-slider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    transition: background 0.3s;
}

.volume-slider:hover {
    background: rgba(255, 255, 255, 0.3);
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
    transition: transform 0.2s, box-shadow 0.2s;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
}

.volume-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
    transition: transform 0.2s, box-shadow 0.2s;
}

.volume-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
}

.volume-value {
    min-width: 45px;
    text-align: right;
    color: #ffd700;
    font-weight: bold;
    font-size: 0.9rem;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
}

/* Tabla de Records */
.records-table {
    max-height: 300px;
    overflow-y: auto;
}

.record-row {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    margin: 5px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    font-size: 0.85rem;
    transition: all 0.3s;
    border-left: 3px solid transparent;
}

.record-row:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(5px);
    border-left-color: #ffd700;
}

.record-row.highlight {
    background: rgba(255, 215, 0, 0.3);
    border-left-color: #ffd700;
    animation: glow 1s ease-in-out;
}

@keyframes glow {

    0%,
    100% {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    }

    50% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    }
}

.record-rank {
    font-weight: bold;
    color: #ffd700;
    min-width: 30px;
}

.record-name {
    flex: 1;
    margin: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.record-score {
    font-weight: bold;
    color: #4facfe;
}

/* Botones */
.button-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.btn-control,
.btn-primary {
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-control {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.btn-primary:hover,
.btn-control:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.btn-primary:active,
.btn-control:active {
    transform: translateY(0);
}

/* Modales */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease-in;
}

.modal.active {
    display: flex;
}

/* Feedback táctil para todos los botones */
button:active,
.item-slot:active,
.menu-btn:active,
.btn-control:active,
.btn-primary:active {
    transform: scale(0.95);
    filter: brightness(1.2);
}



.modal-content {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.95) 0%, rgba(118, 75, 162, 0.95) 100%);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 3px solid rgba(255, 255, 255, 0.3);
    animation: slideIn 0.4s ease-out;
    min-width: 300px;
}

.modal-settings-content {
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    text-align: left;
}

.modal-settings-content h2 {
    text-align: center;
}

.modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    color: #ffd700;
}

.help-section {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 2px solid rgba(255, 255, 255, 0.25);
}

.help-section h3 {
    font-size: 1.1rem;
    color: #ffd700;
    margin-bottom: 0.6rem;
}

.help-block {
    font-size: 0.9rem;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.95);
    margin-bottom: 0.6rem;
}

.help-intro {
    margin-bottom: 0.8rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.help-items-list {
    margin: 0.4rem 0 0 1rem;
    padding-left: 0.5rem;
    font-size: 0.82rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.9);
}

.help-items-list li {
    margin-bottom: 0.35rem;
}

.modal-content input {
    width: 100%;
    padding: 15px;
    font-size: 1.1rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    margin-bottom: 8px;
    text-align: center;
    transition: all 0.3s;
    touch-action: manipulation;
}

.modal-content input:focus {
    outline: none;
    border-color: #ffd700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    transform: scale(1.02);
}

/* Hint para móvil: toca para abrir teclado */
.modal-input-hint {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
    margin: -10px 0 16px 0;
    display: none;
}

@media (max-width: 600px) {
    .modal-input-hint {
        display: block;
    }
}

.final-stats {
    margin: 20px 0;
    font-size: 1.2rem;
}

.final-stats p {
    margin: 10px 0;
}

.game-over-footer {
    margin-top: 1.25rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.game-over-credits-line {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.8);
}

.btn-credits {
    padding: 6px 14px;
    font-size: 0.85rem;
    background: transparent;
    color: #ffd700;
    border: 2px solid rgba(255, 215, 0, 0.6);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.btn-credits:hover {
    background: rgba(255, 215, 0, 0.2);
    color: #fff;
}

/* Créditos (scroll tipo película) */
.credits-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, #0a0015 0%, #1a0a2e 30%, #1a0a2e 70%, #0a0015 100%);
    z-index: 3000;
    overflow: hidden;
    align-items: center;
    justify-content: center;
}

.credits-overlay.active {
    display: flex;
    flex-direction: column;
}

.credits-scroll-container {
    flex: 1;
    width: 100%;
    overflow: hidden;
    position: relative;
}

.credits-content {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    text-align: center;
    animation: credits-scroll 45s linear infinite;
    padding-bottom: 100vh;
}

@keyframes credits-scroll {
    0% {
        transform: translateX(-50%) translateY(100vh);
    }

    100% {
        transform: translateX(-50%) translateY(-100%);
    }
}

.credits-title {
    font-size: 2rem;
    font-weight: bold;
    color: #ffd700;
    margin: 2rem 0 0.5rem 0;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

.credits-subtitle {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 2rem;
}

.credits-role {
    font-size: 0.9rem;
    color: rgba(255, 215, 0, 0.9);
    margin: 1.25rem 0 0.25rem 0;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.credits-name {
    font-size: 1.1rem;
    color: #fff;
    margin: 0 0 0.5rem 0;
}

.credits-end {
    font-size: 1.3rem;
    color: #ffd700;
    margin: 3rem 0 4rem 0;
}

.credits-close-btn {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 24px;
    font-size: 0.95rem;
    font-weight: bold;
    color: #fff;
    background: rgba(255, 215, 0, 0.3);
    border: 2px solid #ffd700;
    border-radius: 10px;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s;
}

.credits-close-btn:hover {
    background: rgba(255, 215, 0, 0.5);
}

.credits-ff-btn {
    position: absolute;
    bottom: 5rem;
    /* Encima del botón de cerrar */
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s;
}

.credits-ff-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.credits-ff-btn:active {
    background: rgba(255, 215, 0, 0.2);
    border-color: #ffd700;
}

.credits-logo-section {
    margin: 1.5rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.credits-logo {
    max-width: 180px;
    height: auto;
    margin-top: 0.5rem;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.3));
}

/* Modal desbloqueo Sound Test */
.unlocked-modal-content {
    background: linear-gradient(135deg, #1a0b2e 0%, #4a148c 100%);
    border: 3px solid #ffd700;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.4);
}

.unlocked-title {
    font-size: 2rem;
    color: #ffd700;
    margin-bottom: 1rem;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
    animation: pulse-title 1.5s infinite ease-in-out;
}

.unlocked-icon {
    font-size: 4rem;
    margin: 1rem 0;
    animation: float 3s ease-in-out infinite;
}

.unlocked-text {
    font-size: 1.2rem;
    color: #fff;
    margin-bottom: 0.5rem;
}

.unlocked-subtext {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 1.5rem;
}

@keyframes pulse-title {

    0%,
    100% {
        transform: scale(1);
        text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
    }

    50% {
        transform: scale(1.05);
        text-shadow: 0 0 20px rgba(255, 215, 0, 1);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.final-stats span {
    color: #ffd700;
    font-weight: bold;
    font-size: 1.4rem;
}

.btn-secondary {
    margin-top: 10px;
    padding: 8px 16px;
    font-size: 0.9rem;
    background: transparent;
    color: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    cursor: pointer;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.stats-records {
    margin: 1rem 0;
    text-align: left;
}

.stats-records .record-item {
    margin: 0.4rem 0;
}

/* Footers with Brand Logo */
.start-footer,
.game-over-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.game-over-footer {
    margin-top: 1.5rem;
}

.credits-text {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 0.8rem;
}

.author-name {
    color: #ffd700;
    font-weight: bold;
}

.brand-logo-link {
    display: block;
    line-height: 0;
    transition: transform 0.2s;
}

.brand-logo-link:hover {
    transform: scale(1.1);
}

.brand-logo {
    height: 55px;
    width: auto;
    filter: drop-shadow(0 0 10px rgba(0, 240, 255, 0.3));
}

.btn-credits {
    margin-top: 1.2rem;
    background: transparent;
    color: #ffd700;
    border: 1px solid #ffd700;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-credits:hover {
    background: rgba(255, 215, 0, 0.1);
}

.no-stats {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.95rem;
}

/* Animación de flash al eliminar líneas */
@keyframes flash {

    0%,
    100% {
        background-color: rgba(255, 255, 255, 0.1);
    }

    50% {
        background-color: rgba(255, 255, 255, 0.8);
    }
}

.flash-line {
    animation: flash 0.3s ease-in-out;
}

/* Animaciones para efectos locos */
@keyframes confetti-fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

@keyframes pulse-pressure {

    0%,
    100% {
        opacity: 0.3;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(1.02);
    }
}

@keyframes rotate-pieces {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes glitch-shake {

    0%,
    100% {
        transform: translate(0, 0);
        filter: hue-rotate(0deg);
    }

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

    20% {
        transform: translate(2px, -2px);
        filter: hue-rotate(180deg);
    }

    30% {
        transform: translate(-2px, -2px);
        filter: hue-rotate(270deg);
    }

    40% {
        transform: translate(2px, 2px);
        filter: hue-rotate(360deg);
    }

    50%,
    100% {
        transform: translate(0, 0);
        filter: hue-rotate(0deg);
    }
}

@keyframes breathing {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }
}

/* Clases para aplicar efectos */
.pressure-overlay {
    animation: pulse-pressure 1s ease-in-out infinite;
}

.glitch-effect {
    animation: glitch-shake 0.2s linear infinite;
}

.breathing-effect {
    animation: breathing 1s ease-in-out infinite;
}

/* Controles Táctiles */
.touch-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    margin-bottom: 8px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    flex-wrap: wrap;
    flex-shrink: 0;
    z-index: 20;
    position: relative;
}

.touch-btn {
    min-width: 50px;
    min-height: 50px;
    font-size: 1.8rem;
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, rgba(79, 172, 254, 0.8), rgba(0, 240, 240, 0.8));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
    user-select: none;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    /* Remove default tap highlight */
}

/* Ensure feedback works on touch devices */
.touch-btn:active,
.touch-btn.active {
    transform: scale(0.9) !important;
    background: linear-gradient(135deg, rgba(79, 172, 254, 1), rgba(0, 240, 240, 1)) !important;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.6), inset 0 0 10px rgba(0, 0, 0, 0.2) !important;
    filter: brightness(1.3) !important;
}

.touch-btn:active {
    background: linear-gradient(135deg, rgba(79, 172, 254, 1), rgba(0, 240, 240, 1));
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.touch-btn:hover {
    background: linear-gradient(135deg, rgba(79, 172, 254, 1), rgba(0, 240, 240, 1));
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

/* Responsive: móvil vertical - todo debe caber en 100dvh sin cortes */
@media (max-width: 768px) {
    .game-container {
        height: 100dvh;
        max-height: 100dvh;
        padding: 2px 4px;
        /* Reduced padding */
        max-width: 100vw;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        justify-content: flex-start;
        /* Ensure starts at very top */
        padding-top: 0 !important;
        margin-top: 0 !important;
    }

    body {
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden !important;
        height: 100dvh !important;
        align-items: flex-start !important;
        /* Force content to top */
    }

    .mobile-title-section {
        display: block !important;
        order: 0;
        width: 100%;
        max-width: 100%;
        text-align: center;
        margin: 0 !important;
        padding: 0 !important;
        flex-shrink: 0;
        box-sizing: border-box;
    }

    .mobile-title-section #titleCanvas {
        width: auto;
        /* Auto width to preserve aspect ratio */
        height: auto;
        max-height: 48px;
        /* Increased from 32px to match visual balance */
        max-width: 100%;
        box-sizing: border-box;
        object-fit: contain;
    }

    .desktop-title-section {
        display: none !important;
    }

    /* Fila de juego: reservar espacio generoso para barra inferior (ítems + opciones) */
    .game-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-rows: auto 1fr;
        gap: 4px;
        order: 1;
        flex: 1 1 auto;
        min-height: 0;
        /* max-height: calc(100dvh - 175px); REMOVED: let flex handle height */
        overflow: hidden;
        align-items: stretch;
        justify-items: stretch;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Puntaje: primera fila, no desbordar ancho */
    .side-panel.left-panel {
        grid-column: 1;
        grid-row: 1;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        max-height: 44px;
        /* Reduced from 52px */
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        align-items: center;
        gap: 2px;
        padding: 2px 2px;
        flex-shrink: 0;
        z-index: 1;
        overflow: hidden;
        box-sizing: border-box;
    }

    .side-panel.left-panel .info-section {
        margin-bottom: 0;
        flex: 0 0 auto;
        min-width: 35px;
        /* Reduced */
        max-width: 60px;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .side-panel.left-panel .info-section h3 {
        font-size: 0.5rem;
        /* Reduced */
    }

    .side-panel.left-panel .player-name,
    .side-panel.left-panel .score-value,
    .side-panel.left-panel .level-value,
    .side-panel.left-panel .lines-value {
        font-size: 0.6rem;
        /* Reduced */
    }

    /* Tablero: segunda fila */
    .game-area {
        grid-column: 1 / -1;
        grid-row: 2;
        min-width: 0;
        width: 100%;
        min-height: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0 2px;
        z-index: 2;
        overflow: hidden;
    }

    .game-area #gameCanvas {
        flex: 1 1 auto;
        min-height: 0;
        width: auto;
        height: auto;
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }

    .side-panel {
        min-width: 0;
        flex-shrink: 0;
        box-sizing: border-box;
    }

    /* Siguiente: primera fila, columna derecha; que no se corte a la derecha */
    .side-panel.next-panel {
        grid-column: 2;
        grid-row: 1;
        max-height: 44px;
        /* Reduced from 52px */
        width: 100%;
        max-width: 100%;
        min-width: 0;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 3px 2px;
        z-index: 1;
        overflow: hidden;
        box-sizing: border-box;
    }

    .side-panel.next-panel .next-piece-section {
        display: flex;
        align-items: center;
        gap: 2px;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
    }

    .side-panel.next-panel .next-piece-section h3 {
        margin-bottom: 0;
        font-size: 0.55rem;
        /* Reduced from 0.6rem */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-right: 2px;
    }

    .side-panel.next-panel #nextCanvas {
        width: 30px;
        /* Reduced from 40px */
        height: 30px;
        max-width: 100%;
        flex-shrink: 0;
    }

    #titleCanvas {
        max-width: 100%;
        height: auto;
    }

    .game-title {
        font-size: 2.2rem;
    }

    .press-start {
        font-size: 1.5rem;
    }

    .touch-btn {
        min-width: 40px;
        min-height: 40px;
        font-size: 1.35rem;
    }

    /* Barra inferior: solo para items en móvil */
    .bottom-bar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 2px 4px;
        margin-top: 2px;
        flex-shrink: 0;
        z-index: 3;
        order: 2;
        min-height: 40px;
        /* Reduced further */
        max-height: 60px;
        overflow: visible;
        box-sizing: border-box;
        background: rgba(0, 0, 0, 0.35);
        backdrop-filter: blur(8px);
        border-radius: 8px;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .bottom-bar .controls-info {
        display: none !important;
    }

    .bottom-bar .item-slots {
        display: flex;
        flex-wrap: wrap;
        gap: 3px;
        justify-content: center;
        min-height: 0;
        width: auto;
        flex: 1 1 auto;
        /* Allow items to take available space */
        min-width: 100px;
    }

    .bottom-bar .item-slot {
        min-width: 48px;
        padding: 2px 4px;
        font-size: 0.52rem;
    }

    /* Ocultar sección de botones de texto en móvil */
    .bottom-bar .button-section {
        display: none !important;
    }

    /* Mostrar y estilizar iconos móviles */
    .mobile-only-icons {
        display: flex !important;
        flex-direction: row;
        gap: 4px;
        margin-left: 4px;
        align-items: center;
        justify-content: center;
    }

    .icon-btn {
        background: rgba(0, 0, 0, 0.5);
        border: 1px solid rgba(255, 255, 255, 0.4);
        color: #fff;
        border-radius: 5px;
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.1s, transform 0.1s;
    }

    .icon-btn:active {
        background: rgba(255, 215, 0, 0.4);
        transform: scale(0.9);
        border-color: #ffd700;
    }

    .bottom-bar .btn-control {
        padding: 4px 6px;
        font-size: 0.65rem;
    }

    .touch-controls {
        margin-bottom: 4px;
        padding: 6px;
        gap: 8px;
    }
}

/* Pantallas móviles muy bajas: reservar más espacio para barra inferior, escalar tablero */
@media (max-width: 768px) and (max-height: 620px) {


    .game-area {
        justify-content: flex-start;
    }

    /* .game-area #gameCanvas {
        transform: scale(0.88);
        transform-origin: top center;
    } */

    .mobile-title-section #titleCanvas {
        max-height: 26px;
    }

    .side-panel.left-panel,
    .side-panel.next-panel {
        max-height: 44px;
    }

    .side-panel.left-panel .info-section h3 {
        font-size: 0.5rem;
    }

    .side-panel.left-panel .player-name,
    .side-panel.left-panel .score-value,
    .side-panel.left-panel .level-value,
    .side-panel.left-panel .lines-value {
        font-size: 0.6rem;
    }

    .side-panel.next-panel #nextCanvas {
        width: 36px;
        height: 36px;
    }

    .bottom-bar {
        min-height: 44px;
        max-height: 64px;
    }
}

@media (max-width: 768px) and (max-height: 520px) {


    /* .game-area #gameCanvas {
        transform: scale(0.75);
        transform-origin: top center;
    } */

    .mobile-title-section {
        margin-bottom: 0;
    }

    .mobile-title-section #titleCanvas {
        max-height: 22px;
    }

    .side-panel.left-panel,
    .side-panel.next-panel {
        max-height: 40px;
    }

    .side-panel.next-panel #nextCanvas {
        width: 32px;
        height: 32px;
    }

    .bottom-bar {
        min-height: 42px;
        max-height: 58px;
    }
}

/* Sound Test (desbloqueado al eliminar 20+ líneas) */
.sound-test-content {
    width: 100%;
    max-width: 520px;
    box-sizing: border-box;
}

.sound-test-hint {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 12px;
    text-align: center;
}

.sound-test-track-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 16px;
    padding: 8px 0;
}

.sound-test-track-btn {
    min-width: 140px;
    font-size: 0.85rem;
    padding: 8px 12px;
}

.sound-test-equalizer-wrap {
    width: 100%;
    background: #1a1a2e;
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 16px;
    box-sizing: border-box;
}

.sound-test-equalizer {
    display: block;
    width: 100%;
    height: 100px;
    border-radius: 4px;
    box-sizing: border-box;
}