/* =========================================
   VARIABLES DEL MOTOR
   Els valors poden ser modificats pel theme
   ========================================= */

:root {
    --game-background: #111111;
    --game-surface: #1b1b1b;
    --game-primary: #8b1e1e;
    --game-secondary: #b78a46;
    --game-text: #f2f2f2;
    --game-muted: #aaaaaa;

    --font-title: Georgia, serif;
    --font-text: Arial, sans-serif;

    --radius: 10px;

    --content-width: 560px;

    --game-menu-surface: color-mix(
    in srgb,
    var(--game-surface) 85%,
    white
   );
}


/* =========================================
   BASE
   Mobile-first
   ========================================= */

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    min-height: 100vh;

    background: var(--game-background);
    color: var(--game-text);

    font-family: var(--font-text);
    font-size: 16px;
    line-height: 1.5;
}


/* =========================================
   APP
   ========================================= */

#app {
    min-height: 100vh;

    display: flex;
    justify-content: center;

    padding: 18px 16px 32px;
}

.landing {
    width: 100%;
    max-width: var(--content-width);
}

/* =========================================
   COVER
   ========================================= */

.game-cover {
    width: 100%;
    aspect-ratio: 3 / 2;

    overflow: hidden;

    border-radius: var(--radius);

    margin-bottom: clamp(18px, 3vh, 30px);
}

.game-cover img {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: cover;
}


/* =========================================
   TÍTOLS
   ========================================= */

.game-header {
    text-align: center;

    margin-bottom: clamp(18px, 3vh, 30px);
}

.game-header h1 {
    margin: 0;

    font-family: var(--font-title);

    font-size: clamp(2rem, 11vw, 2.7rem);
    line-height: 1.05;
}

.game-subtitle {
    margin: 8px 0 0;

    color: var(--game-secondary);

    font-size: 1rem;
}

.game-description {
    margin: 0 0 clamp(26px, 5vh, 50px);

    color: var(--game-muted);

    text-align: center;
}

/* =========================================
   BOTONS
   ========================================= */

.landing-actions {
    display: flex;
    flex-direction: column;

    gap: clamp(12px, 2vh, 20px);
}

.button {
    width: 100%;
    min-height: 54px;

    padding: 14px 20px;

    border: 0;
    border-radius: var(--radius);

    font-family: var(--font-text);
    font-size: 1rem;
    font-weight: 600;

    cursor: pointer;

    touch-action: manipulation;
}

.button-primary {
    background: var(--game-primary);
    color: var(--game-text);
}

.button-secondary {
    background: var(--game-surface);
    color: var(--game-text);

    border: 1px solid var(--game-secondary);
}

.button:active {
    transform: scale(0.98);
}


/* =========================================
   ACCESSIBILITAT
   ========================================= */

.button:focus-visible {
    outline: 3px solid var(--game-secondary);
    outline-offset: 3px;
}


/* =========================================
   PANTALLES MOLT PETITES
   ========================================= */

@media (max-width: 360px) {

    #app {
        padding-left: 12px;
        padding-right: 12px;
    }

    .game-header h1 {
        font-size: 2rem;
    }

}


/* =========================================
   DESKTOP / TABLET
   El disseny continua sent el mateix.
   Només limitem i centrem el contingut.
   ========================================= */

@media (min-width: 768px) {

    #app {
        padding-top: 28px;
        padding-bottom: 48px;
    }

}

/* =========================================
   PANTALLES INTERIORS
   ========================================= */

.screen {
    width: 100%;
    max-width: var(--content-width);
}

.back-button {
    padding: 8px 0;
    border: none;
    background: transparent;
    color: var(--game-secondary);
    font: inherit;
    cursor: pointer;
}

.screen-header {
    margin: 32px 0;
    text-align: center;
}

.screen-header h1 {
    margin: 0 0 12px;
    font-family: var(--font-title);
    font-size: clamp(1.8rem, 8vw, 2.5rem);
}

.screen-header p {
    margin: 0;
    color: var(--game-muted);
}


/* =========================================
   FORMULARIS
   ========================================= */

.form-field {
    margin-bottom: 28px;
}

.form-field label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
}

.form-field input {
    width: 100%;
    min-height: 54px;
    padding: 14px;

    border: 1px solid var(--game-secondary);
    border-radius: var(--radius);

    background: var(--game-surface);
    color: var(--game-text);

    font-family: var(--font-text);
    font-size: 16px;
}

