:root {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --surface2: #273549;
  --border:   #334155;
  --accent:   #f59e0b;
  --accent2:  #fbbf24;
  --success:  #22c55e;
  --danger:   #ef4444;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --radius:   12px;
  --tab-h:    60px;
  --float-h:  64px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

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

/* ── Setup overlay ── */
#setup-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#setup-overlay.hidden { display: none; }

.setup-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 20px;
}
.splash-hero {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 0 4px;
}
.splash-icon { font-size: 2.8rem; line-height: 1; }
.setup-card h1 { font-size: 1.6rem; font-weight: 900; text-align: center; }
.setup-card .subtitle { color: var(--muted); font-size: 0.85rem; text-align: center; }

.setup-switch-hint {
  text-align: center; font-size: 0.82rem; color: var(--muted); margin-top: 4px;
}
.setup-link {
  background: none; border: none; color: var(--accent);
  font-size: 0.82rem; font-weight: 700; cursor: pointer; padding: 0;
  text-decoration: underline; text-underline-offset: 2px;
}

.setup-panel { display: none; flex-direction: column; gap: 12px; }
.setup-panel.active { display: flex; }

label { font-size: 0.85rem; color: var(--muted); }
.label-hint { font-weight: 400; font-size: 0.78rem; color: var(--border); }

input[type=text], input[type=password] {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px;
  color: var(--text); font-size: 1rem; width: 100%;
  outline: none;
}
input[type=text]:focus, input[type=password]:focus { border-color: var(--accent); }

.field-hint { font-size: 0.8rem; min-height: 1rem; }
.field-hint.ok    { color: var(--success); }
.field-hint.error { color: var(--danger); }

.pin-input {
  text-align: center; letter-spacing: 0.4em;
  font-size: 1.4rem; font-family: monospace;
}

.avatar-name-row {
  display: flex; align-items: center; gap: 12px;
}
.avatar-name-row input { flex: 1; }
.avatar-preview {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--surface2); border: 2px solid var(--border);
  flex-shrink: 0; transition: opacity 0.2s;
}

.btn {
  padding: 14px 20px; border-radius: 10px; border: none;
  font-size: 1rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:active { opacity: 0.85; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:active { background: var(--surface2); }
.btn-danger { background: var(--danger); color: #fff; }

/* ── Main layout ── */
#app { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#app.hidden { display: none; }

.tab-content {
  flex: 1; overflow-y: auto; padding: 16px;
  display: none;
}
.tab-content.active { display: block; }

/* ── Bottom nav ── */
.bottom-nav {
  height: var(--tab-h); flex-shrink: 0;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: transparent; border: none;
  color: var(--muted); font-size: 0.65rem; font-weight: 600;
  cursor: pointer; gap: 3px;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--accent); }

/* ── Home Tab ── */
.home-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.home-title { font-size: 1.1rem; font-weight: 800; }

.home-period-toggle { display: flex; gap: 4px; }
.home-period-btn {
  padding: 6px 13px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-size: 0.78rem; font-weight: 700; cursor: pointer;
}
.home-period-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

.home-stats-row {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 12px;
}
.home-stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 12px; text-align: center;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.home-stat-card:not([onclick]) { cursor: default; }
.home-stat-card.active { border-color: var(--accent); background: #1a1200; }
.home-stat-val { font-size: 2.2rem; font-weight: 800; color: var(--accent); line-height: 1; }
.home-stat-label { font-size: 0.72rem; color: var(--muted); margin-top: 5px; text-transform: uppercase; letter-spacing: 0.06em; }
.home-stat-hint { font-size: 0.65rem; color: var(--border); margin-top: 3px; }

.home-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 16px 0 10px; cursor: pointer;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em;
  color: var(--muted); text-transform: uppercase;
}
.home-section-header:active { opacity: 0.7; }
.home-section-more { color: var(--accent); font-size: 0.72rem; letter-spacing: 0; text-transform: none; font-weight: 600; }

.home-top3 { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.home-top3::-webkit-scrollbar { display: none; }
.top3-chip {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 10px;
}
.top3-chip.is-me { border-color: var(--accent); background: #1a1200; }
.top3-medal { font-size: 0.9rem; }
.top3-avatar { width: 22px; height: 22px; border-radius: 50%; }
.top3-name { font-size: 0.8rem; font-weight: 700; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top3-count { font-size: 0.85rem; font-weight: 800; color: var(--accent); }

.feed-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 8px;
}
.feed-item.is-mine { border-color: var(--accent); background: #1a1200; }
.feed-info { flex: 1; min-width: 0; }
.feed-name { font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; }
.feed-plate { font-size: 0.92rem; font-weight: 700; }
.feed-code { font-family: monospace; color: var(--accent); margin-right: 4px; }
.feed-time { font-size: 0.7rem; color: var(--border); flex-shrink: 0; text-align: right; }

/* ── Legacy Stats styles (kept for profile tab) ── */
.stats-page-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
}
.stats-display-name { font-weight: 800; font-size: 1.1rem; }
.stats-subtitle { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }

.stat-cards {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-bottom: 24px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 8px; text-align: center;
}
.stat-val { font-size: 1.9rem; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 0.68rem; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.06em; }

.recent-plate {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 8px;
}
.recent-code { font-weight: 800; font-size: 1rem; min-width: 40px; font-family: monospace; color: var(--text); }
.recent-name { flex: 1; font-size: 0.88rem; color: var(--muted); }
.recent-time { font-size: 0.72rem; color: var(--border); }

/* ── Floating Controls ── */
.floating-controls {
  flex-shrink: 0; height: var(--float-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 15;
}

.float-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; width: 58px; height: 46px; flex-shrink: 0;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); cursor: pointer;
  font-size: 0.6rem; font-weight: 700;
}
.float-btn svg { width: 18px; height: 18px; }
#voice-btn.listening { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.2s infinite; }
#camera-btn.active { background: var(--success); color: #fff; border-color: var(--success); }

.float-search-btn {
  flex: 1; height: 46px;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 14px;
  color: var(--muted); font-size: 0.9rem; cursor: pointer;
  text-align: left;
}
.float-search-btn svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); }
.float-search-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.7} }

