/* ==========================================================================
   speedo.css — chrome shared by every gauge page: status line, stat tiles,
   cards, controls. The instrument itself lives in the skin stylesheet, which also
   restyles the blocks below to match via body[data-skin].
   ========================================================================== */

/* Every instrument sits in .hero, so fullscreen and double-tap have one thing
   to target. */
.hero {
    width: 100%;
    max-width: 460px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ---------------- toolbar above the instrument ---------------- */
.tool-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 460px;
    min-height: 44px;
    margin-bottom: 16px;
}

.fs-btn {
    position: absolute;
    right: 0;
    width: 42px;
    height: 42px;
    background-color: var(--surface-raised);
    border: 1px solid var(--divider-color);
    box-shadow: var(--shadow-1);
}

/* The button goes position: fixed in fullscreen, so the bar has to stay in the
   tree but take up no room. */
body.fs .unit-switch {
    display: none;
}

body.fs .tool-bar {
    min-height: 0;
    margin: 0;
}

/* ---------------- unit switch ---------------- */
.unit-switch {
    display: inline-flex;
    border: 1px solid var(--divider-color);
    border-radius: 20px;
    overflow: hidden;
    background: var(--surface-raised);
}

.unit-switch button {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-color-secondary);
    font-family: inherit;
    font-size: .8125rem;
    font-weight: 600;
    padding: 8px 16px;
    min-height: 38px;
    cursor: pointer;
}

.unit-switch button + button {
    border-left: 1px solid var(--divider-color);
}

.unit-switch button[aria-pressed=true] {
    background: var(--primary-color);
    color: var(--on-primary);
}

.unit-switch button:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

/* Nothing to show before the first measurement. */
body.no-data .chart-card,
body.no-data .track-card,
body.no-data .splits-card {
    display: none;
}

/* ---------------- status + stats ---------------- */
.block {
    width: 100%;
    margin-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bar-wrap {
    width: 100%;
    height: 6px;
    background-color: var(--track-color);
    border-radius: 999px;
    overflow: hidden;
}

.bar {
    height: 100%;
    width: 0;
    background-color: var(--primary-color);
    border-radius: 999px;
    transition: width .2s linear, background-color .3s;
}

.bar.over {
    background-color: var(--error-color);
}

/* Text, not a flex row: a flex dot ends up stranded left when the message
   wraps to two lines. */
.status {
    display: block;
    font-size: .875rem;
    line-height: 1.45;
    color: var(--text-color-secondary);
    min-height: 20px;
    text-align: center;
}

.dot {
    display: inline-block;
    vertical-align: baseline;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--text-color-secondary);
}

.dot.good {
    background: var(--good-color);
}

.dot.fair {
    background: var(--warn-color);
}

.dot.poor {
    background: var(--error-color);
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
}

/* Pages that show three tiles shouldn't stretch them across four columns. */
.stats[data-count="3"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
    padding: 11px 8px;
    border-radius: 12px;
    background-color: var(--surface-raised);
    box-shadow: var(--shadow-1);
    text-align: center;
    min-width: 0;
}

.stat .k {
    display: block;
    font-size: .6875rem;
    font-weight: 500;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-color-secondary);
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat .v {
    display: block;
    font-family: var(--font-mono);
    font-size: 1.125rem;
    font-weight: 500;
    font-feature-settings: "tnum";
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat .v .u {
    font-size: .7rem;
    font-weight: 400;
    color: var(--text-color-secondary);
    margin-left: 2px;
}

/* ---------------- cards: graph, route, splits ---------------- */
.card {
    width: 100%;
    margin-top: 14px;
    padding: 10px;
    border-radius: 12px;
    background-color: var(--surface-raised);
    box-shadow: var(--shadow-1);
    overflow: hidden;
}

.card-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: .6875rem;
    font-weight: 500;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-color-secondary);
    padding: 2px 4px 8px;
}

.chart-card {
    height: 170px;
}

#chart {
    display: block;
    width: 100%;
    height: 100%;
}


.track-card canvas {
    display: block;
    width: 100%;
    height: 190px;
}

.splits-card {
    padding: 10px 12px 12px;
}

.splits {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
    font-family: var(--font-mono);
}

.splits th,
.splits td {
    padding: 6px 4px;
    text-align: right;
    border-bottom: 1px solid var(--divider-color);
    color: var(--text-color-secondary);
}

.splits th {
    font-family: var(--font-sans);
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 500;
}

.splits th:first-child,
.splits td:first-child {
    text-align: left;
}

.splits tr:last-child td {
    border-bottom: none;
}

.splits td.best {
    color: var(--good-color);
    font-weight: 500;
}

.splits-empty {
    font-size: .8rem;
    color: var(--text-color-secondary);
    padding: 10px 4px;
    text-align: center;
}

.ad-slot {
    width: 100%;
    max-width: 728px;
    min-height: 280px;
    margin: 22px auto 0;
}

/* ---------------- speed alert chips ---------------- */
.alert-row {
    width: 100%;
    margin-top: 14px;
}

.alert-row .card-title {
    padding-left: 0;
}

/* ---------------- controls ---------------- */
.controls {
    position: sticky;
    bottom: 0;
    z-index: 55;
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 8px;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    min-height: 80px;
    border-top: 1px solid var(--divider-color);
    background-color: var(--surface-color);
}

/* ---------------- fullscreen ---------------- */
body.fs .header,
body.fs .chart-card,
body.fs .track-card,
body.fs .splits-card,
body.fs .alert-row,
body.fs .ad-slot,
body.fs .article,
body.fs .related,
body.fs .foot {
    display: none;
}

body.fs .app {
    height: 100vh;
    height: 100svh;
}

body.fs .main {
    justify-content: center;
    max-width: none;
}

body.fs .hero {
    max-width: min(560px, 62vh);
}

body.fs .fs-btn {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    right: 10px;
    width: 46px;
    height: 46px;
    color: var(--text-color);
}

/* ---------------- responsive ---------------- */
@media (max-width:600px) {
    .stats {
        gap: 8px;
    }

    .stat {
        padding: 8px 5px;
        border-radius: 10px;
    }

    .stat .v {
        font-size: 1.0625rem;
    }

    .stat .k {
        font-size: .625rem;
        letter-spacing: .02em;
    }

    .chart-card {
        height: 140px;
    }

    .track-card canvas {
        height: 160px;
    }

    .controls {
        min-height: 72px;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    }
}

@media (max-height:520px) and (orientation:landscape) {
    .main {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 18px;
        padding: 8px 12px;
        max-width: none;
    }

    .chart-card,
    .track-card,
    .splits-card,
    .alert-row,
    .ad-slot {
        display: none;
    }

    .hero {
        max-width: 46vh;
    }

    .block {
        max-width: 340px;
        margin-top: 0;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat {
        padding: 5px 6px;
    }

    .stat .v {
        font-size: .85rem;
    }

    .stat .k {
        font-size: .58rem;
        margin-bottom: 1px;
    }

    .controls {
        min-height: 56px;
    }

    .controls .btn span {
        display: none;
    }
}
