:root {
    color-scheme: dark;
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1d232c;
    --border: #262d37;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #58a6ff;
    --radius: 14px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.4;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 8rem;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    -webkit-text-size-adjust: 100%;
}

a {
    color: var(--accent);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.page {
    max-width: 40rem;
    margin: 0 auto;
    padding: 0 1rem calc(1.5rem + env(safe-area-inset-bottom));
}

/* Header */

.top {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0 -1rem;
    padding: calc(0.9rem + env(safe-area-inset-top)) 1rem 0.9rem;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 650;
    letter-spacing: -0.01em;
}

h1:focus {
    outline: none;
}

.subtitle {
    margin: 0.15rem 0 0;
    color: var(--muted);
    font-size: 0.875rem;
}

.toggle {
    display: inline-flex;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.toggle a {
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 550;
    text-decoration: none;
    white-space: nowrap;
}

.toggle a.active {
    background: var(--surface-2);
    color: var(--text);
    box-shadow: 0 0 0 1px var(--border);
}

/* Price level colour: --level runs from 0 (cheapest) to 1 (most expensive) */

.value,
.prices li {
    --hue: calc(140 - var(--level, 0.5) * 140);
    --level-color: hsl(var(--hue) 70% 58%);
}

/* Summary */

.summary {
    display: grid;
    gap: 0.6rem;
    margin: 1rem 0;
}

@media (min-width: 48rem) {
    .summary {
        grid-template-columns: minmax(0, 1fr) minmax(0, 2.4fr) minmax(0, 2.4fr);
    }
}

.card {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.8rem 0.9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: inherit;
    text-decoration: none;
}

.card.now {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.card .label {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.card .value {
    font-size: 1.5rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.card .value[style] {
    color: var(--level-color);
}

.card .hint {
    color: var(--muted);
    font-size: 0.8rem;
}

/* Lowest, highest and average of a day, side by side */

.day-summary .label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0.2rem 0 0;
}

.stats div {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.stats dt {
    color: var(--muted);
    font-size: 0.75rem;
}

.stats dd {
    margin: 0;
}

.day-summary.forecast .value {
    font-style: italic;
    opacity: 0.8;
}

/* Phones: compact summary so the price list starts high on the screen */

@media (max-width: 47.99rem) {
    .summary {
        gap: 0.4rem;
        margin: 0.75rem 0;
    }

    .summary .card {
        padding: 0.5rem 0.8rem;
    }

    .card.now {
        flex-direction: row;
        align-items: baseline;
        gap: 0.6rem;
    }

    .card.now .hint {
        margin-left: auto;
    }

    .summary .value {
        font-size: 1.15rem;
        line-height: 1.25;
    }

    .day-summary {
        display: grid;
        grid-template-columns: 5.25rem minmax(0, 1fr);
        align-items: center;
    }

    .day-summary .label {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .stats {
        gap: 0.5rem;
        margin: 0;
    }

    .stats dt {
        font-size: 0.7rem;
    }

    .stats .hint {
        font-size: 0.72rem;
    }

    /* The list shows fewer past hours than the chart (PriceOverview:ListHoursBack) */
    .day.chart-only,
    .prices li.chart-only {
        display: none;
    }

    /* Hidden rows are always first, so the first visible row starts the list */
    .prices li.chart-only + li:not(.chart-only) {
        border-top: 0;
    }
}

/* Days */

.day + .day {
    margin-top: 1.25rem;
}

.day h2 {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin: 0 0 0.5rem;
    font-size: 1rem;
    font-weight: 650;
}

.day-date {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.badge {
    padding: 0.05rem 0.5rem;
    border: 1px dashed color-mix(in srgb, var(--muted) 70%, transparent);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Price list (mobile first) */

.prices {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* Positioned so visually hidden labels stay inside the scroll container */
.prices li {
    position: relative;
    display: grid;
    grid-template-columns: 5.5rem 1fr 3.5rem;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.75rem;
    padding: 0.35rem 0.9rem;
    border-top: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.prices li:first-child {
    border-top: 0;
}

.prices li.past {
    opacity: 0.45;
}

.prices li.current {
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
    box-shadow: inset 3px 0 0 var(--accent);
}

.time {
    font-weight: 550;
}

.time .end {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.85em;
}

.tick {
    display: none;
}

.bar {
    height: 0.5rem;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.bar span {
    display: block;
    width: calc(var(--size, 0) * 1%);
    height: 100%;
    background: var(--level-color);
    border-radius: inherit;
}

.price {
    text-align: right;
    font-weight: 650;
    color: var(--level-color);
}

/* Forecasts: striped bars and softer prices */

.prices li.forecast .bar span {
    background: repeating-linear-gradient(
        135deg,
        var(--level-color) 0 4px,
        color-mix(in srgb, var(--level-color) 35%, transparent) 4px 7px);
}

.prices li.forecast .price {
    font-style: italic;
    opacity: 0.8;
}

/* Larger screens: each day is a group of columns in a horizontally scrolling chart */

@media (min-width: 48rem) {
    .page {
        max-width: 72rem;
        padding-inline: 1.5rem;
    }

    .top {
        margin-inline: -1.5rem;
        padding-inline: 1.5rem;
    }

    .chart {
        /* Width of a quarter hour; hour columns are 4 units. Narrow enough to show most of tomorrow next to today */
        --unit: 0.33rem;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        overflow: hidden;
    }

    .days {
        display: flex;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
        padding-bottom: 0.4rem;
    }

    .day {
        flex: none;
        display: flex;
        flex-direction: column;
    }

    .day + .day {
        margin-top: 0;
        border-left: 1px solid var(--border);
    }

    .day.forecast {
        background: repeating-linear-gradient(
            135deg,
            transparent 0 10px,
            color-mix(in srgb, var(--surface-2) 45%, transparent) 10px 20px);
    }

    /* Stays at the left edge while the rest of its day scrolls by */
    .day h2 {
        position: sticky;
        left: 0;
        align-self: flex-start;
        margin: 0;
        padding: 0.8rem 0.9rem 0.4rem;
        font-size: 0.9rem;
        white-space: nowrap;
    }

    .day .prices {
        display: flex;
        align-items: stretch;
        gap: 2px;
        height: 20rem;
        padding: 0.4rem 0.75rem 0.3rem;
        background: none;
        border: 0;
        border-radius: 0;
        overflow: visible;
    }

    .chart.dense .day .prices {
        gap: 1px;
    }

    .prices li {
        flex: none;
        width: calc(var(--span, 4) * var(--unit));
        min-height: 0;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.35rem;
        padding: 0 0 0.1rem;
        border-top: 0;
        border-radius: 6px;
    }

    .prices li:hover {
        background: var(--surface-2);
        opacity: 1;
    }

    .prices li.current {
        box-shadow: inset 0 -3px 0 var(--accent);
    }

    .time {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .price {
        order: 1;
        /* Wider than the column, centered over it */
        margin-inline: -1rem;
        font-size: 0.78rem;
        letter-spacing: -0.02em;
        text-align: center;
        white-space: nowrap;
    }

    .bar {
        order: 2;
        flex: 1;
        display: flex;
        align-items: flex-end;
        height: auto;
        background: none;
        border-radius: 0;
        overflow: visible;
    }

    .bar span {
        width: 100%;
        height: calc(var(--size, 0) * 1%);
        border-radius: 4px 4px 1px 1px;
    }

    .tick {
        order: 3;
        display: block;
        height: 1.1rem;
        color: var(--muted);
        font-size: 0.78rem;
        text-align: center;
        white-space: nowrap;
    }

    .prices li.current .tick,
    .prices li.current .price {
        color: var(--text);
        font-weight: 700;
        opacity: 1;
    }

    /* Columns are too narrow for every price label: show only the current and hovered price. Labels keep their
       space (and stay readable by screen readers) so all bars share the same height scale. */
    .prices li:not(.current, :hover) .price {
        opacity: 0;
    }

    .chart.dense li:not(.wide) .tick {
        overflow: visible;
        text-align: left;
    }

    .chart.dense li:not(.wide) .bar span {
        border-radius: 2px 2px 0 0;
    }
}

/* States and footer */

.notice {
    margin: 1rem 0;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--muted);
}

.notice.error {
    border-color: #6e2b2b;
    color: #ffb4a9;
}

footer {
    margin-top: 1.25rem;
    color: var(--muted);
    font-size: 0.8rem;
    text-align: center;
}

footer p {
    margin: 0.25rem 0;
}
