/* The page of a castell (/estadistiques/castells/{slug}) */

.ec-engrunes-fila {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;

    .engrunes {
        margin: 0;
    }

    .ec-cerca {
        flex: 0 0 15rem;
    }

    @media (width < 36rem) {
        flex-direction: column;
        align-items: stretch;

        .ec-cerca {
            flex: none;
        }
    }
}

.ec {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 76rem;
    margin: 1rem auto 0;

    h2 {
        font-size: 1.05rem;
        color: var(--color-secondary);
        margin-bottom: 0.75rem;
    }

    .ec-bloc {
        background: var(--color-white);
        border-radius: 0.75rem;
        box-shadow: var(--shadow-sm);
        padding: 1rem;

        @media (width >= 48rem) {
            padding: 1.25rem;
        }
    }
}

/* Header: the castell in the middle of the sostre */

.ec-capcalera {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.9rem;
}

.ec-tira {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 0.9rem;
    width: 100%;

    @media (width < 36rem) {
        gap: 0.5rem;
    }
}

.ec-veins {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    overflow: hidden;

    &.ec-veins-abans {
        justify-content: flex-end;
    }
}

.ec-vei {
    flex-shrink: 0;
    padding: 0.2rem 0.55rem;
    border-radius: 0.4rem;
    background-color: var(--grup);
    color: var(--grup-text);
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08);
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    /* Fainter the farther */
    opacity: calc(1 - var(--lluny) * 0.14);
    transition: opacity 0.15s, filter 0.15s, box-shadow 0.15s;

    /* Inside it: the row hides what goes out of it */
    &:hover,
    &:focus-visible {
        color: var(--grup-text);
        opacity: 1;
        filter: brightness(0.92);
        box-shadow: inset 0 0 0 2px rgb(0 0 0 / 0.3);
        outline: none;
    }

    @media (width < 36rem) {
        font-size: 0.78rem;
    }
}

.ec-fletxa {
    flex-shrink: 0;
    margin: 0 0.35rem;
    font-size: 0.78rem;
    color: var(--color-gray-darker);
    white-space: nowrap;

    @media (width < 48rem) {
        display: none;
    }
}

.ec-castell {
    margin: 0;
    padding: 0.6rem 1.3rem;
    border-radius: 1rem;
    background-color: var(--grup);
    color: var(--grup-text);
    box-shadow: 0 6px 18px rgb(0 0 0 / 0.15), inset 0 0 0 1px rgb(0 0 0 / 0.08);
    font-family: var(--font-title);
    font-size: 3.2rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;

    /* Nobody did it: it is not in the sostre yet */
    &.ec-castell-mai {
        border: 3px dashed var(--grup);
        background-color: var(--color-white);
        color: var(--color-black);
        box-shadow: none;
    }

    @media (width < 36rem) {
        padding: 0.45rem 0.9rem;
        font-size: 2.3rem;
    }
}

.ec-resum {
    margin: 0;
    text-align: center;
    text-wrap: balance;
    color: var(--color-gray-darkest);
}

.ec-sumari {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--color-gray-darkest);
    text-wrap: pretty;

    /* Safari's pretty evens out every line, and on a phone that leaves a wide gap on the right */
    @media (width < 36rem) {
        text-wrap: wrap;
    }

    p {
        margin: 0;
    }

    p + p {
        margin-top: 0.75rem;
    }

    a {
        color: inherit;
        text-decoration-color: var(--color-gray-dark);
        text-underline-offset: 2px;

        &:hover {
            text-decoration-color: currentColor;
        }
    }
}

/* Figures */

.ec-fites {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0.75rem;

    @media (width < 36rem) {
        grid-template-columns: 1fr 1fr;
    }
}

.ec-fita {
    background: var(--color-white);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    padding: 0.9rem 1rem;

    h2 {
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--color-gray-darker);
        margin-bottom: 0.5rem;
    }

    .ec-fita-gran {
        margin: 0 0 0.2rem;
        font-family: var(--font-title);
        font-size: 1.6rem;
        font-weight: 800;
        line-height: 1.2;

        &.ec-fita-text {
            font-size: 1.15rem;
        }

        small {
            font-size: 0.85rem;
            font-weight: 500;
            color: var(--color-gray-darker);
        }
    }

    .ec-fita-peu {
        margin: 0;
        font-size: 0.8rem;
        color: var(--color-gray-darkest);
    }

    &.ec-fita-pendent {
        background: repeating-linear-gradient(-45deg, var(--color-white), var(--color-white) 8px, #fafafa 8px, #fafafa 16px);
    }
}

/* A colla's name in its colour, as in the baròmetre */
.ec-colla-cel {
    display: inline-block;
    padding: 0 0.5rem;
    border-radius: 0.375rem;
    background-color: var(--colla);
    color: var(--colla-text);
    font-family: var(--font-body, inherit);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;

    &:is(a):hover {
        color: var(--colla-text);
        text-decoration: underline;
    }
}

/* The page, and beside it the charts and the castells of its family */

