:root {
  --bg: #0d0e10;
  --bg2: #15171a;
  --card: #1a1d21;
  --card2: #22262b;
  --line: #2c3137;
  --text: #f1f3f5;
  --muted: #9aa3ad;
  --accent: #c8f53b;
  --accent-ink: #141a00;
  --accent-soft: rgba(200, 245, 59, .14);
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #60a5fa;
  --radius: 16px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f7; --bg2: #eceef1; --card: #ffffff; --card2: #f1f3f5; --line: #dfe3e8;
    --text: #15181c; --muted: #5f6b77; --accent: #5a8f00; --accent-ink: #ffffff; --accent-soft: rgba(90, 143, 0, .12);
    --good: #15803d; --warn: #b45309; --bad: #dc2626; --info: #2563eb;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f5f7; --bg2: #eceef1; --card: #ffffff; --card2: #f1f3f5; --line: #dfe3e8;
  --text: #15181c; --muted: #5f6b77; --accent: #5a8f00; --accent-ink: #ffffff; --accent-soft: rgba(90, 143, 0, .12);
  --good: #15803d; --warn: #b45309; --bad: #dc2626; --info: #2563eb;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  overscroll-behavior-y: contain;
}
body.no-nav { padding-bottom: 24px; }
body.resting { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 96px); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

#app { max-width: 640px; margin: 0 auto; padding: calc(16px + var(--safe-t)) 16px 0; }

