:root {
  --bg: #0a0a0d;
  --card: #111116;
  --line: #1f1f2a;
  --line-soft: #181822;
  --fg: #e8e8ee;
  --fg-dim: #8a8a99;
  --fg-faint: #555560;
  --accent: #179BE7;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.brand-stripe { height: 4px; width: 100%; background: var(--accent); }

/* ---------------- Layout: header + (sidebar | map) ---------------- */
/* 100dvh tracks the *visible* viewport on mobile (no clipping behind iOS
   Safari's address/tool bars); 100vh is the fallback for older browsers. */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

header.strip {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px;
  padding: max(12px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  z-index: 1100;
}
header .brand { display: flex; align-items: center; gap: 12px; }
header .brand .logo { height: 26px; width: auto; display: block; }
header .brand .pipe { color: var(--accent); font-weight: 500; }
header .brand .title {
  font-size: 13px; letter-spacing: 0.04em; color: var(--fg); font-weight: 600;
}
header .meta {
  font-family: ui-monospace, monospace;
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--fg-faint); text-align: right;
}

.body { flex: 1; display: flex; min-height: 0; }

/* ---------------- Sidebar ---------------- */
aside {
  width: 340px; flex: 0 0 340px;
  border-right: 1px solid var(--line-soft);
  background: var(--bg);
  display: flex; flex-direction: column; min-height: 0;
}
/* "My Teams" — favorites picked during onboarding, pinned to the top */
.my-teams { padding: 14px 16px 12px; border-bottom: 1px solid var(--line-soft); }
.my-teams[hidden] { display: none; }
.my-teams .row-label {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--fg-faint); margin-bottom: 9px;
}
.mt-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.my-teams .mt-head .row-label { margin-bottom: 0; }
.mt-edit {
  background: none; border: none; cursor: pointer; font-family: inherit;
  color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
}
.mt-edit:hover { text-decoration: underline; }
.mt-pick {
  width: 100%; padding: 10px 12px; border-radius: 10px; cursor: pointer;
  border: 1px dashed var(--line); background: var(--card); color: var(--fg-dim);
  font-family: inherit; font-size: 12.5px; font-weight: 600; text-align: center;
  transition: border-color 0.12s ease, color 0.12s ease;
}
.mt-pick:hover { border-color: var(--accent); color: var(--fg); }
.mt-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mt-chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
  padding: 4px 9px 4px 5px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  font-family: inherit; transition: border-color 0.12s ease, background 0.12s ease;
}
.mt-chip:hover { border-color: var(--accent); background: rgba(23,155,231,0.10); }
.mt-chip .chip-logo { width: 18px; height: 18px; object-fit: contain; }
.mt-chip .chip-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px;
  font-size: 9px; font-weight: 800;
}
.mt-chip .mt-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; margin: -2px -3px -2px 1px; border-radius: 50%;
  font-size: 14px; line-height: 1; color: var(--fg-faint);
}
.mt-chip .mt-x:hover { background: rgba(255,255,255,0.10); color: #ff6b6b; }

.search-box { padding: 14px 16px 10px; border-bottom: 1px solid var(--line-soft); }
.search-box input {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  font-size: 13px; outline: none;
}
.search-box input:focus { border-color: var(--accent); }

.filters { padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.filters .row-label {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--fg-faint); margin-bottom: 8px;
}
.league-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  cursor: pointer; user-select: none;
  font-size: 11px; letter-spacing: 0.06em; font-weight: 600;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg-dim);
  transition: all 0.12s ease;
}
.chip:hover { border-color: var(--fg-faint); color: var(--fg); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

select.team-select {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  font-size: 13px; outline: none; margin-bottom: 12px;
}
select.team-select:last-of-type { margin-bottom: 0; }
select.team-select:focus { border-color: var(--accent); }

.list-head {
  padding: 10px 16px 6px;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--fg-faint);
}
.bar-list { flex: 1; overflow-y: auto; padding: 0 8px 16px; }
.bar-item {
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
}
.bar-item:hover { background: var(--card); border-color: var(--line); }
.bar-item.active { background: rgba(23,155,231,0.10); border-color: var(--accent); }
.bar-item .bi-name { font-weight: 600; font-size: 13.5px; color: var(--fg); }
.bar-item .bi-hood { font-size: 11.5px; color: var(--fg-dim); margin-top: 2px; }
.bar-item .bi-teams { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.empty-note { padding: 24px 16px; color: var(--fg-faint); font-size: 12.5px; font-style: italic; }

/* Team chip (logo + name) used in list + popups */
.team-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em;
  padding: 3px 8px 3px 4px; border-radius: 999px;
  background: rgba(255,255,255,0.04); color: var(--fg);
}
.team-chip .chip-logo { width: 18px; height: 18px; object-fit: contain; display: block; }
.team-chip .dot, .team-chip .chip-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px;
  font-size: 9px; font-weight: 800;
}
.team-chip .lg { color: var(--fg-faint); font-weight: 600; font-size: 9.5px; }

