* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  height: 100vh; overflow: hidden;
  display: flex; flex-direction: column;
  background: #f8fafc; color: #1e293b;
}

/* ── 지도 로딩 오버레이 ── */
#map-loader {
  position: fixed; inset: 0; background: rgba(255,255,255,0.75);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 9000; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  transition: opacity 0.3s ease;
}
#map-loader.fade-out { opacity: 0; pointer-events: none; }
#map-loader .loader-spinner {
  width: 38px; height: 38px;
  border: 3px solid #e5e7eb; border-top-color: #16a34a;
  border-radius: 50%; animation: loader-spin 0.75s linear infinite;
}
#map-loader .loader-text { font-size: 13px; color: #94a3b8; font-weight: 500; }
@keyframes loader-spin { to { transform: rotate(360deg); } }

/* ── 지도 ── */
#marathon-map-wrap { flex: 1; position: relative; }
#marathon-map { width: 100%; height: 100%; }
#map-legend {
  position: absolute; top: 8px; right: 8px;
  background: rgba(255,255,255,0.92); border-radius: 8px;
  padding: 6px 10px; font-size: 11px; z-index: 10;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.legend-item { display: flex; align-items: center; gap: 5px; color: #374151; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid white; box-shadow: 0 1px 2px rgba(0,0,0,0.3); flex-shrink: 0; }

.map-fab {
  position: absolute; z-index: 1000;
  width: 40px; height: 40px; background: white; border: none; border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3); cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.map-fab:hover { background: #f0f0f0; }
.lb-hidden { display: none !important; }
#locate-btn { bottom: 198px; right: 12px; } /* JS가 시트 실측 위치를 매 프레임 추적해서 bottom 갱신 */
.locate-status {
  position: absolute; z-index: 1000; right: 58px; bottom: 198px;
  background: white; padding: 5px 10px; border-radius: 99px;
  font-size: 11px; color: #374151; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  display: none;
}
.locate-status.visible { display: block; }
#locate-btn svg { width: 22px; height: 22px; }

/* ── 바텀시트 ── */
#marathon-sheet {
  position: fixed; bottom: calc(56px + env(safe-area-inset-bottom)); left: 0; right: 0;
  height: calc(100vh - 112px);
  background: #fff; border-radius: 10px 10px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.14);
  z-index: 2000; display: flex; flex-direction: column;
  transform: translateY(50%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
#marathon-sheet.ms-expanded { transform: translateY(56px); }
#marathon-sheet.ms-peek     { transform: translateY(50%); }
#marathon-sheet.ms-min      { transform: translateY(calc(100% - 102px)); }

#sheet-handle-bar {
  flex-shrink: 0; padding: 10px 0 6px;
  display: flex; justify-content: center; cursor: grab; user-select: none;
}
#sheet-handle { width: 36px; height: 4px; background: #d1d5db; border-radius: 2px; }

/* ── 필터 영역 ── */
#sheet-filters { flex-shrink: 0; padding: 0 12px 8px; border-bottom: 1px solid #f1f5f9; }

#search-row { margin-bottom: 8px; }
#search-row input {
  width: 100%; padding: 8px 12px;
  border: 1.5px solid #e2e8f0; border-radius: 8px;
  font-size: 14px; outline: none; background: #f8fafc; color: #111;
}
#search-row input:focus { border-color: #16a34a; background: #fff; }

/* 필터 바: 버튼 + 칩 + 카운트 + 정렬 */
#filter-bar {
  display: flex; align-items: center; gap: 6px; min-height: 32px;
}
#filter-trigger {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; border: 1.5px solid #e2e8f0;
  border-radius: 99px; background: white;
  font-size: 12px; font-weight: 600; color: #374151;
  cursor: pointer; flex-shrink: 0; transition: all 0.15s;
  white-space: nowrap;
}
#filter-trigger.has-filter { border-color: #16a34a; color: #16a34a; }
#filter-trigger:active { background: #f0fdf4; }

#filter-chips {
  display: flex; gap: 5px; flex: 1;
  overflow-x: auto; scrollbar-width: none;
}
#filter-chips::-webkit-scrollbar { display: none; }

.active-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 4px 8px; border-radius: 99px;
  background: #fff1f0; color: #e11d48;
  font-size: 11px; font-weight: 600; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
  border: 1px solid #fecdd3;
  transition: background 0.12s;
}
.active-chip:active { background: #ffe4e6; }
.chip-x { font-size: 13px; line-height: 1; color: #f43f5e; }

#filter-right {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto;
}
#count-label { font-size: 12px; color: #64748b; white-space: nowrap; }
#sort-btn {
  display: flex; align-items: center; gap: 2px;
  font-size: 12px; font-weight: 600; color: #374151;
  border: none; background: none; cursor: pointer; padding: 0;
  white-space: nowrap;
}
#sort-btn:active { color: #16a34a; }

