:root {
  color-scheme: dark;
  --bg: #0e0f11;
  --surface: #17191c;
  --surface-2: #1f2226;
  --line: #2a2d32;
  --text: #f2f1ed;
  --muted: #9a9da3;
  --accent: #c8f24a;
  --on-accent: #12160a;
  --danger: #ff7a6b;
  --radius: 14px;
  --gutter: 16px;
  --tabs-h: 56px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f5f4f1;
    --surface: #ffffff;
    --surface-2: #efeee9;
    --line: #dfddd6;
    --text: #17181a;
    --muted: #666a70;
    --accent: #2f5d00;
    --on-accent: #ffffff;
    --danger: #b3261e;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) var(--gutter)
    calc(var(--tabs-h) + env(safe-area-inset-bottom) + 32px);
  min-height: 100dvh;
  outline: none;
}

h1 { font-size: 30px; line-height: 1.1; letter-spacing: -0.02em; margin: 0; font-weight: 700; }
h2 {
  font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); margin: 28px 0 10px;
}
h3 { font-size: 16px; margin: 0; font-weight: 600; }
p { margin: 0 0 12px; }
a { color: inherit; text-decoration: none; }
small { color: var(--muted); font-size: 14px; }
strong { font-weight: 600; }

.top { margin-bottom: 8px; }
.eyebrow { color: var(--muted); font-size: 14px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 6px 0 0; }
.back { display: inline-block; color: var(--muted); font-size: 15px; padding: 6px 12px 6px 0; margin-bottom: 6px; }
.back::before { content: "‹ "; }

/* Lists of tappable rows */
.rows { display: grid; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; min-height: 60px;
}
.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-main strong, .row-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--muted); font-size: 14px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-meta.done { color: var(--accent); font-weight: 600; }
a.row::after { content: "›"; color: var(--muted); font-size: 20px; line-height: 1; }
.row.today { border-color: var(--accent); }

.empty {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 20px 16px; color: var(--muted); text-align: center;
}
.empty a { color: var(--accent); font-weight: 600; }

/* Exercise cards */
.ex { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ex + .ex { margin-top: 8px; }
.ex summary {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 64px;
  cursor: pointer; list-style: none;
}
.ex summary::-webkit-details-marker { display: none; }
.ex-n {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); font-variant-numeric: tabular-nums;
}
.ex.done .ex-n { background: var(--accent); color: var(--on-accent); }
.ex-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.ex-main small { font-variant-numeric: tabular-nums; }
.ex-state { color: var(--accent); font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.ex-body { padding: 0 16px 16px; border-top: 1px solid var(--line); }
.ex-note { color: var(--muted); font-size: 14px; margin: 12px 0 0; }
.last { font-size: 14px; margin: 12px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.last b { color: var(--text); font-weight: 600; }

/* Forms */
form { margin: 0; }
.field { display: block; margin-top: 14px; }
.field > span, label.field > span, .label {
  display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px;
}
input[type="text"], input[type="date"], input[type="password"], select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  -webkit-appearance: none; appearance: none; font-variant-numeric: tabular-nums;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.load { display: flex; gap: 8px; }
.load input { flex: 1; min-width: 0; }
.sets { display: grid; grid-template-columns: repeat(auto-fit, minmax(52px, 1fr)); gap: 8px; }
.sets input { text-align: center; padding-left: 4px; padding-right: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }

button {
  font: inherit; font-size: 16px; font-weight: 600; color: var(--text);
  min-height: 48px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer;
}
button:active { opacity: 0.75; }
button:disabled { opacity: 0.5; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.unit { flex: none; width: 60px; font-variant-numeric: tabular-nums; }
button.quiet { background: none; border-color: transparent; color: var(--muted); font-weight: 500; padding: 10px 8px; }
button.danger { color: var(--danger); }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.actions .primary { flex: 1; }

.history { margin-top: 14px; border-top: 1px solid var(--line); }
.history-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line);
  font-size: 14px; font-variant-numeric: tabular-nums;
}
.history-row span:first-child { flex: none; width: 92px; color: var(--muted); }
.history-row span:nth-child(2) { flex: 1; min-width: 0; }
.history-row button { min-height: 40px; }

/* Cards and content */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card p { color: var(--muted); font-size: 15px; }

.datepick { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 14px; }
.datepick input { width: auto; flex: 1; min-height: 44px; }

.prose p, .prose li { font-size: 16px; line-height: 1.55; }
.prose ul, .prose ol { padding-left: 22px; margin: 0 0 14px; }
.prose li { margin-bottom: 6px; }
.table { overflow-x: auto; margin: 0 calc(var(--gutter) * -1) 16px; padding: 0 var(--gutter); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; vertical-align: top; padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
td:first-child { font-weight: 600; min-width: 84px; }
td:last-child, th:last-child { padding-right: 0; }

/* Photos */
.poses { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pose {
  position: relative; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--muted); font-size: 13px; padding: 0; min-height: 0;
  font-weight: 500;
}
label.pose { border-style: dashed; cursor: pointer; }
.pose img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pose .tag {
  position: absolute; left: 6px; bottom: 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: #fff; background: rgb(0 0 0 / 0.55); padding: 2px 6px; border-radius: 6px;
}
.pose input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.checkin { margin-top: 24px; }
h2 + .checkin { margin-top: 0; }
.checkin header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.checkin header h3 { flex: 1; }
.checkin header span { color: var(--muted); font-variant-numeric: tabular-nums; }
.checkin header button { min-height: 40px; }
.checkin-note { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

.viewer {
  position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / 0.94);
  display: grid; place-items: center; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Data */
.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.file { display: block; width: 100%; font-size: 15px; color: var(--muted); }
.file::file-selector-button {
  font: inherit; font-weight: 600; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; min-height: 48px; padding: 10px 16px; margin-right: 12px;
}
.preview { margin-top: 14px; font-size: 15px; }
.preview ul { list-style: none; padding: 0; margin: 0 0 12px; }
.preview li { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.preview li span:first-child { flex: 1; min-width: 0; }
.preview li span:last-child { color: var(--muted); white-space: nowrap; }
.error { color: var(--danger); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--surface); min-width: 72px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; margin: 12px 0 0;
}
details.card summary { font-weight: 600; cursor: pointer; }

/* Bottom tabs */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
#tabs a {
  height: var(--tabs-h); display: grid; place-items: center;
  font-size: 15px; font-weight: 600; color: var(--muted);
}
#tabs a[aria-current="page"] { color: var(--accent); }
body.locked #tabs { display: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 12px); z-index: 40;
  background: var(--text); color: var(--bg); font-size: 15px; font-weight: 600;
  padding: 10px 16px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
