/* ============================================================
   WORKOUT TRACKER — redesigned skin
   Flat ink ground, hairline-bordered cards, one brass accent.
   Dark is the default theme (script.js adds .dark-mode to body);
   light mode = same components, different token values.
   ============================================================ */

/* ---------- RESET ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;  /* width/height include padding + border */
}

/* ---------- DESIGN TOKENS ----------
   Every color in the app comes from these variables.
   body holds the LIGHT values; body.dark-mode overrides them.
   Change a token once, the whole app follows. */
body {
    --bg: #f6f6f3;           /* page ground (warm off-white) */
    --card: #ffffff;         /* card surface */
    --card-2: #f0f0ec;       /* inset surface (stat grid, tiles) */
    --line: #e3e3dd;         /* hairline borders */
    --text: #1c1c1f;         /* primary text */
    --muted: #71717a;        /* secondary text, idle icons */
    --brass: #a87f1c;        /* THE accent - deeper gold for light bg */
    --brass-ink: #ffffff;    /* text placed on brass */
    --brass-soft: rgba(168, 127, 28, 0.12);  /* brass tint for focus rings */
    --moss: #2e9d6e;         /* done / success */
    --ember: #d24936;        /* destructive only */
    --radius: 14px;

    /* tip markup colors (*red*...*red* etc.) - darker tones so they
       stay legible on the light ground */
    --c-red: #c2402e;
    --c-blue: #2f6fba;
    --c-yellow: #96700a;
    --c-orange: #bd6212;

    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

body.dark-mode {
    --bg: #0c0c0e;           /* ink ground */
    --card: #17171a;         /* graphite cards */
    --card-2: #1e1e22;
    --line: #27272d;
    --text: #f4f4f2;
    --muted: #8e8e98;
    --brass: #d4a72c;        /* brighter brass holds contrast on ink */
    --brass-ink: #141003;    /* near-black text on brass (not white!) */
    --brass-soft: rgba(212, 167, 44, 0.16);
    --moss: #58b98a;
    --ember: #e0604e;

    /* brighter markup tones for the dark ground */
    --c-red: #e0604e;
    --c-blue: #6aa9e9;
    --c-yellow: #d9b64a;
    --c-orange: #e08a3c;
}

/* tip color markup spans (generated by parseColorText in script.js) */
.c-red { color: var(--c-red); }
.c-blue { color: var(--c-blue); }
.c-yellow { color: var(--c-yellow); }
.c-orange { color: var(--c-orange); }

/* numbers everywhere read as data: monospace + tabular figures */
.num,
.stat .v,
.stat-tile .v,
.calendar-day,
.streak-chip {
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

/* ---------- BASE ELEMENTS ---------- */
button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

button:focus-visible,
.sheet-input:focus-visible {
    outline: 2px solid var(--brass);
    outline-offset: 2px;
}

/* hides an element visually but keeps it for screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- HEADER ---------- */
header {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px 20px 6px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.kicker {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 600;
    color: var(--muted);
}

header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-top: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.streak-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.streak-chip svg { color: var(--brass); }

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- MAIN ---------- */
main {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 16px 110px;  /* bottom space clears the floating buttons */
}

/* ---------- TABS ---------- */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--line);
    margin: 8px 0 16px;
}

.tab-btn {
    flex: 1;
    padding: 9px 2px 11px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;      /* underline sits on top of the hairline */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}

.tab-btn.active {
    color: var(--text);
    border-bottom-color: var(--brass);
}

/* finished days get a small moss check after the label */
.tab-btn.completed::after {
    content: "✓";
    color: var(--moss);
    font-size: 11px;
    font-weight: 700;
}

/* 2-day split: the off-cycle pair shrinks and dims, but stays tappable */
.tab-btn.off-cycle {
    flex: 0.55;
    opacity: 0.45;
    font-size: 11px;
}

/* ---------- WORKOUT SECTIONS (show/hide by tab) ---------- */
.workout-day { display: none; }
.workout-day.active {
    display: block;
    animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .workout-day.active { animation: none; }
}

/* ---------- EXERCISE LIST + CARDS ---------- */
.exercises-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 28px 16px;
    font-size: 13px;
}