.ec-cos {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;

    .ec-principal,
    .ec-lateral {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
        min-width: 0;
    }

    /* On narrow screens the charts go before the list of every time, the longest */
    @media (width < 62rem) {
        .ec-principal,
        .ec-lateral {
            display: contents;
        }

        .ec-totes {
            order: 1;
        }
    }

    @media (width >= 62rem) {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 22rem;
        align-items: start;

        &.ec-cos-buit {
            grid-template-columns: minmax(0, 22rem);
        }

        .ec-lateral {
            position: sticky;
            top: 5rem;
        }
    }
}

.ec-grafic {
    margin: 0 -0.5rem;
}

/* Who did it */

.ec-taula {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;

    th {
        padding: 0 0.5rem 0.5rem;
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--color-gray-darker);
        text-align: left;
        white-space: nowrap;
    }

    td {
        padding: 0.55rem 0.5rem;
        border-top: 1px solid var(--color-gray-lighter);
        vertical-align: middle;
    }

    .ec-n {
        text-align: right;
        font-variant-numeric: tabular-nums;
        font-weight: 700;
        white-space: nowrap;
    }

    .ec-mes-carregats {
        font-size: 0.75rem;
        font-weight: 600;
        color: #8A7000;
    }

    .ec-taula-barra {
        width: 30%;
    }

    .ec-taula-data {
        font-size: 0.82rem;
        color: var(--color-gray-darker);
        white-space: nowrap;

        a {
            color: inherit;
            text-decoration: none;

            &:hover {
                text-decoration: underline;
            }
        }
    }

    /* The dates are in its story */
    @media (width < 36rem) {
        .ec-taula-data {
            display: none;
        }

        .ec-taula-barra {
            width: 50%;
        }
    }
}

.ec-barres {
    display: flex;
    height: 0.55rem;
    border-radius: 1rem;
    overflow: hidden;
    background: var(--color-gray-lighter);

    span {
        display: block;
        height: 100%;
    }
}

/* Who is nearest, if nobody did it */

.ec-propers-peu {
    margin: -0.4rem 0 0.9rem;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--color-gray-darker);
}

.ec-propers {
    .ec-propers-punts {
        width: 45%;
    }

    .ec-propers-fila {
        display: flex;
        align-items: center;
        gap: 0.6rem;
    }

    .ec-propers-pista {
        flex: 1;
        height: 0.55rem;
        border-radius: 1rem;
        background: var(--color-gray-lighter);
        overflow: hidden;
    }

    .ec-propers-barra {
        display: block;
        height: 100%;
        border-radius: 1rem;
        box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08);
    }

    .ec-propers-xifra {
        min-width: 3.6rem;
        text-align: right;
        font-variant-numeric: tabular-nums;
        font-weight: 700;
    }

    @media (width < 36rem) {
        .ec-propers-punts {
            width: auto;
        }

        .ec-propers-pista {
            display: none;
        }
    }
}

.ec-barra-d { background: var(--color-castell-d-dark); }
.ec-barra-c { background: var(--color-castell-c-dark); }
.ec-barra-id { background: var(--color-castell-id-dark); }
.ec-barra-i { background: var(--color-castell-if-dark); }

.ec-llegenda {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
    font-size: 0.78rem;
    color: var(--color-gray-darkest);

    li::before {
        content: '';
        display: inline-block;
        width: 0.6rem;
        height: 0.6rem;
        margin-right: 0.35rem;
        border-radius: 50%;
        vertical-align: -1px;
    }

    .ec-llegenda-d::before { background: var(--color-castell-d-dark); }
    .ec-llegenda-c::before { background: var(--color-castell-c-dark); }
    .ec-llegenda-id::before { background: var(--color-castell-id-dark); }
    .ec-llegenda-i::before { background: var(--color-castell-if-dark); }
}

/* Its story */

.ec-linia {
    --ec-data: 5.6rem;

    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;

    &::before {
        content: '';
        position: absolute;
        left: calc(var(--ec-data) + 0.95rem);
        top: 0.5rem;
        bottom: 0.5rem;
        width: 2px;
        background: var(--color-gray-light);
    }

    .ec-fet {
        position: relative;
        display: flex;
        gap: 1.5rem;
        padding: 0 0 1.05rem;

        &:last-child {
            padding-bottom: 0;
        }

        &::before {
            content: '';
            position: absolute;
            left: calc(var(--ec-data) + 0.95rem - 5px);
            top: 0.3rem;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: var(--color-white);
            border: 3px solid var(--punt);
        }

        &.ec-fet-gran::before {
            background: var(--punt);
            box-shadow: 0 0 0 4px color-mix(in srgb, var(--punt) 30%, transparent);
        }
    }

    time {
        flex: 0 0 var(--ec-data);
        padding-top: 0.1rem;
        text-align: right;
        font-size: 0.8rem;
        color: var(--color-gray-darker);
    }

    .ec-fet-text {
        flex: 1;
        min-width: 0;
        padding-left: 0.6rem;
        font-size: 0.92rem;
        line-height: 1.45;

        small {
            display: block;
            font-size: 0.8rem;
            color: var(--color-gray-darker);

            a {
                color: inherit;
            }
        }
    }

    @media (width < 36rem) {
        --ec-data: 4.2rem;
    }
}

