/* Mobile-first: single column, large tap targets. */
:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --text: #1c1d1f;
    --muted: #63666b;
    --border: #d9dbde;
    --accent: #0b6e4f;
    --accent-text: #ffffff;
    --danger: #b3261e;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #131416;
        --surface: #1d1f22;
        --text: #eceef0;
        --muted: #a0a4aa;
        --border: #34373c;
        --accent: #3fbf93;
        --accent-text: #0c1512;
        --danger: #ff8a80;
    }
}

*, *::before, *::after { box-sizing: border-box; }

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

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

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.site-header nav { display: flex; align-items: center; gap: 16px; }
.site-header form { margin: 0; }
.brand { color: var(--text); font-weight: 700; text-decoration: none; }

main { max-width: 480px; margin: 0 auto; padding: 24px 16px 48px; }

h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 0.9rem; }

label { display: block; font-weight: 600; margin-bottom: 4px; }

input[type="text"], input[type="email"], input[type="tel"], input[type="password"] {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

input:focus-visible, button:focus-visible, a:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 10px 20px;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

main form button[type="submit"] { width: 100%; }

.button.secondary { background: transparent; color: var(--accent); }
.button.small { min-height: 40px; padding: 6px 14px; }

button.link {
    min-height: 40px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font-weight: 400;
    text-decoration: underline;
}

.actions { display: flex; flex-wrap: wrap; gap: 12px; }
.actions .button { flex: 1 1 140px; }

.errorlist, .messages { list-style: none; margin: 0 0 12px; padding: 0; }
.errorlist li { color: var(--danger); font-size: 0.95rem; }
.messages li {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    margin-bottom: 8px;
}
.messages li.error { border-color: var(--danger); }
.helptext, form span { color: var(--muted); font-size: 0.9rem; }
form ul:not(.errorlist) { color: var(--muted); font-size: 0.9rem; padding-left: 20px; }

/* Profile forms and settings */
h2 { font-size: 1.15rem; margin: 0; }
.step-count { margin: 0 0 4px; }
.field { margin-bottom: 20px; }
.back { margin-top: 16px; text-align: center; }

input[type="number"], select {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-weight: 600; margin-bottom: 4px; }
.helptext { margin-bottom: 8px; }

/* Radio and checkbox lists: each option is a full-width tap target. */
fieldset label {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    margin: 0 0 8px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font-weight: 400;
    cursor: pointer;
}
fieldset label:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
fieldset input[type="radio"], fieldset input[type="checkbox"] {
    flex: none;
    width: 22px;
    height: 22px;
    accent-color: var(--accent);
}

.segmented {
    display: flex;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.segmented a {
    flex: 1;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 8px;
    background: var(--surface);
    color: var(--text);
    text-align: center;
    text-decoration: none;
    font-size: 0.95rem;
}
.segmented a[aria-current] { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.card {
    margin-bottom: 16px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}
.card header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card header a { padding: 8px 0 8px 16px; }
.card dl { margin: 0; }
.card dl div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; }
.card dt { color: var(--muted); flex: none; }
.card dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

/* A lone checkbox sits beside its label. */
.field:has(> input[type="checkbox"]) { display: flex; flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 12px; min-height: 48px; }
.field > input[type="checkbox"] { flex: none; width: 22px; height: 22px; accent-color: var(--accent); }
.field:has(> input[type="checkbox"]) label { margin: 0; font-weight: 400; }

/* Today's circuit */
.facts { display: flex; flex-wrap: wrap; gap: 6px 8px; list-style: none; margin: 0 0 16px; padding: 0; }
.facts li { padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 0.9rem; }
.notice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin-bottom: 16px; padding: 6px 12px; border: 1px solid var(--accent); border-radius: 10px; }
main form.notice button[type="submit"] { width: auto; }
details.card summary { font-weight: 600; cursor: pointer; min-height: 28px; }
details.card ul { margin: 8px 0 0; padding-left: 20px; }
details.card li { margin-bottom: 4px; }
.stations { list-style: none; margin: 0; padding: 0; }
.station { scroll-margin-top: 12px; }
.station-head { display: flex; align-items: flex-start; gap: 12px; }
.station-head > div { flex: 1; min-width: 0; }
.station-head p { margin: 0; }
.station .number { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 700; }
.station .dose { flex: none; max-width: 40%; text-align: right; font-variant-numeric: tabular-nums; }
.station > p { margin: 10px 0; }
.station form button[type="submit"] { width: auto; }
.caution { color: var(--danger); }
.today-only { margin-top: 24px; }

/* Header wraps on narrow phones */
.site-header { flex-wrap: wrap; }
.site-header nav { flex-wrap: wrap; gap: 4px 14px; }

input[type="date"], textarea {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
.danger, button.danger { border-color: var(--danger); background: var(--danger); color: var(--surface); }
.button.secondary.danger { background: transparent; color: var(--danger); }
.how-to { display: block; width: 100%; max-width: 320px; height: auto; margin: 10px auto 0; }
.weights { margin-bottom: 20px; }
.weights p { margin: 0 0 12px; }
.save-circuit, main > form + details { margin-top: 16px; }
.notes { overflow-wrap: anywhere; }

/* Dashboard */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0 8px; }
.stat { display: flex; flex-direction: column; gap: 2px; margin: 0; color: var(--text); text-decoration: none; }
.stat strong { font-size: 1.3rem; line-height: 1.25; }
.stat .muted { font-size: 0.85rem; }
.meter { display: block; height: 6px; margin-top: 8px; border-radius: 3px; background: var(--border); overflow: hidden; }
.meter span { display: block; height: 100%; max-width: 100%; background: var(--accent); }

/* History and favorites */
h2.week { margin: 20px 0 8px; font-size: 1rem; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; color: var(--text); text-decoration: none; }
.row > span:first-child { display: flex; justify-content: space-between; gap: 12px; }

/* Workout player */
[x-cloak] { display: none !important; }
.player { text-align: center; }
.player .big { width: 100%; min-height: 64px; font-size: 1.3rem; margin: 12px 0; }
.player .phase { margin: 0; font-size: 1.2rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.player .clock { margin: 0; font-size: clamp(5rem, 30vw, 9rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.phase-work .phase, .phase-work .clock { color: var(--accent); }
.phase-rest .phase, .phase-round-rest .phase, .phase-ready .phase { color: var(--muted); }
.player .where { margin: 8px 0 16px; }
.player .now { text-align: left; }
.player .now .dose { margin: 2px 0 0; font-weight: 700; }
.controls { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; margin-top: 16px; }
.controls button { padding-left: 8px; padding-right: 8px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; min-height: 44px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.checklist { list-style: none; margin: 0 0 16px; padding: 0; text-align: left; }
.checklist label { display: flex; align-items: center; gap: 14px; min-height: 48px; margin: 0; cursor: pointer; }
.checklist label > span { flex: 1; display: flex; justify-content: space-between; gap: 12px; font-weight: 400; }
.checklist input[type="checkbox"] { flex: none; width: 28px; height: 28px; accent-color: var(--accent); }
.checklist .checked { border-color: var(--accent); }
.checklist .checked strong { text-decoration: line-through; color: var(--muted); }
.checklist p { margin: 8px 0; }
/* Weight inputs sit in a fieldset but are plain labelled fields, not option rows. */
fieldset.weights label { display: block; min-height: 0; margin: 0 0 4px; padding: 0; border: 0; background: none; font-weight: 600; cursor: default; }

/* Account menu: the avatar button opens a dropdown */
.site-header { position: relative; }
.menu summary { list-style: none; cursor: pointer; border-radius: 50%; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1;
}
.site-header .menu nav {
    position: absolute;
    top: calc(100% + 6px);
    right: 12px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: min(260px, calc(100vw - 24px));
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}
.menu nav p { margin: 0; padding: 6px 10px 8px; overflow-wrap: anywhere; border-bottom: 1px solid var(--border); }
.menu nav a, .menu nav button.link {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    text-align: left;
    justify-content: flex-start;
}
.menu nav a:hover, .menu nav button.link:hover { background: var(--bg); }
.menu nav form { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

/* Like and dislike */
.rate { display: flex; gap: 8px; margin: 0; }
.chip, main form.rate button[type="submit"] {
    width: auto;
    min-height: 40px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font-weight: 400;
    font-size: 0.95rem;
}
main form.rate .like.on { border-color: var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 600; }
main form.rate .dislike.on { border-color: var(--danger); background: var(--danger); color: var(--surface); font-weight: 600; }
.station-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.prefs { list-style: none; margin: 0; padding: 0; }
details.card ul.prefs { padding-left: 0; }
.pref { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
li.card.pref { margin-bottom: 8px; padding: 8px 12px 8px 16px; }
details .pref { padding: 6px 0; border-top: 1px solid var(--border); }
details .pref:first-child { border-top: 0; }
.pref > span, .pref > strong { min-width: 0; overflow-wrap: anywhere; }
.pref .rate { flex: none; }

/* Exercise details, as a page or in the dialog on the likes page */
.exercise h2 { font-size: 1.3rem; }
.exercise > p.muted { margin: 2px 0 0; }
.exercise .rate { margin: 12px 0; }
.exercise dl { margin: 0; }
.exercise dl div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; border-top: 1px solid var(--border); }
.exercise dt { color: var(--muted); flex: none; }
.exercise dd { margin: 0; text-align: right; }
.notice-box { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--danger); border-radius: 10px; }
.notice-box ul { margin: 6px 0 0; padding-left: 20px; }
dialog.sheet {
    width: min(440px, calc(100vw - 24px));
    max-height: calc(100dvh - 32px);
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
}
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.55); }
dialog.sheet > form { display: flex; justify-content: flex-end; margin: -8px -4px 0 0; }
main dialog.sheet form .close { width: auto; min-height: 40px; padding: 0 4px; }
.pref > a { min-width: 0; overflow-wrap: anywhere; padding: 8px 0; }

/* Log form: the favorite name appears when the toggle is on */
.favorite { margin-bottom: 20px; }
.favorite .field { margin-bottom: 8px; }
.favorite-name { display: none; }
.favorite:has(input[type="checkbox"]:checked) .favorite-name { display: block; }
@supports not selector(:has(*)) { .favorite-name { display: block; } }
.favorite-saved { margin: 0 0 20px; padding: 10px 12px; border: 1px solid var(--accent); border-radius: 10px; }
