:root {
    color-scheme: light dark;
    --bg: #f7f8fb;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #657386;
    --border: #d9e0ea;
    --ok: #087f5b;
    --ok-bg: #d3f9d8;
    --high: #c92a2a;
    --high-bg: #ffe3e3;
    --low: #1c64b7;
    --low-bg: #dbeafe;
    --stale: #8a5a00;
    --stale-bg: #fff3bf;
    --error: #9b1c1c;
    --error-bg: #ffe8cc;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

.dashboard {
    min-height: 100vh;
    display: grid;
    align-content: center;
    gap: 18px;
    width: min(760px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0;
}

.reading-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: clamp(20px, 4vw, 36px);
    box-shadow: 0 20px 70px rgba(23, 32, 42, 0.08);
}

.top-row,
.reading-grid,
.meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 32px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.sound-toggle {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    min-height: 38px;
    padding: 8px 12px;
}

.sound-toggle:hover,
.sound-toggle:focus-visible {
    border-color: var(--muted);
}

.sound-toggle.sound-enabled {
    background: var(--ok-bg);
    border-color: transparent;
    color: var(--ok);
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.25rem);
    line-height: 1;
    white-space: nowrap;
}

.status-pill {
    min-width: 96px;
    border-radius: 999px;
    padding: 9px 14px;
    text-align: center;
    font-weight: 800;
    border: 1px solid transparent;
}

.status-in_range {
    background: var(--ok-bg);
    color: var(--ok);
}

.status-high {
    background: var(--high-bg);
    color: var(--high);
}

.status-low {
    background: var(--low-bg);
    color: var(--low);
}

.status-stale,
.status-loading {
    background: var(--stale-bg);
    color: var(--stale);
}

.status-error {
    background: var(--error-bg);
    color: var(--error);
}

.reading-grid {
    margin: 44px 0;
    justify-content: flex-start;
    gap: 40px;
}

.glucose {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    min-width: 0;
    flex: 1 1 260px;
}

.previous-reading {
    width: 132px;
    flex: 0 0 132px;
    border-right: 1px solid var(--border);
    padding-right: 22px;
}

.previous-value-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.previous-value {
    font-size: 2.2rem;
    line-height: 1;
    font-weight: 900;
}

.previous-arrow {
    color: var(--muted);
    font-size: 1.25rem;
    font-weight: 900;
}

.previous-time {
    margin-top: 7px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.glucose-value {
    font-size: clamp(5rem, 20vw, 9rem);
    line-height: 0.85;
    font-weight: 900;
    letter-spacing: 0;
}

.glucose-unit {
    color: var(--muted);
    font-size: 1.1rem;
    font-weight: 800;
    line-height: 1;
}

.trend {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 260px;
    flex: 0 0 auto;
}

.trend-arrow {
    width: 86px;
    height: 86px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 3rem;
    font-weight: 900;
}

.trend-text {
    font-size: 1.35rem;
    font-weight: 850;
}

.reading-time {
    margin-top: 6px;
    color: var(--muted);
    font-weight: 650;
}

.meta-row {
    border-top: 1px solid var(--border);
    padding-top: 22px;
}

.label {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.meta-row strong {
    font-size: 1.2rem;
}

.message,
.notice {
    color: var(--muted);
    font-weight: 650;
}

.message {
    margin: 22px 0 0;
}

.notice {
    margin: 0;
    text-align: center;
}

body[data-state="high"] .glucose-value,
body[data-state="high"] .trend-arrow {
    color: var(--high);
}

body[data-state="low"] .glucose-value,
body[data-state="low"] .trend-arrow {
    color: var(--low);
}

body[data-state="in_range"] .glucose-value,
body[data-state="in_range"] .trend-arrow {
    color: var(--ok);
}

body[data-state="high"] .previous-value,
body[data-state="low"] .previous-value,
body[data-state="in_range"] .previous-value {
    color: var(--text);
}

@media (max-width: 680px) {
    .dashboard {
        min-height: 100svh;
        width: min(100% - 20px, 760px);
        padding: 10px 0;
        align-content: start;
    }

    .reading-panel {
        padding: 18px;
    }

    .top-row,
    .reading-grid,
    .meta-row {
        align-items: flex-start;
        gap: 16px;
    }

    .top-row,
    .reading-grid {
        flex-direction: column;
    }

    .eyebrow {
        font-size: 0.72rem;
        line-height: 1.25;
    }

    h1 {
        font-size: 2.15rem;
        line-height: 1.05;
        white-space: normal;
    }

    .status-pill {
        align-self: stretch;
    }

    .top-actions {
        width: 100%;
    }

    .sound-toggle {
        flex: 1;
    }

    .reading-grid {
        margin: 26px 0;
        width: 100%;
    }

    .glucose {
        width: 100%;
        align-items: center;
        text-align: center;
        gap: 8px;
    }

    .glucose-value {
        font-size: clamp(5.5rem, 34vw, 8rem);
        line-height: 0.82;
    }

    .glucose-unit {
        font-size: 1rem;
    }

    .trend {
        width: 100%;
        min-width: 0;
        align-items: center;
        border-top: 1px solid var(--border);
        padding-top: 16px;
    }

    .previous-reading {
        width: 100%;
        flex: none;
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 8px 14px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        padding-right: 0;
        padding-bottom: 16px;
    }

    .previous-reading .label {
        margin-bottom: 0;
    }

    .previous-value-row {
        justify-self: end;
    }

    .previous-value {
        font-size: 1.8rem;
    }

    .previous-time {
        grid-column: 1 / -1;
        margin-top: 0;
    }

    .trend-arrow {
        width: 72px;
        height: 72px;
        flex: 0 0 auto;
    }

    .meta-row {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        width: 100%;
        gap: 12px;
        padding-top: 18px;
    }

    .message {
        margin-top: 18px;
        line-height: 1.35;
    }

    .notice {
        font-size: 0.82rem;
        line-height: 1.35;
    }
}

@media (max-width: 420px) {
    .reading-panel {
        padding: 16px;
    }

    h1 {
        font-size: 1.85rem;
    }

    .top-actions {
        gap: 8px;
    }

    .sound-toggle,
    .status-pill {
        min-height: 40px;
        padding: 8px 10px;
        font-size: 0.9rem;
    }

    .glucose-value {
        font-size: clamp(4.8rem, 36vw, 6.8rem);
    }

    .trend {
        gap: 12px;
    }

    .trend-arrow {
        width: 62px;
        height: 62px;
        font-size: 2.4rem;
    }

    .trend-text {
        font-size: 1.08rem;
    }

    .reading-time {
        font-size: 0.9rem;
    }

    .meta-row strong {
        font-size: 1.05rem;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101419;
        --panel: #171d24;
        --text: #edf2f7;
        --muted: #a7b4c4;
        --border: #2c3642;
        --ok-bg: #123f32;
        --high-bg: #4d1717;
        --low-bg: #17335c;
        --stale-bg: #47360d;
        --error-bg: #522312;
    }
}
