*, *::before, *::after { box-sizing: border-box; }

html, body { overflow-x: clip; }

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

body {
  margin: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

.page {
  max-width: 34rem;
  margin: 0 auto;
  padding: var(--space-md) var(--space-md) calc(5.5rem + env(safe-area-inset-bottom));
  padding-top: calc(var(--space-md) + env(safe-area-inset-top));
}
.page-bare { padding-bottom: var(--space-xl); }

h1, h2 { font-family: var(--font-display); margin: 0; line-height: 1.15; overflow-wrap: anywhere; min-width: 0; }
h1 { font-size: var(--text-xl); font-weight: 750; letter-spacing: -0.02em; }
h2 { font-size: var(--text-md); font-weight: 700; }
p { margin: 0; }
a { color: inherit; }

.muted { color: var(--color-muted); }
.hint { color: var(--color-muted); font-size: var(--text-xs); }
.unit { font-size: var(--text-xs); font-weight: 600; color: var(--color-muted); margin-left: 0.25em; }
.empty { padding: var(--space-md) 0; }

:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-md); margin-bottom: var(--space-md); min-height: var(--tap);
}
.back { text-decoration: none; color: var(--color-muted); font-weight: 600; padding: var(--space-xs) 0; white-space: nowrap; }
.link { background: none; border: 0; padding: var(--space-xs) 0; font: inherit; font-size: var(--text-sm); font-weight: 600; color: var(--color-accent); text-decoration: none; cursor: pointer; }

.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: var(--space-lg) 0 var(--space-sm);
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-muted);
}
.section-title .count { letter-spacing: 0; text-transform: none; font-weight: 600; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 var(--space-lg);
  border: var(--rule-width) solid transparent; border-radius: var(--radius-md);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; white-space: nowrap;
  background: var(--color-fill); color: var(--color-ink);
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-accent); color: var(--color-accent-ink); }
.btn-primary:hover { background: oklch(47% 0.17 40); }
.btn-quiet { background: var(--color-surface); border-color: var(--color-rule); }
.btn-quiet:hover { background: var(--color-fill); }
.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-danger:hover { background: oklch(92% 0.05 25); }
.btn-wide { width: 100%; }
.btn-big { min-height: 3.75rem; font-size: var(--text-lg); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); flex: none;
  background: none; border: 0; border-radius: var(--radius-pill);
  font: inherit; font-size: 1.4rem; color: var(--color-muted); cursor: pointer;
}
button.icon-btn:hover { background: var(--color-fill); }
.icon-btn.danger:hover { background: var(--color-danger-soft); color: var(--color-danger); }

/* Cards & lists */
.card {
  background: var(--color-surface); border: var(--rule-width) solid var(--color-rule);
  border-radius: var(--radius-md); padding: var(--space-md); margin-bottom: var(--space-md);
}
.card-action { display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); text-decoration: none; margin-bottom: var(--space-md); }

.list { list-style: none; margin: 0; padding: 0; border-top: var(--rule-width) solid var(--color-rule); }
.list-row {
  display: flex; align-items: center; gap: var(--space-sm);
  border-bottom: var(--rule-width) solid var(--color-rule); min-height: 4rem;
}
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; text-decoration: none; padding: var(--space-sm) 0; }
.list-main.with-thumb { flex-direction: row; align-items: center; gap: var(--space-sm); }
.list-main.with-thumb > span { display: flex; flex-direction: column; min-width: 0; }
.list-main .muted { font-size: var(--text-sm); }
.thumb { width: 3rem; height: 3rem; flex: none; border-radius: var(--radius-sm); object-fit: cover; background: var(--color-fill); }
.thumb-empty { display: block; }
.badge {
  padding: 0.2rem 0.6rem; border-radius: var(--radius-pill);
  background: var(--color-accent-soft); color: var(--color-accent); font-weight: 700; font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

/* Forms */
.stack { display: flex; flex-direction: column; gap: var(--space-md); }
label { display: flex; flex-direction: column; gap: var(--space-2xs); font-size: var(--text-sm); font-weight: 600; min-width: 0; }
input:not([type="checkbox"]):not([type="file"]) {
  width: 100%; min-height: var(--tap); padding: 0 var(--space-sm);
  border: var(--rule-width) solid var(--color-rule); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-ink); font: inherit; font-size: 1rem;
}
input[type="file"] { font: inherit; font-size: var(--text-sm); padding: var(--space-xs) 0; max-width: 100%; }
.check { flex-direction: row; align-items: center; gap: var(--space-xs); min-height: var(--tap); font-weight: 500; }
.check input { width: 1.25rem; height: 1.25rem; accent-color: var(--color-accent); }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-sm); }