.exercise-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.exercise-card.done { opacity: 0.62; }

/* brass label above the topmost unchecked exercise */
.card-upnext {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 700;
    color: var(--brass);
    padding: 10px 14px 0;
}

/* --- card header row: chevron / check / name / synced chip --- */
.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
}

.btn-collapse {
    width: 28px;
    height: 28px;
    margin: -5px;             /* bigger touch target without extra layout */
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    flex-shrink: 0;
}

.btn-collapse svg { transition: transform 0.18s ease; }
.exercise-card.collapsed .btn-collapse svg { transform: rotate(-90deg); }

@media (prefers-reduced-motion: reduce) {
    .btn-collapse svg { transition: none; }
}

/* circular done checkbox */
.check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1.5px solid var(--muted);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;       /* check mark hidden until done */
    padding: 0;
}

.exercise-card.next-up .check { border-color: var(--brass); }

.exercise-card.done .check {
    background: var(--moss);
    border-color: var(--moss);
    color: var(--bg);         /* check mark contrasts with the moss fill */
}

.exercise-name {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word;
}

.exercise-card.done .exercise-name {
    color: var(--muted);
    text-decoration: line-through;
    font-weight: 500;
}

/* chip shown when a same-named exercise exists in the paired day */
.duplicate-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 2.5px 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* collapsed cards show only the header row */
.exercise-card.collapsed .card-body { display: none; }

/* ---------- ALTERNATIVE GROUPS ----------
   Same-day backup exercises (linked via the edit sheet) render as one
   bordered unit separated by an "or" divider. Checking any member
   checks the whole group. */
.alt-group {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

/* cards inside a group drop their own border - the group carries it */
.alt-group .exercise-card {
    border: none;
    border-radius: 0;
}

.alt-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--brass);
    background: var(--card);
}

/* hairlines either side of the "or" */
.alt-divider::before,
.alt-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}

/* --- stat grid: the four headline numbers --- */
/* 1px gap over a line-colored background = clean hairlines even when
   long free-text values force the grid to wrap to two rows */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
    gap: 1px;
    background: var(--line);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.stat {
    background: var(--card-2);
    padding: 10px 6px 11px;
    text-align: center;
    min-width: 0;
}

.stat .l {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    font-weight: 600;
}

.stat .v {
    font-size: 13.5px;
    font-weight: 600;
    margin-top: 2px;
    overflow-wrap: break-word;
}

/* faded note under a stat value ("got 7-6-6" when max wasn't hit) */
.stat .stat-note {
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-variant-numeric: tabular-nums;
    font-size: 10px;
    color: var(--muted);
    opacity: 0.85;
    margin-top: 2px;
    overflow-wrap: break-word;
}

/* --- meta rows: prose fields below the numbers --- */
.card-meta {
    padding: 11px 14px 2px;
    display: grid;
    gap: 7px;
}

.card-meta .m {
    display: flex;
    gap: 8px;
    font-size: 12.5px;
}

.card-meta .k {
    color: var(--muted);
    width: 88px;
    flex-shrink: 0;
}

.card-meta .val {
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word;
}

.card-meta .val.failure {
    color: var(--brass);
    font-weight: 600;
}

/* --- action row: quiet icons instead of colored pills --- */
.card-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px 10px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}

.icon-btn:active { background: var(--card-2); }

/* quick log (bolt) is the highlighted action */
.icon-btn.log {
    color: var(--brass);
    background: var(--brass-soft);
}

/* delete sits apart, in ember */
.icon-btn.danger {
    color: var(--ember);
    margin-left: auto;
}

/* ---------- COMPLETE WORKOUT BUTTON ---------- */
.btn-complete-workout {
    margin-top: 14px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--brass);
    color: var(--brass-ink);
    border-radius: 13px;
    padding: 14px;
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.btn-complete-workout:active { opacity: 0.85; }

