:root {
  --bg: #0f0f10;
  --surface: #1b1c1e;
  --surface2: #26272a;
  --surface3: #313236;
  --border: #2c2d31;
  --text: #f5f5f7;
  --text2: #9b9ba1;
  --text3: #6e6e74;
  --accent: #4d8dff;
  --accent-dim: rgba(77, 141, 255, 0.14);
  --green: #30d158;
  --green-dim: rgba(48, 209, 88, 0.14);
  --red: #ff453a;
  --red-dim: rgba(255, 69, 58, 0.12);
  --orange: #ff9f0a;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea { user-select: text; -webkit-user-select: text; }

.hidden { display: none !important; }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#screen {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--sat) + 16px) 16px 24px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

/* ── Nagłówki ekranów ─────────────────────── */
.screen-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.4px;
  margin: 8px 0 20px;
}

.section-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text2);
  margin: 24px 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-label .link { text-transform: none; letter-spacing: 0; }

/* ── Przyciski ────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, opacity 0.15s;
  color: var(--text);
  background: var(--surface2);
}

.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-soft-accent { background: var(--accent-dim); color: var(--accent); }
.btn-green { background: var(--green); color: #04240f; }
.btn-danger { background: var(--red-dim); color: var(--red); }
.btn-sm { width: auto; padding: 8px 16px; font-size: 14px; border-radius: 10px; }

.link {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}

/* ── Karty ────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-tappable { cursor: pointer; transition: transform 0.08s; }
.card-tappable:active { transform: scale(0.98); }

.card-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.card-sub { font-size: 14px; color: var(--text2); line-height: 1.45; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text3);
  font-size: 15px;
  line-height: 1.5;
}
.empty-state .big { font-size: 40px; margin-bottom: 12px; }

/* ── Pasek zakładek ───────────────────────── */
#tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: rgba(18, 18, 20, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding-bottom: var(--sab);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 7px;
  background: none;
  border: none;
  color: var(--text3);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}

.tab svg { width: 25px; height: 25px; fill: currentColor; }
.tab.active { color: var(--accent); }

/* ── Pasek wznowienia treningu ────────────── */
.resume-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 12px 8px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.resume-info { display: flex; align-items: center; gap: 10px; }
.resume-title { font-size: 14px; font-weight: 700; }
.resume-time { font-size: 12px; color: var(--text2); font-variant-numeric: tabular-nums; }

.resume-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ── Overlay aktywnego treningu ───────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.wo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--sat) + 10px) 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.wo-header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.wo-minimize {
  background: var(--surface2);
  border: none;
  color: var(--text2);
  width: 34px; height: 34px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.wo-title-wrap { min-width: 0; }
.wo-title {
  font-size: 16px;
  font-weight: 800;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  width: 100%;
  padding: 0;
}
.wo-elapsed { font-size: 12.5px; color: var(--text2); font-variant-numeric: tabular-nums; }

.wo-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--sab) + 120px);
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

/* ── Blok ćwiczenia w treningu ────────────── */
.ex-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.ex-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.ex-block-name { font-size: 16px; font-weight: 700; color: var(--accent); }

.ex-menu-btn {
  background: none; border: none;
  color: var(--text3);
  font-size: 20px;
  cursor: pointer;
  padding: 2px 8px;
  line-height: 1;
}

.set-grid {
  display: grid;
  grid-template-columns: 36px 1fr 64px 64px 44px;
  gap: 8px;
  align-items: center;
}

.set-grid-head {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text3);
  text-align: center;
  padding-bottom: 6px;
}

.set-row { display: contents; }

.set-num {
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--text2);
  background: var(--surface2);
  border-radius: 8px;
  padding: 8px 0;
  border: none;
  font-family: inherit;
  cursor: pointer;
}

.set-prev {
  text-align: center;
  font-size: 13px;
  color: var(--text3);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  white-space: nowrap;
}

.set-input {
  width: 100%;
  padding: 8px 2px;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.set-input:focus { outline: none; border-color: var(--accent); }
.set-input::placeholder { color: var(--text3); font-weight: 500; }

.set-check {
  width: 100%;
  padding: 8px 0;
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  color: var(--text3);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.set-row.done .set-check { background: var(--green); color: #04240f; }
.set-row.done .set-input { background: var(--green-dim); }
.set-row.done .set-num { background: var(--green-dim); color: var(--green); }

.add-set-btn {
  width: 100%;
  margin-top: 10px;
  padding: 9px;
  background: var(--surface2);
  border: none;
  border-radius: 10px;
  color: var(--text2);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.wo-footer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(var(--sab) + 12px);
  background: linear-gradient(transparent, var(--bg) 30%);
  display: flex;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}

/* ── Timer przerwy ────────────────────────── */
.rest-bar {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--sab) + 12px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.rest-progress {
  position: absolute;
  inset: 0;
  background: var(--accent-dim);
  transform-origin: left;
}

.rest-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 16px;
}

.rest-time {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 86px;
  text-align: center;
}

.rest-adjust {
  background: var(--surface3);
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.rest-skip {
  background: var(--accent);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
}

/* ── Bramka logowania ─────────────────────── */
.auth-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 150;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
}

.auth-gate .logo { font-size: 60px; margin-bottom: 8px; }
.auth-gate .logo-img { width: 96px; height: 96px; margin-bottom: 12px; }
.auth-gate h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.5px; }
.auth-gate .tagline { color: var(--text2); font-size: 15px; margin: 8px 0 32px; line-height: 1.5; }
.auth-gate .btn { max-width: 340px; }

/* ── Modale ───────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.18s;
}

@keyframes fadeIn { from { opacity: 0; } }

.modal-sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes slideUp { from { transform: translateY(60px); opacity: 0.5; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
}

.modal-title { font-size: 19px; font-weight: 800; }

.modal-close {
  background: var(--surface2);
  border: none;
  color: var(--text2);
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 18px calc(var(--sab) + 20px);
}

/* ── Wyszukiwarka i filtry ────────────────── */
.search-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  margin-bottom: 12px;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-input::placeholder { color: var(--text3); }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  background: var(--surface2);
  border: none;
  border-radius: 20px;
  color: var(--text2);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active { background: var(--accent); color: #fff; }

/* ── Lista ćwiczeń ────────────────────────── */
.ex-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.ex-item-name { font-size: 15.5px; font-weight: 600; }
.ex-item-group { font-size: 13px; color: var(--text2); margin-top: 2px; }

.ex-item-check {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--surface3);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  color: transparent;
}

.ex-item.selected .ex-item-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Statystyki ───────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 4px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.stat-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--text2); margin-top: 3px; }