.top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; min-height: 40px; }
.top .back { color: var(--text); text-decoration: none; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; font-size: 1.2rem; cursor: pointer; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 12px; }
.card.accent { background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--card); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(.99); }
.section { margin-top: 20px; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 4px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card2); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
  user-select: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; border-radius: 10px; font-size: .9rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { text-decoration: none; color: var(--text); font-size: 1.2rem; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); display: inline-grid; place-items: center; cursor: pointer; flex: none; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .72rem; font-weight: 700; letter-spacing: .02em; background: var(--card2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.main { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.good { color: var(--good); }
.badge.warn { color: var(--warn); }

.alert { border-radius: 14px; padding: 12px 14px; border: 1px solid var(--line); background: var(--card); }
.alert.warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.alert.tip { border-color: color-mix(in srgb, var(--info) 45%, var(--line)); }
.alert.info { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.alert b { display: block; margin-bottom: 2px; }
.alert + .alert { margin-top: 8px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat .v { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .75rem; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }

/* Formularze */
label.field { display: block; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg2); outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 90px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 42px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--card2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-weight: 500;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale .chip { justify-content: center; padding: 0; flex-direction: column; min-height: 58px; border-radius: 14px; font-size: 1.35rem; gap: 0; }
.scale .chip small { font-size: .62rem; font-weight: 600; }
.q { padding: 14px 0; border-top: 1px solid var(--line); }
.q:first-child { border-top: 0; padding-top: 0; }
.q > .lbl { font-weight: 700; margin-bottom: 10px; display: flex; justify-content: space-between; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }

/* Wynik samopoczucia */
.ring { --p: 50; width: 96px; height: 96px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--ring-c, var(--accent)) calc(var(--p) * 1%), var(--card2) 0);
  display: grid; place-items: center; }
.ring::before { content: ""; position: absolute; }
.ring > div { width: 76px; height: 76px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-weight: 800; font-size: 1.5rem; }

/* Trening */
.wk-head { position: sticky; top: 0; z-index: 20; margin: calc(-16px - var(--safe-t)) -16px 12px; padding: calc(10px + var(--safe-t)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.progress { height: 6px; border-radius: 99px; background: var(--card2); overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.ex { padding: 16px; }
.ex.done-all { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.ex-head { display: flex; gap: 12px; align-items: flex-start; }
.ex-num { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; background: var(--card2); border: 1px solid var(--line); color: var(--muted); margin-top: 2px; }
.ex-num.ok { background: var(--good); color: #062b12; border-color: transparent; }
.ex-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ex-title { font-weight: 750; font-size: 1.12rem; line-height: 1.25; cursor: pointer; margin-top: 4px; }

/* Partie mięśniowe */
.muscles { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.mz { display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; font-weight: 600; padding: 2px 8px 2px 7px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.mz::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--mc); opacity: .55; }
.mz.main { color: var(--text); background: color-mix(in srgb, var(--mc) 16%, transparent); border-color: color-mix(in srgb, var(--mc) 40%, transparent); }
.mz.main::before { opacity: 1; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.pill { display: inline-flex; align-items: baseline; gap: 4px; padding: 5px 10px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); font-size: .8rem; color: var(--muted); white-space: nowrap; }
.pill b { color: var(--text); font-size: .95rem; font-variant-numeric: tabular-nums; }
.pill.sm { padding: 3px 8px; font-size: .78rem; color: var(--text); }
.ex-why { font-size: .8rem; color: var(--muted); margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: var(--bg2); border-left: 3px solid var(--accent); }
.warmups { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.wu-l { font-size: .78rem; color: var(--warn); font-weight: 700; margin-right: 2px; }

.sets { margin-top: 14px; }
.set { display: grid; grid-template-columns: 30px minmax(0, 1fr) minmax(0, 1fr) 64px 52px; gap: 6px; align-items: center; margin-top: 6px; }
.set.hdr { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 0; text-align: center; }
.set .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .8rem; color: var(--muted); background: var(--card2); justify-self: center; }
.set input, .set select { width: 100%; min-height: 46px; text-align: center; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-weight: 700; font-size: 1.05rem; padding: 0 2px; font-variant-numeric: tabular-nums; }
.set input::placeholder { color: var(--muted); opacity: .6; }
.set select { font-size: .95rem; -webkit-appearance: none; appearance: none; text-align-last: center; }
.set select.empty { color: var(--muted); font-weight: 500; }
.set input:focus, .set select:focus { border-color: var(--accent); outline: none; }
.set .ok { min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); font-size: 1.2rem; cursor: pointer; color: var(--muted); }
.set.done .n { background: var(--good); color: #062b12; }
.set.done input, .set.done select { background: color-mix(in srgb, var(--good) 10%, var(--bg2)); border-color: color-mix(in srgb, var(--good) 30%, var(--line)); }
.set.done .ok { background: var(--good); color: #062b12; border-color: transparent; }
.ex-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }

/* Timer przerwy / stoper */
.rest {
  --rc: var(--accent);
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 10px); z-index: 40;
  width: min(608px, calc(100% - 24px)); background: var(--card); border: 2px solid var(--rc); border-radius: 20px; padding: 10px 12px;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.45); transition: border-color .3s, background .3s;
}
body.no-nav .rest { bottom: calc(var(--safe-b) + 12px); }
.rest.soon { --rc: var(--warn); }
.rest.go { --rc: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--card)); animation: restPulse 1s ease-in-out infinite; }
.rest.work { --rc: var(--info); }
@keyframes restPulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--good) 35%, transparent), 0 12px 32px rgba(0,0,0,.45); } }
.rest-ring { position: relative; width: 64px; height: 64px; flex: none; cursor: pointer; }
.rest-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.rest-ring circle { fill: none; stroke-width: 4; }
.rest-ring .bg { stroke: var(--card2); }
.rest-ring .fg { stroke: var(--rc); stroke-linecap: round; stroke-dasharray: 100; transition: stroke-dashoffset .25s linear, stroke .3s; }
.rest-ring .t { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; }
.rest-info { min-width: 0; cursor: pointer; }
.rest-phase { font-weight: 800; color: var(--rc); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rest.big .rest-phase { white-space: normal; }
.rest-next { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rest-btns { display: flex; gap: 6px; align-items: center; flex: none; }
.rest-btns .btn { padding: 0 10px; }
.rest-x { width: 36px; height: 36px; }

/* Pełny ekran – duże cyfry, czytelne z odległości */
.rest.big { inset: 0; left: 0; transform: none; width: 100%; bottom: 0; border-radius: 0; border-width: 0; flex-direction: column; justify-content: center; gap: 20px; padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b)); z-index: 70; background: var(--bg); }
.rest.big.go { background: color-mix(in srgb, var(--good) 18%, var(--bg)); }
.rest.big .rest-ring { width: min(78vw, 340px); height: min(78vw, 340px); }
.rest.big .rest-ring circle { stroke-width: 2.5; }
.rest.big .rest-ring .t { font-size: min(18vw, 84px); }
.rest.big .rest-info { text-align: center; flex: none; max-width: 100%; }
.rest.big .rest-phase { font-size: 1.6rem; }
.rest.big .rest-next { font-size: 1rem; white-space: normal; margin-top: 6px; }
.rest.big .rest-btns { gap: 10px; }
.rest.big .rest-btns .btn { min-height: 52px; padding: 0 20px; font-size: 1.05rem; }
.pill.tap { cursor: pointer; font: inherit; font-size: .8rem; }
.pill.tap b { color: var(--accent); }