/* ---------- FLOATING BUTTONS ---------- */
.btn-float {
    position: fixed;
    bottom: 22px;
    right: 18px;
    width: 54px;
    height: 54px;
    border-radius: 17px;
    background: var(--brass);
    color: var(--brass-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.45);
    z-index: 900;
}

.btn-float-history {
    left: 18px;
    right: auto;
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--card);
    color: var(--muted);
    border: 1px solid var(--line);
    box-shadow: none;
}

/* ---------- MODALS AS BOTTOM SHEETS ---------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 2000;
    align-items: flex-end;      /* sheet slides up from the bottom */
    justify-content: center;
}

.modal.active { display: flex; }

.sheet {
    background: var(--card);
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: 22px 22px 0 0;
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    overflow-y: auto;
    /* env() keeps content above the iPhone home indicator */
    padding: 10px 18px calc(20px + env(safe-area-inset-bottom, 0px));
}

.sheet-grab {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    margin: 2px auto 14px;
}

.sheet h2 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 14px;
}

/* --- form fields --- */
.field { margin-bottom: 12px; }

.f-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 5px;
}

/* lowercase explanatory hint inside a field label */
.f-hint {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
}

.sheet-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    padding: 10px 12px;
    /* 16px stops iOS Safari from zooming in when a field is focused */
    font-size: 16px;
    font-family: inherit;
}

.sheet-input:focus {
    outline: none;
    border-color: var(--brass);
    box-shadow: 0 0 0 3px var(--brass-soft);
}

.sheet-input.num { text-align: center; }

.sheet-input::placeholder { color: var(--muted); }

textarea.sheet-input {
    resize: vertical;
    min-height: 64px;
}

select.sheet-input { cursor: pointer; }

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.grid4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

/* long free-text values ("1.15 minutes") need room on small phones */
@media (max-width: 420px) {
    .grid4 { grid-template-columns: 1fr 1fr; }
}

.sheet-btns {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.btn-ghost {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    font-weight: 600;
    text-align: center;
}

.btn-solid {
    flex: 2;
    padding: 12px;
    background: var(--brass);
    color: var(--brass-ink);
    border-radius: 12px;
    font-weight: 700;
    text-align: center;
}

.btn-solid:active,
.btn-ghost:active { opacity: 0.8; }

/* ---------- COOLDOWN REMINDER TOAST ----------
   Drops in from the top (clear of the floating buttons), sized for
   one thumb-tap to dismiss. Sits above sheets so it's visible even
   if the quick-log sheet is open. */
.cooldown-toast {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translate(-50%, -16px);
    display: flex;
    align-items: center;
    gap: 12px;
    width: min(calc(100% - 28px), 420px);
    padding: 12px 16px;
    background: var(--card);
    border: 1px solid var(--brass);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    cursor: pointer;
}

.cooldown-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.cooldown-toast svg {
    flex-shrink: 0;
    color: var(--brass);
}

.ct-text {
    font-size: 13px;
    line-height: 1.4;
    color: var(--muted);
}

.ct-text strong {
    display: block;
    font-size: 14px;
    color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
    .cooldown-toast { transition: opacity 0.25s ease; }
}

/* ---------- HISTORY SHEET ---------- */
.stat-tiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 6px;
}

.stat-tile {
    background: var(--card-2);
    border: 1px solid var(--line);
    border-radius: 13px;
    padding: 12px 14px;
}

.stat-tile .l {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-tile .l svg { color: var(--brass); }

.stat-tile .v {
    font-size: 17px;
    font-weight: 700;
    margin-top: 4px;
    letter-spacing: -0.02em;
}

/* --- calendar --- */
.calendar-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 14px 0 10px;
}