.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px 10px;
  margin-bottom: 12px;
}

.chart-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; }

/* ── Wiersze ustawień ─────────────────────── */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 15.5px;
  font-weight: 600;
}

.setting-row:last-child { border-bottom: none; }
.setting-value { color: var(--text2); font-weight: 500; display: flex; align-items: center; gap: 6px; }

/* ── Formularze ───────────────────────────── */
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  margin: 16px 0 6px;
}

.form-input {
  width: 100%;
  padding: 13px 14px;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}
.form-input:focus { outline: none; border-color: var(--accent); }

/* ── Toast ────────────────────────────────── */
.toast {
  position: fixed;
  top: calc(var(--sat) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface3);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 24px;
  font-size: 14.5px;
  font-weight: 600;
  z-index: 300;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.25s;
  max-width: 85vw;
  text-align: center;
}

@keyframes toastIn { from { transform: translate(-50%, -16px); opacity: 0; } }

/* ── PR badge ─────────────────────────────── */
.pr-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 159, 10, 0.15);
  color: var(--orange);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 12px;
}

/* Historia — wiersz ćwiczenia w karcie */
.hist-ex-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 3px 0;
}
.hist-ex-row .name { color: var(--text); font-weight: 500; }
.hist-ex-row .best { color: var(--text2); font-variant-numeric: tabular-nums; }

.wo-meta {
  display: flex;
  gap: 18px;
  margin: 10px 0 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.wo-meta-item .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.wo-meta-item .l { font-size: 11.5px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.4px; }

/* ── Pasek postępu ────────────────────────── */
.progress {
  height: 9px;
  background: var(--surface3);
  border-radius: 5px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  transition: width 0.3s;
}
.progress-fill.over { background: var(--orange); }
.progress-fill.done { background: var(--green); }

/* ── Segmenty (pod-zakładki) ──────────────── */
.seg {
  display: flex;
  background: var(--surface2);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.seg button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 9px;
  background: none;
  color: var(--text2);
  font-family: inherit;
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
}
.seg button.active { background: var(--accent); color: #fff; }

/* ── Kafelki pomiarów ─────────────────────── */
.meas-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.meas-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.08s;
}
.meas-tile:active { transform: scale(0.97); }
.meas-name { font-size: 12.5px; color: var(--text2); font-weight: 600; }
.meas-value { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.meas-delta { font-size: 12px; font-weight: 600; margin-top: 1px; }

/* ── Szybkie przyciski (woda itp.) ────────── */
.quick-btns { display: flex; gap: 8px; margin-top: 12px; }
.quick-btns .btn { padding: 12px 6px; font-size: 14.5px; }

/* ── Pasek dni (passa) ────────────────────── */
.day-strip { display: flex; gap: 4px; margin-top: 12px; }
.day-cell {
  flex: 1;
  text-align: center;
  padding: 7px 0 5px;
  background: var(--surface2);
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.2;
}
.day-cell.today { outline: 2px solid var(--accent); }
.day-cell .dow { font-size: 9px; color: var(--text3); display: block; font-weight: 700; }

/* ── Sugestia progresji ───────────────────── */
.hint-bar {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(255, 214, 10, 0.08);
  border: 1px solid rgba(255, 214, 10, 0.25);
  border-radius: 10px;
  color: var(--text2);
  font-family: inherit;
  font-size: 12.5px;
  padding: 8px 11px;
  margin-bottom: 12px;
  cursor: pointer;
  line-height: 1.4;
}
.hint-bar b { color: var(--text); }

/* ── Kalendarz ────────────────────────────── */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-dow {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text3);
  padding-bottom: 2px;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text2);
  background: var(--surface2);
  border-radius: 8px;
  line-height: 1.1;
  gap: 1px;
}
.cal-cell.wo { background: var(--accent-dim); color: var(--accent); font-weight: 700; cursor: pointer; }
.cal-cell.today { outline: 2px solid var(--accent); }
.cal-cell.future { opacity: 0.35; }
.cal-dot { font-size: 10px; }

/* ── Karta passy ──────────────────────────── */
.streak-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, rgba(255,159,10,0.14), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 12px;
  cursor: pointer;
  transition: transform 0.08s;
}
.streak-card:active { transform: scale(0.98); }
.streak-flame { font-size: 32px; }
.streak-num { font-size: 22px; font-weight: 800; }
