:root {
  /* Motyw EightGates: zieleń stroju (akcent), pomarańcz getrów (--accent-2), czerwień opaski (błędy), papier zwoju / czerń włosów. */
  --bg: #f5eedb;
  --surface: #fffaee;
  --surface-2: #ece1c6;
  --text: #1c1a15;
  --muted: #655a45;
  --line: #e0d4b4;
  --accent: #146b2b;
  --accent-2: #c95a06;
  --ok: #1a6c32;
  --warn: #984803;
  --error: #b3221b;
  --on-accent: #fff;
  --body-base: #e6dcc2;
  --load-none: #c4b89c;
  --load-low: #4f86e8;
  --load-optimal: #3a9a6a;
  --load-high: #e2b13c;
  --load-over: #d24f36;
  /* Energia chakry (pasek postępu mezocyklu w nagłówku): turkusowa poświata. */
  --chakra: #0a7ea4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0e100d; --surface: #171a15; --surface-2: #22261f; --text: #efeadc; --muted: #aaa694; --line: #2e3329;
    --accent: #4fcf6a; --accent-2: #ff9838; --ok: #72d48c; --warn: #ffa24d; --error: #ff7d6e; --on-accent: #071c0c;
    --body-base: #2a2e26; --load-none: #474d41; --load-low: #5f93ee; --load-optimal: #4fb07f; --load-high: #d9ad45; --load-over: #e2654c;
    --chakra: #38d6f5;
    color-scheme: dark;
  }
}
:root[data-theme=dark] {
  --bg: #0e100d; --surface: #171a15; --surface-2: #22261f; --text: #efeadc; --muted: #aaa694; --line: #2e3329;
  --accent: #4fcf6a; --accent-2: #ff9838; --ok: #72d48c; --warn: #ffa24d; --error: #ff7d6e; --on-accent: #071c0c;
  --body-base: #2a2e26; --load-none: #474d41; --load-low: #5f93ee; --load-optimal: #4fb07f; --load-high: #d9ad45; --load-over: #e2654c;
  --chakra: #38d6f5;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-top: env(safe-area-inset-top, 0px);
}
body.sheet-open { overflow: hidden; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 4px; }
h3 { font-size: 17px; margin: 2px 0; }
p { margin: 6px 0; }
small, .muted { font-size: 13px; color: var(--muted); }
small { display: block; }
a { color: var(--accent); }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-error { color: var(--error); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* Nagłówki dostają fokus z kodu (tabindex=-1) tylko dla czytnika ekranu; nie są interaktywne, więc bez obwódki. */
[tabindex="-1"]:focus-visible { outline: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button, input, select, textarea {
  font: inherit;
  font-size: 16px;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
button, .button { cursor: pointer; min-height: 48px; }
button:disabled { opacity: .5; cursor: default; }
input, select { min-height: 48px; width: 100%; }
textarea { width: 100%; }
input[type=checkbox], input[type=radio] { width: 22px; min-height: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin-top: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
.button {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; color: inherit; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.primary, .is-selected { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.is-selected small { color: inherit; opacity: .9; }
.danger { color: var(--error); }
.full-width { width: 100%; margin-top: 10px; }
.pill { background: var(--surface-2); border-color: transparent; border-radius: 24px; padding: 6px 16px; }
.pill.is-selected { background: var(--accent); }

.app-header {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  padding: 8px 16px 10px; background: var(--bg); text-align: center;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0; font-size: 21px; font-weight: 800; letter-spacing: .02em; line-height: 1.2; }
.app-header svg.icon.brand-mark { width: 28px; height: 28px; color: var(--accent); flex-shrink: 0; stroke-width: 2.2; }
.brand-accent { color: var(--accent); }
/* Status planu w jednej linii: na wąskim ekranie skraca się nazwa planu (najmniej ważna), reszta zostaje. */
.header-status { display: flex; justify-content: center; max-width: 532px; margin: 2px auto 0; font-size: 13px; color: var(--muted); white-space: nowrap; }
.header-status > span + span::before { content: "\00a0·\00a0"; }
.header-status .plan-name { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.header-status .plan-name ~ span { flex-shrink: 0; }
/* Pasek chakry: postęp mezocyklu na dole nagłówka (zastępuje dawną zielono-pomarańczową linię). */
.chakra-meter { display: flex; align-items: center; gap: 8px; max-width: 532px; margin: 8px auto 0; }
.app-header svg.icon.chakra-symbol { width: 26px; height: 26px; flex-shrink: 0; color: var(--chakra); stroke-width: 2; filter: drop-shadow(0 0 3px var(--chakra)); }
.chakra-percent { min-width: 3.2em; text-align: right; font-size: 13px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.chakra-bar { flex: 1; height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.chakra-bar > i {
  display: block; height: 100%; border-radius: 5px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--chakra) 45%, transparent), var(--chakra) 70%, color-mix(in srgb, var(--chakra) 60%, #fff));
  box-shadow: 0 0 6px var(--chakra), 0 0 12px color-mix(in srgb, var(--chakra) 50%, transparent);
}
@media (prefers-reduced-motion: no-preference) {
  .chakra-bar > i { background-size: 200% 100%; animation: chakraFlow 3.5s ease-in-out infinite alternate; }
  @keyframes chakraFlow { from { background-position: 0 0; } to { background-position: 100% 0; } }
}
main { max-width: 560px; margin: 0 auto; padding: 4px 14px calc(96px + env(safe-area-inset-bottom, 0px)); }
body.rest-active main { padding-bottom: calc(176px + env(safe-area-inset-bottom, 0px)); }
.storage-warning { background: var(--warn); color: var(--on-accent); padding: 8px 16px; font-size: 14px; }
.corrupt-warning { background: var(--surface); border-bottom: 3px solid var(--error); padding: 10px 16px; font-size: 14px; }
.corrupt-warning > div { max-width: 532px; margin: 0 auto; }
.corrupt-warning .button-row { margin-top: 6px; }
svg.icon.empty-icon { width: 40px; height: 40px; color: var(--accent); stroke-width: 1.6; margin-bottom: 4px; }
.reminder { display: flex; gap: 12px; align-items: flex-start; border-left: 4px solid var(--accent-2); }
.reminder > .icon { width: 30px; height: 30px; color: var(--accent-2); margin-top: 2px; }
.gates { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 12px 0 2px; padding: 0; list-style: none; }
.gates li { height: 8px; border-radius: 4px; background: var(--surface-2); }
.gates li.is-open { background: var(--accent); }
.gates li.is-open:last-child { background: var(--accent-2); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin: 12px 0; }
summary { cursor: pointer; min-height: 48px; display: flex; align-items: center; gap: 8px; font-weight: 600; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸"; color: var(--muted); width: 12px; }
details[open] > summary::before { content: "▾"; }
details.card { padding-top: 4px; padding-bottom: 4px; }
details.card[open] { padding-bottom: 16px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row-end { align-items: flex-end; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; align-items: end; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 6px; }
.grid-4 input { padding: 10px 8px; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.button-row > * { flex: 1 1 0; }
.icon-button { width: 48px; padding: 0; display: inline-grid; place-items: center; flex-shrink: 0; }
svg.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.badge { display: inline-block; background: var(--surface-2); border-radius: 8px; padding: 1px 8px; font-size: 12px; color: var(--text); }
.is-selected .badge { background: var(--on-accent); color: var(--accent); }

.progress { height: 6px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin: 8px 0 2px; }
.progress > i { display: block; height: 100%; background: var(--ok); }
.progress > i.level-yellow { background: var(--warn); }
.progress > i.level-red { background: var(--error); }
.score { font-size: 44px; font-weight: 700; line-height: 1; }
.score small { display: inline; font-size: 16px; }
.level-green { color: var(--ok); }
.level-yellow { color: var(--warn); }
.level-red { color: var(--error); }
.notes { padding-left: 20px; margin: 8px 0; }
.notes li { margin: 6px 0; }
.notes [data-level=red]::marker { color: var(--error); }
.notes [data-level=yellow]::marker { color: var(--warn); }
.notes [data-level=green]::marker { color: var(--ok); }

.list-option { display: block; width: 100%; text-align: left; margin-top: 8px; }
.list-option small { color: inherit; opacity: .85; }
.day-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.day-grid .list-option { margin: 0; }
.file-button:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
label.file-button { margin-top: 0; font-size: 16px; color: var(--text); }
.plan-exercise { border-top: 1px solid var(--line); padding: 10px 0 4px; margin-top: 10px; }
.plan-exercise .row { align-items: flex-start; }
.plan-exercise label { margin-top: 6px; }
.icon-group { display: flex; gap: 4px; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; text-align: center; }
th, td { padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { font-weight: 600; color: var(--muted); }
th[scope=row] { text-align: left; color: var(--text); font-weight: 500; }
.current-column { background: var(--surface-2); }

.set-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.set-list button { width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 8px; background: var(--surface-2); border-color: transparent; }
.target-line { font-size: 15px; margin: 6px 0 0; }
.skipped { background: var(--surface-2); }
.skipped .pill { background: var(--surface); }
.previous-note { margin-top: 4px; font-style: italic; }
.secondary-actions button { padding: 8px; font-size: 15px; }
.button-row > .quick-log { flex-grow: 1.4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 60px; }
.quick-log span { font-size: 19px; }
.quick-log small { color: inherit; font-weight: 400; opacity: .9; }
.quick-log + button { white-space: nowrap; }
.undo-line:not(:empty) { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 15px; }
.undo-line span { flex: 1; min-width: 0; }

.stepper { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; align-items: center; margin-top: 4px; }
.stepper button { min-height: 56px; font-size: 24px; padding: 0; }
.stepper input { min-height: 56px; font-size: 26px; font-weight: 700; text-align: center; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input { -moz-appearance: textfield; }
.field-title { display: block; font-size: 13px; color: var(--muted); margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; padding: 0; border: 0; }
.chips button { min-width: 48px; padding: 8px 10px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; border: 0; padding: 0; margin: 8px 0 0; }
.segmented label { margin: 0; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 15px; cursor: pointer; }
.segmented label:has(input:checked) { border-color: var(--accent); background: var(--surface-2); font-weight: 600; }
.checkbox-label { display: flex; align-items: center; gap: 10px; min-height: 48px; color: var(--text); font-size: 16px; }
.result { display: flex; justify-content: space-between; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.result b { font-size: 20px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.stats div { background: var(--surface-2); border-radius: 12px; padding: 8px; text-align: center; }
.stats b { display: block; font-size: 20px; }

.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 4px 2px env(safe-area-inset-bottom, 0px);
}
.tab-bar a {
  min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; text-decoration: none; border-radius: 12px;
}
.tab-bar svg { width: 52px; height: 30px; padding: 3px 14px; border-radius: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-bar a[aria-current=page] { color: var(--accent); font-weight: 600; }
.tab-bar a[aria-current=page] svg { background: var(--surface-2); }

.rest-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  max-width: 536px; margin: 0 auto; z-index: 6;
  display: flex; align-items: center; gap: 8px;
  background: var(--text); color: var(--bg); border-radius: 18px; padding: 8px 8px 12px 16px;
  box-shadow: 0 6px 24px #0003;
}
.rest-bar[hidden] { display: none; }
.rest-bar strong { font-size: 24px; flex: 1; }
.rest-bar button { background: none; color: inherit; border-color: currentColor; min-width: 64px; }
.rest-bar .progress { position: absolute; left: 16px; right: 16px; bottom: 5px; height: 3px; margin: 0; background: #8884; }
.rest-bar .progress > i { background: var(--accent); }

.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: #0009; display: flex; align-items: flex-end; }
.sheet {
  max-height: 92vh; overflow: auto; width: 100%; max-width: 560px; margin: 0 auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
}
.sheet-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-header h2 { margin: 0; }

.day-card > summary .badge { margin-left: 6px; font-weight: 400; }
.plan-exercise .row small { flex: 1; min-width: 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.tile b { display: block; font-size: 22px; }
.tile b .muted { font-size: 16px; font-weight: 400; }
.body-map { display: block; width: 100%; max-width: 360px; margin: 8px auto 0; }
.body-map .body-base { fill: var(--body-base); stroke: var(--line); stroke-width: 1.5; }
.body-map text { fill: var(--muted); font-size: 13px; }
.muscle-region { cursor: pointer; outline: none; }
.muscle-region path { fill: var(--load-none); stroke: var(--surface); stroke-width: 1.2; }
.muscle-region[data-level=low] path { fill: var(--load-low); }
.muscle-region[data-level=optimal] path { fill: var(--load-optimal); }
.muscle-region[data-level=high] path { fill: var(--load-high); }
.muscle-region[data-level=over] path { fill: var(--load-over); }
.muscle-region:focus-visible path, .muscle-region.is-selected path { stroke: var(--text); stroke-width: 2.5; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; }
.load-none { background: var(--load-none); }
.load-low { background: var(--load-low); }
.load-optimal { background: var(--load-optimal); }
.load-high { background: var(--load-high); }
.load-over { background: var(--load-over); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.muscle-info { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; margin-top: 10px; }
.muscle-list { list-style: none; padding: 0; margin: 8px 0 0; }
.muscle-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.muscle-list .progress { margin-top: 4px; }
.chip-link { display: inline-flex; align-items: center; min-height: 48px; margin-top: 10px; padding: 6px 16px; border-radius: 24px; background: var(--surface-2); text-decoration: none; font-weight: 600; }
.chart { display: block; width: 100%; height: auto; margin-top: 8px; }
.chart .grid-line { stroke: var(--line); }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart polyline { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart circle { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.history-set { display: grid; grid-template-columns: 60px 1fr 1fr 1fr; gap: 6px; align-items: center; margin-top: 6px; }
.preview-list { list-style: none; padding: 0; margin: 4px 0 0; }
.preview-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.preview-list li > span:last-child { text-align: right; white-space: nowrap; }
.gates.wizard-steps { grid-template-columns: repeat(4, 1fr); margin: 10px 0 0; }
.wizard-day { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 6px; }
.history-hint { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; margin-top: 8px; display: flex; align-items: center; gap: 10px; }
.history-hint button { flex-shrink: 0; }
.wizard-footer { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--line); margin: 16px -16px 0; padding: 4px 16px calc(14px + env(safe-area-inset-bottom, 0px)); }
.volume-status { font-weight: 600; white-space: nowrap; }
.chips.day-count-chips { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-count-chips button { min-width: 0; padding: 8px 0; }
