:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* zapas na stopke + bezpieczny obszar iPhone (pasek home) */
  padding-bottom: calc(3.8rem + env(safe-area-inset-bottom, 0px));
}

.hidden { display: none !important; }

header {
  padding: calc(0.9rem + env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px)) 0.5rem max(1rem, env(safe-area-inset-left, 0px));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}
.head-right { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; }
.live {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  padding: 0.3rem 0.6rem; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); color: var(--muted); background: var(--panel);
}
.batt-chip {
  font-size: 0.72rem; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 0.2rem 0.55rem; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); color: var(--text); background: var(--panel);
}
.batt-chip.low { color: var(--red); border-color: #f8514966; }
.live.on { color: #3fb950; border-color: #23863644; }
.live.on::first-letter { animation: pulse 1.6s infinite; }
.live.stale { color: var(--yellow); border-color: #d2992244; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.stat.next-point { border-color: #58a6ff55; }
.stat.hr-tile { border-color: #f8514966; }
.stat.hr-tile #hr-bpm { color: #ff7b72; }
.hr-unit { font-size: 0.85rem; color: var(--muted); }
.hr-sub { font-size: 0.75rem; color: var(--muted); font-weight: 400; margin-left: 0.5rem; }
h1 { font-size: 1.35rem; letter-spacing: 0.02em; }
h1 .sub { font-size: 0.8rem; color: var(--muted); font-weight: 400; display: block; }

h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0 0 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

section { padding: 0.8rem 0.8rem 0.2rem; }

.banner {
  margin: 0.5rem 0.8rem;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  background: #4d3800;
  border: 1px solid var(--yellow);
  color: #ffdf5d;
  font-size: 0.9rem;
}
.banner.offcourse { background: #3d1d00; border-color: #bd561d; color: #ffab70; }

/* finish */
.finish-banner {
  margin: 0.6rem 0.8rem 0.2rem;
  padding: 1.4rem 1rem;
  text-align: center;
  border-radius: 16px;
  background: linear-gradient(160deg, #16351f, #0d1f14);
  border: 1px solid var(--green);
  box-shadow: 0 0 30px #3fb95033;
}
.fb-flag { font-size: 2.6rem; line-height: 1; }
.fb-title {
  font-size: 1.8rem; font-weight: 800; letter-spacing: 0.12em;
  color: var(--green); margin-top: 0.2rem;
}
.fb-time { font-size: 1.15rem; margin-top: 0.4rem; }
.fb-time span { font-weight: 700; font-variant-numeric: tabular-nums; }
.fb-sub { color: var(--muted); font-size: 0.85rem; margin-top: 0.3rem; }

/* countdown */
#countdown-box { text-align: center; padding: 2.2rem 1rem 1.2rem; }
.cd-label { color: var(--muted); letter-spacing: 0.25em; font-size: 0.85rem; }
.countdown {
  font-size: clamp(2.2rem, 11vw, 4.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  margin: 0.3rem 0;
}
.cd-when { color: var(--muted); font-size: 0.95rem; }

/* big numbers */
.bignum-grid { display: grid; grid-template-columns: 1fr; gap: 0.6rem; }
@media (min-width: 640px) { .bignum-grid { grid-template-columns: repeat(3, 1fr); } }
.bignum {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}
.bn-value { font-size: 2.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.bn-unit { font-size: 1rem; color: var(--muted); margin-left: 0.3rem; }
.bn-label { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.bn-sub { color: var(--muted); font-size: 0.68rem; margin-top: 0.25rem; opacity: 0.8; font-variant-numeric: tabular-nums; }
.bn-value.ahead { color: var(--green); }
.bn-value.behind { color: var(--red); }

.progressbar {
  height: 6px; border-radius: 3px; background: var(--border);
  margin-top: 0.6rem; overflow: hidden;
}
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.5s; }

/* profile */
.hint { font-size: 0.7rem; color: var(--muted); text-transform: none; letter-spacing: 0; opacity: 0.8; }
#profile-wrap {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
#profile-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#profile { display: block; height: 300px; }
.subchart { display: block; height: 90px; margin-top: 2px; }
#profile-ele-axis {
  position: absolute; top: 0; left: 0; width: 34px; height: 300px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(13,17,23,0.85), rgba(13,17,23,0));
}
#profile-ele-axis div, .sub-axis div {
  position: absolute; left: 5px; transform: translateY(-50%);
  font-size: 0.65rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.sub-axis {
  position: absolute; left: 0; width: 40px; height: 90px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(13,17,23,0.9), rgba(13,17,23,0));
}
.sub-axis .cap {
  top: 10px; transform: none; font-weight: 700; font-size: 0.6rem;
  letter-spacing: 0.05em;
}
.tip {
  position: absolute; transform: translate(-50%, -110%);
  background: #1f2733; border: 1px solid var(--border);
  padding: 0.35rem 0.6rem; border-radius: 6px;
  font-size: 0.8rem; white-space: nowrap; pointer-events: none; z-index: 5;
}

/* stats panel */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.6rem 0.8rem;
}
.stat.wide { grid-column: span 2; }
@media (min-width: 640px) { .stat.wide { grid-column: span 3; } }
.s-label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }
.s-value { font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 0.1rem; }
.s-value.small { font-size: 1.05rem; }
.s-sub { color: var(--accent); font-size: 0.8rem; margin-top: 0.2rem; font-variant-numeric: tabular-nums; }

/* map */
#map {
  height: 55vh; min-height: 320px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel);
}
.follow { font-size: 0.75rem; color: var(--muted); text-transform: none; letter-spacing: 0; }
.follow input { vertical-align: -2px; }
.leaflet-container { background: #0a0d12; }
.leaflet-tile.tiles-dim { filter: brightness(0.7) contrast(1.05) saturate(0.8); }

.runner-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 3px solid #fff;
  box-shadow: 0 0 12px var(--accent);
}
/* ludzik z dymkiem imienia na mapie */
.runner-pin { text-align: center; width: 90px; transform: translateX(-35px); }
.runner-name {
  display: inline-block; background: var(--accent); color: #fff;
  font-size: 0.72rem; font-weight: 700; padding: 0.15rem 0.5rem;
  border-radius: 999px; box-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
.runner-name::after {
  content: ''; display: block; margin: 0 auto;
  border: 5px solid transparent; border-top-color: var(--accent);
  border-bottom: 0; width: 0;
}
.runner-emoji {
  font-size: 22px; line-height: 1; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.6));
  transform: scaleX(-1); /* emoji biegnie w lewo — trasa idzie w prawo */
}
/* odbicie ludzika w SVG robi atrybut transform w app.js —
   CSS transform-box na <text> jest zle liczony przez Safari */

footer {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(13, 17, 23, 0.92);
  border-top: 1px solid var(--border);
  /* marginesy + bezpieczny obszar iPhone (pasek home u dolu) */
  padding: 0.55rem max(1rem, env(safe-area-inset-right, 0px))
           calc(0.55rem + env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
  font-size: 0.8rem; color: var(--muted);
  display: flex; gap: 1rem; justify-content: space-between;
  backdrop-filter: blur(6px);
}
#demo-tag { color: var(--yellow); font-weight: 700; }
