/* ============================================================
   WERISA FIT — DESIGN SYSTEM
   Palette: deep slate ground, track-orange for effort/energy,
   route-teal for distance/route, warm off-white text.
   Type: Space Grotesk for numbers/headings (geometric, built
   for a stat-heavy screen), system sans for body copy.
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
  --bg: #14171a;
  --surface: #1d2226;
  --surface-2: #242a2f;
  --accent: #ff6b35;
  --accent-dim: #ff6b3522;
  --route: #2ec4b6;
  --route-dim: #2ec4b622;
  --danger: #ff5a5f;
  --text: #eceff1;
  --muted: #8a939a;
  --border: #2b3236;
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --nav-h: 76px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  /* iOS Safari (incl. standalone/home-screen mode) rubber-bands the
     whole page on overscroll unless the page itself can't scroll.
     #app becomes the real scroll container instead. */
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.num, h1, h2, .stat-value, .big-number, .nav-label, .btn {
  font-family: "Space Grotesk", -apple-system, sans-serif;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  position: relative;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

.screen { display: none; padding: calc(20px + var(--safe-top)) 20px 20px; animation: fadein .18s ease; }
.screen.active { display: block; }

@keyframes fadein { from { opacity: 0; transform: translateY(6px);} to {opacity:1; transform: translateY(0);} }

.screen-title {
  font-size: 28px;
  font-weight: 700;
  margin: 4px 0 20px;
  letter-spacing: -0.02em;
}

.subtle { color: var(--muted); font-size: 14px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 18px;
  border: 1px solid var(--border);
}

.card + .card { margin-top: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.stat-card { padding: 16px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.stat-value small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 3px; }

/* ---------- Progress ring (Today steps) ---------- */
.ring-card { display: flex; align-items: center; gap: 18px; }
.ring-wrap { position: relative; width: 108px; height: 108px; flex-shrink: 0; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-track { stroke: var(--surface-2); }
.ring-progress { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .4s ease; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center .val { font-size: 20px; font-weight: 700; }
.ring-center .pct { font-size: 11px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 18px; border-radius: 999px;
  font-size: 17px; font-weight: 700; letter-spacing: 0.01em;
  border: none; cursor: pointer; -webkit-user-select: none; user-select: none;
}
.btn-primary { background: var(--accent); color: #1a0e08; }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #2a0a0a; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 480px; margin: 0 auto;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(29,34,38,0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 40;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; color: var(--muted); background: none; border: none; cursor: pointer;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 21px; line-height: 1; }
.nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.03em; }

/* ---------- Activity type picker ---------- */
.type-option {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px; border-radius: var(--radius-md); background: var(--surface);
  border: 2px solid var(--border); margin-bottom: 12px; cursor: pointer;
}
.type-option.selected { border-color: var(--accent); background: var(--accent-dim); }
.type-option .name { font-size: 17px; font-weight: 700; }
.type-option .icon { font-size: 26px; }

/* ---------- Active run ---------- */
#map-active, #map-detail { width: 100%; height: 220px; border-radius: var(--radius-md); overflow: hidden; background: var(--surface-2); }
.run-hero { text-align: center; margin: 18px 0 22px; }
.run-hero .big-number { font-size: 64px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.run-hero .unit { color: var(--muted); font-size: 15px; margin-top: 4px; }
.gps-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2); padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--route); box-shadow: 0 0 0 4px var(--route-dim); }
.dot.off { background: var(--danger); }

/* ---------- Lists ---------- */
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; background: var(--surface); border-radius: var(--radius-md);
  margin-bottom: 10px; border: 1px solid var(--border); cursor: pointer;
}
.list-item .type-badge { font-size: 12px; color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.list-item .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-item .right { text-align: right; }
.section-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 20px 0 10px; }
.section-label:first-child { margin-top: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab { flex: 1; text-align: center; padding: 10px; border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer; border: 1px solid var(--border); }
.tab.active { background: var(--accent); color: #1a0e08; border-color: var(--accent); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .glyph { font-size: 40px; margin-bottom: 10px; }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.cal-dow { font-size: 11px; color: var(--muted); padding-bottom: 6px; }
.cal-day { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13px; cursor: pointer; }
.cal-day.active-day { background: var(--accent-dim); border: 1px solid var(--accent); }
.cal-day.light-day { background: var(--route-dim); border: 1px solid var(--route); }
.cal-day .dayn { font-weight: 600; }
.cal-day.empty { background: transparent; cursor: default; }

/* ---------- Inputs ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 16px;
}

/* ---------- Badges / streak / achievements ---------- */
.streak-banner { display: flex; align-items: center; gap: 10px; padding: 16px; border-radius: var(--radius-md); background: linear-gradient(135deg, var(--accent-dim), transparent); border: 1px solid var(--border); margin-bottom: 16px; }
.streak-banner .flame { font-size: 26px; }
.achv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.achv { background: var(--surface); border-radius: var(--radius-md); padding: 14px 8px; text-align: center; border: 1px solid var(--border); }
.achv.locked { opacity: 0.35; }
.achv .glyph { font-size: 26px; display: block; margin-bottom: 6px; }
.achv .label { font-size: 11px; color: var(--muted); font-weight: 600; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); color: var(--text); padding: 12px 20px; border-radius: 999px;
  font-size: 14px; border: 1px solid var(--border); opacity: 0; pointer-events: none; transition: all .25s ease;
  max-width: 90%; text-align: center; z-index: 60;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Permission overlay ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,23,26,0.92); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 24px; }
.overlay-card { background: var(--surface); border-radius: var(--radius-lg); padding: 28px; max-width: 380px; text-align: center; border: 1px solid var(--border); }
.overlay-card .glyph { font-size: 40px; margin-bottom: 14px; }
.overlay-card h3 { margin: 0 0 10px; font-size: 19px; }
.overlay-card p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 20px; }

/* ---------- Divider link row ---------- */
.link-row { display: flex; align-items: center; justify-content: space-between; padding: 16px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.link-row:last-child { border-bottom: none; }
.link-row .chev { color: var(--muted); }

.disclaimer { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 10px; padding: 12px; background: var(--surface-2); border-radius: var(--radius-sm); }

/* ---------- iOS "Add to Home Screen" banner ---------- */
#ios-install-banner {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  max-width: 456px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 50;
}
#ios-install-banner .glyph { font-size: 24px; flex-shrink: 0; }
#ios-install-banner .body { flex: 1; font-size: 13px; line-height: 1.4; color: var(--text); }
#ios-install-banner .body b { color: var(--accent); }
#ios-install-banner .share-glyph { display: inline-block; padding: 0 3px; }
#ios-install-banner .close-btn {
  background: none; border: none; color: var(--muted); font-size: 20px; line-height: 1;
  padding: 4px; cursor: pointer; flex-shrink: 0;
}

::-webkit-scrollbar { display: none; }