.form-field input:focus {
    outline: 2px solid var(--game-primary);
    outline-offset: 2px;
}

.form-error {
    color: #ff8585;
    margin-bottom: 18px;
}


/* =========================================
   SELECTOR DE JUGADORS
   ========================================= */

.number-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.number-selector button {
    width: 60px;
    height: 54px;

    border: 1px solid var(--game-secondary);
    border-radius: var(--radius);

    background: var(--game-surface);
    color: var(--game-text);

    font-size: 1.6rem;
    cursor: pointer;
}

.number-selector output {
    font-size: 1.5rem;
    font-weight: 600;
}

/* =========================================
   CONFIRMACIÓ D'EQUIP
   ========================================= */

.team-created {
    text-align: center;
}

.team-summary {
    margin: 36px 0;
    padding: 24px 18px;
    background: var(--game-surface);
    border-radius: var(--radius);
}

.team-summary h2 {
    margin: 0 0 8px;
    font-family: var(--font-title);
    font-size: 1.6rem;
}

.team-summary > p {
    color: var(--game-muted);
}

.team-code {
    margin: 30px 0 18px;
    padding: 20px 12px;
    border: 1px solid var(--game-secondary);
    border-radius: var(--radius);
}

.team-code span {
    display: block;
    margin-bottom: 10px;
    color: var(--game-secondary);
    font-size: 0.8rem;
    letter-spacing: 1px;
}

.team-code strong {
    display: block;
    font-size: clamp(2rem, 10vw, 3rem);
    letter-spacing: 0.15em;
    overflow-wrap: anywhere;
}

.team-code-help {
    font-size: 0.9rem;
    line-height: 1.5;
}

.button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* =========================================
   RECUPERACIÓ DE PARTIDA
   ========================================= */

.recovery input {
    text-align: center;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

/* =========================================
   MOTOR DE JOC
   ========================================= */
.gameplay { display:block; }
.gameplay-title { font-family:var(--font-title);font-size:1.9rem;text-align:center;margin:12px 0; }
.game-meta,.game-time { color:var(--game-muted);text-align:center; }
.game-time {font-variant-numeric:tabular-nums;margin:14px 0 24px;}
.game-card { background:var(--game-surface);border-radius:var(--radius);padding:18px;margin:20px 0;overflow-wrap:anywhere; }
.game-card h2 {font-family:var(--font-title);font-size:1.25rem;margin:0 0 16px;}
.game-card .button {margin:12px 0 0;}
.stage-media {max-width:100%;width:100%;height:auto;border-radius:var(--radius);display:block;margin:12px 0;}
.stage-answer {width:100%;min-height:52px;padding:12px;font:inherit;background:var(--game-background);color:var(--game-text);border:1px solid var(--game-secondary);border-radius:var(--radius);}
.game-success {color:var(--game-secondary);font-weight:700;}
.stage-label {font-weight:600;}
.gameplay > .button {margin:10px 0;}
.game-card details {margin:10px 0;}
.game-card summary {cursor:pointer;}

/* =========================================================
   LANDING CINEMATOGRÀFICA
   Portada comuna per a tots els jocs
   ========================================================= */


/* ---------------------------------------------------------
   CONTENIDOR PRINCIPAL
   --------------------------------------------------------- */

#app:has(> .landing) {
    padding: 0;
    min-height: 100vh;
    min-height: 100dvh;
}


/* ---------------------------------------------------------
   PORTADA
   --------------------------------------------------------- */

.landing {
    position: relative;

    width: 100%;
    max-width: 560px;

    min-height: 100vh;
    min-height: 100dvh;

    margin: 0 auto;

    display: flex;
    flex-direction: column;
    justify-content: flex-end;

    overflow: hidden;

    isolation: isolate;

    background: var(--game-background);
}


/* ---------------------------------------------------------
   FOTOGRAFIA DE FONS
   --------------------------------------------------------- */

.landing .game-cover {
    position: absolute;
    inset: 0;

    width: 100%;
    height: 100%;

    margin: 0;
    border-radius: 0;
    aspect-ratio: auto;

    overflow: hidden;

    z-index: -2;
}

.landing .game-cover img {
    width: 100%;
    height: 100%;

    display: block;

    object-fit: cover;
    object-position: center;
}


