:root {
  --green: #2d6a4f;
  --green-light: #52b788;
  --green-pale: #d8f3dc;
  --gold: #b7791f;
  --gold-light: #f6ad55;
  --gold-pale: #fef3c7;
  --bg: #0f1f17;
  --bg2: #162a1f;
  --bg3: #1e3728;
  --text: #e8f5ee;
  --text2: #9dbfaa;
  --text3: #6a9678;
  --border: rgba(255,255,255,0.08);
  --header-h: 56px;
  --nav-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

#app { display: flex; flex-direction: column; height: 100dvh; }

/* Header */
#header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 10;
}
#header-left { display: flex; align-items: center; gap: 10px; }
.app-icon { font-size: 22px; }
.app-title {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}
#header-stats { display: flex; gap: 8px; }
.stat-pill {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.stat-num {
  font-family: 'Fraunces', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--green-light);
}
.stat-label {
  font-size: 11px;
  color: var(--text3);
}

/* Nav */
#nav {
  height: var(--nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  order: 10;
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text3);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: color 0.2s;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-btn.active { color: var(--green-light); }
.nav-btn svg { transition: stroke 0.2s; }

/* Views */
.view { flex: 1; overflow: hidden; display: none; }
.view.active { display: flex; flex-direction: column; }

/* Map */
#view-map { position: relative; }
#map { width: 100%; height: 100%; }

/* Leaflet dark overrides */
.leaflet-container { background: #0a1a10 !important; }
.leaflet-tile { filter: saturate(0.3) brightness(0.4); }

/* GPS Panel */
#gps-panel {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 8px 8px 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1000;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  white-space: nowrap;
}
#gps-status { display: flex; align-items: center; gap: 8px; }
.gps-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text3);
  transition: background 0.3s;
}
.gps-dot.active { background: var(--green-light); animation: pulse 1.5s infinite; }
.gps-dot.searching { background: var(--gold-light); animation: pulse 0.8s infinite; }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.5;transform:scale(1.3)} }
#gps-text { font-size: 13px; color: var(--text2); }
#gps-btn {
  background: var(--green);
  color: var(--green-pale);
  border: none;
  border-radius: 30px;
  padding: 8px 16px;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
#gps-btn:active { background: var(--green-light); }
#gps-btn.stop { background: #5a2020; color: #ffb3b3; }

/* Location info */
#location-info {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 40px 12px 16px;
  z-index: 1000;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
#location-info.hidden { display: none; }
#info-gemeinde {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
#info-kanton { font-size: 13px; color: var(--text3); margin-top: 2px; }
#info-close {
  position: absolute;
  top: 10px; right: 10px;
  background: var(--bg3);
  border: none;
  color: var(--text3);
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
}

/* Toast */
#toast {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: var(--green-pale);
  border-radius: 30px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  white-space: nowrap;
  transition: opacity 0.3s;
}
#toast.hidden { display: none; }
#toast.kanton { background: var(--gold); color: var(--gold-pale); }

/* Badges View */
#view-badges { overflow-y: auto; }
#badges-content { padding: 20px 16px 24px; }
#badges-content h2 {
  font-family: 'Fraunces', serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  margin-top: 28px;
}
#badges-content h2:first-child { margin-top: 0; }

/* Progress cards */
#progress-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.prog-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.prog-num {
  font-family: 'Fraunces', serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--green-light);
  line-height: 1;
}
.prog-label { font-size: 12px; color: var(--text3); margin-top: 4px; }
.prog-bar {
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
}
.prog-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.8s ease;
  width: 0%;
}
.prog-fill.green { background: var(--green-light); }
.prog-fill.gold { background: var(--gold-light); }
.prog-total { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* Kantone Grid */
#kantone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}
.kanton-badge {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  position: relative;
  transition: border-color 0.3s, background 0.3s;
}
.kanton-badge.partial {
  border-color: var(--gold);
  background: rgba(183,121,31,0.1);
}
.kanton-badge.complete {
  border-color: var(--green-light);
  background: rgba(82,183,136,0.1);
}
.kanton-abbr {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text2);
  display: block;
}
.kanton-badge.partial .kanton-abbr { color: var(--gold-light); }
.kanton-badge.complete .kanton-abbr { color: var(--green-light); }
.kanton-name { font-size: 10px; color: var(--text3); display: block; margin-top: 3px; line-height: 1.2; }
.kanton-prog { font-size: 10px; color: var(--text3); display: block; margin-top: 4px; }
.kanton-badge.complete::after {
  content: '✓';
  position: absolute;
  top: 4px; right: 6px;
  font-size: 10px;
  color: var(--green-light);
}

/* Gemeinden search & list */
#gemeinden-search { margin-bottom: 12px; }
#search-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
}
#search-input::placeholder { color: var(--text3); }
#search-input:focus { outline: none; border-color: var(--green); }

#gemeinden-list { display: flex; flex-direction: column; gap: 6px; }
.gemeinde-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green-light);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s;
}
.gemeinde-item:active { background: var(--bg3); }
.gemeinde-item-name { font-size: 14px; font-weight: 500; color: var(--text); }
.gemeinde-item-kanton { font-size: 12px; color: var(--text3); }
.gemeinde-item-date { font-size: 11px; color: var(--text3); }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text3);
  font-size: 14px;
  line-height: 1.6;
}
.empty-state-icon { font-size: 40px; display: block; margin-bottom: 12px; }

/* Map polygon styles (applied via Leaflet) */
.gemeinde-unvisited { cursor: pointer; }
.gemeinde-visited { cursor: pointer; }

/* Loading */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s;
}
#loading.fade { opacity: 0; pointer-events: none; }
#loading-inner { text-align: center; }
.loading-cross {
  font-size: 60px;
  color: var(--green);
  animation: spin 3s linear infinite;
  display: block;
  margin-bottom: 20px;
}
@keyframes spin { from{transform:rotate(0deg)} to{transform:rotate(360deg)} }
#loading-text {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  color: var(--text);
  margin-bottom: 8px;
}
#loading-sub { font-size: 13px; color: var(--text3); }

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
  background: var(--bg2) !important;
  color: var(--text) !important;
  border-radius: 12px !important;
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5) !important;
}
.leaflet-popup-tip { background: var(--bg2) !important; }
.popup-title {
  font-family: 'Fraunces', serif;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.popup-kanton { font-size: 12px; color: var(--text3); margin-bottom: 10px; }
.popup-btn {
  background: var(--green);
  color: var(--green-pale);
  border: none;
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  width: 100%;
  font-weight: 500;
}
.popup-visited {
  color: var(--green-light);
  font-size: 12px;
  text-align: center;
  margin-top: 6px;
}

/* Manual mark mode info */
#manual-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(45,106,79,0.9);
  color: var(--green-pale);
  border-radius: 30px;
  padding: 6px 16px;
  font-size: 12px;
  z-index: 900;
  white-space: nowrap;
  pointer-events: none;
}