/* ── Plate Overlay ── */
.plate-overlay {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: calc(var(--tab-h) + var(--float-h));
  background: var(--bg);
  z-index: 20;
  display: flex; flex-direction: column;
  transform: translateY(100vh);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.plate-overlay.open { transform: translateY(0); }

.overlay-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px 10px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.overlay-search-wrap {
  flex: 1; position: relative;
}
.overlay-search-wrap svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--muted); pointer-events: none;
}
.overlay-search-wrap input {
  width: 100%; padding: 10px 12px 10px 36px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.95rem; outline: none;
}
.overlay-search-wrap input:focus { border-color: var(--accent); }
.overlay-close {
  width: 36px; height: 36px; flex-shrink: 0;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 50%; color: var(--muted); cursor: pointer;
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
}
.overlay-body {
  flex: 1; overflow-y: auto; padding: 4px 16px 24px;
}

.state-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}
.state-btn {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: pointer; min-height: 60px; justify-content: center;
}
.state-btn:active { transform: scale(0.96); }
.state-btn .code { font-size: 1.1rem; font-weight: 800; }
.state-btn .pts { font-size: 0.65rem; color: var(--muted); }
.state-btn.spotted { background: #052e16; border-color: var(--success); }
.state-btn.spotted .code { color: var(--success); }
.state-btn.canada { background: #1c1033; border-color: #7c3aed; }
.state-btn.canada.spotted { background: #2e1065; border-color: #a78bfa; }
.state-btn.canada.spotted .code { color: #a78bfa; }

/* ── State list (search overlay rows) ── */
.state-list { display: flex; flex-direction: column; gap: 6px; }
.state-list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer; width: 100%; text-align: left;
  color: var(--text);
  transition: opacity 0.15s;
}
.state-list-item:active { opacity: 0.75; }
.sli-code {
  font-family: monospace; font-weight: 800; font-size: 0.9rem;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 8px; min-width: 42px;
  text-align: center; flex-shrink: 0;
}
.sli-name { font-size: 0.92rem; font-weight: 600; }
.state-list-item.spotted .sli-code { background: #052e16; border-color: var(--success); color: var(--success); }
.state-list-item.spotted .sli-name { color: var(--success); }
.state-list-item.canada .sli-code { background: #1c1033; border-color: #7c3aed; color: #a78bfa; }
.state-list-item.canada.spotted .sli-code { background: #2e1065; border-color: #a78bfa; }

/* ── Section header ── */
.section-header {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em;
  color: var(--muted); text-transform: uppercase;
  margin: 16px 0 10px;
}

/* ── PWA Install Banner ── */
.install-banner {
  position: fixed; bottom: calc(var(--tab-h) + 8px); left: 12px; right: 12px; z-index: 90;
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: slideUp 0.3s ease;
}
.install-banner.hidden { display: none; }
.install-banner-text { flex: 1; font-size: 0.85rem; line-height: 1.35; display: flex; align-items: center; gap: 8px; }
.install-banner-icon { font-size: 1.3rem; flex-shrink: 0; }
.install-banner-btns { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.install-banner-btn {
  background: var(--accent); color: #000; border: none;
  border-radius: 8px; padding: 7px 16px; font-size: 0.85rem; font-weight: 700; cursor: pointer;
}
.install-banner-dismiss {
  background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: 4px;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Toast ── */
#toast {
  position: fixed; bottom: calc(var(--tab-h) + var(--float-h) + 12px); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 20px; font-size: 0.9rem; font-weight: 600;
  pointer-events: none; opacity: 0; transition: all 0.25s;
  white-space: nowrap; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { border-color: var(--success); color: var(--success); }
#toast.error { border-color: var(--danger); color: var(--danger); }

/* ── Leaderboard ── */
.lb-overlay-stats {
  display: flex; gap: 12px; margin-bottom: 16px;
}
.lb-overlay-stat {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.lb-overlay-stat span { font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.lb-overlay-stat small { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.period-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.period-tab {
  flex: 1; padding: 9px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); font-size: 0.8rem; font-weight: 700; cursor: pointer;
}
.period-tab.active { background: var(--accent); color: #000; border-color: var(--accent); }

.player-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 8px; cursor: pointer;
}
.player-rank { font-size: 1.2rem; width: 28px; text-align: center; flex-shrink: 0; }
.player-info { flex: 1; min-width: 0; }
.player-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-sub { font-size: 0.8rem; color: var(--muted); }
.player-pts { font-size: 1.4rem; font-weight: 800; color: var(--accent); }
.player-row.is-me { border-color: var(--accent); background: #1a1200; }

.player-detail {
  flex: 0 0 100%; display: none;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
}
.player-row.expanded .player-detail { display: block; }
.state-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.state-tag {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 8px;
  font-size: 0.75rem; font-weight: 700; color: var(--text);
  font-family: monospace; letter-spacing: 0.03em;
}

.avatar-sm {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface2); flex-shrink: 0;
}

.family-stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.family-stat-label { color: var(--muted); font-size: 0.85rem; }
.family-stat-val { font-size: 1.8rem; font-weight: 800; color: var(--accent); }

/* ── US SVG Map ── */
#us-svg-map { margin-top: 12px; }
#us-svg { display: block; width: 100%; }

#us-svg path.state,
#us-svg .state path {
  fill: #1e293b !important;
  stroke: #334155 !important;
  stroke-width: 0.75 !important;
  stroke-opacity: 1 !important;
  fill-opacity: 1 !important;
  cursor: pointer;
  transition: fill 0.15s;
}
#us-svg path.state:hover,
#us-svg .state:hover path { fill: #273549 !important; }
#us-svg path.state.spotted,
#us-svg .state.spotted path {
  fill: #052e16 !important;
  stroke: #22c55e !important;
}
#us-svg path.state.spotted:hover,
#us-svg .state.spotted:hover path { fill: #063a1d !important; }

/* ── Canada SVG Map ── */
#ca-svg-map { margin-top: 12px; }
#ca-svg { display: block; width: 100%; }

#ca-svg path.ca-province,
#ca-svg .ca-province path {
  fill: #1c1033 !important;
  stroke: #4b5563 !important;
  stroke-width: 1 !important;
  stroke-opacity: 1 !important;
  fill-opacity: 1 !important;
  cursor: pointer;
  transition: fill 0.15s;
}
#ca-svg path.ca-province:hover,
#ca-svg .ca-province:hover path { fill: #26164a !important; }
#ca-svg path.ca-province.spotted,
#ca-svg .ca-province.spotted path {
  fill: #2e1065 !important;
  stroke: #a78bfa !important;
}
#ca-svg path.ca-province.spotted:hover,
#ca-svg .ca-province.spotted:hover path { fill: #3b1a7a !important; }

/* ── SVG state/province labels ── */
.state-label {
  font-size: 10px;
  font-weight: 700;
  fill: #94a3b8;
  pointer-events: none;
  user-select: none;
}

/* ── State Detail Drawer ── */
#state-drawer-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.55);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
#state-drawer-backdrop.open { opacity: 1; pointer-events: auto; }

#state-drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 82vh;
  overflow-y: auto;
}
#state-drawer.open { transform: translateY(0); }

.drawer-handle {
  width: 36px; height: 4px;
  background: var(--border); border-radius: 2px;
  margin: 12px auto 0;
  flex-shrink: 0;
}
#state-drawer-content { padding: 16px 20px 36px; }

.drawer-state-name {
  font-size: 1.7rem; font-weight: 800;
  margin: 6px 0 4px;
}
.drawer-rarity {
  font-size: 0.82rem; color: var(--muted); margin-bottom: 4px;
}
.drawer-my-badge {
  display: inline-block;
  background: #1a1200; border: 1px solid var(--accent);
  border-radius: 6px; padding: 3px 10px;
  font-size: 0.78rem; font-weight: 700; color: var(--accent);
  margin-bottom: 4px;
}

.drawer-section-label {
  font-size: 0.68rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin: 18px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.drawer-first-row {
  display: flex; align-items: center; gap: 10px;
}
.drawer-first-row .spotter-name { font-weight: 700; font-size: 0.95rem; }
.drawer-first-row .spotter-date { font-size: 0.78rem; color: var(--muted); }

.drawer-top3 { display: flex; flex-direction: column; gap: 10px; }
.drawer-top3-row { display: flex; align-items: center; gap: 10px; }
.drawer-medal { font-size: 1.1rem; width: 22px; flex-shrink: 0; }
.drawer-bar-wrap { flex: 1; height: 6px; background: var(--surface2); border-radius: 3px; }
.drawer-bar { height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.4s; }
.drawer-bar.ca { background: #7c3aed; }
.drawer-bar-count { font-size: 0.85rem; font-weight: 800; color: var(--accent); min-width: 20px; text-align: right; }
.drawer-bar-count.ca { color: #a78bfa; }
.drawer-spotter-name { font-size: 0.88rem; font-weight: 700; min-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.drawer-timeline { display: flex; flex-direction: column; gap: 8px; }
.drawer-tl-item { display: flex; align-items: center; gap: 8px; }
.drawer-tl-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); flex-shrink: 0; }
.drawer-tl-dot.mine { background: var(--accent); }
.drawer-tl-name { font-size: 0.85rem; font-weight: 600; flex: 1; }
.drawer-tl-date { font-size: 0.72rem; color: var(--muted); }

.drawer-unspotted {
  text-align: center; color: var(--muted);
  padding: 28px 0 8px; font-size: 0.9rem;
}

/* ── Map / tracker ── */
.geo-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 3px;
  font-size: 0.6rem;
}
.geo-cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: 5px 2px;
  text-align: center; font-weight: 700;
  min-height: 36px; display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.geo-cell.empty { background: transparent; border-color: transparent; pointer-events: none; }
.geo-cell.spotted { background: #052e16; border-color: var(--success); color: var(--success); }
.geo-cell.ca-spotted { background: #2e1065; border-color: #a78bfa; color: #a78bfa; }


.progress-bar-wrap { margin: 20px 0 8px; }
.progress-label { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 6px; }
.progress-label span:last-child { color: var(--accent); font-weight: 700; }
.progress-bar { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.4s; }
.progress-fill.ca { background: #7c3aed; }

/* ── Scrapbook ── */
.photo-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
.photo-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; cursor: pointer;
}
.photo-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.photo-card-info { padding: 8px 10px; }
.photo-card-code { font-weight: 800; font-size: 1rem; }
.photo-card-meta { font-size: 0.7rem; color: var(--muted); }

.no-photos {
  text-align: center; color: var(--muted); padding: 48px 24px;
  font-size: 0.9rem;
}

/* ── Profile tab ── */
.profile-hero {
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 16px 20px; gap: 10px;
}
.avatar-lg {
  width: 96px; height: 96px; border-radius: 50%;
  background: var(--surface2); border: 3px solid var(--accent);
}
.profile-name-view {
  display: flex; align-items: center; gap: 10px;
}
.profile-display-name { font-size: 1.4rem; font-weight: 800; }
.edit-name-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 12px;
  color: var(--muted); font-size: 0.8rem; cursor: pointer;
}
.edit-name-btn:active { background: var(--surface); }
.profile-name-edit {
  display: none; width: 100%; flex-direction: column; gap: 8px;
}
.username-tag { color: var(--muted); font-size: 0.85rem; }

.profile-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; margin-bottom: 12px;
}
.profile-card h3 { margin-bottom: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.stat-row span:first-child { color: var(--muted); font-size: 0.9rem; }
.stat-row span:last-child { font-weight: 700; }

.family-code-display {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px;
  font-size: 1.4rem; font-weight: 800; letter-spacing: 0.15em;
  text-align: center; margin: 8px 0; color: var(--accent);
}

/* ── Loading / spinner ── */
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--surface2);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite; margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Photo lightbox ── */
#lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.9);
  display: none; align-items: center; justify-content: center; flex-direction: column;
  gap: 16px; padding: 24px;
}
#lightbox.show { display: flex; }
#lightbox img { max-width: 100%; max-height: 70vh; border-radius: 12px; }
#lightbox .lb-info { color: var(--text); text-align: center; }
#lightbox .lb-close {
  position: absolute; top: 20px; right: 20px;
  background: var(--surface); border: none; border-radius: 50%;
  width: 40px; height: 40px; color: var(--text); font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ── How to play ── */
.rules-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.rules-list li {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
  font-size: 0.9rem; line-height: 1.5;
}
.rules-list li strong { color: var(--accent); }

/* ── Camera preview ── */
#camera-preview {
  position: fixed; inset: 0; z-index: 150;
  background: #000;
  display: none; flex-direction: column;
}
#camera-preview.show { display: flex; }
#camera-preview video { flex: 1; object-fit: cover; }
#camera-preview .cam-bar {
  display: flex; gap: 12px;
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  background: var(--bg); align-items: center; justify-content: center;
  flex-shrink: 0; min-height: 110px;
}
#cam-capture-btn {
  width: 70px; height: 70px; border-radius: 50%;
  border: 4px solid #fff; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#cam-capture-btn::after {
  content: ''; width: 56px; height: 56px;
  background: #fff; border-radius: 50%;
}
#cam-cancel-btn {
  position: absolute; top: 16px; left: 16px;
  background: rgba(0,0,0,0.5); border: none; border-radius: 50%;
  width: 40px; height: 40px; color: #fff; font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

canvas#cam-canvas { display: none; }

/* ── Avatar Picker ── */
.avatar-pick-wrap {
  position: relative; cursor: pointer; display: inline-flex;
  flex-direction: column; align-items: center; gap: 4px;
}
.avatar-pick-hint {
  font-size: 0.65rem; color: var(--accent); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.avatar-preview {
  width: 72px; height: 72px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface2);
}
.avatar-pick-wrap:active .avatar-preview { opacity: 0.8; }

#avatar-picker {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}
#avatar-picker.open { transform: translateY(0); }
.avatar-picker-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-size: 1rem; font-weight: 700; flex-shrink: 0;
}
.avatar-picker-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 12px; padding: 20px; overflow-y: auto;
}
.avatar-option {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: 14px; padding: 12px 8px; cursor: pointer;
  transition: border-color 0.15s;
}
.avatar-option img { width: 56px; height: 56px; border-radius: 50%; }
.avatar-option span { font-size: 0.62rem; color: var(--muted); font-weight: 600; }
.avatar-option.selected { border-color: var(--accent); background: #1a1200; }
.avatar-option.selected span { color: var(--accent); }
.avatar-option:active { opacity: 0.75; }

/* ── Regional Collections ── */
.region-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-bottom: 10px;
}
.region-card.complete { border-color: var(--success); }
.region-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.region-name { font-weight: 700; font-size: 0.88rem; }
.region-count { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.region-bar { height: 6px; background: var(--surface2); border-radius: 3px; margin-bottom: 10px; overflow: hidden; }
.region-fill { height: 100%; background: var(--success); border-radius: 3px; transition: width 0.5s; }
.region-codes { display: flex; flex-wrap: wrap; gap: 4px; }
.region-code {
  font-family: monospace; font-size: 0.7rem; font-weight: 700;
  padding: 2px 6px; border-radius: 4px;
  background: var(--surface2); color: var(--muted);
}
.region-code.spotted { background: #052e16; color: var(--success); }

/* ── Achievements Tab ── */
.ach-header { margin-bottom: 4px; }
.ach-header h2 { margin: 0; }
.ach-count { font-size: 0.8rem; color: var(--muted); margin: 0 0 12px; }

.ach-subtabs {
  display: flex; gap: 8px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.ach-subtab {
  background: none; border: none; color: var(--muted);
  font-size: 0.9rem; font-weight: 600; padding: 8px 16px;
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.ach-subtab.active { color: var(--accent); border-bottom-color: var(--accent); }

.ach-panel { display: none; }
.ach-panel.active { display: block; }

.trophy-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  padding-bottom: 16px;
}
.trophy-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 10px 12px;
  text-align: center; position: relative; min-height: 110px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.trophy-card.earned {
  border-color: var(--accent); background: #1a1200;
  box-shadow: 0 0 14px rgba(245,158,11,0.18);
}
.trophy-card.locked { opacity: 0.38; filter: grayscale(0.5); }
.trophy-check {
  position: absolute; top: 7px; right: 9px;
  font-size: 0.65rem; font-weight: 800; color: var(--accent);
  background: rgba(245,158,11,0.15); border-radius: 4px; padding: 1px 4px;
}
.trophy-icon { font-size: 2rem; line-height: 1; margin-top: 2px; }
.trophy-name { font-weight: 700; font-size: 0.8rem; margin-top: 4px; }
.trophy-desc { font-size: 0.68rem; color: var(--muted); line-height: 1.3; }

/* ── State drawer owner ── */
.drawer-owner {
  font-size: 0.82rem; color: var(--muted);
  background: var(--surface2); border-radius: 8px;
  padding: 7px 12px; margin: 6px 0 2px;
}

/* ── Streak badge on home chips ── */
.top3-streak { font-size: 0.68rem; color: var(--accent); font-weight: 700; }

/* ── Player Profile Drawer ── */
#player-drawer-backdrop {
  position: fixed; inset: 0; z-index: 62;
  background: rgba(0,0,0,0.55);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
#player-drawer-backdrop.open { opacity: 1; pointer-events: auto; }
#player-drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 63;
  background: var(--surface); border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 85vh; overflow-y: auto;
}
#player-drawer.open { transform: translateY(0); }
#player-drawer-content { padding: 8px 20px 40px; }
.player-drawer-hero { text-align: center; padding: 12px 0 14px; }
.player-drawer-name { font-size: 1.1rem; font-weight: 800; margin-top: 8px; }
.you-tag { color: var(--accent); font-size: 0.85rem; font-weight: 600; }
.pd-group-pills {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px;
}
.pd-group-pill {
  padding: 5px 14px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); font-size: 0.78rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.pd-group-pill.active { background: var(--accent); border-color: var(--accent); color: #000; }
.pd-group-pill:active { opacity: 0.75; }

.pd-group-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
}
.pd-group-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--accent); margin-bottom: 10px;
}
.pd-group-stats { display: grid; grid-template-columns: repeat(3, 1fr); }
.pd-group-stat { text-align: center; }
.pd-group-stat span { display: block; font-size: 1.5rem; font-weight: 800; color: var(--text); line-height: 1.1; }
.pd-group-stat small { font-size: 0.6rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.pd-alltime-row {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
  padding: 2px 0 14px; font-size: 0.82rem; color: var(--muted);
  border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.pd-alltime-row strong { color: var(--text); font-weight: 700; }
.pd-alltime-dot { color: var(--border); }
.player-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.player-badge-chip {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px; font-size: 0.78rem; font-weight: 600;
  color: var(--text);
}

@media (min-width: 500px) {
  .state-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
}

/* ── Invite Banner (setup screen) ── */
.invite-banner {
  display: flex; align-items: center; gap: 10px;
  background: #1a1200; border: 1px solid var(--accent);
  border-radius: 10px; padding: 12px 14px;
  font-size: 0.88rem; color: var(--text);
}
.invite-banner.hidden { display: none; }
.invite-banner-icon { font-size: 1.3rem; flex-shrink: 0; }

/* ── Groups list (profile tab) ── */
.group-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.group-row:last-child { border-bottom: none; }
.group-row-info { flex: 1; }
.group-row-name { font-weight: 700; font-size: 0.9rem; }
.group-row-meta { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.group-row-active {
  font-size: 0.7rem; color: var(--success);
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  background: #052e16; border-radius: 4px; padding: 2px 6px;
}
.group-invite-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px;
  color: var(--muted); font-size: 0.78rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.group-invite-btn:active { background: var(--surface); color: var(--text); }
.group-switch-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px;
  color: var(--muted); font-size: 0.75rem; cursor: pointer;
}
.group-switch-btn:active { background: var(--surface2); }

/* ── Invite Join Modal (for logged-in users) ── */
.invite-join-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.invite-join-modal.hidden { display: none; }
.invite-join-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 24px;
  width: 100%; max-width: 360px;
  text-align: center;
}
.invite-join-icon { font-size: 2.5rem; margin-bottom: 8px; }
.invite-join-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.invite-join-sub { font-size: 0.85rem; color: var(--muted); }

/* ── Sign Out button ── */
.signout-btn { width: 100%; margin-bottom: 24px; color: var(--danger); border-color: var(--danger); }
.signout-btn:active { background: rgba(239,68,68,0.1); }

/* ── Onboarding Guide Overlay ── */
.onboarding-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(15,23,42,0.96);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.onboarding-overlay.hidden { display: none; }
.onboarding-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 24px;
  width: 100%; max-width: 420px;
  max-height: 88dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  text-align: center;
}
.onboarding-icon { font-size: 3rem; line-height: 1; }
.onboarding-card h2 { font-size: 1.3rem; font-weight: 800; }
.onboarding-sub { color: var(--muted); font-size: 0.88rem; margin-top: -6px; }
.onboarding-card .rules-list { text-align: left; padding-left: 18px; }
.onboarding-card .rules-list li { margin-bottom: 8px; font-size: 0.88rem; line-height: 1.45; }
.onboarding-hint { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

/* ── Feed delete button ── */
.feed-delete-btn {
  background: transparent; border: none;
  color: var(--muted); font-size: 0.82rem;
  padding: 6px 8px; cursor: pointer; border-radius: 6px;
  flex-shrink: 0; line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.feed-delete-btn:active { color: var(--danger); background: rgba(239,68,68,0.12); }

/* ── Group switcher (header tap → bottom sheet) ── */
.home-group-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text); font-size: 1.1rem; font-weight: 800;
  padding: 0; max-width: 180px;
}
.home-group-btn-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.home-group-caret { color: var(--accent); font-size: 0.85rem; flex-shrink: 0; }

