/* ---------------------------------------------------------------------------
   Tokens
   Light and dark are both selected, not flipped. Dark is the default on a
   phone in a garage; light follows the OS.
--------------------------------------------------------------------------- */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --rule: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  --good-text: #006300;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 14px;
  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --line: #2c2c2a;
    --rule: #383835;
    --accent: #3987e5;
    --good-text: #0ca30c;
    --shadow: none;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --line: #2c2c2a;
  --rule: #383835;
  --accent: #3987e5;
  --good-text: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  min-height: 100svh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

/* --------------------------------------------------------------------------
   Shell
-------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  background: none;
  border: 0;
  padding: 10px 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 550;
  color: var(--muted);
}
.tabbar button[aria-current='page'] { color: var(--accent); }
.tabbar svg { width: 22px; height: 22px; }

/* --------------------------------------------------------------------------
   Cards & type
-------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card.flush { padding: 0; overflow: hidden; }

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}
.h2 { margin: 0 0 2px; font-size: 22px; font-weight: 680; letter-spacing: -0.02em; }
.sub { margin: 0; color: var(--ink-2); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }

.hero {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.hero .unit { font-size: 17px; font-weight: 550; color: var(--muted); letter-spacing: 0; }

/* --------------------------------------------------------------------------
   Buttons
-------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: var(--surface);
  font-weight: 600;
  transition: transform 0.06s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: var(--surface-2); }
.btn.danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); }
.btn.block { display: flex; width: 100%; }
.btn.lg { min-height: 56px; font-size: 17px; }
.btn:disabled { opacity: 0.4; cursor: default; }

/* --------------------------------------------------------------------------
   Today
-------------------------------------------------------------------------- */
.daychips { display: flex; gap: 6px; margin: 0 0 16px; }
.daychip {
  flex: 1;
  padding: 8px 4px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  line-height: 1.25;
}
.daychip[data-on='1'] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: var(--accent);
}

.exrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.exrow:last-child { border-bottom: 0; }
.exrow .nm { font-weight: 600; }
.exrow .meta { font-size: 13px; color: var(--muted); }
.exrow .wt { font-size: 20px; font-weight: 680; letter-spacing: -0.02em; white-space: nowrap; }

.flag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
}
.flag.warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--ink); }
.flag.crit { background: color-mix(in srgb, var(--crit) 15%, var(--surface)); color: var(--crit); }
.flag.good { background: color-mix(in srgb, var(--good) 15%, var(--surface)); color: var(--good-text); }

/* --------------------------------------------------------------------------
   Workout
-------------------------------------------------------------------------- */
.setlist { list-style: none; margin: 0; padding: 0; }
.set {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.set:last-child { border-bottom: 0; }
.set .lbl { width: 70px; flex: none; white-space: nowrap; font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* The work sets all share one weight, so the plate list is stated once above
   them rather than repeated on every row — it's read once, when loading. */
.workload {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 8px 0 6px;
}
.workload .pl {
  font-size: 19px;
  font-weight: 680;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.workload small { font-size: 12.5px; font-weight: 500; color: var(--muted); }
/* The plate list is the headline here, so it gets the weight and room to wrap;
   the total sits underneath as a footnote. */
.set .wt {
  flex: 1;
  min-width: 0;
  font-size: 16.5px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.set .wt .tofail { font-size: 14px; font-weight: 550; color: var(--ink-2); white-space: nowrap; }
.set .wt small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.01em;
  font-variant-numeric: normal;
}
.set.done .wt { color: var(--muted); }

.reppill {
  min-width: 64px;
  height: var(--tap);
  padding: 0 14px;
  border-radius: 12px;
  border: 1.5px solid var(--rule);
  background: var(--surface);
  font-size: 18px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
}
.reppill[data-state='hit'] {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}
.reppill[data-state='miss'] {
  background: color-mix(in srgb, var(--crit) 15%, var(--surface));
  border-color: var(--crit);
  color: var(--crit);
}
.stepper { display: flex; gap: 6px; align-items: center; }
.stepper button {
  width: 40px; height: var(--tap);
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--surface-2);
  font-size: 20px;
  font-weight: 600;
}

.plates {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Rest timer */
/* An author `display` beats the UA stylesheet's [hidden] rule, so the attribute
   alone would leave the timer on screen after the workout ends. */
.rest[hidden] { display: none; }
.rest {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--page);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
}
.rest .t { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.rest .bar { flex: 1; height: 5px; border-radius: 3px; background: rgba(128, 128, 128, 0.4); overflow: hidden; }
.rest .bar i { display: block; height: 100%; background: var(--page); border-radius: 3px; }
.rest button {
  border: 0;
  background: rgba(128, 128, 128, 0.25);
  color: inherit;
  border-radius: 9px;
  height: 38px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Charts
-------------------------------------------------------------------------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--rule); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: 0.09; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .lastlabel { fill: var(--ink); font-size: 13px; font-weight: 650; }
.chart .hit { pointer-events: all; fill: transparent; }

.tip {
  position: absolute;
  z-index: 40;
  pointer-events: none;
  background: var(--ink);
  color: var(--page);
  font-size: 12.5px;
  font-weight: 550;
  padding: 6px 9px;
  border-radius: 8px;
  white-space: nowrap;
  transform: translate(-50%, -140%);
  opacity: 0;
  transition: opacity 0.1s;
}
.tip[data-on='1'] { opacity: 1; }

/* --------------------------------------------------------------------------
   Forms / settings
-------------------------------------------------------------------------- */
.field { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field label { flex: 1; font-size: 15px; }
.field label small { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.field input, .field select {
  width: 104px;
  height: 42px;
  padding: 0 10px;
  text-align: right;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}
.field select { text-align: left; width: 132px; }
.field input[type='checkbox'] { width: 26px; height: 26px; }

table.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
table.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
table.grid td.num, table.grid th.num { text-align: right; }

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: 0.4; margin-bottom: 10px; }

.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  background: var(--ink);
  color: var(--page);
  padding: 11px 16px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 550;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
  max-width: min(520px, calc(100vw - 32px));
}
.toast[data-on='1'] { opacity: 1; transform: translateX(-50%) translateY(-6px); }

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