* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  background: #111;
  color: #fff;
}

/* Stats bar */
#statsBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#infoBtn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.3);
  background: none;
  color: rgba(255,255,255,0.6);
  font-size: 14px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer;
  flex-shrink: 0;
}

#hideBirdsBtn {
  padding: 4px 10px;
  border-radius: 14px;
  border: 1.5px solid rgba(255,255,255,0.2);
  background: none;
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

#hideBirdsBtn.active {
  background: rgba(78, 205, 196, 0.2);
  border-color: rgba(78, 205, 196, 0.4);
  color: #4ecdc4;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: #4ecdc4;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Search bar */
#searchWrap {
  position: fixed;
  top: calc(max(8px, env(safe-area-inset-top)) + 56px);
  left: 12px;
  right: 12px;
  z-index: 1002;
}

#searchBox {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 0 12px;
  height: 44px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

#searchIcon {
  flex-shrink: 0;
  opacity: 0.5;
}

#searchInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 16px;
  font-family: inherit;
  height: 40px;
  line-height: 40px;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;
}

#searchInput::placeholder {
  color: rgba(255,255,255,0.4);
}

#searchClear {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 22px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

#searchResults {
  margin-top: 4px;
  background: rgba(15, 15, 15, 0.82);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  overflow: hidden;
  max-height: 50vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.search-result:last-child { border-bottom: none; }

.search-result:active {
  background: rgba(255,255,255,0.08);
}

.search-result img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-meta {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
}

.search-no-results {
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: rgba(255,255,255,0.4);
}

/* Species filter cards */
#filterCards {
  position: fixed;
  top: calc(max(8px, env(safe-area-inset-top)) + 104px);
  left: 12px;
  right: 12px;
  z-index: 1001;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}

#filterCards::-webkit-scrollbar { display: none; }

.filter-card {
  flex-shrink: 0;
  width: 80px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  position: relative;
}

.filter-card img {
  width: 80px;
  height: 60px;
  object-fit: cover;
  display: block;
}

.filter-card-name {
  font-size: 10px;
  font-weight: 500;
  color: #fff;
  text-align: center;
  padding: 4px 4px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-card-close {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  border: none;
  color: #fff;
  font-size: 13px;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}

/* Map */
#map {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Hide default leaflet controls on mobile */
.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
  font-size: 8px !important;
  background: rgba(0,0,0,0.5) !important;
  color: rgba(255,255,255,0.5) !important;
}
.leaflet-control-attribution a { color: rgba(255,255,255,0.6) !important; }

/* Layer toggle button */
#layerToggle {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  right: 16px;
  z-index: 1001;
  width: 44px;
  height: 44px;
  border-radius: 22px;
  border: none;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

#layerMenu {
  position: fixed;
  bottom: calc(max(24px, env(safe-area-inset-bottom)) + 52px);
  right: 16px;
  z-index: 1001;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

#layerMenu label {
  font-size: 14px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

#layerMenu label {
  font-size: 13px;
}

#layerMenu input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #4ecdc4;
}

.layer-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255,255,255,0.3);
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.layer-section-title:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

#tagFilterBtns {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255,255,255,0.06);
}

.tag-filter-btn {
  flex: 1;
  padding: 5px 8px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.tag-filter-btn.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

/* Info modal */
#infoModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#infoContent {
  background: rgba(20, 20, 20, 0.97);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  color: #fff;
}

#infoClose {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

#infoContent h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

#infoContent h3 {
  font-size: 14px;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 16px 0 8px;
}

#infoContent p {
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255,255,255,0.7);
  margin-bottom: 8px;
}

#infoContent ul {
  font-size: 13px;
  line-height: 1.6;
  color: rgba(255,255,255,0.7);
  padding-left: 18px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
}

.legend-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  margin: 0 4px;
}

.legend-cluster {
  width: 24px !important;
  height: 24px !important;
  font-size: 10px !important;
}

/* Bottom sheet */
#bottomSheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1002;
  background: rgba(20, 20, 20, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px 16px 0 0;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: transform 0.3s ease;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

#bottomSheet.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

#sheetHandle {
  width: 36px;
  height: 4px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  margin: 8px auto;
}

#sheetContent {
  padding: 0 16px 16px;
}

#sheetHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

#sheetTitle {
  font-size: 18px;
  font-weight: 600;
}

#sheetClose {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 28px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

/* Weather row */
#wxRow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  margin-bottom: 16px;
}

#wxIcon {
  width: 48px;
  height: 48px;
}

#wxInfo {
  flex: 1;
}

#wxCondition {
  font-size: 14px;
  color: rgba(255,255,255,0.8);
}

#wxTemp {
  font-size: 22px;
  font-weight: 700;
}

