@font-face {
  font-family: 'Lexend';
  src: url('fonts/lexend.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #4f5d6d;
  --line: #dde3ea;
  --soft: #eef2f6;
  --accent: #1d5fd1;
  --accent-ink: #ffffff;
  --accent-soft: #e3ecfb;
  --good: #146c37;
  --good-soft: #e2f3e8;
  --warn: #8a4b00;
  --warn-soft: #fbefdc;
  --danger: #b42318;
  --series: #2a78d6;
  --radius: 14px;
  --tap: 52px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b1017;
    --card: #151c26;
    --ink: #e8eef5;
    --muted: #a3b0bf;
    --line: #273244;
    --soft: #1c2533;
    --accent: #6aa8ff;
    --accent-ink: #08101c;
    --accent-soft: #1b2a42;
    --good: #6fdc95;
    --good-soft: #15291d;
    --warn: #f2bd5c;
    --warn-soft: #2c2312;
    --danger: #ff8a80;
    --series: #3987e5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.45 'Lexend', -apple-system, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; color: var(--muted); text-transform: none; margin: 24px 4px 8px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.bar {
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; margin-bottom: 8px;
}
.bar h1 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.bar .title-sm { font-size: 20px; }
.bar .spacer { flex: 1; }
.pillthumb { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; margin-left: -6px; }

/* How to do it */
.howname { font-size: 20px; font-weight: 600; margin: 0 4px 12px; }
.howpics figure { margin: 0 0 12px; }
.howpics img { display: block; width: 100%; height: auto; border-radius: 10px; background: var(--soft); }
.howpics figcaption { font-weight: 600; margin-top: 6px; }
.steps summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.steps ol { margin: 8px 0 0; padding-left: 22px; }
.steps li { margin-bottom: 10px; }
.navbtn {
  min-height: 44px; min-width: 44px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; background: var(--soft); color: var(--ink);
  font-weight: 500; font-size: 16px; text-decoration: none;
}

/* Cards and rows */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 10px 16px;
  color: inherit; text-decoration: none;
  border-top: 1px solid var(--line);
}
.list > .row:first-child, .list > :first-child .row { border-top: 0; }
.row:active { background: var(--soft); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-name { font-weight: 500; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--muted); }
.row-target {
  flex: none; font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums;
  padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--ink);
}
.row-chev { color: var(--muted); flex: none; }

details.group { margin-bottom: 8px; }
details.group > summary {
  list-style: none; display: flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  font-weight: 600; cursor: pointer;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary .count { color: var(--muted); font-weight: 400; }
details.group > summary::after { content: '›'; margin-left: auto; color: var(--muted); font-size: 22px; transition: transform .15s; }
details.group[open] > summary::after { transform: rotate(90deg); }
details.group[open] > summary { border-radius: var(--radius) var(--radius) 0 0; }
details.group > .list { border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }

.search {
  width: 100%; min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); font-size: 17px;
}

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); font-weight: 500; text-decoration: none; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.big { min-height: 64px; font-size: 20px; }
.btn.danger { color: var(--danger); }
.btn + .btn, .btn + .note, .stack > * + * { margin-top: 8px; }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 8px 4px; min-height: 44px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
label.btn input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
label.btn { position: relative; cursor: pointer; }

/* The "Beat this today" card */
.beat { border: 2px solid var(--accent); }
.beat .label { font-size: 15px; font-weight: 600; color: var(--muted); }
.beat .target { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; margin: 4px 0 8px; }
.beat .big { font-size: 48px; font-weight: 650; line-height: 1.05; letter-spacing: -0.5px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 15px; font-weight: 600;
  background: var(--accent-soft); color: var(--ink); white-space: nowrap;
}
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.why { font-size: 16px; }
.last { font-size: 15px; color: var(--muted); margin-top: 8px; }
.note { border-radius: 10px; padding: 10px 12px; font-size: 15px; margin-top: 10px; background: var(--soft); }
.note.warn { background: var(--warn-soft); }
.note.good { background: var(--good-soft); }
.note strong { font-weight: 600; }
.meta { font-size: 14px; color: var(--muted); margin: -4px 4px 12px; }

