:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #21252e;
  --border: #2b2f3a;
  --text: #e6e8ec;
  --muted: #9aa0ac;
  --accent: #4ade80;
  --accent-ink: #06240f;
  --danger: #f87171;
  --info: #7dd3fc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ---- Header / nav ---- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); }
.site-nav { display: flex; align-items: center; gap: 0.35rem; }
.nav-link {
  text-decoration: none;
  color: var(--muted);
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  font-weight: 500;
}
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
}
.nav-icon svg { width: 1.15rem; height: 1.15rem; display: block; }
.nav-user { display: inline-flex; align-items: center; gap: 0.4rem; }

/* ---- Avatars / logos ---- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
  vertical-align: middle;
}
.avatar-xs { width: 1.5rem; height: 1.5rem; font-size: 0.7rem; }
.avatar-sm { width: 2rem; height: 2rem; font-size: 0.8rem; }
.avatar-lg { width: 4.5rem; height: 4.5rem; font-size: 1.7rem; }
.heading-avatar { display: flex; align-items: center; gap: 0.85rem; }
.heading-avatar h1 { margin: 0; }
.avatar-edit { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }

.container { max-width: 880px; margin: 0 auto; padding: 1.5rem; }

/* ---- Buttons ---- */
button,
.btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
button:hover,
.btn:hover { filter: brightness(1.08); }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-row { display: flex; gap: 0.75rem; margin-top: 1.5rem; flex-wrap: wrap; }

/* Small inline action button (table rows, list items) */
.linkbtn {
  padding: 0.25rem 0.6rem;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}
.linkbtn.danger { color: var(--danger); border-color: var(--danger); }
.inline-form { display: inline; margin: 0; }

/* ---- Hero / landing ---- */
.hero { padding: 3rem 0; }
.hero h1 { font-size: 2.4rem; margin: 0 0 0.5rem; }
.lead { font-size: 1.15rem; }
.muted { color: var(--muted); }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem;
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }

/* ---- Forms ---- */
form { display: grid; gap: 0.85rem; max-width: 420px; }
label { display: grid; gap: 0.3rem; font-size: 0.9rem; }
input, textarea, select {
  padding: 0.55rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}
form button { justify-self: start; }
.hint { color: var(--muted); font-size: 0.8rem; }
.field-error { display: block; color: var(--danger); font-size: 0.82rem; }

/* Log-a-run form: a compact two-column grid; its card shrink-wraps to it
   (.log-card) so there is no dead space and inputs stay a modest width. */
.run-form {
  max-width: none;
  grid-template-columns: 13rem 13rem;
  gap: 0.85rem 1.4rem;
  align-items: start;  /* fields keep their natural height; no stretching to the row */
}
.run-form .run-form-wide { grid-column: 1 / -1; }
.run-form textarea { resize: vertical; }
.log-card { width: fit-content; max-width: 100%; }
@media (max-width: 560px) {
  .run-form { grid-template-columns: 13rem; }
}

fieldset.duration-fields { border: 0; padding: 0; margin: 0; }
fieldset.duration-fields legend { font-size: 0.9rem; padding: 0; margin-bottom: 0.3rem; }
.duration-inputs { display: flex; align-items: center; gap: 0.7rem; }
.duration-part { display: flex; align-items: center; gap: 0.35rem; }
.duration-part input { width: 3.6rem; text-align: center; }
.duration-suffix { color: var(--muted); font-size: 0.85rem; }

/* ---- Disclosures (collapsible forms) ---- */
.disclosure { margin: 1rem 0; }
.disclosure summary { list-style: none; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::before { content: "+ "; font-weight: 700; }
.disclosure[open] summary::before { content: "\2013 "; }
.disclosure-body { margin-top: 0.6rem; }
.action-row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }
.action-row .disclosure { margin: 0; }