/* ---------------------------------------------------------
   DEGRADAT SOBRE LA FOTOGRAFIA
   --------------------------------------------------------- */

.landing::before {
    content: "";

    position: absolute;
    inset: 0;

    z-index: -1;

    pointer-events: none;

    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.35) 0%,
        rgba(0, 0, 0, 0.05) 25%,
        rgba(0, 0, 0, 0.20) 45%,
        rgba(0, 0, 0, 0.72) 68%,
        rgba(0, 0, 0, 0.94) 100%
    );
}


/* ---------------------------------------------------------
   BARRA SUPERIOR
   --------------------------------------------------------- */

.landing-topbar {
    position: absolute;

    top: 0;
    left: 0;
    right: 0;

    z-index: 5;

    display: flex;
    align-items: center;
    justify-content: space-between;

    padding:
        calc(16px + env(safe-area-inset-top, 0px))
        18px
        16px;
}

.landing-topbar-left,
.landing-topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}


/* ---------------------------------------------------------
   BOTONS D'ICONA
   --------------------------------------------------------- */

.landing-icon-button {
    width: 44px;
    height: 44px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;

    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;

    background: rgba(0, 0, 0, 0.40);
    color: var(--game-text);

    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    cursor: pointer;

    touch-action: manipulation;

    transition:
        background 0.2s ease,
        transform 0.15s ease;
}

.landing-icon-button svg {
    width: 23px;
    height: 23px;
}

.landing-icon-button:active {
    transform: scale(0.94);
    background: rgba(0, 0, 0, 0.65);
}

.landing-icon-button:focus-visible {
    outline: 3px solid var(--game-secondary);
    outline-offset: 3px;
}


/* ---------------------------------------------------------
   CONTINGUT INFERIOR
   --------------------------------------------------------- */

.landing-content {
    position: relative;
    z-index: 1;

    width: 100%;

    padding:
        100px
        24px
        calc(32px + env(safe-area-inset-bottom, 0px));
}


/* ---------------------------------------------------------
   TÍTOL I SUBTÍTOL
   --------------------------------------------------------- */

.landing .game-header {
    margin: 0 0 18px;

    text-align: left;
}

.landing .game-header h1 {
    margin: 0;

    font-family: var(--font-title);

    font-size: clamp(2.3rem, 10vw, 3.5rem);
    font-weight: 700;
    line-height: 1.05;

    color: var(--game-text);

    text-wrap: balance;

    text-shadow: 0 3px 12px rgba(0, 0, 0, 0.55);
}

.landing .game-subtitle {
    margin: 14px 0 0;

    font-family: var(--font-text);
    font-size: 1.05rem;
    font-weight: 600;

    color: var(--game-secondary);

    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65);
}


/* ---------------------------------------------------------
   DESCRIPCIÓ
   --------------------------------------------------------- */

.landing .game-description {
    margin: 0 0 30px;

    font-family: var(--font-text);
    font-size: 0.98rem;
    line-height: 1.6;

    color: var(--game-text);

    text-align: left;

    opacity: 0.92;

    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.70);
}


/* ---------------------------------------------------------
   INFORMACIÓ DE LA PARTIDA GUARDADA
   --------------------------------------------------------- */

.landing-session-info {
    margin: 0 0 20px;

    padding: 12px 16px;

    border-left: 3px solid var(--game-secondary);

    background: rgba(0, 0, 0, 0.35);

    color: var(--game-text);

    font-family: var(--font-text);
    font-size: 0.9rem;

    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}


/* ---------------------------------------------------------
   ACCIONS DE LA LANDING
   --------------------------------------------------------- */

.landing .landing-actions {
    display: flex;
    flex-direction: column;

    gap: 12px;
}

.landing .landing-actions .button {
    width: 100%;
    min-height: 58px;

    font-family: var(--font-text);
    font-size: 1.05rem;
    font-weight: 700;

    letter-spacing: 0.025em;
}

.landing .landing-actions .button-primary {
    background: var(--game-primary);
    color: var(--game-text);

    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.35);
}


/* ---------------------------------------------------------
   NOVA PARTIDA COM A ACCIÓ SECUNDÀRIA
   Quan existeix una partida guardada
   --------------------------------------------------------- */

