:root {
  color-scheme: light;
  --bg: #f1f3f5;
  --surface: #ffffff;
  --surface-soft: #f7f8f9;
  --text: #111820;
  --muted: #8b939b;
  --line: #e7eaed;
  --blue: #39a8df;
  --blue-dark: #218fc6;
  --blue-soft: #dff1fb;
  --green: #40b984;
  --red: #e86a68;
  --shadow: 0 4px 16px rgb(28 38 48 / 6%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; min-width: 320px; overflow-x: hidden; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgb(57 168 223 / 30%); outline-offset: 2px; }

.app-shell { width: min(100%, 620px); min-height: 100vh; margin: 0 auto; padding: max(8px, env(safe-area-inset-top)) 10px calc(92px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: flex-end; gap: 14px; min-height: 50px; padding: 0 6px 10px; }
.eyebrow { margin: 0 0 3px; color: var(--blue-dark); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 26px; line-height: 1.08; }
h2 { margin-bottom: 0; font-size: 18px; line-height: 1.2; }
h3 { margin-bottom: 4px; font-size: 16px; }
.icon-button { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 50%; background: var(--blue); color: #fff; font-size: 18px; font-weight: 800; }
.icon-button:hover, .primary-button:hover, .fab:hover { background: var(--blue-dark); }
.icon-button--small { width: 34px; height: 34px; background: var(--surface-soft); color: var(--muted); font-size: 25px; font-weight: 400; }
.connection-strip { display: flex; align-items: center; gap: 7px; margin: 0 6px 12px; color: var(--green); font-size: 12px; font-weight: 700; }
.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

.segmented-control { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin-bottom: 16px; padding: 3px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.segmented-control--2 { grid-template-columns: repeat(2, 1fr); }
.segment { min-height: 34px; border-radius: 9px; background: transparent; color: var(--text); font-size: 13px; }
.segment.is-active { background: var(--blue); color: #fff; }
.event-search { position: relative; display: block; margin: -6px 0 14px; }
.event-search input { width: 100%; min-height: 40px; padding: 0 38px 0 12px; border: 1px solid transparent; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); font-size: 16px; }
.event-search input::placeholder { color: var(--muted); }
.event-search-clear { position: absolute; top: 50%; right: 7px; display: grid; width: 26px; height: 26px; place-items: center; transform: translateY(-50%); border-radius: 50%; background: var(--surface-soft); color: var(--muted); font-size: 20px; line-height: 1; }
.event-search-clear:hover { background: var(--blue-soft); color: var(--blue-dark); }
.year-heading { display: flex; width: 100%; align-items: baseline; gap: 7px; margin: 0 0 14px; padding: 0 8px; background: transparent; color: var(--text); text-align: left; }
.year-heading-main { display: inline-flex; align-items: baseline; gap: 7px; }
.year-caret { width: 9px; color: var(--muted); font-size: 14px; }
.year-heading strong { font-size: 18px; }
.year-heading span { color: var(--muted); font-size: 13px; }
.month-label { margin: 0 14px 8px; font-size: 13px; font-weight: 800; text-transform: uppercase; }
.event-list { display: grid; gap: 10px; margin-bottom: 18px; }
.event-card, .section-card, .profile-card, .calendar-card, .result-card { border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.event-card { padding: 16px 14px 12px; }
.event-card.is-clickable, .result-row, .participant-row, .registration-row, .calendar-event { cursor: pointer; }
.event-card.is-clickable:hover, .result-row:hover, .participant-row:hover, .registration-row:hover, .calendar-event:hover { background: var(--surface-soft); }
.event-title-row, .event-meta, .result-row, .participant-row, .registration-row, .profile-line, .section-heading, .calendar-heading { display: flex; align-items: center; }
.event-title-row, .section-heading, .calendar-heading { justify-content: space-between; gap: 10px; }
.event-title { margin-bottom: 6px; font-size: 16px; font-weight: 800; }
.event-meta, .subtle { color: var(--muted); font-size: 12px; }
.distance-tags, .chip-row, .filter-row { display: flex; flex-wrap: wrap; gap: 7px; }
.distance-tags { margin: 10px 0 9px; }
.chip { display: inline-flex; align-items: center; min-height: 24px; padding: 0 9px; border-radius: 999px; background: #eef0f2; color: var(--text); font-size: 12px; white-space: nowrap; }
.chip.is-active { background: var(--blue); color: #fff; }
.event-participants { display: grid; gap: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.event-participant-count { padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.past-event-stats { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 11px; color: var(--muted); font-size: 12px; }
.past-event-stats span:last-child { font-size: 16px; }
.event-card--past .event-title { font-weight: 500; }
.past-results-distance { padding: 10px 14px 5px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.past-detail-card .result-row { padding-right: 14px; padding-left: 14px; }
.participant-line { display: flex; align-items: center; gap: 6px; overflow: hidden; color: var(--blue-dark); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.participant-line span:first-child { overflow: hidden; text-overflow: ellipsis; }
.event-arrow { color: var(--muted); font-size: 16px; }

.fab { position: fixed; right: max(18px, calc(50% - 282px)); bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 5; display: grid; width: 54px; height: 54px; place-items: center; border-radius: 50%; background: var(--blue); box-shadow: 0 5px 12px rgb(34 126 173 / 28%); color: #fff; font-size: 30px; font-weight: 300; }
.bottom-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 4; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: min(100%, 620px); margin: 0 auto; padding: 8px 12px max(9px, env(safe-area-inset-bottom)); background: rgb(255 255 255 / 96%); box-shadow: 0 -4px 16px rgb(28 38 48 / 6%); }
.nav-button { display: grid; grid-template-rows: 36px 14px; justify-items: center; align-items: center; gap: 3px; min-height: 58px; padding: 2px 5px; border-radius: 10px; background: transparent; color: var(--muted); font-size: 10px; line-height: 1; }
.nav-button.is-active { color: var(--text); }
.nav-icon { display: grid; width: 46px; height: 34px; place-items: center; border-radius: 17px; line-height: 1; }
.nav-icon img { display: block; width: 25px; height: 25px; object-fit: contain; opacity: .62; }
.nav-button.is-active .nav-icon { background: var(--blue-soft); }
.nav-button.is-active .nav-icon img { opacity: 1; }

.calendar-card { margin-bottom: 12px; padding: 12px; }
.calendar-heading { margin-bottom: 9px; }
.calendar-heading h2 { font-size: 15px; }
.round-button { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 8px; background: var(--surface-soft); color: var(--text); }
.calendar-week, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
.calendar-week { margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.calendar-day { display: grid; min-height: 38px; place-items: center; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--text); font-size: 12px; }
.calendar-day.is-event { background: var(--blue-soft); color: var(--blue-dark); font-weight: 800; }
.calendar-day.is-selected { border-color: var(--blue); }
.calendar-day.is-empty { pointer-events: none; }
.calendar-events { display: grid; padding: 0 14px; }
.calendar-event { padding: 13px 0; border-bottom: 1px solid var(--line); }
.calendar-event:last-child { border-bottom: 0; }

.filter-row { gap: 5px; overflow-x: auto; flex-wrap: nowrap; margin-bottom: 14px; padding-bottom: 2px; }
.filter-row .chip { flex: 0 0 auto; }
.results-filter { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.results-filter .filter-row { flex: 1 1 auto; margin-bottom: 0; }
.results-common-filter { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; border-radius: 999px; background: var(--surface); color: var(--text); font-size: 12px; box-shadow: var(--shadow); }
.results-common-filter input { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); }
.results-back-button { margin-bottom: 12px; }
.result-group-card .section-heading { padding: 14px 14px 6px; margin-bottom: 0; }
.result-group-footer-button { display: block; margin: 10px 14px 14px; }
.result-card { overflow: hidden; margin-bottom: 14px; }
.result-card-header { padding: 14px 14px 9px; }
.result-row, .participant-row, .registration-row { justify-content: space-between; gap: 10px; min-height: 48px; padding: 8px 14px; border-top: 1px solid var(--line); }
.profile-result-row { min-height: 66px; }
.result-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.result-action-button { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 9px; background: var(--surface-soft); color: var(--muted); font-size: 22px; line-height: 1; }
.result-action-button:hover { background: var(--blue-soft); color: var(--blue-dark); }
.result-action-button--danger { color: var(--red); font-size: 26px; }
.result-person, .registration-main { min-width: 0; }
.result-person strong, .registration-main strong { display: block; overflow: hidden; color: var(--blue-dark); font-size: 13px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.my-profile-chip { min-height: 22px; margin-left: 5px; padding: 0 8px; background: var(--blue); color: #fff; font-size: 11px; font-weight: 700; vertical-align: middle; }
.result-time { flex: 0 0 auto; font-size: 16px; font-weight: 800; }
.medal { display: inline-block; width: 25px; color: var(--text); }

.profile-card, .section-card { margin-bottom: 12px; padding: 14px; }
.profile-card { display: grid; gap: 8px; }
.profile-card .profile-name { font-size: 20px; }
.profile-line { justify-content: space-between; gap: 10px; }
.profile-name { font-size: 18px; font-weight: 800; }
.profile-handle, .link { color: var(--blue-dark); }
.wmm-progress { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 8px; color: var(--text); font-size: 12px; font-weight: 700; }
.wmm-stars { display: inline-flex; gap: 2px; letter-spacing: 0; }
.wmm-star { color: #d5d9dd; font-size: 16px; line-height: 1; }
.wmm-star.is-complete { color: #f4b400; }
.progress-bar { overflow: hidden; height: 7px; border-radius: 10px; background: var(--line); }
.progress-bar span { display: block; width: 64%; height: 100%; border-radius: inherit; background: var(--blue); }
.section-heading { margin-bottom: 8px; }
.section-heading h2 { font-size: 16px; }
.text-button, .primary-button, .secondary-button { min-height: 34px; padding: 0 12px; border-radius: 8px; }
.text-button { background: var(--blue); color: #fff; font-size: 12px; font-weight: 700; }
.secondary-button { background: var(--surface-soft); color: var(--text); }
.primary-button { width: 100%; background: var(--blue); color: #fff; font-weight: 700; }

.progress-filter-row { margin-bottom: 10px; }
.progress-filter-row .chip { border: 1px solid transparent; }
.progress-ranks-toggle { display: inline-flex; align-items: center; gap: 7px; }
.progress-ranks-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); }
.chart-card { overflow: hidden; padding: 12px; }
.chart { width: 100%; height: 178px; }
.chart-gridline { stroke: #e1e6ea; stroke-width: 1; }
.chart-line { fill: none; stroke: var(--red); stroke-linecap: round; stroke-linejoin: round; stroke-width: 3; }
.chart-point { fill: var(--red); }
.chart-point-label { fill: var(--text); font-size: 10px; font-weight: 700; pointer-events: none; }
.chart-axis-label { fill: var(--muted); font-size: 10px; }
.chart-rank-line { stroke-dasharray: 4 3; stroke-width: 1.4; }
.chart-rank-line--target { stroke: var(--blue); }
.chart-rank-line--achieved { stroke: #f5a623; }
.chart-rank-label { font-size: 10px; font-weight: 700; }
.chart-rank-label--target { fill: var(--blue-dark); }
.chart-rank-label--achieved { fill: #d68b00; }
.empty-state { padding: 32px 18px; border-radius: 12px; background: var(--surface); color: var(--muted); text-align: center; }

.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; align-items: end; background: rgb(10 18 25 / 45%); }
.modal { width: min(100%, 620px); max-height: min(86vh, 700px); min-width: 0; margin: 0 auto; overflow: auto; padding: 18px; border-radius: 16px 16px 0 0; background: var(--surface); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.form-grid { display: grid; gap: 12px; }
.form-field { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.form-field input, .form-field select { width: 100%; min-width: 0; min-height: 42px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); color: var(--text); font-size: 16px; }
.form-field legend { padding: 0; }
.form-hint { font-weight: 400; }
.distance-field { gap: 9px; border: 0; padding: 0; }
.distance-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.distance-option { min-height: 30px; padding: 0 11px; border-radius: 999px; background: #eef0f2; color: var(--text); font-size: 12px; }
.distance-option.is-selected,
.distance-option[aria-pressed="true"] { background: var(--blue); color: #fff; }
.detail-distance-picker { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0 6px; }
.detail-distance-list { display: flex; flex-wrap: wrap; gap: 0 9px; margin-top: 12px; color: #fff; font-size: 13px; font-weight: 800; line-height: 1.45; }
.detail-distance-list span:not(:last-child)::after { content: ","; }
.detail-registration-status { margin: 6px 0 10px; }
.detail-action-row { display: flex; flex-wrap: wrap; gap: 8px; }
.danger-button { color: #b42318; }
button:disabled { cursor: not-allowed; opacity: .55; }
.registration-link { display: inline-flex; margin-top: 14px; color: #fff; font-size: 13px; font-weight: 700; text-decoration: underline; }
.modal-actions { display: grid; gap: 8px; margin-top: 18px; }
.detail-hero { margin-bottom: 12px; padding: 18px 14px; border-radius: 12px; background: var(--blue); color: #fff; }
.detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.detail-title-row .secondary-button { flex: 0 0 auto; background: rgb(255 255 255 / 85%); color: var(--text); }
.detail-hero .subtle { color: rgb(255 255 255 / 78%); }
.detail-hero h2 { margin-bottom: 7px; font-size: 21px; }
.toast { position: fixed; right: 14px; bottom: calc(82px + env(safe-area-inset-bottom)); left: 14px; z-index: 20; padding: 12px 14px; border-radius: 10px; background: #15202b; box-shadow: var(--shadow); color: #fff; font-size: 13px; text-align: center; }
[hidden] { display: none !important; }
@media (min-width: 700px) {
  .app-shell { padding-right: 18px; padding-left: 18px; }
  .bottom-nav { border-radius: 16px 16px 0 0; }
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 16px; }
}
