/* Onest font, stored in this project (fonts/), so the app makes no requests to other servers.
   One "variable" file covers all weights 400–700. License: fonts/OFL.txt */
@font-face {
  font-family: "Onest";
  src: url("fonts/onest-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* Layout: one narrow, thumb-friendly column — date, progress toward the daily goal, exercise cards that toggle */
:root {
  --bg: #F3F6F5;          /* background: light, slightly green */
  --surface: #FFFFFF;     /* cards */
  --fg: #17201D;          /* main text */
  --muted: #5A6762;       /* secondary text: dark enough for 4.5:1 contrast on every background */
  --line: #DCE3E0;        /* borders */
  --accent: #2A7382;      /* teal green: checkmarks and progress */
  --accent-soft: #E0EEF0; /* background of a checked card */
  --on-accent: #FFFFFF;
  /* day colors in the calendar */
  --good: #2A7382;        /* goal reached (same as the accent; teal so it stays distinct from red for colorblind users) */
  --partial: #E2B33C;     /* some done */
  --missed: #D9644F;      /* nothing done */
  --on-day: #FFFFFF;      /* number on a green day */
  --on-partial: #17201D;  /* number on a yellow day: dark, for contrast */
  --on-missed: #17201D;   /* number on a red day: dark, for contrast (a darker red would look like the teal to colorblind users) */
  --danger: #B3412E;      /* Remove buttons: a darker red, so red text on white is readable */

  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101513; --surface: #182120; --fg: #E6EDEA; --muted: #91A09A;
    --line: #26312E; --accent: #6FD0B0; --accent-soft: #1C3029; --on-accent: #0E1A16;
    --good: #6FD0B0; --partial: #E7C15A; --missed: #D9644F; --on-day: #0E1A16; --on-partial: #0E1A16;
    --on-missed: #0E1A16; --danger: #D9644F;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101513; --surface: #182120; --fg: #E6EDEA; --muted: #91A09A;
  --line: #26312E; --accent: #6FD0B0; --accent-soft: #1C3029; --on-accent: #0E1A16;
  --good: #6FD0B0; --partial: #E7C15A; --missed: #D9644F; --on-day: #0E1A16; --on-partial: #0E1A16;
  --on-missed: #0E1A16; --danger: #D9644F;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
/* "hidden" must always win, even over display: flex on .view — that's how tabs are switched */
[hidden] { display: none !important; }
html, body { min-height: 100%; } /* min-height, not height: long tabs (Stats) must grow and scroll */
/* room for the iPhone notch and home indicator */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  padding-inline: 16px;
  /* bottom padding leaves room for the tab bar */
  padding-block: 24px calc(96px + env(safe-area-inset-bottom, 0px));
}
.app { max-width: 440px; margin-inline: auto; }
/* each tab is a column of blocks */
.view { display: flex; flex-direction: column; gap: 24px; }

/* Header: weekday and date */
.weekday { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.date { margin: 2px 0 0; font-size: 28px; font-weight: 700; letter-spacing: -.01em; text-wrap: balance; }

/* Progress card: ring on the left, message on the right */
.progress {
  display: flex; align-items: center; gap: 20px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.ring { position: relative; flex: none; width: 96px; height: 96px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); } /* start the fill at 12 o'clock */
.ring circle { fill: none; stroke-width: 10; }
.ring-track { stroke: var(--line); }
/* pathLength="100" in the HTML: dash 100 = the whole circle, offset 100 = empty, 0 = full */
.ring-fill { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset .5s ease; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; grid-auto-flow: column; align-items: baseline; font-variant-numeric: tabular-nums; }
.ring-label b { font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.ring-label span { font-size: 16px; font-weight: 600; color: var(--muted); }
.progress-text { min-width: 0; }
.progress-text p { margin: 0; }
.status { font-size: 20px; font-weight: 700; line-height: 1.25; text-wrap: balance; }
/* goal reached: accent-colored card, light ring and text on it */
.progress { transition: background .3s, border-color .3s; }
.progress.done { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.progress.done .ring-track { stroke: color-mix(in srgb, var(--on-accent) 25%, transparent); }
.progress.done .ring-fill { stroke: var(--on-accent); }
.progress.done .ring-label span, .progress.done .count { color: inherit; opacity: .9; }
.count { margin-top: 4px !important; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Exercise list */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  width: 100%;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  min-height: 60px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) { .item:hover { border-color: var(--accent); } } /* only on devices with a mouse */
.item:active { transform: scale(.98); }
.item[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; }
/* done: the name fades, so what's left stands out */
.item[aria-pressed="true"] .name { color: var(--muted); }
/* the card that was just checked: its checkmark pops */
.item.pop[aria-pressed="true"] .check { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  transition: background .2s, border-color .2s;
}
.check svg { width: 14px; height: 14px; opacity: 0; transition: opacity .15s; }
.check path { fill: none; stroke: var(--on-accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.item[aria-pressed="true"] .check { background: var(--accent); border-color: var(--accent); }
.item[aria-pressed="true"] .check svg { opacity: 1; }

.name { flex: 1; min-width: 0; font-weight: 500; }
.dose { flex: none; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

.note { margin: 0; font-size: 13px; color: var(--muted); }

/* ---------- Calendar ---------- */
.cal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cal-title { margin: 0; font-size: 24px; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  font: inherit; font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 7 columns: Monday to Sunday */
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-weekdays span { text-align: center; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }

.day {
  aspect-ratio: 1; max-width: 100%;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--fg);
  font: inherit; font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums;
  padding: 0;
}
button.day { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.day:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.day.good    { background: var(--good);    color: var(--on-day); }
.day.partial { background: var(--partial); color: var(--on-partial); }
.day.missed  { background: var(--missed);  color: var(--on-missed); }
.day.before, .day.future { color: var(--muted); }   /* before you started / not yet: no colored circle */
.day.today { box-shadow: inset 0 0 0 2px var(--fg); }             /* ring around today */
.day.selected { outline: 2px solid var(--fg); outline-offset: 2px; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.good { background: var(--good); }
.dot.partial { background: var(--partial); }
.dot.missed { background: var(--missed); }

/* What was done on the selected day */
.day-detail { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.day-detail:empty { display: none; }
.day-detail h2 { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.day-detail p { margin: 0; font-size: 14px; color: var(--muted); }
.day-detail ul { margin: 10px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- Stats ---------- */
/* Period switch: three buttons joined into one control */
.segmented { display: flex; gap: 4px; padding: 4px; background: var(--line); border-radius: 12px; }
.segmented button {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--fg); }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Headline number */
.hero p { margin: 0; }
.hero-label { font-size: 14px; color: var(--muted); }
.hero-value { font-size: 56px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.hero-sub { font-size: 14px; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card-title { margin: 0; font-size: 17px; font-weight: 600; }
.card-sub { margin: -8px 0 0; font-size: 13px; color: var(--muted); }

/* Per-exercise horizontal bars: name, bar, count at the tip */
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 7.5em 1fr; align-items: center; gap: 10px; font-size: 14px; }
.bar-name { min-width: 0; overflow-wrap: anywhere; }
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-fill { height: 12px; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 2px; }
.bar-fill.zero { background: var(--line); }
.bar-value { flex: none; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Weekly stacked columns */
.weeks { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; align-items: end; }
.week {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 0; background: transparent; padding: 4px 0; border-radius: 8px;
  color: var(--muted); font: inherit; font-size: 11px; font-variant-numeric: tabular-nums;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.week:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.week[aria-pressed="true"] { background: var(--accent-soft); color: var(--fg); }
/* the column: 7 day-slots tall, stacked from the bottom, 2px gaps between segments */
.week-col {
  width: 100%; max-width: 24px; height: 112px;
  display: flex; flex-direction: column-reverse; gap: 2px;
  border-bottom: 1px solid var(--line);
}
.seg { flex: none; }
.seg.good { background: var(--good); }
.seg.partial { background: var(--partial); }
.seg.missed { background: var(--missed); }
.week-col .seg:last-child { border-radius: 4px 4px 0 0; } /* rounded top end, square at the baseline */
.week-detail { margin: 0; font-size: 14px; color: var(--muted); min-height: 1.45em; }

/* ---------- Streak ---------- */
/* Big card: flame + number, the labels under it */
.streak-hero {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 20px 24px 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
  text-align: center;
}
.streak-hero p { margin: 0; }
.streak-number {
  display: flex; align-items: center; gap: 8px;
  color: var(--accent);
  font-size: clamp(96px, 30vw, 140px); line-height: .95; font-weight: 700; letter-spacing: -.05em;
  font-variant-numeric: tabular-nums;
}
.flame { width: .45em; height: .45em; flex: none; fill: currentColor; }
.flame-arc { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.streak-label { margin-top: 8px !important; font-size: 18px; font-weight: 600; }
.streak-sub { font-size: 15px; color: var(--muted); }

/* Best streak: title and dates on the left, number on the right */
.best-row { flex-direction: row; align-items: center; justify-content: space-between; padding: 18px 20px; }
.best-row p { margin: 0; }
.best-dates { font-size: 14px; color: var(--muted); }
.best-value { flex: none; font-variant-numeric: tabular-nums; }
.best-value b { font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.best-value span { font-size: 15px; color: var(--muted); }

/* Last 7 days: dot and the weekday letter under it */
.week-dots { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.week-dots li { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.week-dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.week-dot.good    { background: var(--good); }
.week-dot.partial { background: var(--partial); }
.week-dot.missed  { background: var(--missed); }
.week-dot.pending, .week-dot.before { border-color: var(--line); } /* today with nothing yet / before you started: empty circle */
.week-dots li.today { color: var(--fg); font-weight: 700; }
.week-dots li.today .week-dot { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg); } /* ring around today, like in Calendar */

.streak-msg { text-align: center; padding-inline: 8px; }
.streak-msg p { margin: 0; text-wrap: balance; }
.streak-msg-title { font-size: 17px; font-weight: 600; }
.streak-msg-body { font-size: 15px; color: var(--muted); }

/* ---------- Today header with the settings button ---------- */
.today-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.icon-btn { display: grid; place-items: center; flex: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Settings ---------- */
.settings-header { display: flex; align-items: center; gap: 12px; }

.stepper { display: flex; align-items: center; gap: 20px; }
.stepper-value { min-width: 2ch; text-align: center; font-size: 32px; font-weight: 700; }

.edit-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.edit-row { display: flex; flex-direction: column; gap: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.edit-row:last-child { border-bottom: 0; padding-bottom: 0; }
.edit-fields, .add-form { display: grid; grid-template-columns: 1fr 6.5em; gap: 8px; }
.add-form .primary-btn { grid-column: 1 / -1; }
.edit-actions { display: flex; gap: 8px; }
.edit-actions .danger { margin-left: auto; }

.field {
  width: 100%; min-width: 0; min-height: 44px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--fg);
  font: inherit; font-size: 16px; /* 16px stops iPhone from zooming in on focus */
}
.field::placeholder { color: var(--muted); }
.field:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.small-btn, .primary-btn, .secondary-btn {
  min-height: 40px; padding: 0 14px; border-radius: 10px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.small-btn { border: 1px solid var(--line); background: var(--surface); color: var(--fg); min-width: 44px; }
.small-btn:disabled { opacity: .35; cursor: default; }
.small-btn.danger { color: var(--danger); }
.primary-btn { border: 0; background: var(--accent); color: var(--on-accent); }
.primary-btn.danger-fill { background: var(--danger); color: var(--on-accent); }
.secondary-btn { border: 1px solid var(--line); background: var(--surface); color: var(--fg); }
.small-btn:focus-visible, .primary-btn:focus-visible, .secondary-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* the label works as the button for the hidden file input */
#backup-file:focus-visible + .secondary-btn, .secondary-btn:has(+ #backup-file:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.removed-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; color: var(--muted); }

.backup-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.backup-msg { margin: 0; font-size: 14px; color: var(--muted); }
.backup-msg:empty { display: none; }

/* hides an element visually but keeps it usable (for the file input) */
/* a title that gets focus when its screen opens: no ring, the whole screen changed */
[tabindex="-1"]:focus { outline: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; max-width: 140px; min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; border-radius: 12px; background: transparent;
  color: var(--muted); font: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
/* icon above the word; it takes the tab's text color */
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