@media (max-width: 400px) {
  .rest { gap: 8px; padding: 8px 10px; }
  .rest-ring { width: 56px; height: 56px; }
  .rest-btns .btn.sm { min-height: 34px; padding: 0 7px; font-size: .8rem; }
  .rest:not(.big) .rest-x { display: none; }
}


/* Nawigacja */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); display: flex; justify-content: center;
}
nav.tabs .in { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 640px; }
nav.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; }
nav.tabs a svg { width: 24px; height: 24px; }
nav.tabs a.on { color: var(--accent); }
nav.tabs a.live { color: var(--accent); }
nav.tabs a.live svg { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* Arkusz (bottom sheet) */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 640px; max-height: 88dvh; overflow: auto; background: var(--bg); border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 10px 16px calc(20px + var(--safe-b)); animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 80; background: var(--card2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.35); max-width: calc(100% - 32px); animation: fade .2s; font-weight: 600; }

/* Wykresy */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .line2 { fill: none; stroke: var(--info); stroke-width: 2; stroke-dasharray: 4 4; }
.chart .dot { fill: var(--accent); }
.chart .area { fill: var(--accent-soft); }
.bars .bar { display: grid; grid-template-columns: 110px 1fr 44px; gap: 8px; align-items: center; font-size: .85rem; margin-top: 8px; }
.bars .track { height: 10px; border-radius: 99px; background: var(--card2); position: relative; overflow: hidden; }
.bars .fill { height: 100%; border-radius: 99px; background: var(--accent); }
.bars .zone { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--good) 22%, transparent); }

.tabs-inline { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; scrollbar-width: none; }
.tabs-inline .chip { flex: none; }

.plates { display: flex; align-items: center; gap: 3px; justify-content: center; margin: 14px 0; min-height: 90px; }
.plate { border-radius: 4px; display: grid; place-items: center; font-size: .65rem; font-weight: 800; color: #fff; writing-mode: vertical-rl; }
.bar-rod { height: 12px; width: 40px; background: #9aa3ad; border-radius: 3px; }

.ex-img { width: 100%; border-radius: 12px; background: #fff; max-height: 260px; object-fit: contain; }
.imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }

.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 10px 14px; border-radius: 16px; max-width: 88%; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }

.login { min-height: 80dvh; display: grid; place-items: center; }
.logo { font-size: 2.6rem; }
.pr { color: var(--accent); font-weight: 800; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 360px) {
  .set { grid-template-columns: 22px 1fr 1fr 56px 42px; gap: 4px; }
  .bars .bar { grid-template-columns: 90px 1fr 36px; }
}

/* Onboarding / dieta */
.dots { display: flex; gap: 6px; margin-bottom: 14px; }
.dots span { flex: 1; height: 4px; border-radius: 9px; background: var(--card2); }
.dots span.on { background: var(--accent); }
.chips.opts { flex-direction: column; }
.chip.opt { flex-direction: column; align-items: flex-start; border-radius: 14px; padding: 10px 14px; text-align: left; gap: 2px; }
.chip.opt span { font-size: .8rem; font-weight: 500; opacity: .75; }
.kcal { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
.macro-bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; margin: 10px 0; background: var(--card2); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.macros div { display: flex; flex-direction: column; }
.macros b { font-size: 1.1rem; }
.macros span { font-size: .75rem; color: var(--muted); }

@media (max-width: 480px) {
  .ex-num { display: none; }
  .ex { padding: 14px; }
}

/* Czas treningu + zajęty sprzęt */
.time-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: .78rem; color: var(--muted); }
.time-line b { color: var(--text); }
.time-line.warn, .time-line.warn b { color: var(--warn); }
.time-line .btn.sm { min-height: 30px; font-size: .78rem; padding: 0 10px; }
.rest-busy { margin-top: 4px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); background: var(--card2); color: var(--text); font-size: .74rem; font-weight: 600; cursor: pointer; }
.rest.big .rest-busy { font-size: 1rem; padding: 8px 16px; margin-top: 12px; }
