:root {
  --bg: #0b1329;
  --bg-2: #0f1a36;
  --card: #131f3f;
  --card-2: #1a2850;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --primary: #10b981;
  --primary-dark: #059669;
  --cyan: #06b6d4;
  --sky: #38bdf8;
  --amber: #f59e0b;
  --danger: #f87171;
  --text: #f8fafc;
  --muted: #94a3b8;
  --faint: #64748b;
  --nav-h: 64px;
  --nav-space: 100px;
  --radius: 16px;
}

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

html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: var(--primary); }

.i {
  width: 1.25em; height: 1.25em; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* Pages */
.page {
  display: none;
  position: absolute; top: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: 100vh; height: 100dvh;
  flex-direction: column;
  overflow-x: hidden; overflow-y: auto;
  padding-bottom: var(--nav-space);
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(120% 50% at 50% -10%, rgba(16, 185, 129, 0.12), transparent 60%),
    var(--bg);
}
.page.active { display: flex; }
#scan-page { overflow: hidden; padding-bottom: 0; background: #000; }
#profile-page, #settings-page { overscroll-behavior: contain; }
#map-page { overflow: hidden; padding-bottom: 0; }

.app-header {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px 10px;
}
.app-header img { width: 30px; height: 30px; }
.app-header span { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.app-header.overlay {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  padding-bottom: 28px;
  background: linear-gradient(180deg, rgba(11, 19, 41, 0.85), transparent);
}

/* Navigation */
.nav-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(calc(100% - 28px), 420px); height: var(--nav-h);
  padding: 6px; display: flex; gap: 4px;
  background: rgba(19, 31, 63, 0.78);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 10000;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 16px; color: var(--muted);
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.02em;
  transition: color 0.2s, background 0.2s;
}
.nav-item .i { font-size: 1.35rem; }
.nav-item.active { color: var(--primary); background: rgba(16, 185, 129, 0.12); }

/* Scan */
#camera-container { position: absolute; inset: 0; overflow: hidden; background: #000; }
video { width: 100%; height: 100%; object-fit: cover; }
#gallery-preview { display: none; position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; z-index: 2; }
#hidden-canvas { display: none; }

.reticle {
  position: absolute; top: 38%; left: 50%;
  width: 232px; height: 232px; transform: translate(-50%, -50%);
  pointer-events: none; z-index: 3;
  border-radius: 28px;
  box-shadow: 0 0 0 9999px rgba(5, 10, 25, 0.5);
}
.reticle svg { width: 100%; height: 100%; fill: none; stroke: var(--primary); stroke-width: 4; stroke-linecap: round; }

.scan-controls {
  position: absolute; left: 0; right: 0; bottom: 214px; z-index: 4;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 28px;
}
.scan-controls > div:first-child { justify-self: start; }
.scan-controls > div:last-child { justify-self: end; }
.round-btn {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(19, 31, 63, 0.72); border: 1px solid var(--line-strong);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  color: var(--text); font-size: 1.3rem;
}
.round-btn.accent { background: var(--primary); border-color: transparent; }
.camera-button { display: none; }
.capture-button {
  width: 72px; height: 72px; border-radius: 50%;
  border: 4px solid #fff; padding: 5px; background: none;
  transition: transform 0.15s;
}
.capture-button::after { content: ''; display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; }
.capture-button:active { transform: scale(0.92); }

.retry-camera-button {
  display: none; position: absolute; top: 90px; left: 50%; transform: translateX(-50%); z-index: 4;
  padding: 10px 16px; border-radius: 999px; white-space: nowrap;
  background: var(--card); border: 1px solid var(--line-strong); font-weight: 600; font-size: 0.9rem;
}

/* Bottom sheet */
#results-card {
  position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto;
  width: 100%; max-width: 480px; height: 82vh; height: 82dvh;
  padding: 10px 20px 0;
  background: var(--card);
  border-top: 1px solid var(--line-strong);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  z-index: 10;
  transform: translateY(calc(100% - 190px));
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
  touch-action: none;
}
.drag-handle { width: 40px; height: 4px; background: var(--line-strong); border-radius: 99px; margin: 0 auto 16px; cursor: grab; }
.card-content { overflow-y: auto; max-height: calc(82dvh - 40px); padding-bottom: 120px; touch-action: pan-y; }
#status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.92rem; padding: 6px 0; }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 10px; border-radius: 999px; margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
}
.chip::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--bin, var(--faint)); box-shadow: 0 0 10px var(--bin, transparent); }
.label-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; text-transform: capitalize; }
.confidence { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 0.85rem; color: var(--muted); }
.confidence-track { flex: 1; height: 5px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.confidence-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--cyan)); transition: width 0.3s; }