/* ── 리스트 ── */
#race-list {
  flex: 1; overflow-y: auto; padding: 10px 12px 20px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
#race-list::-webkit-scrollbar { width: 4px; }
#race-list::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 2px; }

/* ── 필터 팝업 ── */
#filter-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 3000; opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
#filter-backdrop.visible { opacity: 1; pointer-events: auto; }

#filter-popup {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff; border-radius: 20px 20px 0 0;
  z-index: 3100; display: flex; flex-direction: column;
  max-height: 80vh;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
#filter-popup.visible { transform: translateY(0); }

.fp-handle-bar { padding: 10px 0 4px; display: flex; justify-content: center; }
.fp-handle { width: 36px; height: 4px; background: #d1d5db; border-radius: 2px; }

#fp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px 12px;
}
#fp-title { font-size: 16px; font-weight: 700; color: #0f172a; }
#fp-reset {
  font-size: 13px; color: #64748b; border: none; background: none;
  cursor: pointer; text-decoration: underline; padding: 0;
}
#fp-reset:active { color: #16a34a; }

#fp-body { overflow-y: auto; flex: 1; padding: 0 16px 8px; }
.fp-section { margin-bottom: 20px; }
.fp-section-title {
  font-size: 12px; font-weight: 700; color: #94a3b8;
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.fp-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.fp-chip {
  padding: 7px 14px; border: 1.5px solid #e2e8f0;
  border-radius: 99px; background: white;
  font-size: 13px; font-weight: 500; color: #475569;
  cursor: pointer; transition: all 0.15s;
}
.fp-chip.active {
  background: #f0fdf4; color: #16a34a;
  border-color: #16a34a; font-weight: 700;
}
.fp-months { gap: 6px; }
.fp-months .fp-chip { padding: 6px 12px; font-size: 12px; }

#fp-footer {
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  border-top: 1px solid #f1f5f9;
}
#fp-apply {
  width: 100%; padding: 14px;
  background: #16a34a; color: white;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: background 0.15s;
}
#fp-apply:active { background: #15803d; }

.race-card { cursor: pointer; }
.race-card:active { background: #f8fafc; }

/* ── 카드 ── */
.race-card {
  background: white; border: 1px solid #e2e8f0;
  border-radius: 12px; padding: 12px 14px;
  display: flex; gap: 12px; align-items: flex-start;
  transition: box-shadow 0.15s, border-color 0.3s;
}
.race-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,0.08); }
.race-card.closed { background: #f8fafc; }
.race-card.highlighted { border-color: #16a34a; box-shadow: 0 0 0 2px rgba(22,163,74,0.2); }
.race-date { min-width: 52px; text-align: center; }
.race-date .month  { font-size: 10px; color: #64748b; font-weight: 500; }
.race-date .day    { font-size: 20px; font-weight: 800; line-height: 1.1; color: #16a34a; }
.race-date .weekday{ font-size: 10px; color: #64748b; }
.race-info { flex: 1; min-width: 0; }
.race-name { font-size: 14px; font-weight: 700; color: #0f172a; margin-bottom: 4px; line-height: 1.35; }
.race-meta { font-size: 11px; color: #64748b; display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 4px; }
.badge { display: inline-block; padding: 2px 7px; border-radius: 99px; font-size: 10px; font-weight: 600; }
.badge-open   { background: #dcfce7; color: #15803d; }
.badge-closed { background: #f1f5f9; color: #64748b; }
.badge-soon   { background: #fef3c7; color: #92400e; }
.dist-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.dist-tag { padding: 2px 6px; background: #f0fdf4; color: #16a34a; border-radius: 4px; font-size: 10px; font-weight: 600; }
.race-link {
  align-self: center; padding: 5px 10px;
  border-radius: 7px; font-size: 11px; font-weight: 600;
  text-decoration: none; white-space: nowrap; transition: all 0.15s;
}
.race-link.apply  { background: #f0fdf4; color: #16a34a; border: 1px solid #86efac; }
.race-link.apply:hover { background: #16a34a; color: white; }
.race-link.detail { background: #f8fafc; color: #64748b; border: 1px solid #cbd5e1; }
.race-link.detail:hover { background: #e2e8f0; }

.loading { text-align: center; padding: 40px 20px; color: #94a3b8; font-size: 14px; }
.error   { text-align: center; padding: 40px 20px; color: #dc2626; font-size: 13px; }
