@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;700&display=swap');

* {
    box-sizing: border-box;
}

.mobile-only {
    display: none !important;
}

.desktop-only {
    display: block !important;
}

body {
    background: url('assets/delta_background.png') center center no-repeat;
    background-size: cover;
    font-family: 'Outfit', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    color: #fff;
}

/* Capa de post-procesado: Moire, Viñeteado y Color */
body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    backdrop-filter: contrast(1.1);
    background:
        radial-gradient(circle, rgba(230, 213, 195, 0.1) 0%, rgba(0, 0, 0, 0.5) 100%),
        /* Viñeteado cálido */
        rgba(44, 30, 18, 0.2);
    z-index: -2;
}

body::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.05) 0px, rgba(0, 0, 0, 0.05) 1px, transparent 1px, transparent 2px),
        radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 100% 3px, 6px 6px;
    /* Mix de Scanlines y Moire */
    z-index: -1;
    pointer-events: none;
    opacity: 0.8;
}

.game-container {
    text-align: center;
}

h1 {
    font-size: 2.5rem;
    margin: 0;
    font-family: 'Outfit', sans-serif;
    letter-spacing: 8px;
    /* Més espai */
    background: linear-gradient(to bottom, #fff8e7 0%, #d4b493 50%, #8c6a48 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    font-weight: 800;
    /* Més gruixut */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    /* Ombra per donar volum */
    /* Ombra per donar volum */
}

.title-animate {
    animation: titleEntrance 1.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes titleEntrance {
    0% {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
        letter-spacing: 15px;
        /* Efecte d'ajuntar lletres */
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        letter-spacing: 8px;
    }
}

/* Responsive visibility classes */
.desktop-only {
    display: flex !important;
}

.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }
}

#game-container {
    /* Tornem al "Xocolata" - Usuari vol "como antes" */
    background: linear-gradient(145deg, #4a3b2a 0%, #6d5236 50%, #3e2b1f 100%);
    padding: 18px;
    border-radius: 16px;
    /* Marc fi i minimalista mantingut */
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 0 0 1px rgba(93, 70, 54, 0.3),
        0 30px 60px rgba(0, 0, 0, 0.7);

    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    width: 700px;
    max-width: 95vw;
}

/* ... (skip content not modifying) ... */

#stats {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
    background: transparent;
    backdrop-filter: none;
    padding: 0;
    border-radius: 12px;
    border: none;
    min-width: 200px;
    box-shadow: none;
    height: 600px;
    /* Alçada del canvas més o menys */
}

#game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding-bottom: 15px;
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
}

#game-body {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
}

#board-side {
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: center;
}

#board-container {
    position: relative;
    padding: 5px;
    /* Reduït al mínim */
    /* Truc per fer border-radius + gradient border */
    background: linear-gradient(#141414, #141414) padding-box,
        linear-gradient(135deg, #8c6a48 0%, #3d2b1f 100%) border-box;
    border: 2px solid transparent;
    border-radius: 6px;

    /* Ombra suau */
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);

    display: flex;
    justify-content: center;
    align-items: center;
    margin: 12px;
}

#game-over-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 10, 5, 0.95);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 10;
    cursor: pointer;
}

#game-over-overlay h2 {
    font-size: 1.5rem;
    /* Text més petit */
    margin-bottom: 5px;
    color: #e6d5c3;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    text-transform: uppercase;
}

#game-over-overlay #final-score {
    font-size: 1.2rem;
    font-weight: bold;
    color: #fff;
    margin: 5px 0;
}

.click-hint {
    display: none;
    /* Ocultat per petició de l'usuari */
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}



@keyframes fadeOutBonus {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    10% {
        opacity: 1;
        transform: scale(1.2);
    }

    /* Flashazo entrada */
    20% {
        opacity: 1;
        transform: scale(1);
    }

    /* Normalización */
    80% {
        opacity: 1;
        transform: translateY(0);
    }

    /* Mantener visible */
    100% {
        opacity: 0;
        transform: translateY(-10px);
    }

    /* Desvanecer al final */
}

@keyframes levelUpPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
        border-color: #d4c3b0;
    }

    50% {
        transform: scale(1.1);
        box-shadow: 0 0 20px #E6B800;
        border-color: #E6B800;
    }

    100% {
        transform: scale(1);
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
        border-color: #d4c3b0;
    }
}

.level-up-anim {
    animation: levelUpPulse 1s ease-out;
}

.bonus-text {
    height: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #ffffff;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.4);
    margin-top: 2px;
    opacity: 0;
    /* Por defecto oculto */
    letter-spacing: 0.5px;
}

.bonus-visible {
    animation: fadeOutBonus 2s ease-out forwards;
}

#tetris {
    position: relative;
    background: rgba(255, 255, 255, 0.02);
    /* Pràcticament transparent */
    border: 1px solid rgba(140, 106, 72, 0.2);
    border-radius: 2px;
    z-index: 2;
    touch-action: manipulation;
    /* Evita retraso de clic en móvil */
}