.calendar-month-title {
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.btn-calendar-nav {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: var(--card-2);
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-day-header {
    text-align: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 0 6px;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    border-radius: 10px;
}

.calendar-day.other-month {
    color: var(--muted);
    opacity: 0.45;
}

.calendar-day.today {
    box-shadow: inset 0 0 0 1.5px var(--brass);
    font-weight: 700;
}

.calendar-day.has-workout {
    background: var(--brass);
    color: var(--brass-ink);
    font-weight: 700;
}

/* --- weekly split toggle --- */
.split-field { margin-top: 16px; }

.seg {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
}

.seg-btn {
    flex: 1;
    text-align: center;
    padding: 8px 4px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    border-radius: 8px;
    border: 1px solid transparent;
}

.seg-btn.on {
    background: var(--card-2);
    color: var(--text);
    border-color: var(--line);
}

.split-note {
    font-size: 12px;
    color: var(--muted);
    margin-top: 7px;
    line-height: 1.5;
}

/* --- backup actions --- */
.backup-row {
    display: flex;
    gap: 10px;
    margin: 16px 0 4px;
}

.btn-secondary {
    flex: 1;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
    background: var(--card-2);
}

.btn-close-sheet {
    width: 100%;
    margin-top: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    font-weight: 600;
}

/* --- sync: header chip + sheet (sync.js builds the markup) --- */
.sync-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;              /* with the header's padding, a 44px tap */
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--muted);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    position: relative;
}
.sync-chip::after { content: ''; position: absolute; inset: -5px; }  /* widens the tap area */
.sync-chip:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.sync-chip[data-phase="synced"] .sync-dot { background: var(--moss); }
.sync-chip[data-phase="pending"] .sync-dot,
.sync-chip[data-phase="syncing"] .sync-dot { background: var(--brass); }
/* Not synced is the one state that must not be missed: text and border turn too,
   so it does not rest on the dot's color alone. */
.sync-chip[data-phase="error"],
.sync-chip[data-phase="notice"],
.sync-chip[data-phase="signedOut"] { color: var(--text); border-color: var(--brass); }
.sync-chip[data-phase="error"] .sync-dot,
.sync-chip[data-phase="notice"] .sync-dot { background: var(--brass); }
.sync-note { font-size: 13px; line-height: 1.5; color: var(--muted); margin: 0 0 12px; }
.sync-note strong { color: inherit; font-weight: 600; word-break: break-all; }
.sync-error { font-size: 13px; line-height: 1.5; font-weight: 600; margin: 0 0 12px; }
.sync-wide { width: 100%; min-height: 44px; }
#syncSheet .btn-secondary { min-height: 44px; }

/* Inside the Life OS hub: the hub's header is already above, so drop the
   extra top space meant for a phone's status bar. Nothing is hidden. */
html.embed header { padding-top: 10px; }

/* Three chips and a title do not fit one row on a narrow phone. */
@media (max-width: 420px) {
    header { flex-wrap: wrap; }
    .header-actions { margin-left: auto; }
}

/* ---------- DESKTOP (768px and up) ---------- */
@media (min-width: 768px) {
    header { padding-top: 36px; }
    header h1 { font-size: 28px; }

    /* sheets become centered dialogs instead of bottom sheets */
    .modal {
        align-items: center;
        padding: 24px;
    }

    .sheet {
        border-radius: 22px;
        border-bottom: 1px solid var(--line);
    }

    .sheet-input { font-size: 14px; }  /* no iOS zoom concern on desktop */

    /* hover feedback (touch devices don't hover) */
    .icon-btn:hover { background: var(--card-2); color: var(--text); }
    .icon-btn.log:hover { background: var(--brass-soft); color: var(--brass); }
    .icon-btn.danger:hover { color: var(--ember); }
    .btn-icon:hover,
    .btn-calendar-nav:hover,
    .btn-secondary:hover,
    .btn-ghost:hover { border-color: var(--muted); }
    .btn-solid:hover,
    .btn-complete-workout:hover,
    .btn-float:hover { filter: brightness(1.06); }
    .btn-float { transition: transform 0.15s ease; }
    .btn-float:hover { transform: scale(1.05); }
    .tab-btn:hover { color: var(--text); }
}