/* Logging */
.logday { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: 15px; color: var(--muted); }
.logday strong { color: var(--ink); }
.logday > span { flex: 1; }
.dateinput { min-height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 15px; max-width: 160px; }
.stepper { display: grid; grid-template-columns: 1fr 64px minmax(72px, 96px) 64px; align-items: center; gap: 8px; margin-bottom: 10px; }
.stepper .lab { font-weight: 500; }
.stepper .lab small { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.stepper button {
  height: 60px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--soft); font-size: 28px; font-weight: 500; line-height: 1;
}
.stepper button:active { background: var(--accent-soft); }
.stepper input {
  height: 60px; width: 100%; text-align: center; font-size: 26px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  font-variant-numeric: tabular-nums;
}
/* Pinned to the bottom, in thumb reach. */
.logpanel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  max-width: 560px; margin: 0 auto;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .08);
}
.logpanel .stepper { margin-bottom: 8px; }
.logpanel .stepper button, .logpanel .stepper input { height: 52px; }
.logrow { display: flex; gap: 8px; }
.logrow .wu {
  flex: none; min-height: 60px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--soft); font-weight: 500;
}
.logrow .wu[aria-pressed=true] { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.logrow .btn { flex: 1; min-height: 60px; }
body.logging main { padding-bottom: calc(env(safe-area-inset-bottom) + 220px); }
body.logging .toast { bottom: calc(env(safe-area-inset-bottom) + 200px); }
.card.logday { margin-bottom: 0; padding: 8px 8px 8px 16px; }

.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0 0 8px; font-size: 16px; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); }

ol.sets { list-style: none; margin: 0; padding: 0; }
ol.sets li {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  min-height: 56px; padding: 6px 4px 6px 16px; border-top: 1px solid var(--line);
}
ol.sets li:first-child { border-top: 0; }
ol.sets .n { color: var(--muted); width: 20px; font-variant-numeric: tabular-nums; }
ol.sets .s { font-weight: 600; font-size: 18px; font-variant-numeric: tabular-nums; }
ol.sets .x { margin-left: auto; width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 20px; border-radius: 10px; }

/* History */
.hist .day { display: flex; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.hist .day:first-child { border-top: 0; }
.hist .when { flex: none; width: 92px; color: var(--muted); font-size: 15px; }
.hist .what { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.hist .what .best { font-size: 14px; font-weight: 600; color: var(--good); }

.chart { position: relative; padding: 12px 8px 4px; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart svg:focus-visible { outline-offset: -2px; }
.chart .tip {
  position: absolute; top: 4px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 500;
  padding: 4px 10px; border-radius: 8px; white-space: nowrap; pointer-events: none;
}
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series); stroke: var(--card); stroke-width: 2; }
.chart .star { fill: var(--ink); font-size: 13px; }
.chart .endlabel { fill: var(--ink); font-size: 13px; font-weight: 600; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.legend { font-size: 14px; color: var(--muted); margin: 4px 8px 8px; }

/* Forms */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 500; margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 14px; margin-top: 4px; }
.field input:not([type=checkbox]), .field select, .field textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: 17px;
}
.field textarea { min-height: 96px; resize: vertical; }
.pair { display: flex; align-items: center; gap: 10px; }
.pair input { flex: 1; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chips button { min-height: 44px; min-width: 56px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft); font-weight: 500; }
.chips button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

table.plain { width: 100%; border-collapse: collapse; font-size: 15px; }
table.plain th, table.plain td { text-align: left; padding: 8px 4px; border-top: 1px solid var(--line); vertical-align: top; }
table.plain th { font-weight: 600; }
.small { font-size: 14px; color: var(--muted); }
.center { text-align: center; }
.empty { text-align: center; padding: 32px 16px; }
.empty h2 { color: var(--ink); font-size: 22px; margin: 0 0 8px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px);
  max-width: 528px; margin: 0 auto; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 16px; min-height: 56px;
  background: var(--ink); color: var(--bg); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25); font-weight: 500;
}
.toast span { flex: 1; }
.toast button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--bg); color: var(--ink); font-weight: 600; }

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