:root {
  color-scheme: light;
  --bg: #f3f3ef;
  --surface: #fcfcfb;
  --ink: #15191a;
  --ink-2: #52514e;
  --ink-3: #7a7973;
  --line: #dbdfd9;
  --accent: #164b41;
  --accent-ink: #ffffff;
  --accent-soft: #e2eeea;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4b00;
  --danger: #b3261e;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111312;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-3: #95948c;
    --line: #2f302d;
    --accent: #5fbfa6;
    --accent-ink: #0b1f1a;
    --accent-soft: #1d302b;
    --warn-bg: #3a2f10;
    --warn-ink: #ffd98a;
    --danger: #ff8a80;
    --series-1: #3987e5;
    --series-2: #d95926;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111312; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --ink-3: #95948c; --line: #2f302d;
  --accent: #5fbfa6; --accent-ink: #0b1f1a; --accent-soft: #1d302b; --warn-bg: #3a2f10; --warn-ink: #ffd98a;
  --danger: #ff8a80; --series-1: #3987e5; --series-2: #d95926;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* No double-tap zoom (rapid taps on the +/- steppers); pinch-zoom still works. */
html, body, button, a, input, select, textarea, label { touch-action: manipulation; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
.top { padding: calc(12px + env(safe-area-inset-top)) 16px 4px; }
.top h1 { margin: 0; font-size: 15px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
main { max-width: 640px; margin: 0 auto; padding: 8px 16px 16px; display: grid; gap: 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 2px 0 8px; font-size: 20px; }
.card h3 { margin: 0; font-size: 17px; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }
.muted { color: var(--ink-2); font-weight: 400; }
.small { font-size: 14px; }
.badge { font-size: 10px; letter-spacing: .08em; padding: 2px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-top: 10px; }
.row.small { margin-top: 6px; }
.row.date-row { flex-wrap: nowrap; align-items: end; }
.row.date-row label.check { padding-bottom: 11px; }
.stack { display: grid; gap: 10px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--ink-2); flex: 1 1 140px; min-width: 0; }
label.check { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; padding-bottom: 10px; font-size: 16px; color: var(--ink); }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; padding: 0; flex: none; accent-color: var(--accent); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
  min-width: 0; max-width: 100%;
}
/* iOS gives date fields a fixed intrinsic width that overflows the layout; let them size like other inputs. */
input[type="date"] { -webkit-appearance: none; appearance: none; display: block; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 18px; min-height: 48px;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; flex: 1 1 auto; text-align: center;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger, .link.danger { color: var(--danger); }
.link { font: inherit; font-size: 14px; background: none; border: 0; color: var(--accent); padding: 8px 4px; cursor: pointer; }

.plainlist { list-style: none; margin: 4px 0 0; padding: 0; }
.plainlist li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.plainlist li:first-child { border-top: 0; }
.exname { font-weight: 500; }

.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius); padding: 12px 14px; font-size: 15px; }

.cycle.deload { border-color: var(--series-2); }
.weeks { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; margin-top: 10px; }
.weeks i { height: 8px; border-radius: 4px; background: var(--line); }
.weeks i.done { background: var(--accent); opacity: .45; }
.weeks i.now { background: var(--accent); }
.weeks i.dl { outline: 1px dashed var(--ink-3); outline-offset: 1px; }

/* Session toggle */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.seg button {
  font: inherit; font-weight: 600; padding: 10px; border-radius: 12px; border: 1px solid var(--line);
  background: transparent; color: var(--ink); display: grid; cursor: pointer;
}
.seg button small { font-weight: 400; color: var(--ink-2); }
.seg button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Exercise logging */
.ex header { display: grid; gap: 2px; }
.ex details { margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.ex details p { margin: 4px 0 0; }
.ex summary { cursor: pointer; color: var(--accent); }
.last { margin: 8px 0 4px; font-size: 14px; color: var(--ink-2); }
.hint { margin: 0 0 8px; font-size: 14px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); }
.hint.increase { font-weight: 600; }
.sets { display: grid; gap: 8px; }
.set { display: grid; grid-template-columns: 22px 1fr 14px 1fr; align-items: center; gap: 6px; }
.setno { font-weight: 600; color: var(--ink-3); text-align: center; }
.set.filled .setno { color: var(--accent); }
.times { color: var(--ink-3); text-align: center; }
.stepper { display: grid; grid-template-columns: 40px 1fr 40px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.stepper input { border: 0; border-radius: 0; text-align: center; padding: 8px 2px; font-size: 18px; font-weight: 600; min-width: 0; background: transparent; }
.stepper input::placeholder { color: var(--ink-3); font-weight: 400; }
.stepper button { font: inherit; font-size: 20px; border: 0; background: transparent; color: var(--accent); cursor: pointer; min-height: 44px; }
.set.filled .stepper { border-color: var(--accent); }

/* Progress */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 6px; }
.stats div { display: grid; }
.stats .big { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats .muted { font-size: 12px; }
.chart { position: relative; margin-top: 8px; }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--series-1); }
.chart .line.s2 { stroke: var(--series-2); }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .dot.s1 { fill: var(--series-1); }
.chart .dot.s2 { fill: var(--series-2); }
.chart .crosshair { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.swatch.s1 { background: var(--series-1); }
.swatch.s2 { background: var(--series-2); }
.tooltip {
  position: absolute; top: 28px; width: 160px; padding: 8px 10px; font-size: 13px; line-height: 1.5;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .15); pointer-events: none;
}
.history { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; font-variant-numeric: tabular-nums; }
.history th { text-align: left; color: var(--ink-3); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.history th, .history td { padding: 8px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.history td:first-child { white-space: nowrap; color: var(--ink-2); }

.rules { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 15px; }

/* Bottom nav */
nav {
  position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav a { display: grid; justify-items: center; gap: 2px; padding: 8px 0 10px; font-size: 12px; color: var(--ink-3); text-decoration: none; }
nav a span { font-size: 18px; line-height: 1; }
nav a.active { color: var(--accent); font-weight: 600; }
body.signed-out nav { display: none; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; max-width: calc(100% - 32px);
}
