:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --text: #15181d;
    --muted: #5d6673;
    --border: #e1e5ea;
    --track: #e9edf1;
    --accent: #0f8a7e;
    --accent-soft: rgba(15, 138, 126, 0.14);
    --accent-text: #ffffff;
    --warning-bg: #fff6e5;
    --warning-border: #f0c36b;
    --error: #c2412d;
    --error-soft: rgba(194, 65, 45, 0.1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216;
        --card: #181c22;
        --text: #eef1f5;
        --muted: #9aa4b2;
        --border: #2a3039;
        --track: #252b33;
        --accent: #3cc4b4;
        --accent-soft: rgba(60, 196, 180, 0.18);
        --accent-text: #08201d;
        --warning-bg: #2e2412;
        --warning-border: #8a6a28;
        --error: #f08a78;
        --error-soft: rgba(240, 138, 120, 0.12);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
    max-width: 40rem;
    margin: 0 auto;
    padding: max(1.25rem, env(safe-area-inset-top)) 1rem 2rem;
}

h1 {
    margin: 0;
    font-size: 1.75rem;
}

h2 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
}

h2.spaced {
    margin-top: 1.5rem;
}

p {
    margin: 0.25rem 0;
}

.subtitle,
.hint,
footer {
    color: var(--muted);
}

.hint {
    font-size: 0.9rem;
}

.subtitle {
    margin: 0.15rem 0 0;
}

/* --- Layout --- */

.top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.1rem 1.25rem;
    margin-bottom: 1rem;
}

.warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
}

.grid2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0.75rem 0;
}

/* --- Tabs and chips --- */

.tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.25rem;
    background: var(--track);
    border-radius: 999px;
    padding: 0.25rem;
    margin-bottom: 1rem;
}

.tab {
    background: transparent;
    color: var(--muted);
    padding: 0.5rem 0.25rem;
    font-size: 0.9rem;
}

.tab[aria-current="page"] {
    background: var(--card);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.chip {
    display: inline-block;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    white-space: nowrap;
}

.chip.low {
    background: var(--error-soft);
    color: var(--error);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
}

.chip-button {
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.chip-button[aria-pressed="true"] {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

/* --- Buttons and forms --- */

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1rem;
}

.actions.tight {
    margin-top: 0;
    gap: 0.5rem;
    justify-content: flex-end;
}

.actions.left {
    justify-content: flex-start;
}

button {
    font: inherit;
    font-weight: 600;
    border: 0;
    border-radius: 999px;
    padding: 0.65rem 1.3rem;
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
}

button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

button.danger {
    background: transparent;
    color: var(--error);
    border: 1px solid var(--error);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
}

input[type="number"],
input[type="date"],
input[type="text"],
input[type="password"] {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font: inherit;
    font-weight: 400;
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}

#mac,
#cloud-key {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

fieldset.choice {
    border: 0;
    padding: 0;
    margin: 0.5rem 0 0;
}

fieldset.choice legend {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

fieldset.choice label {
    font-weight: 400;
    margin: 0.25rem 0;
}

.alert-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
}

.alert-row .check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
}

.alert-row .inline {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 400;
    color: var(--muted);
}

.alert-row .inline input {
    width: 5rem;
    margin: 0;
}

.share {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 12px;
    background: var(--bg);
}

.share input {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.8rem;
}

.qr {
    display: block;
    width: 220px;
    max-width: 100%;
    height: auto;
    margin: 0.75rem auto;
    border-radius: 8px;
}

.warning-text {
    color: var(--error);
}

.error {
    color: var(--error);
    margin: 0.5rem 0 0;
}

/* --- Readiness --- */

.score-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.25rem;
}

.score {
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.score-tier {
    font-weight: 600;
    line-height: 1.3;
}

.big-label {
    font-size: 1.5rem;
    font-weight: 700;
}

.meter {
    display: block;
    height: 8px;
    border-radius: 999px;
    background: var(--track);
    overflow: hidden;
}

.meter-fill {
    display: block;
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: 999px;
}

.meter-fill.low {
    background: var(--error);
}

.contributors {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0;
}

.contributors li {
    display: grid;
    grid-template-columns: 6.5rem 1fr;
    grid-template-areas: "label meter" "label value";
    column-gap: 0.75rem;
    align-items: center;
    padding: 0.35rem 0;
}

.contributors .c-label {
    grid-area: label;
    font-weight: 600;
}

.contributors .meter {
    grid-area: meter;
}

.contributors .c-value {
    grid-area: value;
    font-size: 0.85rem;
    color: var(--muted);
}

/* --- Flags, stats, weekly --- */

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

.flag {
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    background: var(--error-soft);
    margin-bottom: 0.4rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
    gap: 0.75rem;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--muted);
}

.stat-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.weekly .week-row {
    display: grid;
    grid-template-columns: 7rem 1fr auto;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
    align-items: baseline;
}

.weekly .week-row:last-child {
    border-bottom: 0;
}

.c-label {
    font-weight: 600;
}

/* --- Live heart rate --- */

.bpm {
    margin: 0.5rem 0 0;
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.bpm .provisional {
    opacity: 0.45;
}

.unit {
    margin-left: 0.35rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--muted);
}

/* --- Charts --- */

.chart {
    display: block;
    width: 100%;
    height: auto;
    margin: 0.5rem 0;
}

.chart-band {
    fill: var(--accent-soft);
}

.chart-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2.5;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart-dot {
    fill: var(--accent);
}

.chart-axis {
    fill: var(--muted);
    font-size: 12px;
}

.chart-grid {
    stroke: var(--border);
    stroke-dasharray: 3 4;
}

.chart-empty {
    color: var(--muted);
    padding: 2rem 0;
    text-align: center;
}

/* --- Log and footer --- */

summary {
    font-weight: 600;
    cursor: pointer;
}

pre {
    max-height: 16rem;
    overflow: auto;
    padding: 0.75rem;
    border-radius: 10px;
    background: var(--bg);
    font-size: 0.75rem;
    white-space: pre-wrap;
    word-break: break-all;
}

footer {
    font-size: 0.85rem;
    text-align: center;
}

a {
    color: var(--accent);
}

[hidden] {
    display: none !important;
}

@media (max-width: 420px) {
    .weekly .week-row {
        grid-template-columns: 1fr auto;
    }

    .weekly .week-row .hint {
        grid-column: 1 / -1;
    }

    .contributors li {
        grid-template-columns: 5.5rem 1fr;
    }
}
