/* ============================================================
   Tantgympa — mobile-first, playful theme
   ============================================================ */

:root {
  --bg-1: #f5f0ff;
  --bg-2: #e8f7ff;
  --ink: #1f1533;
  --muted: #6b5f85;
  --brand: #7c3aed;
  --brand-2: #ec4899;
  --card: #ffffff;
  --card-border: #ece3ff;
  --ok: #16a34a;
  --err: #dc2626;
  --shadow: 0 8px 24px rgba(124, 58, 237, 0.12);
  --radius: 22px;
  --font: "Baloo 2", "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  overscroll-behavior-y: none;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 18px 10px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--card-border);
}

.brand { font-weight: 800; font-size: 1.25rem; display: flex; align-items: center; gap: 6px; }
.brand-name { background: linear-gradient(90deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  border: none;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 999px;
  font-size: 1.15rem;
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease;
}
.icon-btn:active { transform: scale(0.88); }

/* Current-user chip in the top bar (tap to switch person) */
.user-chip {
  border: 2px solid var(--card-border);
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 999px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.15s ease;
}
.user-chip:active { transform: scale(0.88); }
.user-chip[hidden] { display: none; }
.user-chip .mini-avatar { width: 28px; height: 28px; }

/* ---------- Layout ---------- */
main {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 18px calc(env(safe-area-inset-bottom, 0px) + 32px);
}

.step { animation: step-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }
.step[hidden] { display: none !important; }

@keyframes step-in {
  from { opacity: 0; transform: translateY(22px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.step-head { text-align: center; margin-bottom: 22px; }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 6px;
}
h1 { margin: 0 0 4px; font-size: 1.7rem; font-weight: 800; }
.subtitle { margin: 0; color: var(--muted); font-size: 1rem; }

/* ---------- Grids ---------- */
.grid {
  display: grid;
  gap: 14px;
}
.who-grid { grid-template-columns: repeat(3, 1fr); }
.sport-grid { grid-template-columns: repeat(2, 1fr); }

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 10px 16px;
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}
.tile:active { transform: scale(0.94); }
.tile:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.tile-emoji { font-size: 2.4rem; line-height: 1; }
.tile-label { font-weight: 700; font-size: 0.95rem; text-align: center; word-break: break-word; }
.tile-hint { font-size: 0.75rem; color: var(--muted); }

/* Member avatars (image URL, emoji, or initial fallback) */
.tile-avatar {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f3e8ff, #e0f2fe);
  border: 2px solid var(--card-border);
  color: var(--brand);
  font-weight: 800;
  font-size: 1.1rem;
  overflow: hidden;
}
.tile-avatar-emoji { font-size: 2.4rem; }
.tile-avatar-initial { font-size: 2rem; }

.mini-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: -4px;
  box-shadow: 0 0 0 2px #fff;
  flex: none;
}
/* Emoji / initial chips share the same size as the image avatar */
span.mini-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f3e8ff, #e0f2fe);
  color: var(--brand);
  font-weight: 800;
}
.mini-avatar-emoji { font-size: 1rem; }
.mini-avatar-initial { font-size: 0.78rem; }

.sport-grid .tile { padding: 26px 12px; }
.sport-grid .tile-emoji { font-size: 3.4rem; }

/* ---------- Details ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 14px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.detail-block { background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.field-label { display: block; font-weight: 700; margin-bottom: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.78rem; }

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.stepper-btn {
  border: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  width: 60px;
  height: 60px;
  border-radius: 20px;
  font-size: 1.9rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.stepper-btn:active { transform: scale(0.9); }
.stepper-value {
  font-size: 3.2rem;
  font-weight: 800;
  min-width: 84px;
  text-align: center;
  color: var(--brand);
  /* it's an input now — keep it looking like the old output */
  border: none;
  background: transparent;
  outline: none;
  padding: 0;
  font-family: var(--font);
}

