:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #15171c;
  --muted: #6b7280;
  --line: #e7e9ee;
  --soft: #f1f3f6;
  --brand: #0b2a5b;
  --accent: #f5b301;
  --strava: #fc4c02;
  --up: #16a34a;
  --down: #e11d48;
  --gold: #d4a017;
  --silver: #8d99a6;
  --bronze: #b0703c;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 "Be Vietnam Pro", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
.wrap { max-width: 1260px; margin: 0 auto; padding: 0 16px; }
button, select, input { font: inherit; color: inherit; }
a { color: inherit; }

/* top bar */
.topbar { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-in { display: flex; align-items: center; gap: 24px; height: 76px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand b { display: block; font-size: 22px; font-weight: 800; letter-spacing: -.02em; color: var(--brand); line-height: 1.1; }
.brand b em { font-style: normal; color: var(--accent); }
.brand small { display: block; font-size: 10.5px; letter-spacing: .22em; color: var(--muted); font-weight: 600; margin-top: 3px; }
.nav { margin-left: auto; display: flex; gap: 28px; }
.nav a { text-decoration: none; font-weight: 700; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; color: #374151; padding: 6px 0; border-bottom: 3px solid transparent; }
.nav a.active { color: var(--ink); border-color: var(--accent); }
.btn-strava { display: inline-flex; align-items: center; gap: 8px; background: var(--ink); color: #fff; border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.btn-strava:hover { background: var(--strava); }

.crumbs { font-size: 12.5px; color: var(--muted); margin: 18px 0 6px; }
.crumbs span { margin: 0 4px; }
.crumbs b { color: var(--ink); font-weight: 600; }
.head h1 { font-size: 34px; font-weight: 800; letter-spacing: -.03em; margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; }
.powered { display: inline-flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 700; letter-spacing: .1em; color: #374151; }
.sub { margin: 4px 0 0; color: #374151; font-size: 14px; }

/* period banner */
.period { margin-top: 18px; background: linear-gradient(110deg, var(--brand) 0%, #173f80 60%, #1e4f9c 100%); color: #fff; border-radius: var(--radius); padding: 18px 22px; display: flex; align-items: center; gap: 28px; flex-wrap: wrap; position: relative; overflow: hidden; }
.period::after { content: ""; position: absolute; right: -40px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: rgba(245,179,1,.14); }
.period-dates { display: flex; align-items: center; gap: 18px; }
.pd small { display: block; font-size: 11px; letter-spacing: .14em; opacity: .75; font-weight: 600; }
.pd b { font-size: 26px; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.arrow { color: var(--accent); }
.period-status { flex: 1; min-width: 220px; display: grid; gap: 6px; position: relative; z-index: 1; }
.pill { justify-self: start; background: var(--accent); color: #1a1300; font-weight: 700; font-size: 12.5px; padding: 4px 12px; border-radius: 999px; }
.pill.live::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #c2410c; margin-right: 6px; vertical-align: 1px; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.bar { height: 6px; background: rgba(255,255,255,.18); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .6s; }
.period-status small { opacity: .85; font-size: 12.5px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.stat small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat b { font-size: 28px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-right: 6px; }
.stat span { color: var(--muted); font-size: 13px; }

/* controls */
.controls { display: flex; gap: 10px; flex-wrap: wrap; margin: 20px 0 12px; align-items: center; }
.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: transparent; padding: 8px 16px; border-radius: 9px; font-weight: 600; font-size: 14px; color: #4b5563; cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
#teamSel { margin-left: auto; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 14px; min-width: 230px; }
.search { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0 16px; color: var(--muted); }
.search input { flex: 1; border: 0; outline: 0; padding: 14px 0; background: transparent; color: var(--ink); }
.search:focus-within { border-color: #9ca3af; }

/* table */
.table-wrap { margin-top: 16px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.board { width: 100%; border-collapse: collapse; min-width: 860px; }
.board th { text-align: left; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: #4b5563; font-weight: 700; padding: 14px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.board td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.board tr:last-child td { border-bottom: 0; }
.board .r { text-align: right; }
.board .c { text-align: center; }
.board .num { font-variant-numeric: tabular-nums; }
.board tbody tr.row { cursor: pointer; transition: background .12s; }
.board tbody tr.row:hover { background: #fafbfc; }
.rank { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 15px; min-width: 64px; }
.medal { width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 13px; font-weight: 800; border: 2px solid currentColor; }
.m1 { color: var(--gold); background: #fff8e1; }
.m2 { color: var(--silver); background: #f3f5f7; }
.m3 { color: var(--bronze); background: #fbf1e8; }
.chg { font-size: 11px; font-weight: 700; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.ath { display: flex; align-items: center; gap: 12px; }
.av { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; }
.ath b { display: block; font-weight: 600; font-size: 15px; }
.ath small { display: block; color: var(--muted); font-size: 12.5px; }
.time { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.km { font-weight: 700; font-variant-numeric: tabular-nums; }
.lead { color: var(--up); font-weight: 600; }
.gap { color: #4b5563; }
.dt b { display: block; font-weight: 500; }
.dt small { color: var(--muted); }
.muted { color: #b0b6c0; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px !important; }

tr.detail td { background: #fafbfc; padding: 0 16px 14px 76px; }
.runs { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.runs th { font-size: 11px; color: var(--muted); padding: 10px 8px 6px; border-bottom: 1px solid var(--line); }
.runs td { padding: 7px 8px; border-bottom: 1px dashed var(--line); }
.runs a { color: var(--strava); font-weight: 600; text-decoration: none; }
.chev { display: inline-block; transition: transform .15s; color: var(--muted); margin-left: 6px; font-size: 11px; }
tr.open .chev { transform: rotate(90deg); }

.progress { height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; margin-top: 4px; width: 120px; }
.progress i { display: block; height: 100%; background: var(--accent); }

.updated { font-size: 12.5px; color: var(--muted); text-align: right; margin: 8px 2px 0; }

/* rules */
.rules { margin: 40px 0 24px; }
.rules h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 12px; }
.rules-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.rules-grid > div { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; }
.rules h3 { margin: 0 0 6px; font-size: 15px; }
.rules ul, .rules ol { margin: 0; padding-left: 18px; color: #374151; font-size: 14px; }
.rules li { margin: 4px 0; }

.foot { border-top: 1px solid var(--line); background: #fff; margin-top: 24px; }
.foot-in { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 16px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }

/* dialog */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100% - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10,15,30,.5); }
.dlg { padding: 26px; display: grid; gap: 14px; position: relative; }
.dlg h2 { margin: 0; font-size: 20px; font-weight: 800; }
.dlg p { margin: 0; color: #4b5563; font-size: 14px; }
.dlg label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.dlg select { border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fff; }
.dlg .x { position: absolute; right: 14px; top: 10px; border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.btn-connect { display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--strava); color: #fff; border: 0; border-radius: 10px; padding: 13px; font-weight: 700; cursor: pointer; }
.btn-connect:disabled { opacity: .45; cursor: not-allowed; }
.note { color: var(--muted); font-size: 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120px); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 500; transition: transform .3s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .nav { display: none; }
  .btn-strava { margin-left: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .rules-grid { grid-template-columns: 1fr; }
  #teamSel { margin-left: 0; flex: 1; }
}
@media (max-width: 560px) {
  .topbar-in { height: 64px; gap: 10px; }
  .brand b { font-size: 16px; }
  .brand small { font-size: 9px; letter-spacing: .12em; }
  .brand img { width: 36px; height: 36px; }
  .btn-strava { padding: 9px 12px; font-size: 13px; }
  .btn-strava .lbl-long { display: none; }
  .head h1 { font-size: 26px; }
  .pd b { font-size: 20px; }
  .stat b { font-size: 22px; }
}

.steps { margin: 0; padding-left: 20px; color: #374151; font-size: 14px; display: grid; gap: 4px; }
a.btn-connect { text-decoration: none; }
[hidden] { display: none !important; }

/* login gate + signed-in user */
body.gated .board-only { display: none !important; }
.gate { margin: 22px 0; }
.gate-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 32px 24px; text-align: center; max-width: 560px; margin: 0 auto; }
.gate-card h2 { margin: 0 0 8px; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.gate-card p { margin: 0 0 18px; color: #4b5563; font-size: 14px; }
.btn-ms { display: inline-flex; align-items: center; gap: 10px; background: var(--ink); color: #fff; text-decoration: none; padding: 12px 20px; border-radius: 10px; font-weight: 700; }
.btn-ms:hover { background: #2b2f3a; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; white-space: nowrap; }
.user b { font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.user a { color: var(--muted); text-decoration: none; font-weight: 600; }
.user a:hover { color: var(--ink); }
/* weekly view */
.board th.wk small { display: block; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--muted); font-size: 11px; }
.board th.wk.cur, .board td.wk.cur { background: #fff8e1; }
.board td.wk small { display: block; color: var(--muted); font-size: 11px; }
.board tr.foot-row td { font-weight: 700; background: var(--soft); border-top: 2px solid var(--line); }
@media (max-width: 900px) { .user b { display: none; } }