.stats-row {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    /* Alinearlos arriba para que los títulos coincidan */
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid #5d4636;
    border-radius: 8px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    margin-bottom: 10px;
}

.stat-box {
    text-align: center;
    flex: 1;
    /* Que ocupen el mismo ancho */
}

.stat-label-small {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #e6d5c3;
    margin-bottom: 5px;
    opacity: 0.8;
}

.stat-label {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #b5a493;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.controls-info {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.8rem;
    color: #b5a493;
    text-align: center;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.keys-row {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.controls-info kbd {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #7d5636;
    color: #ffffff;
    /* Plata/Blanco modesto */
    box-shadow: 0 2px 0 #3d2b1f;
    font-weight: bold;
    font-size: 0.85rem;
    margin: 0 2px;
    /* Animación de entrada: destello de atención al cargar */
    animation: keysEntranceGlow 2.5s ease-out forwards;
}

@keyframes keysEntranceGlow {
    0% {
        box-shadow: 0 0 0px #ffffff;
        transform: scale(1);
    }

    10% {
        box-shadow: 0 0 30px #ffffff, 0 0 10px rgba(255, 255, 255, 0.5);
        transform: scale(1.1);
        background: rgba(255, 255, 255, 0.4);
        color: #fff;
    }

    30% {
        box-shadow: 0 0 10px #ffffff;
        transform: scale(1);
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
    }

    100% {
        box-shadow: 0 2px 0 #3d2b1f;
        transform: translateY(0);
    }
}

/* Efecto de flash al empezar */
.start-flash-overlay {
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    background-color: #fff;
    pointer-events: none;
    z-index: 100;
    border-radius: 4px;
    opacity: 0;
}

.start-flash {
    animation: startFlashAnim 0.8s ease-out forwards;
}

@keyframes startFlashAnim {
    0% {
        opacity: 0.95;
    }

    100% {
        opacity: 0;
    }
}

#reset-btn {
    background: rgba(125, 86, 54, 0.2);
    color: #b5a493;
    border: 1px solid #7d5636;
    padding: 6px 15px;
    border-radius: 4px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: none;
}

#reset-btn:hover {
    background: #7d5636;
    color: #fff;
}

#reset-btn:active {
    transform: translateY(1px);
}

.header-btn {
    background: rgba(120, 120, 120, 0.2);
    /* Fondo grisáceo muy suave */
    color: #e0e0e0;
    /* Texto plateado claro */
    border: 1px solid #b5b5b5;
    /* Borde plateado modesto */
    padding: 0;
    border-radius: 4px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 42px;
    /* Reducido de 60px a 42px */
    height: 30px;
    /* Altura original */
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

.header-btn:hover {
    background: rgba(200, 200, 200, 0.25);
    border-color: #ffffff;
    color: #ffffff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

.header-btn:active {
    transform: translateY(1px) scale(0.96);
}

.header-btn-mobile {
    background: rgba(120, 120, 120, 0.2);
    color: #e0e0e0;
    border: 1px solid #b5b5b5;
    padding: 0;
    border-radius: 3px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 32px;
    /* Reducido de 45px a 32px */
    height: 22px;
    /* Altura original */
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.header-btn-mobile:hover {
    background: rgba(200, 200, 200, 0.25);
    border-color: #ffffff;
}

.header-btn-mobile:active {
    transform: translateY(1px);
}


kbd {
    background: #4d3626;
    border: 1px solid #6d5646;
    border-radius: 3px;
    padding: 2px 6px;
    color: #fff;
    font-family: inherit;
}

#mobile-controls {
    display: none;
    /* Oculto en desktop por defecto, se activa en media query */
    flex-direction: column;
    gap: 15px;
    user-select: none;
    background: rgba(0, 0, 0, 0.15);
    padding: 15px;
    border-radius: 12px;
}


.control-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.m-btn {
    width: 60px;
    height: 60px;
    background: radial-gradient(circle at 30% 30%, #5d4636, #4d3626);
    border: 3px solid #2c1e12;
    border-radius: 50%;
    color: #e6d5c3;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow:
        0 4px 0 #1a120b,
        inset 0 2px 4px rgba(255, 255, 255, 0.1),
        inset 0 -2px 10px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s, box-shadow 0.1s;
    touch-action: manipulation;
}

.m-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #1a120b;
    background: radial-gradient(circle at 30% 30%, #4d3626, #3d2b1f);
}

.info-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #b5a493;
    color: #b5a493;
    font-family: serif;
    font-style: italic;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
}

.info-circle:hover {
    background: #e6d5c3;
    color: #3d2b1f;
    border-color: #e6d5c3;
}


/* --- RESPONSIVE ADJUSTMENTS --- */
@media (max-width: 700px) {
    body {
        align-items: center;
        padding: 5px;
        overflow-y: auto;
        height: auto;
    }

    #game-container {
        padding: 15px;
        gap: 15px;
        width: 100%;
        max-width: 360px;
        margin: 0 auto;
    }

    #game-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        gap: 10px;
    }

    h1 {
        font-size: 1.6rem;
        letter-spacing: 2px;
    }

    #game-body {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }

    .mobile-only {
        display: flex !important;
    }

    .desktop-only {
        display: none !important;
    }

    #mobile-controls {
        display: flex;
        background: transparent;
        padding: 5px;
    }


    .full-ranking {
        width: 95%;
        padding: 15px;
        flex-direction: column;
    }

    .full-ranking>div {
        flex-direction: column !important;
    }
}