.error {
  background: var(--color-danger-soft); color: var(--color-danger); font-weight: 600;
  padding: var(--space-sm) var(--space-md); border-radius: var(--radius-sm); margin: var(--space-sm) 0;
}

.foot-form { margin-top: var(--space-xl); text-align: center; }
.actions { display: grid; gap: var(--space-sm); margin-top: var(--space-xl); }

/* Login */
.login { padding-top: 15vh; display: flex; flex-direction: column; gap: var(--space-md); }
.login h1 { font-size: 2.5rem; }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: calc(var(--space-xs) * -1) 0 var(--space-xs); }
.cal-head h2 { font-size: var(--text-md); }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2xs); }
.cal-dow { text-align: center; font-size: var(--text-xs); font-weight: 600; color: var(--color-muted); padding-bottom: var(--space-2xs); }
.cal-day {
  display: flex; align-items: center; justify-content: center; aspect-ratio: 1; min-height: 2.5rem;
  border-radius: var(--radius-pill); text-decoration: none; font-variant-numeric: tabular-nums; font-weight: 500;
}
.cal-day.is-future { color: var(--color-rule); }
.cal-day.is-today { box-shadow: inset 0 0 0 2px var(--color-ink); font-weight: 700; }
.cal-day.is-gym { background: var(--color-accent); color: var(--color-accent-ink); font-weight: 700; }
.cal-day.is-gym.is-today { box-shadow: 0 0 0 2px var(--color-paper), 0 0 0 4px var(--color-ink); }
/* Walk marker: a small dot under the day number, independent of gym days */
.cal-day { position: relative; }
.cal-day.has-walk::after {
  content: ""; position: absolute; bottom: 0.3rem; left: 50%; width: 0.4rem; height: 0.4rem; margin-left: -0.2rem;
  border-radius: 50%; background: var(--color-walk); box-shadow: 0 0 0 1.5px var(--color-surface);
}
.walk-dot { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--color-walk); }
.walk-form { display: flex; align-items: center; gap: var(--space-sm); flex-wrap: wrap; flex-basis: 100%; }
.walk-form label { font-weight: 600; flex: 1 1 auto; }
.walk-form input[type=number] { width: 6rem; }
.cal-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); margin-top: var(--space-md); flex-wrap: wrap; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-sm); }
.tile { background: var(--color-surface); border: var(--rule-width) solid var(--color-rule); border-radius: var(--radius-md); padding: var(--space-sm); display: flex; flex-direction: column; gap: var(--space-2xs); min-width: 0; }
.tile-label { font-size: var(--text-xs); color: var(--color-muted); font-weight: 600; }
.tile-value { font-size: var(--text-lg); font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.tile-sub { font-size: var(--text-xs); color: var(--color-muted); }

/* Exercise + logger */
.ex-hero { margin-bottom: var(--space-md); }
.ex-photo { display: block; width: 100%; max-height: 14rem; object-fit: cover; border-radius: var(--radius-md); margin-bottom: var(--space-sm); background: var(--color-fill); }
.log-form { display: grid; gap: var(--space-md); }
.stepper-row { display: grid; grid-template-columns: 4rem minmax(0, 1fr) 4rem; gap: var(--space-xs); }
.stepper-row input { min-height: 4rem; text-align: center; font-size: var(--text-num); font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; padding: 0; }
.step {
  min-height: 4rem; border: var(--rule-width) solid var(--color-rule); border-radius: var(--radius-sm);
  background: var(--color-surface); font: inherit; font-size: 1.75rem; font-weight: 500; cursor: pointer; color: var(--color-ink);
}
.step:active { background: var(--color-fill); }
.set-list { list-style: none; margin: 0; padding: 0; counter-reset: set; border-top: var(--rule-width) solid var(--color-rule); }
.set-row { display: flex; align-items: center; gap: var(--space-sm); min-height: 3.5rem; border-bottom: var(--rule-width) solid var(--color-rule); counter-increment: set; }
.set-row::before { content: counter(set); width: 1.75rem; height: 1.75rem; display: grid; place-items: center; border-radius: var(--radius-pill); background: var(--color-fill); font-size: var(--text-xs); font-weight: 700; flex: none; }
.set-main { flex: 1; font-variant-numeric: tabular-nums; }

/* Tab bar */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--color-surface); border-top: var(--rule-width) solid var(--color-rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 3.5rem; text-decoration: none; color: var(--color-muted); font-size: var(--text-xs); font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--color-accent); }
.tabbar svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 40rem) {
  .page { padding-top: var(--space-xl); }
  .tabbar { inset: auto 50% 1rem auto; transform: translateX(50%); width: 32rem; border: var(--rule-width) solid var(--color-rule); border-radius: var(--radius-md); }
}

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