.tip {
  margin-top: 18px; padding: 14px 16px; border-radius: 14px;
  background: rgba(56, 189, 248, 0.07); border: 1px solid rgba(56, 189, 248, 0.18);
  font-size: 0.88rem; color: #cfe9f7;
}
.tip strong { display: flex; align-items: center; gap: 8px; color: var(--sky); font-weight: 600; }
.tip ul { margin: 8px 0 0 18px; padding: 0; display: grid; gap: 4px; }
.note { margin-top: 16px; font-size: 0.85rem; color: var(--muted); line-height: 1.6; }

#contribution-panel { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.thanks { display: flex; align-items: center; gap: 8px; color: var(--primary); font-weight: 600; }

/* Forms and buttons */
.form-container { width: min(100% - 40px, 440px); margin: 0 auto; padding: 8px 0 20px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line-strong);
  font: inherit; font-size: 0.95rem; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18); }
input::placeholder { color: var(--faint); }
select { appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 18px; border-radius: 12px; font-weight: 600; font-size: 0.95rem; width: 100%; transition: background 0.2s, transform 0.1s; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 6px 20px rgba(16, 185, 129, 0.28); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line-strong); }
.btn.danger { color: var(--danger); border: 1px solid rgba(248, 113, 113, 0.35); }
.btn.sm { width: auto; padding: 8px 14px; font-size: 0.8rem; border-radius: 10px; }
.switch-auth { text-align: center; font-size: 0.88rem; color: var(--muted); }
.switch-auth a { font-weight: 600; text-decoration: none; }

/* Profile */
.auth-hero { text-align: center; padding: 28px 20px 18px; }
.auth-hero img { width: 64px; height: 64px; margin-bottom: 14px; }
.auth-hero h2 { font-size: 1.6rem; letter-spacing: -0.02em; }
.auth-hero p { color: var(--muted); margin-top: 4px; }