/* Every time */

.ec-vegades {
    margin: 0;
    padding: 0;
    list-style: none;
}

.ec-vegada {
    display: grid;
    grid-template-columns: 4.2rem 7.5rem 5rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
    border-top: 1px solid var(--color-gray-lighter);
    font-size: 0.88rem;

    &:first-child {
        border-top: 0;
    }

    time {
        font-size: 0.78rem;
        color: var(--color-gray-darker);
    }

    .ec-vegada-colla {
        overflow: hidden;
        padding-left: 0.4rem;
        border-left: 4px solid var(--colla);
        color: inherit;
        font-weight: 600;
        text-decoration: none;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ec-vegada-diada {
        overflow: hidden;
        color: inherit;
        text-decoration: none;
        text-overflow: ellipsis;
        white-space: nowrap;

        &:hover {
            text-decoration: underline;
        }
    }

    .ec-vegada-ronda {
        font-size: 0.75rem;
        color: var(--color-gray-darker);
        white-space: nowrap;
    }

    @media (width < 36rem) {
        grid-template-columns: 4.3rem auto minmax(0, 1fr);
        row-gap: 0.15rem;

        time {
            white-space: nowrap;
        }

        .ec-vegada-diada {
            grid-column: 2 / -1;
            white-space: normal;
        }

        .ec-vegada-ronda {
            display: none;
        }
    }
}

.ec-chip {
    justify-self: start;
    padding: 0.1rem 0.45rem;
    border-radius: 0.3rem;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;

    &.ec-chip-d {
        background: var(--color-castell-d);
        color: #1F5C2E;
    }

    &.ec-chip-c {
        background: var(--color-castell-c);
        color: #6B5500;
    }

    &.ec-chip-id {
        background: var(--color-castell-id);
        color: var(--color-gray-darkest);
    }

    &.ec-chip-i {
        background: var(--color-castell-if);
        color: #8A2323;
    }
}

.ec-plegada {
    border-top: 1px solid var(--color-gray-lighter);

    .ec-totes h2 + & {
        border-top: 0;
    }

    summary,
    &.ec-plegada-fixa {
        display: grid;
        grid-template-columns: 1rem 10rem 2.5rem minmax(0, 1fr);
        align-items: center;
        gap: 0.5rem;
        padding: 0.6rem 0;
        font-size: 0.85rem;
    }

    summary {
        cursor: pointer;
        list-style: none;

        &::-webkit-details-marker {
            display: none;
        }

        &::before {
            content: '›';
            color: var(--color-gray-darker);
            font-size: 1rem;
            line-height: 1;
            transition: transform 0.15s;
        }

        &:hover .ec-plegada-nom {
            text-decoration: underline;
        }
    }

    &[open] summary::before {
        transform: rotate(90deg);
    }

    /* Nothing to unfold: the line starts where the others' name does */
    &.ec-plegada-fixa {
        grid-template-columns: 10rem 2.5rem minmax(0, 1fr);
        padding-left: 1.5rem;
    }

    .ec-plegada-nom {
        font-weight: 600;
    }

    .ec-plegada-total {
        color: var(--color-gray-darker);
        text-align: right;
        font-variant-numeric: tabular-nums;
    }

    .ec-plegada-colles {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;

        .ec-colla-cel {
            font-size: 0.75rem;
        }
    }

    > .ec-vegades {
        margin-bottom: 0.6rem;
    }

    @media (width < 36rem) {
        summary,
        &.ec-plegada-fixa {
            grid-template-columns: 1rem minmax(0, 1fr) auto;
        }

        &.ec-plegada-fixa {
            grid-template-columns: minmax(0, 1fr) auto;
        }

        .ec-plegada-colles {
            grid-column: 2 / -1;
        }

        &.ec-plegada-fixa .ec-plegada-colles {
            grid-column: 1 / -1;
        }
    }
}

/* Beside it */

.ec-familia {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ec-familiar {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 0.35rem;
    background-color: var(--grup);
    color: var(--grup-text);
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08);
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;

    &:hover {
        color: var(--grup-text);
        opacity: 0.85;
    }

    /* Only tried */
    &.ec-familiar-mai {
        background-color: transparent;
        color: var(--color-gray-darker);
        box-shadow: inset 0 0 0 1px var(--color-gray-light);
        font-weight: 500;
    }

    &.ec-familiar-actual {
        outline: 2px solid var(--color-black);
        outline-offset: 2px;
    }
}

.ec-explora {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.9rem;

    a {
        display: inline-flex;
        align-items: center;
        gap: 0.4rem;
        color: var(--color-secondary);
        font-weight: 600;
        text-decoration: none;

        &:hover {
            text-decoration: underline;
        }
    }
}
