:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #16201e;
  --muted: #5f6b68;
  --line: #d9e0de;
  --accent: #0f766e;
  --accent-soft: #d5efeb;
  --accent-text: #ffffff;
  --error: #b42318;
  --warn: #8a5a00;
  --ok: #0f766e;
  --radius: 14px;
  --tap: 44px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --card: #182120;
    --text: #e7eeec;
    --muted: #9aa9a5;
    --line: #2b3735;
    --accent: #2dd4bf;
    --accent-soft: #123d38;
    --accent-text: #062522;
    --error: #ff8a80;
    --warn: #f5c16c;
    --ok: #5eead4;
  }
}

* {
  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;
  padding-bottom: env(safe-area-inset-bottom);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

h2,
h3 {
  font-size: 1rem;
  margin: 0;
}

.section-label {
  margin: 16px 4px 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

form > .section-label:first-child {
  margin-top: 4px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 16px 0 8px;
}

.section-head .section-label {
  margin: 0 4px;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  min-width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
}

#open-settings {
  font-size: 1.25rem;
  margin-left: auto;
}

.date-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: var(--tap);
  border: 0;
  background: transparent;
  font-weight: 650;
  font-size: 1.1rem;
}

.date-btn .muted {
  font-weight: 400;
  font-size: 0.8rem;
}

/* ---------- layout ---------- */

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 12px 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}

.card > h2 {
  margin-bottom: 6px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

/* ---------- controls ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  white-space: nowrap;
  user-select: none;
}

.chip.small {
  min-height: 38px;
  min-width: 38px;
  padding: 0 10px;
}

.chip[aria-pressed='true'],
.segmented [aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.toggle-chip {
  margin-top: 10px;
  font-size: 0.9rem;
}

.toggle-chip:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.toggle-chip input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.chip-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -12px;
  padding: 0 12px 2px;
  scroll-snap-type: x proximity;
}

.chip-scroll::-webkit-scrollbar {
  display: none;
}

.chip-scroll .chip {
  scroll-snap-align: center;
  padding: 0 12px;
}

.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.step-btn {
  width: 56px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  font-size: 1.6rem;
  line-height: 1;
  flex: none;
}

.step-btn.small {
  width: var(--tap);
  height: var(--tap);
  font-size: 1.1rem;
}

.step-btn:active,
.chip:active {
  background: var(--accent-soft);
}

.weight-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.weight-field {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  border-bottom: 2px solid var(--line);
}

.weight-field:focus-within {
  border-color: var(--accent);
}

#weight {
  width: 4.2ch;
  border: 0;
  background: transparent;
  font-size: 2.4rem;
  font-weight: 650;
  text-align: right;
  font-variant-numeric: tabular-nums;
  outline: none;
  padding: 0;
}

#weight:disabled {
  opacity: 0.35;
}

.unit {
  color: var(--muted);
}

.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 10px;
}

.segmented button {
  flex: 1;
  min-height: 40px;
  border: 0;
  background: transparent;
}

.segmented.small {
  margin: 0;
  flex: none;
}

.segmented.small button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.85rem;
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

.yesno {
  display: flex;
  gap: 8px;
}

.yesno .chip {
  flex: 1;
}

.counters {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.counter {
  display: flex;
  align-items: center;
  gap: 10px;
}

.counter > span {
  flex: 1;
}

.counter output {
  min-width: 4.5ch;
  text-align: center;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.session {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.session-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.exercise-item {
  display: grid;
  gap: 6px;
}

.exercise-item .effort {
  padding-left: 4px;
}

.effort {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.effort .muted {
  margin-right: 4px;
}

.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  min-height: 36px;
  padding: 0 4px;
}

#note {
  width: 100%;
  min-height: var(--tap);
  border: 0;
  background: transparent;
  outline: none;
}

.primary,
.secondary {
  min-height: 50px;
  padding: 0 22px;
  border-radius: 12px;
  font-weight: 650;
}

.primary {
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
}

.secondary {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
}

/* ---------- save bar ---------- */

.savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}

.savebar .primary {
  min-width: 40%;
}

.savebar .status {
  flex: 1;
  margin: 0;
}

.status {
  font-size: 0.9rem;
  min-height: 1.2em;
  margin: 8px 0 0;
}

.status.ok {
  color: var(--ok);
}

.status.error {
  color: var(--error);
}

.status.warn {
  color: var(--warn);
}

/* ---------- recent list ---------- */

.recent {
  margin-top: 18px;
}

.recent h2 {
  margin: 0 4px 8px;
  color: var(--muted);
  font-weight: 600;
}

.recent ul {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.recent li + li {
  border-top: 1px solid var(--line);
}

.recent-row {
  display: flex;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 0.9rem;
}

.recent-row[aria-current='date'] {
  background: var(--accent-soft);
}

.recent-date {
  flex: none;
  width: 7.5em;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- settings ---------- */

.field {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.field input {
  min-height: var(--tap);
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* avoids iOS zoom on focus */
}

.file-btn {
  display: inline-flex;
  align-items: center;
  min-height: 50px;
  padding: 0 22px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  color: var(--accent);
  font-weight: 650;
  cursor: pointer;
}

.file-btn input {
  display: none;
}
