:root {
  --bg: #0a0f1c;
  --card: #101a2e;
  --card-2: #16233c;
  --line: #22334f;
  --text: #e7edf7;
  --dim: #8da2c0;
  --primary: #3b82f6;
  --primary-bright: #8ab6ff;   /* readable "blue ink" on dark cards */
  --primary-soft: rgba(59, 130, 246, .16);
  --grad: linear-gradient(100deg, #60a5fa, #2563eb);
  --chart-2: #38bdf8;
  --chart-3: #818cf8;
  --gold: #fbbf24;
  --red: #f87171;
  --good: #4ade80;
  --mid: #fbbf24;
  --low: #f87171;
  --shadow: 0 1px 3px rgba(2, 6, 16, .5), 0 8px 22px -10px rgba(2, 6, 16, .6);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1000px 480px at 85% -10%, rgba(59, 130, 246, .14), transparent 60%),
    radial-gradient(760px 440px at 5% 0%, rgba(56, 189, 248, .09), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}
#app { max-width: 1100px; margin: 0 auto; padding: 16px clamp(12px, 3vw, 32px) 40px; }
a { color: var(--primary-bright); }
h2, h3 { letter-spacing: -.01em; }
.section-title { font-size: 18px; margin: 8px 0 12px; }
.dim { color: var(--dim); }
code { background: var(--card-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; font-size: .92em; }

/* ── top nav ────────────────────────────────────────────── */
.top {
  position: sticky; top: 10px; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  background: rgba(16, 26, 46, .92); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 16px; margin-bottom: 18px;
  flex-wrap: wrap;
}
.brand {
  font-size: 17px; font-weight: 800; letter-spacing: .2px;
  display: flex; align-items: center; gap: 9px;
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.trophy { filter: drop-shadow(0 0 10px rgba(251, 191, 36, .45)); font-size: 21px; }
.nav-links { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav-links a {
  text-decoration: none; color: var(--dim); font-weight: 600; font-size: 14px;
  padding: 7px 13px; border-radius: 9px;
}
.nav-links a:hover { background: var(--card-2); color: var(--text); }
.nav-links a.active { background: var(--primary-soft); color: var(--primary-bright); }
.nav-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.me-chip {
  display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 5px; font-weight: 600; font-size: 14px;
}
.me-chip:hover { border-color: var(--primary); background: var(--primary-soft); }
.me-chip .avatar { width: 26px; height: 26px; font-size: 10px; }
.me-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-btn .spin { display: inline-block; }
.syncing .spin { animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ── buttons ────────────────────────────────────────────── */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text);
  padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  transition: transform .06s ease, border-color .15s ease, background .15s ease, box-shadow .15s;
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
}
button:hover, .btn:hover { border-color: #3a5580; box-shadow: var(--shadow); transform: translateY(-1px); }
button:active, .btn:active { transform: translateY(0); }
.primary { background: var(--grad); color: #fff; border: none; }
.primary:hover { filter: brightness(1.08); }
.ghost { background: transparent; }
.danger { border-color: rgba(248, 113, 113, .4); color: var(--red); background: transparent; }
.danger:hover { background: rgba(248, 113, 113, .08); border-color: var(--red); }
button:disabled { opacity: .55; cursor: default; transform: none !important; box-shadow: none !important; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }

.btn-google { background: #fff; color: #1f2937; border: none; }
.btn-google:hover { filter: brightness(.94); }
.btn-google .mark { color: #4285f4; font-weight: 800; font-size: 16px; }
.btn-google .btn-sub { color: #6b7280; font-weight: 500; }
.btn-whoop { background: #05070c; color: #fff; border-color: #2a2f3a; }
.btn-whoop b { color: #ff4d4d; }
.btn-whoop:hover { border-color: #444c5c; }
.btn-demo { border-style: dashed; color: var(--dim); background: transparent; }

/* ── login page ─────────────────────────────────────────── */
.login-body {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px 16px; gap: 18px;
}
.login-card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 20px 60px -18px rgba(2, 6, 16, .8);
  padding: clamp(28px, 6vw, 52px) clamp(22px, 5vw, 56px);
  max-width: 460px; width: 100%; text-align: center;
}
.login-trophy { font-size: 52px; filter: drop-shadow(0 0 18px rgba(251, 191, 36, .4)); }
.login-card h1 { margin: 10px 0 4px; font-size: clamp(24px, 4.5vw, 32px); letter-spacing: -.02em; }
.tagline { color: var(--dim); font-size: 15px; margin: 0 0 26px; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-buttons { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.login-buttons .btn, .login-buttons button { justify-content: center; padding: 12px 16px; }
.login-buttons .notice { line-height: 1.6; font-size: 13px; }
.fineprint { font-size: 12px; color: var(--dim); margin-top: 22px; line-height: 1.55; }
.login-footer { font-size: 12px; color: var(--dim); }

/* ── cards & layout ─────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px;
}
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 4px 0 14px; }
.controls .section-title { margin: 0 auto 0 0; }
.pills { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px; gap: 2px; box-shadow: var(--shadow); }
.pills button { border: none; background: transparent; padding: 7px 14px; border-radius: 999px; color: var(--dim); font-weight: 600; box-shadow: none !important; }
.pills button:hover { color: var(--text); transform: none; }
.pills button.active { background: var(--grad); color: #fff; }
#scoring-btn { margin-left: auto; color: var(--dim); border: none; font-size: 13px; background: transparent; }
#scoring-btn:hover { color: var(--primary-bright); box-shadow: none; }

/* ── leaderboard table ──────────────────────────────────── */
.board-wrap { overflow-x: auto; }
.board { width: 100%; border-collapse: separate; border-spacing: 0 8px; min-width: 640px; }
.board th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--dim); font-weight: 700; padding: 2px 14px;
}
.board th.num, .board td.num { text-align: right; font-variant-numeric: tabular-nums; }
.board tbody tr { background: var(--card); }
.board td { padding: 12px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.board td:first-child { border-left: 1px solid var(--line); border-radius: 12px 0 0 12px; }
.board td:last-child { border-right: 1px solid var(--line); border-radius: 0 12px 12px 0; }
.board tbody tr:hover td { border-color: #35507c; background: var(--card-2); }
tr.you td { border-color: var(--primary); box-shadow: inset 0 0 0 .5px var(--primary); }
tr.top1 td { background: linear-gradient(90deg, rgba(251, 191, 36, .10), var(--card) 45%); }
tr.top1:hover td { background: linear-gradient(90deg, rgba(251, 191, 36, .12), var(--card-2) 45%); }

.rank { font-weight: 800; font-size: 15px; width: 44px; white-space: nowrap; color: var(--dim); }
.rank .medal { font-size: 18px; }

.athlete { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; color: #fff;
  background: var(--grad); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.athlete .who { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.athlete .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.badges { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.badge {
  font-size: 9.5px; font-weight: 800; letter-spacing: .06em; padding: 2px 6px;
  border-radius: 5px; text-transform: uppercase;
}
.badge.google { background: rgba(66, 133, 244, .2); color: #7baaf7; }
.badge.whoop { background: rgba(255, 77, 77, .16); color: #ff8585; }
.badge.demo { background: rgba(148, 163, 184, .16); color: #9fb0c8; }
.badge.warn { background: rgba(251, 191, 36, .16); color: var(--gold); }
.badge.admin { background: rgba(129, 140, 248, .18); color: #a5b4fc; }
.you-chip { font-size: 9.5px; font-weight: 800; padding: 2px 6px; border-radius: 5px; background: var(--primary-soft); color: var(--primary-bright); }

.score-cell { font-weight: 800; font-size: 17px; color: var(--primary-bright); }
.score-cell .of { color: var(--dim); font-weight: 600; font-size: 11px; }
.spark { opacity: .95; }
.good { color: var(--good); } .mid { color: var(--mid); } .low { color: var(--low); }

.empty { text-align: center; padding: 56px 20px; color: var(--dim); }
.empty-emoji { font-size: 42px; margin-bottom: 8px; }
.empty h2 { color: var(--text); margin: 6px 0; }

footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 22px; font-size: 12px; color: var(--dim); }

/* ── profile ────────────────────────────────────────────── */
.profile-head { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(280px, 1.2fr); gap: 24px; }
.profile-identity { display: flex; gap: 16px; align-items: center; }
.profile-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.profile-name-row { display: flex; gap: 8px; }
.profile-name-row input { font-size: 16px; font-weight: 700; }
.profile-connections h3 { margin: 0 0 8px; font-size: 14px; }

input {
  font: inherit; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 12px; flex: 1; min-width: 0;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.conn-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; margin: 8px 0; flex-wrap: wrap;
}
.conn-row .status, .status { font-size: 12.5px; }
.conn-actions { display: flex; gap: 6px; }
.status.ok { color: var(--good); }
.status.bad { color: var(--mid); }
.danger-card h3 { margin-top: 0; }
.danger-zone { display: flex; gap: 10px; flex-wrap: wrap; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 16px 12px;
}
.stat-value { font-size: 21px; font-weight: 800; color: var(--primary-bright); }
.stat-value .dim { font-size: 12px; }
.stat-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 700; margin-top: 3px; }
.stat-sub { font-size: 11px; color: var(--dim); margin-top: 2px; }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 16px; }
.chart-card h3 { margin: 0 0 10px; font-size: 13.5px; color: var(--dim); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.chart { width: 100%; height: 110px; display: block; }

/* ── data tables (profile history + admin) ──────────────── */
.table-card h3 { margin: 0 0 10px; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 720px; }
.data-table th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--dim); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table tbody tr:hover { background: var(--card-2); }
.data-table tr.no-data td { color: #47597a; }
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ── admin diagnostics ──────────────────────────────────── */
.conn-diagnostics { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-bottom: 16px; }
.conn-diag h3 { margin: 0 0 10px; }
.diag-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px 14px; font-size: 13px; }
.diag-grid .dim { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.diag-wide { grid-column: 1 / -1; word-break: break-all; }
#back-btn { margin-bottom: 12px; }

/* ── dialogs ────────────────────────────────────────────── */
dialog {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px 26px; max-width: 560px; width: calc(100vw - 40px);
  box-shadow: 0 18px 60px -18px rgba(2, 6, 16, .9);
}
dialog::backdrop { background: rgba(3, 7, 15, .7); backdrop-filter: blur(3px); }
dialog h2 { margin-top: 0; }
dialog form { margin-top: 16px; text-align: right; }
dialog p { line-height: 1.55; font-size: 14px; }
.score-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.score-card { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px 8px; }
.score-card h3 { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
.score-card .pts { font-size: 11px; color: var(--primary-bright); font-weight: 700; }
.score-card ul { margin: 0; padding-left: 18px; color: var(--dim); font-size: 13px; line-height: 1.6; }

/* ── toast ──────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 18px; font-size: 14px; box-shadow: 0 10px 30px rgba(2, 6, 16, .6);
  z-index: 50; max-width: min(480px, 90vw);
}
.toast.err { border-color: rgba(248, 113, 113, .5); }
.toast.ok { border-color: rgba(74, 222, 128, .5); }

/* ── responsive ─────────────────────────────────────────── */
@media (max-width: 760px) {
  .board { min-width: 0; }
  .col-sec { display: none; }
  .athlete .name { max-width: 130px; }
  #scoring-btn { margin-left: 0; }
  .profile-head { grid-template-columns: 1fr; }
  .data-table { min-width: 540px; }
  .top { position: static; }
  .me-name { display: none; }
}