/* --- RANKING MODAL --- */
#ranking-form-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.ranking-modal {
    background: #3d2b1f;
    padding: 30px;
    border-radius: 15px;
    border: 3px solid #5d4636;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 15px;
    color: #e6d5c3;
    text-align: center;
    max-width: 90%;
}

.ranking-modal h3 {
    margin: 0;
    color: #e6d5c3;
}

.ranking-modal input {
    background: #2c1e12;
    border: 1px solid #5d4636;
    padding: 10px;
    border-radius: 5px;
    color: #fff;
    font-family: inherit;
}

.ranking-modal button {
    background: #7d5636;
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

/* --- MINI RANKINGS (Inside Stats) --- */
#mini-rankings {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 5px 0;
}

.mini-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.8rem;
    text-align: left;
}

.mini-list li {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.mini-list li span:first-child {
    color: #fff;
}

.mini-list li span:last-child {
    color: #b5a493;
    font-weight: bold;
}

#view-full-ranking {
    background: rgba(125, 86, 54, 0.2);
    border: 1px solid #7d5636;
    color: #e6d5c3;
    font-size: 0.75rem;
    padding: 6px 15px;
    border-radius: 4px;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
    align-self: center;
    /* Centrar botó mes petit */
    width: auto;
}

#view-full-ranking:hover {
    background: #7d5636;
    color: #fff;
}

/* --- FULL RANKING MODAL --- */
.full-ranking {
    width: 600px;
    max-height: 85vh;
}


.ranking-scroll {
    overflow-y: auto;
    margin: 15px 0;
    border: 1px solid #5d4636;
    background: #2c1e12;
    border-radius: 5px;
}

#full-ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#full-ranking-table th,
#full-ranking-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid rgba(93, 70, 54, 0.5);
}

#full-ranking-table th {
    background: #3d2b1f;
    color: #e6d5c3;
    position: sticky;
    top: 0;
}

#full-ranking-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Show controls on screen always if requested */
#mobile-controls {
    margin-top: 10px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 100%;
    max-width: 310px;
    background: transparent;
    padding: 0;
}

.m-btn {
    flex: 1;
    height: 50px;
    border: none;
    background: rgba(61, 43, 31, 0.9);
    color: #b5a493;
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    border-radius: 6px;
    box-shadow:
        0 3px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    /* Animació de fogonazo al carregar */
    animation: keysEntranceGlow 2.5s ease-out forwards;
}

.m-btn svg {
    width: 24px;
    height: 24px;
    opacity: 0.8;
    transition: all 0.1s;
}

.m-btn.center-btn svg {
    width: 28px;
    height: 28px;
    opacity: 1;
}

.m-btn:active {
    background: rgba(44, 30, 18, 0.95);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.6),
        inset 0 2px 4px rgba(0, 0, 0, 0.3);
    transform: translateY(1px);
}

.m-btn:active svg {
    opacity: 1;
    color: #e6d5c3;
    transform: scale(0.9);
}

/* No longer hiding on desktop to support 'on screen' controls */

/* Ranking modal responsive */
.ranking-form-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    box-sizing: border-box;
}

.ranking-modal {
    background: linear-gradient(145deg, #3d2b1f 0%, #2c1e12 100%);
    border: 2px solid #7d5636;
    border-radius: 12px;
    padding: 30px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    position: relative;
}

.ranking-modal h3 {
    color: #e6d5c3;
    text-align: center;
    margin: 0 0 20px 0;
    font-size: 1.5rem;
}

.ranking-scroll {
    overflow-y: auto;
    overflow-x: auto;
}

@media (max-width: 768px) {
    .ranking-modal {
        padding: 15px;
        max-height: 85vh;
    }

    .ranking-modal h3 {
        font-size: 1.2rem;
        margin-bottom: 15px;
    }

    .ranking-modal>div[style*="flex"] {
        flex-direction: column !important;
        gap: 15px !important;
    }

    .ranking-scroll {
        max-height: 250px !important;
    }
}

.ranking-accent {
    color: #e2ddc2 !important;
    font-weight: 600;
}

a.ranking-accent,
a.ranking-accent:link,
a.ranking-accent:visited,
a.ranking-accent:hover,
a.ranking-accent:active {
    color: #e2ddc2 !important;
    text-decoration: underline;
}