/* ---------------- Map ---------------- */
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #0d0d12; }

/* Map marker badge — white disc so transparent logos read on dark tiles */
.bar-marker {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  cursor: pointer;
}
.bar-marker .marker-logo { width: 26px; height: 26px; object-fit: contain; display: block; }
/* Flag markers: fill the badge as a circular flag, no white disc. */
.bar-marker.flag { background: transparent; border: none; box-shadow: none; }
.bar-marker.flag .marker-logo {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.55);
}
.bar-marker .marker-badge {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  font-size: 10px; font-weight: 800; letter-spacing: -0.02em;
}
.bar-marker .plus {
  position: absolute; top: -6px; right: -6px;
  background: var(--accent); color: #fff;
  font-size: 9px; font-weight: 800; line-height: 1;
  border-radius: 999px; padding: 2px 4px; border: 1.5px solid var(--bg);
}

/* Leaflet popup theming */
.leaflet-popup-content-wrapper {
  background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
}
.leaflet-popup-tip { background: var(--card); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 14px 16px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--fg-dim); }
.popup .p-name { font-weight: 700; font-size: 15px; }
.popup .p-hood { color: var(--accent); font-size: 11px; letter-spacing: 0.04em;
  text-transform: uppercase; margin-top: 2px; }
.popup .p-addr { color: var(--fg-dim); font-size: 12px; margin-top: 6px; }
.popup .p-note { color: var(--fg); font-size: 12.5px; margin-top: 8px; line-height: 1.4; }
.popup .p-teams { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.popup .p-dir {
  display: inline-block; margin-top: 12px; font-size: 11px; font-weight: 600;
  color: var(--accent); text-decoration: none; letter-spacing: 0.04em;
}
.popup .p-dir:hover { text-decoration: underline; }

/* Footer / attribution */
footer.foot {
  position: absolute; z-index: 1000;
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  background: rgba(10,10,13,0.82); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px;
  font-size: 10.5px; color: var(--fg-dim); letter-spacing: 0.03em;
}
footer.foot a { color: var(--accent); text-decoration: none; }
footer.foot .pwr { color: var(--fg-faint); }

/* Floating "Find your team" search over the map */
.map-search {
  position: absolute; z-index: 1100;
  top: 18px; left: 50%; transform: translateX(-50%);
  width: clamp(280px, 44%, 560px);
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px;
  background: linear-gradient(135deg, rgba(23,155,231,0.55), rgba(15,108,170,0.42));
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 2px solid var(--accent);
  border-radius: 999px;
  box-shadow: 0 10px 34px rgba(0,0,0,0.45), 0 0 24px rgba(23,155,231,0.5);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.map-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 10px 34px rgba(0,0,0,0.45), 0 0 0 3px rgba(23,155,231,0.35),
              0 0 26px rgba(23,155,231,0.45);
}
.map-search .ms-icon { color: #fff; flex: none; }
.map-search input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  color: #fff; font-size: 15px; letter-spacing: 0.01em;
  font-family: inherit;
}
.map-search input::placeholder { color: rgba(255,255,255,0.85); }

.count-pill {
  position: absolute; top: 10px; right: 10px; z-index: 1000;
  background: rgba(10,10,13,0.82); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px;
  font-size: 11px; font-weight: 600; color: var(--fg);
}
.count-pill b { color: var(--accent); }

/* ---------------- Mobile ---------------- */
.sidebar-toggle {
  display: none; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--fg);
  background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px;
}
@media (max-width: 760px) {
  aside {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 1200;
    transform: translateX(-100%); transition: transform 0.2s ease;
    width: 86%; max-width: 360px;
    padding-left: env(safe-area-inset-left);
    -webkit-overflow-scrolling: touch;
  }
  aside.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.6); }
  .sidebar-toggle { display: inline-block; padding: 9px 14px; font-size: 13px; }
  header .meta { display: none; }
  .map-search {
    top: 12px; left: 12px; right: 12px; transform: none; width: auto;
    padding: 12px 16px;
  }
  .count-pill { top: 66px; }

  /* iOS zooms the page in when you focus an input smaller than 16px — pin all
     text inputs/selects to 16px on phones to keep the layout stable. */
  .search-box input,
  .map-search input,
  .gate-card input,
  select.team-select { font-size: 16px; }

  /* Dim backdrop behind the slide-in sidebar; tap it to close. */
  .scrim {
    position: fixed; inset: 0; z-index: 1150;
    background: rgba(0,0,0,0.5);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }
}