.group-switcher-backdrop {
  position: fixed; inset: 0; z-index: 148;
  background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.group-switcher-backdrop.open { opacity: 1; pointer-events: all; }

.group-switcher {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 149;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.34,1.1,0.64,1);
}
.group-switcher.open { transform: translateY(0); }
.group-switcher-handle {
  width: 36px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 12px auto 4px;
}
.group-switcher-title {
  padding: 8px 20px 14px; font-size: 0.78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.group-switcher-item {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; background: transparent; border: none;
  border-bottom: 1px solid var(--border); cursor: pointer;
  text-align: left; color: var(--text); transition: background 0.15s;
}
.group-switcher-item:last-child { border-bottom: none; }
.group-switcher-item:active { background: var(--surface2); }
.group-switcher-item.active { background: var(--surface2); }
.group-switcher-item-info { flex: 1; }
.group-switcher-item-name { font-weight: 700; font-size: 0.95rem; }
.group-switcher-item-meta { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.group-switcher-check { color: var(--accent); font-weight: 800; font-size: 1rem; }

/* ── Map tab header + view toggle ── */
.map-tab-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.map-tab-header h2 { font-size: 1.1rem; font-weight: 800; }
.map-view-toggle { display: flex; gap: 4px; }
.map-view-btn {
  padding: 6px 13px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-size: 0.78rem; font-weight: 700; cursor: pointer;
}
.map-view-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ── Profile personal coverage ── */
.profile-coverage-btn {
  width: 100%; margin-top: 12px; padding: 10px;
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; color: var(--muted); font-size: 0.85rem;
  font-weight: 600; cursor: pointer; text-align: center;
  transition: border-color 0.15s, color 0.15s;
}
.profile-coverage-btn:hover { border-color: var(--accent); color: var(--accent); }
