:root {
  --bg: #1e1e22;
  --bg-light: #2a2a30;
  --bg-elev: #34343c;
  --fg: #f0f0f0;
  --fg-dim: #b0b0b0;
  --border: #444;
  --hsv-blue: #0f3275;
  --hsv-black: #1a1a1a;
  --hsv-white: #ffffff;
  --eu-blue: #003399;
  --eu-yellow: #ffcc00;
  --accent: #003399;
}

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

#map {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 0;
}

.leaflet-container { background: var(--bg); }

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(20, 20, 24, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: max(0.5rem, env(safe-area-inset-top));
}

.brand {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  min-width: 0;
}
.brand-icon {
  width: 28px; height: 28px; border-radius: 6px;
  flex-shrink: 0;
}

.totals {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
  flex-wrap: nowrap;
}

.total-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  white-space: nowrap;
}

.total-chip .dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.4);
}

.view-toggle {
  display: flex;
  background: var(--bg-light);
  border-radius: 999px;
  padding: 2px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.view-toggle button {
  background: transparent; border: 0;
  color: var(--fg-dim);
  padding: 0.3rem 0.7rem;
  font-size: 0.82rem;
  border-radius: 999px;
  cursor: pointer;
}
.view-toggle button.active {
  background: var(--eu-blue);
  color: white;
}

#menu-btn {
  background: var(--bg-light);
  border: 1px solid var(--border);
  color: var(--fg);
  width: 36px; height: 36px;
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* Back-Button (erscheint nur im Land-View) */
.back-btn {
  position: fixed;
  top: calc(0.6rem + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  z-index: 999;
  background: rgba(0, 51, 153, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: white;
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.back-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(48px);
}

/* Bottom-Sheet */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  z-index: 1100;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0.5rem auto;
  flex-shrink: 0;
}
.sheet-content {
  padding: 0.5rem 1rem 1rem;
  overflow-y: auto;
  flex: 1;
}
.sheet-header {
  display: flex; align-items: center;
  margin-bottom: 0.5rem;
}
.sheet h2 { margin: 0; flex: 1; }

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--fg-dim);
  width: 32px; height: 32px;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-light); color: var(--fg); }

/* Stats-Cards: kompakt + klickbar als Filter */
.sheet-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.stat-card {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.stat-card:hover { background: var(--bg-elev); }
.stat-card.selected {
  border-color: var(--eu-yellow);
  background: var(--bg-elev);
}
.stat-card .player-name {
  font-size: 0.8rem;
  color: var(--fg-dim);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.stat-card .player-name .dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.4);
}
.stat-card .stat-value {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 0.2rem;
}
.stat-card .stat-sub {
  font-size: 0.85rem;
  color: var(--fg-dim);
  margin-top: 0.1rem;
}

/* Filter-Tabs */
.sheet-filters {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.2rem;
}
.filter-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg-light);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.filter-tab.active {
  background: var(--eu-blue);
  color: white;
  border-color: var(--eu-blue);
}
.filter-tab .dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.4);
}
.filter-tab .count {
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
  padding: 0 0.4rem;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.sheet-listheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.4rem 0;
  font-size: 0.85rem;
  color: var(--fg-dim);
}
.sort-select {
  background: var(--bg-light);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  font-size: 0.82rem;
}

.activity-list {
  list-style: none;
  padding: 0; margin: 0;
}
.activity-list li {
  padding: 0.5rem 0.3rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  border-radius: 6px;
}
.activity-list li:hover { background: var(--bg-light); }
.activity-list li.selected {
  background: var(--bg-elev);
  border-color: var(--eu-yellow);
}
.activity-list li .dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.4);
}
.activity-list li .a-info {
  flex: 1; min-width: 0;
}
.activity-list li .a-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.activity-list li .a-meta {
  font-size: 0.78rem;
  color: var(--fg-dim);
  margin-top: 0.15rem;
}
.activity-list li .a-dist {
  font-variant-numeric: tabular-nums;
  color: var(--fg-dim);
  font-size: 0.85rem;
  flex-shrink: 0;
}
.strava-link {
  color: #fc4c02;
  text-decoration: none;
  font-size: 0.72rem;
  margin-left: 0.5rem;
  white-space: nowrap;
  border: 1px solid #fc4c02;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}
.strava-link:hover { background: #fc4c02; color: white; }

/* Menü */
.menu {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1200;
  display: none;
}
.menu.open { display: block; }
.menu-inner {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: min(360px, 92vw);
  background: var(--bg);
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  overflow-y: auto;
  border-left: 1px solid var(--border);
}
.menu-inner h2 { margin: 0 0 1rem 0; }
.menu-inner h3 { margin: 1rem 0 0.5rem 0; font-size: 0.95rem; color: var(--fg-dim); }
.menu-inner button, .menu-inner select {
  display: block; width: 100%;
  padding: 0.6rem 0.8rem;
  margin: 0.4rem 0;
  background: var(--bg-light);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}
.menu-inner hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

#sync-status {
  font-size: 0.85rem;
  color: var(--fg-dim);
  margin-top: 0.4rem;
  min-height: 1.2em;
}

.legend {
  list-style: none; padding: 0; margin: 0;
}
.legend li {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.3rem 0;
  font-size: 0.9rem;
}
.legend .swatch {
  width: 18px; height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.3);
}

#me-panel {
  padding: 0.5rem 0;
  font-size: 0.9rem;
  color: var(--fg-dim);
}
#me-panel a {
  display: inline-block;
  margin-top: 0.4rem;
  background: #fc4c02;
  color: white;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  text-decoration: none;
}

/* Mobile-Anpassungen */
@media (max-width: 640px) {
  .brand-text {
    font-size: 0.75rem;
    max-width: 130px;
    white-space: normal;
    line-height: 1.05;
  }
  .totals { gap: 0.25rem; }
  .total-chip { padding: 0.1rem 0.4rem; font-size: 0.75rem; }
  .view-toggle button { padding: 0.25rem 0.55rem; font-size: 0.75rem; }
  .sheet { max-height: 80vh; }
  .stat-card { padding: 0.4rem 0.55rem; }
}
@media (max-width: 380px) {
  .brand-icon { width: 24px; height: 24px; }
  #topbar { padding: 0.4rem 0.5rem; }
}