/* On a desktop-width screen the scrim is never needed. */
.scrim { display: none; }
@media (max-width: 760px) { .scrim { display: block; } }

/* ---------------- Sign-in gate ---------------- */
.gate-overlay {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: rgba(6,6,10,0.74);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.gate-overlay[hidden] { display: none; }
.gate-card {
  position: relative;
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 14px;
  padding: 28px 26px 26px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55);
}
.gate-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; cursor: pointer;
  color: var(--fg-dim); font-size: 22px; line-height: 1;
}
.gate-close:hover { color: var(--fg); }
.gate-title { font-size: 20px; font-weight: 700; color: var(--fg); margin-bottom: 6px; }
.gate-sub { font-size: 13px; color: var(--fg-dim); margin-bottom: 18px; line-height: 1.45; }
.gate-card form { display: flex; flex-direction: column; gap: 10px; }
.gate-card input {
  width: 100%; padding: 11px 13px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  font-size: 14px; outline: none; font-family: inherit;
}
.gate-card input:focus { border-color: var(--accent); }
.gate-error { color: #ff6b6b; font-size: 12px; margin: -2px 0 2px; }
.gate-error[hidden] { display: none; }
.gate-submit {
  margin-top: 4px; padding: 12px 14px; border: none; border-radius: 9px;
  background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: filter 0.15s ease;
}
.gate-submit:hover { filter: brightness(1.08); }

/* ---------------- World Cup toggle (sidebar) ---------------- */
.wc-toggle {
  display: flex; align-items: center; gap: 10px;
  width: calc(100% - 32px); margin: 4px 16px 2px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  color: var(--fg); cursor: pointer; font-family: inherit; text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.wc-toggle:hover { border-color: var(--fg-faint); }
.wc-toggle .wc-emoji { font-size: 20px; line-height: 1; }
.wc-toggle .wc-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.wc-toggle .wc-text b { font-size: 13px; }
.wc-toggle .wc-text small { font-size: 11px; color: var(--fg-dim); }
.wc-switch {
  flex: none; width: 38px; height: 22px; border-radius: 999px;
  background: #2a2a36; position: relative; transition: background 0.15s ease;
}
.wc-knob {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: transform 0.18s ease;
}
.wc-toggle.on { border-color: var(--accent); background: rgba(23,155,231,0.10); }
.wc-toggle.on .wc-switch { background: var(--accent); }
.wc-toggle.on .wc-knob { transform: translateX(16px); }

/* ---------------- Onboarding step 2 — team picker ---------------- */
.gate-card.wide { max-width: 560px; }
.gate-step[hidden] { display: none; }
.pick-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.pick-tab {
  cursor: pointer; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg-dim); font-family: inherit;
}
.pick-tab:hover { color: var(--fg); border-color: var(--fg-faint); }
.pick-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.team-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px; max-height: 46vh; overflow-y: auto; padding: 2px;
  -webkit-overflow-scrolling: touch;
}
.team-tile {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 12px 6px 9px; border-radius: 12px; cursor: pointer; position: relative;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  font-family: inherit; transition: border-color 0.12s ease, background 0.12s ease;
}
.team-tile:hover { border-color: var(--fg-faint); }
.team-tile.sel { border-color: var(--accent); background: rgba(23,155,231,0.12); }
.team-tile.sel::after {
  content: "✓"; position: absolute; top: 4px; right: 7px;
  font-size: 11px; font-weight: 800; color: var(--accent);
}
.tt-logo {
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 40px; border-radius: 9px; background: #fff;
}
.tt-logo .tile-logo { max-width: 38px; max-height: 32px; object-fit: contain; }
.tt-logo .tile-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 32px; padding: 0 6px; border-radius: 7px;
  font-size: 11px; font-weight: 800;
}
.tt-name { font-size: 10.5px; line-height: 1.2; text-align: center; color: var(--fg); }
.pick-actions { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
.pick-actions .gate-submit { flex: 1; margin-top: 0; }
.gate-skip {
  background: none; border: none; color: var(--fg-dim); cursor: pointer;
  font-size: 13px; font-family: inherit; padding: 8px 4px;
}
.gate-skip:hover { color: var(--fg); }
@media (max-width: 760px) {
  .team-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); max-height: 50vh; }
}