#wxWind {
  text-align: right;
}

#wxWindDir {
  font-size: 14px;
  color: rgba(255,255,255,0.6);
}

#wxWindSpeed {
  font-size: 14px;
  font-weight: 600;
}

#wxForecastRow {
  display: flex;
  align-items: flex-end;
  gap: 0;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

#wxForecastRow::-webkit-scrollbar { display: none; }

.wind-day-sep {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255,255,255,0.35);
  padding: 0 6px;
  white-space: nowrap;
  align-self: center;
  border-left: 1px solid rgba(255,255,255,0.12);
  margin-left: 2px;
  padding-left: 6px;
}

.wind-day-sep:first-child {
  border-left: none;
  margin-left: 0;
  padding-left: 0;
}

.wind-hour {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 14px;
}

.wind-time {
  font-size: 8px;
  color: rgba(255,255,255,0.35);
  margin-bottom: 1px;
  white-space: nowrap;
}

.wind-arrow {
  font-size: 14px;
  line-height: 1;
  display: inline-block;
  transform-origin: center;
}

/* Bird list */
#sheetBody h4 {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

#birdList {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bird-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
}

.bird-row img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}

.bird-info {
  flex: 1;
}

.bird-name {
  font-size: 14px;
  font-weight: 500;
}

.bird-time {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
}

/* Station tabs */
#stationTabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255,255,255,0.06);
}

.station-tab {
  flex: 1;
  padding: 8px 0;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.station-tab.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

/* Yard list */
#yardSortBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

#yardCount {
  font-size: 13px;
  color: rgba(255,255,255,0.5);
}

#yardSortBtns {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255,255,255,0.06);
}

.yard-sort {
  padding: 4px 8px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}

.yard-sort.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

#yardTagCount {
  font-size: 12px;
  color: rgba(255,255,255,0.35);
  margin-bottom: 10px;
}

#yardList {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.yard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
}

.yard-row img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.yard-info {
  flex: 1;
  min-width: 0;
}

.yard-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.yard-meta {
  font-size: 10px;
  color: rgba(255,255,255,0.35);
}

.yard-count {
  font-size: 14px;
  font-weight: 700;
  color: #4ecdc4;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

/* Tag view */
#tagView {
  padding: 4px 0;
}

#tagView .tag-field {
  margin-bottom: 12px;
}

#tagView .tag-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgba(255,255,255,0.4);
  margin-bottom: 2px;
}

#tagView .tag-value {
  font-size: 16px;
}

/* Tag timeline player */
#tagTimeline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  margin-top: 12px;
}

#tagPlayBtn {
  background: none;
  border: none;
  color: #4ecdc4;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

#tagSlider {
  flex: 1;
  accent-color: #ff6b6b;
  height: 4px;
}

#tagTimeLabel {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  min-width: 60px;
  text-align: right;
  white-space: nowrap;
}

/* Cluster icons */
.cluster-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  width: 36px;
  height: 36px;
}

.station-cluster {
  background: rgba(78, 205, 196, 0.8);
  border: 2px solid rgba(78, 205, 196, 0.4);
  box-shadow: 0 0 6px rgba(78, 205, 196, 0.3);
}

.tag-cluster {
  background: rgba(255, 107, 107, 0.8);
  border: 2px solid rgba(255, 107, 107, 0.4);
  box-shadow: 0 0 6px rgba(255, 107, 107, 0.3);
}

/* Hide default markercluster styles */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: none !important;
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: none !important;
}

/* Offline terra marker */
.terra-offline {
  filter: grayscale(1) opacity(0.45) !important;
}

/* Track arrow */
.track-arrow {
  color: #ff6b6b;
  font-size: 12px;
  text-shadow: 0 0 3px rgba(0,0,0,0.8);
}

/* Custom popup override */
.leaflet-popup.custom-popup .leaflet-popup-content-wrapper {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  -webkit-transform: translateZ(0);
}
.leaflet-popup.custom-popup .leaflet-popup-content {
  margin: 0 !important;
  padding: 0 !important;
  width: auto !important;
  min-width: 80px;
}
.leaflet-popup.custom-popup .leaflet-popup-tip-container { display: none !important; }
.leaflet-popup.custom-popup { background: transparent !important; border: none !important; box-shadow: none !important; }

/* Hidden utility */
.hidden { display: none !important; }

/* Desktop adjustments */
@media (min-width: 768px) {
  #statsBar {
    justify-content: center;
    gap: 48px;
  }
  .stat-value { font-size: 20px; }
  .stat-label { font-size: 11px; }

  #bottomSheet {
    left: 16px;
    right: auto;
    width: 360px;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
  }
}
