:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #16a34a;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --input: #f0f1f4;
  --radius: 12px;
  --nav-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1f2228;
    --text: #eceef2;
    --muted: #9aa0ab;
    --border: #2e323a;
    --accent: #4ade80;
    --accent-text: #0b1a10;
    --danger: #f87171;
    --input: #2a2e36;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.6rem; margin: 4px 0 16px; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; color: var(--muted); font-weight: 600; }
h3 { font-size: 1.1rem; margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }

/* bottom navigation */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
#nav[hidden] { display: none; }
#nav a {
  flex: 1;
  height: var(--nav-h);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: .9rem;
}
#nav a.active { color: var(--accent); }

/* cards and lists */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.list { list-style: none; margin: 0; padding: 0; }
.list > li {
  display: flex; align-items: center; gap: 8px;
  min-height: 52px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
}
.list > li:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.list > li:last-child { border-bottom: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
.list > li:only-child { border-radius: var(--radius); }
a.item { display: block; color: inherit; text-decoration: none; }
.badge {
  font-size: .75rem; font-weight: 600;
  padding: 2px 8px; border-radius: 99px;
  background: var(--input); color: var(--muted);
  white-space: nowrap;
}
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

/* form controls */
button, .button {
  font: inherit; font-weight: 600;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none;
  touch-action: manipulation;
}
button:disabled { opacity: .5; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.block { width: 100%; }
button.icon { width: 44px; padding: 0; }
input, select {
  font: inherit;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--text);
  width: 100%;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }

/* workout logging */
.exercise-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.previous { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.sets { list-style: none; margin: 0 0 8px; padding: 0; }
.sets li {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px;
  border-bottom: 1px solid var(--border);
}
.sets .n { width: 1.6em; color: var(--muted); font-variant-numeric: tabular-nums; }
.sets .val { flex: 1; font-weight: 600; font-variant-numeric: tabular-nums; }
.entry { display: flex; gap: 6px; align-items: flex-end; }
.entry .field { flex: 1; min-width: 0; }
.entry .field label { text-align: center; margin-bottom: 2px; }
.stepper { display: flex; }
.stepper input { text-align: center; border-radius: 0; padding: 0 2px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper button { min-width: 36px; padding: 0; border-radius: 0; background: var(--input); }
.stepper button:first-child { border-radius: 10px 0 0 10px; border-right: none; }
.stepper button:last-child { border-radius: 0 10px 10px 0; border-left: none; }
.entry .log { width: 56px; padding: 0; font-size: 1.3rem; }
.duration { display: flex; align-items: center; gap: 2px; }
.duration input { text-align: center; padding: 0 4px; font-weight: 600; }

/* toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px;
  font-weight: 600;
  z-index: 20;
}
#toast.error { background: var(--danger); color: #fff; }

/* login */
.login { max-width: 360px; margin: 12vh auto 0; }
.login h1 { text-align: center; }
.list > li.empty { justify-content: center; }
