:root {
  --bg: #f7eef0;
  --card: #ffffff;
  --text: #2b1d2a;
  --muted: #7a6877;
  --line: #ecdfe3;
  --accent: #c2416b;
  --accent-soft: #f6d3de;
  --pred: #e9a6bb;
  --fertile: #d8ecdf;
  --fertile-text: #2f6b45;
  --ovu: #4f9a6a;
  --moon-dark: #3a3046;
  --moon-light: #f4eedc;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(60, 20, 40, 0.06), 0 4px 16px rgba(60, 20, 40, 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1520;
    --card: #2a2030;
    --text: #f3e9ef;
    --muted: #b29fae;
    --line: #3b2f42;
    --accent: #ef7fa3;
    --accent-soft: #5a2a3d;
    --pred: #8a4a60;
    --fertile: #23402f;
    --fertile-text: #9fd8b2;
    --ovu: #6cc08a;
    --moon-dark: #120d16;
    --danger: #ff8a80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
h1 { font-size: 30px; margin: 12px 4px 16px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 20px; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

/* Cykl – górna karta */
.hero { display: flex; align-items: center; gap: 18px; }
.ring-wrap { position: relative; width: 128px; height: 128px; flex: none; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.ring-label { font-size: 12px; color: var(--muted); }
.ring-big { font-size: 38px; font-weight: 700; line-height: 1.05; }
.phase-name { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.phase-desc { color: var(--muted); font-size: 15px; margin: 0; }
@media (max-width: 360px) {
  .hero { flex-direction: column; text-align: center; }
}

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--card); border-radius: 16px; padding: 12px 14px;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.card .stat { background: var(--bg); box-shadow: none; }
.stat-k { font-size: 13px; color: var(--muted); }
.stat-v { font-size: 17px; font-weight: 650; }

/* Przyciski */
.btn {
  appearance: none; border: 0; border-radius: 14px; padding: 13px 18px;
  font: inherit; font-weight: 600; background: var(--accent-soft); color: var(--text);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; text-align: center;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.btn.wide { width: 100%; margin-bottom: 14px; }
.btn:active { transform: scale(0.98); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row .btn { flex: 1 1 140px; }
.icon-btn {
  appearance: none; border: 0; background: var(--bg); color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; font-size: 24px; line-height: 1; cursor: pointer;
}

/* Kalendarz */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head h2 { margin: 0; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.day {
  position: relative; aspect-ratio: 1; border: 0; border-radius: 12px;
  background: transparent; color: var(--text); font: inherit; font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.day.out { visibility: hidden; }
.day.fertile { background: var(--fertile); color: var(--fertile-text); }
.day.ovu { background: var(--ovu); color: #fff; font-weight: 700; }
.day.pred { box-shadow: inset 0 0 0 2px var(--pred); color: var(--accent); background: transparent; }
.day.period { background: var(--accent); color: #fff; font-weight: 600; }
.day.today::after {
  content: ""; position: absolute; bottom: 4px; left: 50%; width: 5px; height: 5px;
  margin-left: -2.5px; border-radius: 50%; background: currentColor;
}
.day.today { outline: 2px solid var(--text); outline-offset: -2px; }
.day .moon-mark { position: absolute; top: 1px; right: 4px; font-size: 10px; opacity: 0.8; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin-top: 12px; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; }
.d-period { background: var(--accent); }
.d-pred { box-shadow: inset 0 0 0 2px var(--pred); }
.d-fertile { background: var(--fertile); box-shadow: inset 0 0 0 1px var(--fertile-text); }
.d-ovu { background: var(--ovu); }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.disclaimer { font-size: 12px; color: var(--muted); text-align: center; margin: 4px 12px 20px; }

/* Księżyc */
.moon-hero { text-align: center; }
#moon-big { width: 180px; height: 180px; margin: 6px auto 8px; display: block; }
.moon-name { font-size: 26px; font-weight: 700; }
.moon-today { color: var(--accent); font-weight: 600; min-height: 1.2em; }
.moon-note { color: var(--muted); margin: 6px 0 14px; }
.stats.two { margin: 0; text-align: left; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list svg { width: 34px; height: 34px; flex: none; }
.list .when { margin-left: auto; color: var(--muted); font-size: 14px; text-align: right; }

/* Ustawienia */
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.field input {
  width: 80px; font: inherit; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); text-align: center;
}
.plain { margin: 0; padding-left: 20px; }
.plain li { margin-bottom: 6px; }
.danger-zone h2 { color: var(--danger); }

/* Dolne menu */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(env(safe-area-inset-bottom) + 6px);
}
.tab {
  flex: 1; appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 12px; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 6px 0; cursor: pointer;
}
.tab-ico { font-size: 22px; line-height: 1; }
.tab.active { color: var(--accent); font-weight: 600; }

/* Okienko wyboru */
dialog {
  border: 0; border-radius: 22px; padding: 20px; width: min(92vw, 420px);
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(20, 10, 20, 0.45); }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 10px; }
.sheet-actions .btn { width: 100%; }
#sheet-close { margin-bottom: 0; background: transparent; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Komunikaty */
[hidden] { display: none !important; }
.banner {
  background: var(--accent-soft); border-radius: 16px; padding: 12px 14px; margin: 8px 0 12px;
  font-size: 14px;
}
.banner p { margin: 0 0 6px; }
.banner p:last-child { margin: 0; }
.banner.error { background: color-mix(in srgb, var(--danger) 18%, var(--card)); }
.btn.small { min-height: 36px; padding: 7px 12px; font-size: 14px; }
.small-note { font-size: 13px; margin-top: 10px; }
.btn.undo { margin: 10px 0 0; background: transparent; border: 1.5px solid var(--line); }

/* Ćwiczenia */
.program-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.program-head h2 { margin-bottom: 4px; }
.pill { font-size: 13px; color: var(--muted); background: var(--bg); padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.steps-line { font-size: 13px; color: var(--muted); }
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.toggle:first-of-type { border-top: 0; }
.toggle input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.ed-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.ed-num { width: 24px; color: var(--muted); font-size: 14px; }
.ed-row select, .ed-row input, #ed-name {
  font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.ed-row select { flex: 1; min-width: 0; }
.ed-row input { width: 64px; text-align: center; }
#ed-name { width: 60%; }
#editor { max-height: 88vh; overflow-y: auto; }
#editor .row { margin: 8px 0; }
.icon-btn.small { width: 34px; height: 34px; font-size: 15px; flex: none; }

/* Trener */
body.training { overflow: hidden; }
.trainer {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: calc(env(safe-area-inset-top) + 16px) 20px calc(env(safe-area-inset-bottom) + 20px);
}
.tr-top { width: 100%; max-width: 520px; display: flex; justify-content: space-between; color: var(--muted); font-size: 15px; }
.tr-stage { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; }
.tr-circle {
  width: min(70vw, 280px); height: min(70vw, 280px); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); transform: scale(1);
  transition-property: transform, background-color; transition-timing-function: ease-in-out;
}
.tr-circle.prep { transform: scale(0.85); background: var(--line); }
.tr-circle.sq { transform: scale(0.62); background: var(--pred); color: var(--text); }
.tr-circle.rel { transform: scale(1); background: var(--fertile); color: var(--fertile-text); }
.tr-circle.done { transform: scale(0.85); background: var(--ovu); color: #fff; }
.tr-count { font-size: 64px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tr-label { font-size: 34px; font-weight: 700; margin-bottom: 4px; }
.tr-next { color: var(--muted); min-height: 1.4em; margin-bottom: 20px; }
.tr-buttons { width: 100%; max-width: 420px; }
@media (prefers-reduced-motion: reduce) { .tr-circle { transition: none; } }

/* Kropelka */
.mascot { display: block; width: 100%; height: 100%; overflow: visible; }
.mascot * { transform-box: view-box; }
.mascot .mascot-all { transform-origin: 60px 136px; animation: bob 3.4s ease-in-out infinite; }
.mascot.droopy .mascot-all { animation: breathe 4.5s ease-in-out infinite; }
.mascot.bouncy .mascot-all { animation: hop 1.1s ease-in-out infinite; }
.mascot.walking .mascot-leg-l { transform-origin: 50px 112px; animation: step 0.9s ease-in-out infinite; }
.mascot.walking .mascot-leg-r { transform-origin: 70px 112px; animation: step 0.9s ease-in-out infinite reverse; }
.mascot .mascot-wave { transform-origin: 93px 86px; animation: wave 1.6s ease-in-out infinite; }
.mascot .mascot-float { animation: float 3s ease-in-out infinite; }
.mascot .mascot-twinkle { animation: twinkle 1.8s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-3px) scale(1.02, 0.98) } }
@keyframes breathe { 0%, 100% { transform: scale(1, 1) } 50% { transform: scale(1.03, 0.97) } }
@keyframes hop { 0%, 100% { transform: translateY(0) scale(1.03, 0.96) } 45% { transform: translateY(-7px) scale(0.98, 1.03) } }
@keyframes step { 0%, 100% { transform: rotate(-12deg) } 50% { transform: rotate(12deg) } }
@keyframes wave { 0%, 100% { transform: rotate(-8deg) } 50% { transform: rotate(14deg) } }
@keyframes float { 0%, 100% { transform: translateY(0); opacity: 0.85 } 50% { transform: translateY(-4px); opacity: 1 } }
@keyframes twinkle { 0%, 100% { opacity: 1 } 50% { opacity: 0.45 } }
@media (prefers-reduced-motion: reduce) { .mascot * { animation: none !important; } }

.tr-circle { flex-direction: column; gap: 0; }
.tr-mascot { width: 40%; aspect-ratio: 120 / 150; }
.tr-count { font-size: 40px; line-height: 1.1; }
.tr-mascot .mascot-all { animation: none; transition: transform 0.4s ease-in-out; }
.tr-circle.sq .tr-mascot .mascot-all { transform: scale(1.1, 0.86); }

/* Karta z kropelką */
.mascot-card { display: flex; align-items: center; gap: 12px; margin: -4px 0 14px; }
.mascot-stage { width: 104px; height: 130px; flex: none; }
.bubble {
  position: relative; background: var(--card); border-radius: 18px; padding: 12px 14px;
  font-size: 15px; box-shadow: var(--shadow); flex: 1;
}
.bubble::before {
  content: ""; position: absolute; left: -8px; top: 50%; margin-top: -8px;
  border: 8px solid transparent; border-right-color: var(--card); border-left: 0;
}
.info p { margin-bottom: 8px; }
.info-phase { font-weight: 650; color: var(--accent); }
.info-h { font-size: 15px; margin: 12px 0 4px; }
.sources li { font-size: 14px; }

/* Nocne niebo */
.sky {
  position: relative; overflow: hidden; color: #f1ecff;
  background: radial-gradient(120% 70% at 50% 25%, #26245a 0%, #12123a 45%, #070818 100%);
  box-shadow: 0 6px 24px rgba(10, 8, 40, 0.35);
}
.sky > *:not(.sky-stars) { position: relative; }
.sky-stars { position: absolute; inset: 0; width: 100%; height: 100%; }
.sky-stars .twinkle { animation: star 3s ease-in-out infinite; }
@keyframes star { 0%, 100% { opacity: 1 } 50% { opacity: 0.2 } }
.sky .moon-date { color: #b9b3dc; font-size: 14px; }
.sky #moon-big { width: 220px; height: 220px; margin: 0 auto 4px; }
.sky .moon-today { color: #ffc9d8; }
.sky .moon-note { color: #cfc9ee; }
.sky .stat { background: rgba(255, 255, 255, 0.08); }
.sky .stat-k { color: #b9b3dc; }
@media (prefers-reduced-motion: reduce) { .sky-stars .twinkle { animation: none; } }
