:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', 'Menlo', monospace;
  --nav-height: 52px;
  --radius: 12px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg: #FFFFFF;
  --surface: #F2F2F7;
  --surface-hover: #E5E5EA;
  --text: #1a1a1a;
  --text-secondary: #86868b;
  --border: rgba(0, 0, 0, 0.06);
  --glass: rgba(255, 255, 255, 0.82);
  --glass-border: rgba(0, 0, 0, 0.08);
  --accent: #2D7A4F;
  --accent-soft: rgba(45, 122, 79, 0.1);
  --popup-bg: rgba(255, 255, 255, 0.95);
  --loading-bar: #2D7A4F;
  --map-style: positron;
}

[data-theme="majorelle"] {
  --bg: #0C0F1F;
  --surface: #141A35;
  --surface-hover: #1E2750;
  --text: #E8E8ED;
  --text-secondary: #7A7A95;
  --border: rgba(255, 255, 255, 0.06);
  --glass: rgba(12, 15, 31, 0.85);
  --glass-border: rgba(255, 255, 255, 0.08);
  --accent: #6EE7A0;
  --accent-soft: rgba(110, 231, 160, 0.1);
  --popup-bg: rgba(20, 26, 53, 0.95);
  --loading-bar: #6EE7A0;
  --map-style: dark-matter;
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #0A0A0A;
  --surface-hover: #161616;
  --text: #E8E8ED;
  --text-secondary: #555;
  --border: rgba(255, 255, 255, 0.06);
  --glass: rgba(0, 0, 0, 0.85);
  --glass-border: rgba(255, 255, 255, 0.08);
  --accent: #4ADE80;
  --accent-soft: rgba(74, 222, 128, 0.1);
  --popup-bg: rgba(10, 10, 10, 0.95);
  --loading-bar: #4ADE80;
  --map-style: dark-matter;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100dvh;
  transition: background var(--transition), color var(--transition);
}

nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  transition: background var(--transition);
}

.nav-left, .nav-right {
  width: 140px;
}

.nav-right {
  display: flex;
  justify-content: flex-end;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.logo-dot {
  color: var(--accent);
  transition: color var(--transition);
}

.nav-center {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
  transition: background var(--transition);
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.tab:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-hover);
}

.tab.active {
  color: var(--text);
  background: var(--accent-soft);
}

.tab.active svg {
  color: var(--accent);
}

.tab:disabled {
  opacity: 0.35;
  cursor: default;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon,
.theme-toggle .icon-stars {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="majorelle"] .theme-toggle .icon-stars { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

main {
  position: relative;
  width: 100%;
  height: calc(100dvh - var(--nav-height));
  margin-top: var(--nav-height);
}

#map {
  width: 100%;
  height: 100%;
}

.maplibregl-ctrl-attrib {
  font-size: 10px !important;
  opacity: 0.5;
  background: none !important;
}

.maplibregl-ctrl-attrib-button {
  background-color: var(--surface) !important;
}

.maplibregl-ctrl-group {
  background: var(--surface) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: 8px !important;
  box-shadow: none !important;
}

.maplibregl-ctrl-group button {
  background: none !important;
  border-color: var(--border) !important;
}

.maplibregl-ctrl-group button span {
  filter: var(--ctrl-filter, none);
}

[data-theme="majorelle"] { --ctrl-filter: invert(1); }
[data-theme="dark"] { --ctrl-filter: invert(1); }

.loading {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  height: 2px;
  z-index: 99;
  opacity: 1;
  transition: opacity 0.5s ease;
}

.loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-bar {
  height: 100%;
  background: var(--loading-bar);
  border-radius: 1px;
  animation: loading 2s ease-in-out infinite;
  transition: background var(--transition);
}

@keyframes loading {
  0% { width: 0; margin-left: 0; }
  50% { width: 60%; margin-left: 20%; }
  100% { width: 0; margin-left: 100%; }
}

.stats-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--glass-border);
  z-index: 100;
  opacity: 0;
  transform: translateY(100%);
  transition: all var(--transition);
}

.stats-bar.visible {
  opacity: 1;
  transform: translateY(0);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  flex: 1;
  padding: 0 12px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s ease;
}

.stat:active {
  transform: scale(0.95);
}

.stat:last-child {
  border-right: none;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.popup {
  position: fixed;
  z-index: 200;
  padding: 14px 18px;
  background: var(--popup-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 240px;
}

.popup.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.popup-species {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.popup-details {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.popup-details span {
  color: var(--text);
  font-weight: 500;
}

.discover-toggle {
  position: fixed;
  top: calc(var(--nav-height) + 12px);
  left: 12px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 90;
  transition: all var(--transition);
}

.discover-toggle:hover {
  color: var(--text);
  background: var(--surface);
}

.discover-toggle.hidden {
  opacity: 0;
  pointer-events: none;
}

.discover-panel {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  bottom: 0;
  width: 300px;
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid var(--glass-border);
  z-index: 95;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform var(--transition);
  padding-bottom: 80px;
}

.discover-panel.open {
  transform: translateX(0);
}

.discover-panel::-webkit-scrollbar {
  width: 0;
}

.discover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 1;
}

.discover-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.discover-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.discover-close:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.discover-section {
  padding: 8px 12px;
}

.discover-section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 4px 4px 8px;
}

.discover-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-bottom: 2px;
}

.discover-card:hover {
  background: var(--surface-hover);
}

.discover-card:active {
  transform: scale(0.98);
}

.card-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--accent-soft);
}

.card-content {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.species-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  margin-top: 4px;
  overflow: hidden;
}

.species-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width var(--transition);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.sheet-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70dvh;
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
  border-radius: 16px 16px 0 0;
  z-index: 301;
  transform: translateY(100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
}

.sheet.open {
  transform: translateY(0);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  flex-shrink: 0;
}

.sheet-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.sheet-content {
  overflow-y: auto;
  padding: 0 8px 20px;
  flex: 1;
}

.sheet-content::-webkit-scrollbar {
  width: 0;
}

.sheet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  transition: all 0.15s ease;
}

.sheet-row.clickable {
  cursor: pointer;
}

.sheet-row.clickable:hover {
  background: var(--surface-hover);
}

.sheet-row.clickable:active {
  transform: scale(0.98);
}

.sheet-rank {
  width: 24px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.sheet-row .card-content {
  flex: 1;
  min-width: 0;
}

.sheet-row .card-value {
  font-size: 13px;
}

@media (max-width: 640px) {
  .nav-left, .nav-right { width: auto; }
  .tab span { display: none; }
  .tab { padding: 6px 10px; }
  .stat-value { font-size: 16px; }
  .stat-label { font-size: 9px; letter-spacing: 0.5px; }
  .discover-panel { width: 260px; }
}
