:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: rgba(60, 60, 67, 0.14);
  --accent: #e8590c;
  --accent-soft: rgba(232, 89, 12, 0.12);
  --navy: #1f3864;
  --good: #1f8a4c;
  --good-soft: rgba(31, 138, 76, 0.12);
  --warn: #b7791f;
  --warn-soft: rgba(183, 121, 31, 0.14);
  --bad: #c92a2a;
  --bad-soft: rgba(201, 42, 42, 0.12);
  --field: #f2f2f7;
  --tabbar: rgba(249, 249, 251, 0.86);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
    --line: rgba(84, 84, 88, 0.55);
    --accent: #ff7a33;
    --accent-soft: rgba(255, 122, 51, 0.16);
    --navy: #8fb0ff;
    --good: #3fcf7f;
    --good-soft: rgba(63, 207, 127, 0.14);
    --warn: #f0b23f;
    --warn-soft: rgba(240, 178, 63, 0.14);
    --bad: #ff6b6b;
    --bad-soft: rgba(255, 107, 107, 0.14);
    --field: #2c2c2e;
    --tabbar: rgba(22, 22, 24, 0.86);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 96px);
  outline: none;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.loading, .empty { color: var(--muted); padding: 48px 0; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* header */
.bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 12px 2px 14px; }
.bar h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.bar p { color: var(--muted); font-size: 15px; margin-top: 2px; }
.bar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.athlete {
  border: 0; border-radius: 999px; padding: 6px 12px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px;
}
.sync { font-size: 12px; color: var(--muted); }
.sync.off { color: var(--warn); }
.back { border: 0; background: none; color: var(--accent); padding: 8px 0 0; font-size: 17px; }

/* controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.stepper, .segment {
  display: flex; background: var(--card); border-radius: 10px; padding: 3px; gap: 2px;
  box-shadow: 0 0 0 0.5px var(--line);
}
.stepper button, .segment button {
  border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-size: 15px; min-width: 40px;
}
.stepper button:disabled { opacity: 0.3; }
.stepper .current { color: var(--muted); }
.segment { flex: 1; }
.segment button { flex: 1; font-weight: 600; color: var(--muted); }
.segment button.on { background: var(--accent); color: #fff; }
.session-sub { color: var(--muted); font-size: 14px; margin: 0 2px 12px; }

/* cards */
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  box-shadow: 0 0 0 0.5px var(--line);
}
.item-head { display: flex; align-items: baseline; gap: 8px; }
.item-head h2 { font-size: 17px; font-weight: 700; flex: 1; }
.n {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--field); color: var(--muted); font-size: 12px; font-weight: 700; flex-shrink: 0;
  transform: translateY(-1px);
}
.rest { font-size: 13px; color: var(--muted); white-space: nowrap; }
.rx { margin-top: 6px; font-size: 16px; }
.hint { margin-top: 6px; font-size: 14px; color: var(--navy); }
.hint.good { color: var(--good); font-weight: 600; }
.hint.muted { color: var(--muted); }
details { margin-top: 8px; }
summary { color: var(--accent); font-size: 14px; font-weight: 600; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: " ›"; }
details[open] summary::after { content: " ⌄"; }
details p { margin-top: 6px; color: var(--muted); font-size: 14px; }
.item-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--field); color: var(--muted);
  text-decoration: none;
}
.log, .logged {
  border: 0; border-radius: 999px; padding: 8px 18px; font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.log { background: var(--accent); color: #fff; }
.logged { background: var(--good-soft); color: var(--good); font-size: 13px; max-width: 60%; text-align: right; }

/* notes */
.note {
  background: var(--card); border-left: 4px solid var(--navy); border-radius: 10px; padding: 10px 12px;
  margin-bottom: 12px; font-size: 14px; box-shadow: 0 0 0 0.5px var(--line);
}
.note.accent { border-color: var(--accent); background: var(--accent-soft); }
.note.warn { border-color: var(--warn); background: var(--warn-soft); }
.note.bad { border-color: var(--bad); background: var(--bad-soft); }
.link { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 600; font-size: inherit; }
.link.strong { font-weight: 700; }

/* lists */
.list { padding: 0; overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 12px 16px; border: 0; background: none; text-align: left; text-decoration: none; color: inherit;
  border-bottom: 0.5px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row span { display: flex; flex-direction: column; min-width: 0; }
.row small { color: var(--muted); font-size: 13px; }
.row .value { align-items: flex-end; font-weight: 700; flex-shrink: 0; }
.chev { color: var(--muted); font-size: 20px; }
.group { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; }
.foot { font-size: 13px; margin: 8px 4px 16px; }
.rule p { margin-top: 4px; font-size: 15px; }
.rule .chips { margin-top: 8px; }
.verdict { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.verdict.good { background: var(--good-soft); color: var(--good); }
.verdict.warn { background: var(--warn-soft); color: var(--warn); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }

/* forms */
.form h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 14px 0 4px; }
.form h3:first-child { margin-top: 0; }
label { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
label > span { display: flex; flex-direction: column; font-size: 16px; }
label small { color: var(--muted); font-size: 12px; }
input, select {
  border: 0; border-radius: 10px; background: var(--field); padding: 10px 12px; font-size: 17px;
  width: 9em; text-align: right; min-width: 0;
}
input[type="date"] { width: auto; }
input[name="position"], input[name="notes"], select { width: 60%; text-align: left; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.grid4 label { flex-direction: column; align-items: stretch; gap: 4px; padding: 0; }
.grid4 label > span { font-size: 12px; color: var(--muted); }
.grid4 input { width: 100%; text-align: center; padding: 10px 4px; }
.primary {
  border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; padding: 13px 18px;
  font-size: 17px;
}
.primary.big { padding: 18px; font-size: 20px; }
.wide { width: 100%; margin: 6px 0 12px; }
.form .wide { margin: 12px 0 0; }
.danger { border: 0; border-radius: 12px; background: var(--bad-soft); color: var(--bad); font-weight: 700; padding: 13px; }
.stats { display: flex; gap: 8px; }
.stats > div { flex: 1; display: flex; flex-direction: column; }
.stats small { color: var(--muted); font-size: 12px; }
.stats b { font-size: 20px; }
.result { margin-top: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.result.good { color: var(--good); }
.result.bad { color: var(--bad); }
.test .link { margin-top: 10px; font-size: 14px; }
.ratios { display: flex; flex-wrap: wrap; gap: 14px; margin: 6px 0; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 13px; padding: 4px 6px; }
.table td { padding: 8px 6px; border-top: 0.5px solid var(--line); vertical-align: top; }
.table td small { display: block; color: var(--accent); font-size: 12px; }
.table tr.now td { font-weight: 700; color: var(--accent); }

/* entry screens */
.center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 12vh 8px 0; }
.center h1 { font-size: 30px; font-weight: 800; }
.center .stack { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; margin-top: 12px; }
.login input { width: 100%; max-width: 320px; text-align: left; }
.login .primary { width: 100%; max-width: 320px; }
.logo { width: 84px; height: 84px; border-radius: 20px; background: url("icon.svg") center / cover; }

/* tab bar */
#tabs:empty { display: none; }
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: var(--tabbar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
}
#tabs button {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; padding: 4px 0;
}
#tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#tabs circle { fill: currentColor; stroke: none; }
#tabs button.on { color: var(--accent); }

/* sheet */
dialog {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 92vh;
  border-radius: 16px 16px 0 0; background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.sheet { padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 0 12px; }
.sheet h2 { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.sheet .danger { margin-top: 16px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translate(-50%, 20px);
  background: rgba(30, 30, 32, 0.92); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 20; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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