.profile-header { padding: 18px 20px 8px; text-align: center; }
.avatar-wrap { position: relative; width: 96px; height: 96px; margin: 0 auto 14px; }
.avatar {
  width: 100%; height: 100%; border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--card-2); color: var(--muted); font-size: 2.4rem;
  border: 3px solid var(--bg); outline: 2px solid var(--primary);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-edit {
  position: absolute; right: -2px; bottom: -2px; width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; border: 3px solid var(--bg); font-size: 0.95rem;
}
.profile-header h2 { font-size: 1.4rem; letter-spacing: -0.02em; }
.stats { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.stat { padding: 8px 14px; border-radius: 999px; font-size: 0.82rem; font-weight: 600; background: var(--card); border: 1px solid var(--line); color: var(--muted); }
#user-points { color: var(--primary); }
.section-title { padding: 22px 20px 6px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 10px 20px 20px; }
.badge-card { padding: 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); opacity: 0.55; }
.badge-card.earned { opacity: 1; border-color: rgba(16, 185, 129, 0.4); background: linear-gradient(180deg, rgba(16, 185, 129, 0.1), var(--card)); }
.badge-icon { width: 40px; height: 40px; border-radius: 12px; margin-bottom: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.35rem; background: rgba(255, 255, 255, 0.06); color: var(--muted); }
.badge-card.earned .badge-icon { background: rgba(16, 185, 129, 0.16); color: var(--primary); }
.badge-name { font-weight: 600; font-size: 0.9rem; }
.badge-desc { font-size: 0.74rem; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.profile-actions { padding: 4px 20px 12px; display: grid; gap: 10px; }
.legal { display: block; text-align: center; padding: 8px 20px 24px; font-size: 0.78rem; color: var(--faint); }

/* Settings */
.settings-body { padding: 8px 20px; display: grid; gap: 18px; }
.back-btn { display: inline-flex; align-items: center; gap: 6px; padding: 18px 16px 6px; color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.settings-title { padding: 0 20px; font-size: 1.6rem; letter-spacing: -0.02em; }
.row { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.switch { position: relative; width: 44px; height: 26px; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--card-2); transition: background 0.2s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { transform: translateX(18px); }
.version { text-align: center; font-size: 0.78rem; color: var(--faint); margin-top: 40px; }

/* Map */
.map-toolbar {
  position: absolute; top: 14px; left: 14px; right: 14px; z-index: 1000;
  display: grid; gap: 10px; padding: 12px;
  background: rgba(19, 31, 63, 0.82); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line-strong); border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.map-toolbar-top { display: flex; align-items: center; gap: 10px; }
.map-toolbar-top img { width: 26px; height: 26px; }
.map-toolbar-top h2 { flex: 1; font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
#nearest-collections-button { padding: 8px 12px; border-radius: 10px; font-size: 0.78rem; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; background: var(--primary); color: #fff; white-space: nowrap; }
#map-filter { padding: 10px 36px 10px 12px; font-size: 0.88rem; }
.map-status {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 92px; z-index: 1000;
  max-width: calc(100% - 28px); padding: 7px 14px; border-radius: 999px;
  background: rgba(19, 31, 63, 0.88); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line-strong); color: var(--muted); font-size: 0.78rem; font-weight: 500; text-align: center;
}
#collection-map { position: absolute; inset: 0; background: var(--bg); }

.leaflet-container { background: var(--bg); font-family: inherit; }
.leaflet-tile-pane { filter: invert(1) hue-rotate(195deg) saturate(0.55) brightness(0.92) contrast(0.95); }
.leaflet-bottom.leaflet-left { bottom: 78px; }
.leaflet-control-attribution { background: rgba(11, 19, 41, 0.7) !important; color: var(--faint) !important; font-size: 9px; border-radius: 6px; margin: 0 0 4px 6px !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.tv-popup .leaflet-popup-content-wrapper { background: var(--card); color: var(--text); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); }
.tv-popup .leaflet-popup-tip { background: var(--card); }
.tv-popup .leaflet-popup-content { margin: 14px 16px; font-size: 0.82rem; line-height: 1.5; }
.tv-popup a.leaflet-popup-close-button { color: var(--muted); }
.pop-title { font-weight: 700; font-size: 0.92rem; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.pop-title::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex-shrink: 0; }
.pop-row { color: var(--muted); }
.pop-row b { color: var(--text); font-weight: 500; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--sky); border: 3px solid #fff; box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.6); animation: pulse 2s infinite; }
@keyframes pulse { to { box-shadow: 0 0 0 18px rgba(56, 189, 248, 0); } }

/* Install banner */
.pwa-banner {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px;
  width: calc(100% - 28px); max-width: 420px; z-index: 9999;
  display: flex; flex-direction: column; gap: 12px; padding: 14px 16px;
  background: rgba(19, 31, 63, 0.92); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line-strong); border-radius: 18px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
}
.pwa-banner-content { display: flex; align-items: center; gap: 12px; }
.pwa-banner-logo { width: 42px; height: 42px; border-radius: 12px; background: var(--bg); padding: 6px; }
.pwa-banner-text { display: flex; flex-direction: column; }
.pwa-banner-text strong { font-size: 0.92rem; }
.pwa-banner-text span { font-size: 0.76rem; color: var(--muted); }
.pwa-banner-actions { display: flex; justify-content: flex-end; gap: 8px; }
.pwa-btn-dismiss { padding: 8px 14px; font-size: 0.82rem; font-weight: 500; color: var(--muted); }
.pwa-btn-install { padding: 8px 18px; border-radius: 10px; font-size: 0.82rem; font-weight: 600; background: var(--primary); color: #fff; }