.presets { display: flex; gap: 10px; margin-top: 14px; justify-content: center; }
.preset {
  border: 2px solid var(--card-border);
  background: var(--bg-1);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.preset.is-selected { background: var(--brand); border-color: var(--brand); color: #fff; }

.distance-row { display: flex; align-items: center; gap: 10px; }
.distance-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: 1.6rem;
  font-weight: 700;
  padding: 12px 16px;
  border: 2px solid var(--card-border);
  border-radius: 16px;
  outline: none;
  transition: border-color 0.15s ease;
}
.distance-input:focus { border-color: var(--brand); }
.unit { font-weight: 700; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 15px 20px;
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
  margin-top: 12px;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 10px 24px rgba(124, 58, 237, 0.35); }
.btn.big { font-size: 1.3rem; padding: 18px 20px; }
.btn.ghost { background: transparent; color: var(--muted); border: 2px solid var(--card-border); box-shadow: none; }

/* ---------- Done ---------- */
.done { text-align: center; padding-top: 8px; }
.done-emoji {
  font-size: 5.5rem;
  line-height: 1;
  display: inline-block;
  animation: bounce 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes bounce {
  0% { transform: scale(0); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
.done-summary {
  display: inline-block;
  margin: 14px auto 0;
  padding: 12px 20px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 1.05rem;
  font-weight: 700;
}
.done-buttons { margin-top: 20px; }

/* ---------- Stats overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(31, 21, 51, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 0.2s ease both;
}
.overlay[hidden] { display: none !important; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  width: 100%;
  max-width: 520px;
  /* compact while loading, expands upward when content is ready */
  max-height: 250px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-1);
  border-radius: 26px 26px 0 0;
  animation: slide-up 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: max-height 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}
.overlay-card.loaded { max-height: 82dvh; }
@keyframes slide-up { from { transform: translateY(60px); opacity: 0.4; } to { transform: none; opacity: 1; } }

/* Header stays put while the content below scrolls */
.overlay-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
  margin-bottom: 0;
  background: var(--bg-1);
  border-bottom: 1px solid var(--card-border);
  z-index: 2;
}
.overlay-head h2 { margin: 0; font-size: 1.4rem; }

/* Only the body scrolls */
.stats-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 18px calc(env(safe-area-inset-bottom, 0px) + 24px);
}

/* ---------- Stats loader (fun) ---------- */
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 0 24px;
  text-align: center;
}
.loader-emojis {
  display: flex;
  gap: 4px;
  font-size: 2rem;
  line-height: 1;
}
.loader-emojis span {
  display: inline-block;
  animation: loader-bounce 1.1s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 0.12s);
}
@keyframes loader-bounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30% { transform: translateY(-12px) rotate(-8deg); }
  60% { transform: translateY(2px) rotate(6deg); }
}

.stats-section { margin-bottom: 18px; }
.stats-section h3 { margin: 0 0 8px; font-size: 1.05rem; }

/* ---------- Goal header + progress rings ---------- */
.goal-header { margin-bottom: 12px; text-align: center; }
.goal-line {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .92rem;
  font-weight: 600;
  text-align: center;
}

.ring-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.ring-pair { display: flex; gap: 10px; flex: none; }
.ring-cell { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.ring-wrap { display: contents; }
.ring {
  --pct: 0;
  --ring-c: #7c3aed;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: conic-gradient(var(--ring-c) calc(var(--pct) * 1%), #efe9fa 0);
  display: inline-grid;
  place-items: center;
  position: relative;
  isolation: isolate;
  font-weight: 800;
  font-size: .95rem;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(124, 58, 237, .08);
}
.ring::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: #fff;
  z-index: -1;
}
.ring-label { font-size: .68rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.ring-meta { display: flex; flex-direction: column; min-width: 0; }
.ring-name { font-weight: 800; font-size: 1.05rem; }
.ring-vals { font-size: .84rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.medal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.medal { font-size: 1.3rem; width: 30px; text-align: center; flex: none; }
.rank-name { flex: 0 0 auto; font-weight: 700; }
.rank-bar-wrap { flex: 1; background: var(--bg-1); border-radius: 999px; height: 14px; overflow: hidden; }
.rank-bar { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); width: 0; transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1); }
.rank-score { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); min-width: 44px; text-align: right; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--err); }

/* ---------- Confetti ---------- */
.confetti-piece {
  position: fixed;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  z-index: 70;
  pointer-events: none;
  animation: confetti-fall var(--fall, 2.6s) linear forwards;
}
@keyframes confetti-fall {
  0% { transform: translate3d(0, -20px, 0) rotate(0); opacity: 1; }
  100% { transform: translate3d(var(--drift, 0px), 105vh, 0) rotate(var(--spin, 720deg)); opacity: 0.85; }
}

/* ---------- View transitions (progressive enhancement) ---------- */
::view-transition-old(root) { animation: vt-out 0.22s ease both; }
::view-transition-new(root) { animation: vt-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes vt-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-14px) scale(0.99); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}