.landing .landing-actions .button-secondary {
    min-height: 46px;

    background: rgba(0, 0, 0, 0.30);

    border: 1px solid rgba(255, 255, 255, 0.35);

    color: var(--game-text);

    font-size: 0.95rem;
    font-weight: 500;

    box-shadow: none;
}


/* ---------------------------------------------------------
   RESPECTAR ELS ELEMENTS OCULTS
   --------------------------------------------------------- */

.landing [hidden] {
    display: none !important;
}


/* ---------------------------------------------------------
   PANTALLES PETITES
   --------------------------------------------------------- */

@media (max-width: 360px) {

    .landing-content {
        padding-left: 18px;
        padding-right: 18px;
    }

    .landing .game-header h1 {
        font-size: clamp(2rem, 10vw, 2.5rem);
    }

    .landing .game-description {
        font-size: 0.9rem;
        margin-bottom: 22px;
    }

}


/* ---------------------------------------------------------
   PANTALLES BAIXES
   Evitar que el contingut quedi retallat
   --------------------------------------------------------- */

@media (max-height: 650px) {

    .landing-content {
        padding-top: 90px;
        padding-bottom: 20px;
    }

    .landing .game-header h1 {
        font-size: clamp(2rem, 8vw, 2.7rem);
    }

    .landing .game-description {
        margin-bottom: 20px;
    }

}


/* ---------------------------------------------------------
   DESKTOP I TABLET
   Portada vertical centrada
   --------------------------------------------------------- */

@media (min-width: 768px) {

    .landing {
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
    }

    .landing-content {
        padding-left: 36px;
        padding-right: 36px;
    }

}

/* =========================================================
   REGISTRE - CONDICIONS LEGALS
   ========================================================= */

.registration-legal {
    margin: 30px 0 24px;
}

.registration-legal h2 {
    margin: 0 0 12px;
    font-family: var(--font-text);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--game-muted);
}

.legal-text {
    max-height: none;
    overflow: visible;

    padding: 18px 20px;

    background: var(--game-surface);
    color: var(--game-muted);

    border: 1px solid color-mix(
        in srgb,
        var(--game-secondary) 35%,
        transparent
    );

    border-radius: var(--radius);

    font-size: 0.85rem;
    line-height: 1.55;

    white-space: pre-line;
}

.legal-acceptance {
    display: flex;
    align-items: flex-start;
    gap: 12px;

    margin-top: 18px;

    font-size: 0.9rem;
    line-height: 1.5;
}

.legal-acceptance input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 2px;
    accent-color: var(--game-primary);
}

/* =========================================================
   REGISTRE COMPACTE
   ========================================================= */

.registration .screen-header {
    margin-bottom: 24px;
}

.registration .screen-header h1 {
    margin-bottom: 0;
    font-size: clamp(1.6rem, 6vw, 2rem);
}

/* Nom i jugadors a la mateixa fila */

.registration-team-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 132px;
    gap: 12px;
    align-items: end;
    margin-bottom: 22px;
}

.registration-team-row .form-field {
    min-width: 0;
    margin-bottom: 0;
}

.registration-team-row label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

/* Nom de l'equip */

.registration-team-name input {
    width: 100%;
    min-width: 0;
    height: 48px;
    padding: 10px 12px;
    font-size: 0.95rem;
}

/* Selector de jugadors */

.registration-team-players .number-selector {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 38px;
    align-items: center;
    width: 100%;
    height: 48px;
    gap: 0;
}

.registration-team-players .number-selector button {
    width: 38px;
    min-width: 0;
    height: 48px;
    padding: 0;
    font-size: 1.2rem;
}

.registration-team-players .number-selector output {
    min-width: 0;
    text-align: center;
    font-size: 1rem;
}

/* Condicions legals */

.registration .registration-legal {
    margin: 0 0 20px;
}

.registration .registration-legal h2 {
    margin-bottom: 10px;
}

.registration .legal-text {
    padding: 14px 16px;
    font-size: 0.82rem;
    line-height: 1.5;
}

.registration .legal-acceptance {
    margin-top: 14px;
    margin-bottom: 0;
}

/* Pantalles estretes */

@media (max-width: 360px) {

    .registration-team-row {
        grid-template-columns: minmax(0, 1fr) 120px;
        gap: 8px;
    }

    .registration-team-players .number-selector {
        grid-template-columns: 34px minmax(0, 1fr) 34px;
    }

    .registration-team-players .number-selector button {
        width: 34px;
    }
}