.data-container-3 {
    margin-top: 40px;
    overflow-x: auto;
    padding: 25px;
    border-radius: 15px;
}

#saveGraphButton {
    text-align: center;
    width: fit-content;
}

.contribution-graph h3 {
    margin-top: 0;
    margin-left: 10px;
}

/* Card header: title on the left, the phone-only range toggle on the right,
   so the control lives inside the card instead of floating past its edge. */
.graph-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}

.graph-head h3 {
    margin-bottom: 0;
}

.heatmap-range-toggle {
    flex: 0 0 auto;
    margin-right: 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-white);
    color: var(--color-text-secondary);
    font-family: inherit;
    font-size: 12px;
    padding: 6px 10px;
    min-height: 32px;
    cursor: pointer;
}

.contribution-graph {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    margin-top: 20px;
    padding: 10px;
    padding-top: 20px;
    padding-bottom: 20px;
    -webkit-overflow-scrolling: touch;
    width: fit-content;
    margin: 0 auto;
}

/* --weeks is set by heatmap.js (52 normally, 26 on a phone); --cell/--gap keep
   the grid, the legend and the month labels in step with each other. */
.graph-wrapper {
    --cell: 10px;
    --gap: 3px;
    --step: calc(var(--cell) + var(--gap));
    --weeks: 52;
    min-width: 700px;
    max-width: 900px;
    margin: 0 auto;
    width: fit-content;
}

#contribution-grid {
    display: grid;
    grid-template-columns: repeat(var(--weeks), var(--cell));
    grid-template-rows: repeat(7, var(--cell));
    grid-auto-flow: column;
    gap: var(--gap);
    margin-bottom: 10px;
    justify-content: center;
}

#contribution-grid .day {
    width: var(--cell);
    height: var(--cell);
    border-radius: 2px;
    background-color: #ebedf0;
}

.graph-legend {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 12px;
    color: #5d6975;
    width: calc(var(--weeks) * var(--step) - var(--gap));
    margin: 0 auto; /* Center the legend container */
}

.legend-colors {
    display: flex;
    gap: 2px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.legend-colors li {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

/* Color scale for the boxes */
.legend-colors li:nth-child(1) { background-color: #ebedf0; }  /* 0 views */
.legend-colors li:nth-child(2) { background-color: rgba(38, 98, 163, 0.25); } /* 1-33% of max */
.legend-colors li:nth-child(3) { background-color: rgba(38, 98, 163, 0.5); }  /* 34-66% of max */
.legend-colors li:nth-child(4) { background-color: rgba(38, 98, 163, 0.75); } /* 67-99% of max */
.legend-colors li:nth-child(5) { background-color: rgba(38, 98, 163, 1); }    /* 100% of max */

#month-labels {
    display: flex;
    margin-bottom: 8px;
    color: var(--color-text-tertiary);
    font-size: 12px;
    align-items: center;
    justify-content: center;
}

#month-labels {
    width: calc(var(--weeks) * var(--step) - var(--gap));
    margin-left: auto;
    margin-right: auto;
}

.month-label {
    width: calc(var(--step) * 4.345);  /* Approximate width of 4.345 weeks */
    text-align: center;
}

.save-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin: 5px auto;
}

.save-buttons button {
    margin: 0;
}

.data-container-3.gradient-active {
    background: linear-gradient(135deg, #6997c7 0%, #cfdae6 100%);
}

.data-container-3.gradient-active .contribution-graph {
    border: none;
}

#gradientButton.gradient-active {
    background: linear-gradient(135deg, #6997c7 0%, #cfdae6 100%);
    color: white;
    border-color: transparent;
}


/* Phones open on 26 weeks, which is sized fluidly so the card fits the screen
   and the cells stay ~11px instead of the old untappable 7px. "Full year" adds
   .full-year, which switches back to fixed cells that scroll inside the card. */
@media screen and (max-width: 768px) {
    .data-container-3 {
        position: relative;
        padding: 10px 0;
    }

    .contribution-graph {
        width: auto;
        padding-left: 8px;
        padding-right: 8px;
    }

    .graph-wrapper {
        min-width: 0;
        max-width: none;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .graph-wrapper::-webkit-scrollbar {
        height: 0;
    }

    #contribution-grid,
    #month-labels,
    .graph-legend {
        width: 100%;
    }

    /* The legend must stay put while the full-year grid scrolls under it. */
    .graph-legend {
        position: sticky;
        left: 0;
    }

    #contribution-grid {
        grid-template-columns: repeat(var(--weeks), minmax(0, 1fr));
        grid-template-rows: repeat(7, auto);
        gap: 2px;
    }

    #contribution-grid .day {
        width: 100%;
        height: auto;
        aspect-ratio: 1;
    }

    .month-label {
        flex: 1 1 0;
        width: auto;
        min-width: 0;
    }

    /* Full year: 52 fluid columns would be 4px, so go back to fixed cells and
       let the card scroll sideways. */
    .full-year .graph-wrapper {
        --cell: 8px;
        --gap: 2px;
    }

    .full-year #contribution-grid,
    .full-year #month-labels {
        width: calc(var(--weeks) * var(--step) - var(--gap));
    }

    .full-year #contribution-grid {
        grid-template-columns: repeat(var(--weeks), var(--cell));
        grid-template-rows: repeat(7, var(--cell));
    }

    .full-year #contribution-grid .day {
        width: var(--cell);
        height: var(--cell);
        aspect-ratio: auto;
    }

    .full-year .month-label {
        flex: 0 0 auto;
        width: calc(var(--step) * 4.345);
    }

    /* Scroll affordance for the full-year view. Lives on the outer container,
       which the Save Image clone does not include. */
    .data-container-3.full-year::after {
        content: '';
        position: absolute;
        top: 10px;
        bottom: 10px;
        right: 0;
        width: 28px;
        pointer-events: none;
        background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.95));
        border-radius: 0 10px 10px 0;
    }

    .save-buttons {
        flex-wrap: wrap;
        gap: 10px;
    }
}