/* ---- Messages ---- */
.flash { padding: 0.65rem 0.85rem; border-radius: 6px; margin-bottom: 1rem; }
.flash.error { background: #3a1d1d; color: var(--danger); }
.flash.success { background: #14331f; color: var(--accent); }

/* ---- Tables ---- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 0.6rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.score { font-weight: 600; color: var(--accent); }
.data-table td.notes { color: var(--muted); max-width: 16rem; }
.data-table tr.me { background: rgba(74, 222, 128, 0.08); }
.data-table th.rank, .data-table td.rank { text-align: right; width: 2.5rem; color: var(--muted); }

.empty-state { color: var(--muted); padding: 2rem 0; text-align: center; }

/* ---- Lists ---- */
.group-list, .member-list, .competition-list, .friend-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}
.group-list li, .member-list li, .competition-list li, .friend-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.group-list li a, .friend-list li a { font-weight: 600; text-decoration: none; }
.friend-actions { display: inline-flex; gap: 0.6rem; }
.push-right { margin-left: auto; }

/* ---- Section headings with an action ---- */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ---- Invite ---- */
.invite code {
  display: inline-block;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  word-break: break-all;
}

/* ---- Leaderboard window toggle ---- */
.leaderboard-controls { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
button.toggle {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}
button.toggle.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: capitalize;
}
.badge-active { background: #14331f; color: var(--accent); }
.badge-upcoming { background: #1e2a3a; color: var(--info); }
.badge-ended { background: var(--surface-2); color: var(--muted); }

/* ---- Competition meta line + rule chips ---- */
.comp-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}
.rule-chip {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

/* ---- Charts ---- */
.chart-card { height: 280px; padding: 0.9rem; }
.chart-card-wide { height: 320px; margin: 1rem 0; }

/* ---- Stat-view metric toggle ---- */
.metric-toggle { display: flex; gap: 0.5rem; margin: 0.85rem 0 0.6rem; flex-wrap: wrap; }
.leaderboard-widget { margin-top: 0.5rem; }
.leaderboard-table th.metric-active,
.leaderboard-table td.metric-active { background: rgba(74, 222, 128, 0.07); }
.rank-icon { margin-left: 0.35rem; font-size: 0.95rem; line-height: 1; }

/* ---- Honeypot field (anti-bot; hidden from real users) ---- */
.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ---- Dev-only quick login ---- */
.dev-panel {
  margin-top: 1.75rem;
  padding: 0.85rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.dev-panel p { margin: 0 0 0.55rem; font-size: 0.85rem; }
.dev-login-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---- Settings rows (label on the left, control on the right) ---- */
.setting-row { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.setting-label { min-width: 8rem; font-weight: 600; font-size: 0.95rem; }

/* ---- Toggle switch (km / mi unit preference) ---- */
.unit-switch { display: flex; align-items: center; gap: 0.6rem; }
.unit-label { font-size: 0.9rem; color: var(--muted); }
.switch { position: relative; display: inline-block; width: 2.6rem; height: 1.5rem; }
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 1.05rem;
  height: 1.05rem;
  left: 0.15rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + .switch-slider {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked + .switch-slider::before {
  transform: translate(1.1rem, -50%);
  background: var(--accent-ink);
}
.switch input:focus-visible + .switch-slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Help tooltip ---- */
.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  margin-left: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  cursor: help;
  position: relative;
  vertical-align: middle;
}
.help::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  bottom: calc(100% + 0.5rem);
  width: max-content;
  max-width: 16rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  z-index: 20;
}
.help:hover::after,
.help:focus::after { opacity: 1; }

/* ---- Password field with show / hide ---- */
.pw-field { position: relative; display: block; }
.pw-field input { width: 100%; padding-right: 2.6rem; }
.pw-toggle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
}
.pw-toggle:hover { background: transparent; color: var(--text); filter: none; }
.pw-toggle svg { width: 1.15rem; height: 1.15rem; display: block; }
.pw-toggle .icon-eye-off { display: none; }
.pw-toggle.revealed .icon-eye { display: none; }
.pw-toggle.revealed .icon-eye-off { display: block; }
