html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f5;
}

/* Loading screen */
#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease-out, visibility 0.4s ease-out;
}

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

.loading-content {
  text-align: center;
  color: #fff;
  padding: 20px;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.loading-status {
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 20px;
}

.loading-progress {
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 0 auto;
  overflow: hidden;
}

.loading-progress-bar {
  height: 100%;
  background: #fff;
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease-out;
}

#map {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

#controls {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 280px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 10;
}

.panel-header {
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  color: #fff;
  padding: 14px 16px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.panel-header .subtitle {
  display: block;
  font-size: 11px;
  opacity: 0.85;
  margin-top: 2px;
}

.section {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
}

.section:last-child {
  border-bottom: none;
}

.section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b7280;
  margin-bottom: 8px;
}

.metric-options {
  display: flex;
  gap: 6px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: #374151;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  transition: all 0.2s;
  flex: 1;
  justify-content: center;
}

.radio-option:hover {
  border-color: #93c5fd;
}

.radio-option input {
  display: none;
}

.radio-option input:checked ~ span {
  color: #2563eb;
}

.radio-option:has(input:checked) {
  border-color: #3b82f6;
  background: #eff6ff;
}

.radio-custom {
  display: none;
}

.filter-dropdown {
  position: relative;
}

.filter-btn {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  font-size: 12px;
  background: #fafafa;
  color: #374151;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s;
}

.filter-btn:hover {
  border-color: #3b82f6;
}

.filter-btn svg {
  color: #9ca3af;
  transition: transform 0.2s;
}

.filter-btn.open svg {
  transform: rotate(180deg);
}

.filter-popup {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
  padding: 6px;
}

.filter-popup.show {
  display: block;
}

/* Backdrop for mobile filter popup */
.filter-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 150;
}

.filter-backdrop.show {
  display: block;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: #374151;
  transition: background 0.15s;
}

.filter-item:hover {
  background: #f9fafb;
}

.filter-item input {
  width: 14px;
  height: 14px;
  accent-color: #3b82f6;
  cursor: pointer;
}

.filter-type-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--pill-border, rgba(107, 114, 128, 0.3));
  background: var(--pill-bg, rgba(107, 114, 128, 0.12));
  color: var(--pill-color, #374151);
  font-weight: 600;
  line-height: 1.3;
}

.filter-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 4px 0;
}

.select-all-btn {
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: #f3f4f6;
  color: #374151;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.select-all-btn:hover {
  background: #e5e7eb;
}

.radius-toggle {
  display: flex;
  background: #f3f4f6;
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.radius-opt {
  flex: 1;
  padding: 6px 0;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.radius-opt:hover {
  color: #374151;
}

.radius-opt.active {
  background: #fff;
  color: #3b82f6;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.hint {
  font-size: 10px;
  color: #9ca3af;
  margin-top: 6px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
  color: #374151;
}

.toggle:first-of-type {
  padding-top: 0;
}

.toggle:last-of-type {
  padding-bottom: 0;
}

.toggle input {
  display: none;
}

.toggle-slider {
  width: 32px;
  height: 18px;
  background: #e5e7eb;
  border-radius: 9px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.toggle input:checked + .toggle-slider {
  background: #3b82f6;
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(14px);
}

.toggle-label {
  font-weight: 500;
}

.legend-section {
  padding-bottom: 14px;
}

.legend-gradient {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #ef4444, #f97316, #eab308, #84cc16, #22c55e);
  margin-bottom: 4px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #9ca3af;
}

#tooltip {
  display: none;
  position: fixed;
  padding: 8px 12px;
  background: #fff;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-line;
  pointer-events: none;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border: 1px solid #e5e7eb;
  max-width: 200px;
}

.maplibregl-popup-content {
  border-radius: 8px;
  padding: 10px 14px;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.maplibregl-popup-close-button {
  font-size: 16px;
  padding: 2px 6px;
}

.filter-popup::-webkit-scrollbar {
  width: 4px;
}

.filter-popup::-webkit-scrollbar-track {
  background: transparent;
}

.filter-popup::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

.amenity-marker {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  border: 2px solid #fff;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s;
}

.amenity-marker:hover {
  transform: scale(1.2);
  z-index: 10;
}

.amenity-marker.in-radius {
  border-color: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.5), 0 0 12px rgba(251, 191, 36, 0.6);
  z-index: 5;
}

.amenity-marker.in-radius:hover {
  z-index: 15;
}

.amenity-marker img {
  filter: brightness(0) invert(1);
}

#radius-info {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 12px 18px;
  z-index: 10;
  text-align: center;
  min-width: 200px;
  max-width: calc(100vw - 24px);
}

#radius-info.percentile-mode {
  width: min(920px, calc(100vw - 24px));
  padding: 12px 18px;
}

.radius-count {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.radius-count a {
  color: #2563eb;
  text-decoration: underline;
  cursor: pointer;
}

.radius-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: center;
}

.radius-type {
  font-size: 11px;
  color: #6b7280;
  white-space: nowrap;
}

.percentile-summary {
  margin-bottom: 6px;
}

.percentile-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b7280;
  margin-bottom: 2px;
}

.percentile-value {
  font-size: 42px;
  line-height: 1;
  font-weight: 800;
  color: #2563eb;
}

.percentile-value span {
  font-size: 20px;
  margin-left: 2px;
  vertical-align: super;
}

.percentile-value em {
  font-size: 67%;
  font-style: normal;
  font-weight: inherit;
  color: inherit;
  margin-left: 6px;
  vertical-align: middle;
}

.percentile-caption {
  font-size: 12px;
  color: #374151;
  margin-top: 2px;
}

.percentile-context {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

.percentile-breakdown {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 8px;
  max-height: 132px;
  overflow-y: auto;
  padding-right: 4px;
}

.percentile-item {
  font-size: 11px;
  color: #4b5563;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.percentile-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

.percentile-item strong {
  font-size: 12px;
  font-weight: 700;
  color: #111827;
}

/* Analysis mode toggle */
.mode-section {
  padding: 10px 16px !important;
}

.mode-toggle {
  display: flex;
  background: #f3f4f6;
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.mode-opt {
  flex: 1;
  padding: 7px 4px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

.mode-opt:hover {
  color: #374151;
}

.mode-opt.active {
  background: #fff;
  color: #2563eb;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mode-opt svg {
  flex-shrink: 0;
}

/* Neighborhood info panel (legacy, now uses modal) */

.hood-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.hood-name {
  font-size: 16px;
  font-weight: 700;
  color: #1f2937;
}

.hood-rank {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: #2563eb;
  padding: 3px 10px;
  border-radius: 999px;
}

.hood-rank.low { background: #ef4444; }
.hood-rank.mid { background: #eab308; color: #1f2937; }
.hood-rank.high { background: #22c55e; }

.hood-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.hood-stat {
  text-align: center;
  padding: 8px 4px;
  background: #f9fafb;
  border-radius: 8px;
}

.hood-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: #2563eb;
}

.hood-stat-label {
  font-size: 10px;
  color: #6b7280;
  margin-top: 2px;
}

.hood-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
}

.hood-type-item {
  font-size: 11px;
  color: #4b5563;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.hood-type-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Citywide / Neighborhood modals */
.modal-content.citywide-content {
  max-width: 900px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-content.citywide-content > .modal-header {
  flex-shrink: 0;
}

.citywide-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.cw-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.cw-stat-card {
  text-align: center;
  padding: 14px 8px;
  background: #f0f7ff;
  border-radius: 10px;
  border: 1px solid #dbeafe;
}

.cw-stat-value {
  font-size: 22px;
  font-weight: 800;
  color: #2563eb;
  line-height: 1.1;
}

.cw-stat-label {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
}

.cw-section {
  margin-bottom: 24px;
}

.cw-section-title {
  font-size: 14px;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cw-chart-container {
  position: relative;
  height: 280px;
  margin-bottom: 12px;
}

.cw-pie-chart {
  height: 320px;
}

.cw-ranking-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.cw-ranking-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
}

.cw-ranking-item:last-child {
  border-bottom: none;
}

.cw-rank-num {
  width: 22px;
  height: 22px;
  background: #f3f4f6;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cw-ranking-item:nth-child(1) .cw-rank-num { background: #fef3c7; color: #92400e; }
.cw-ranking-item:nth-child(2) .cw-rank-num { background: #e5e7eb; color: #374151; }
.cw-ranking-item:nth-child(3) .cw-rank-num { background: #fed7aa; color: #9a3412; }

.cw-rank-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-rank-bar-wrap {
  flex: 2;
  height: 18px;
  background: #f3f4f6;
  border-radius: 9px;
  overflow: hidden;
  position: relative;
}

.cw-rank-bar {
  height: 100%;
  border-radius: 9px;
  transition: width 0.5s ease;
}

.cw-rank-score {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  width: 40px;
  text-align: right;
  flex-shrink: 0;
}

/* Controls row - wraps filter and radius */
.controls-row {
  display: contents;
}

/* Info button - inside panel header on desktop, fixed position on mobile */
.info-btn {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.info-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.panel-header {
  position: relative;
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: #fff;
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow: hidden;
  position: relative;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.35);
}

.modal-header {
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  padding: 24px 24px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.modal-logo {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.modal-title h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.modal-title p {
  margin: 2px 0 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 24px;
}

.modal-tab {
  flex: 1;
  padding: 14px 0;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: #9ca3af;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}

.modal-tab:hover {
  color: #6b7280;
}

.modal-tab.active {
  color: #2563eb;
}

.modal-tab.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: #2563eb;
  border-radius: 2px 2px 0 0;
}

.modal-tab-content {
  display: none;
  padding: 24px;
}

.modal-tab-content.active {
  display: block;
}

.howto-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.howto-list li {
  margin-bottom: 16px;
}

.howto-list li:last-child {
  margin-bottom: 0;
}

.howto-list strong {
  display: block;
  font-size: 13px;
  color: #1f2937;
  margin-bottom: 4px;
}

.howto-list p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #6b7280;
}


.about-section {
  margin-bottom: 20px;
}

.about-section:last-child {
  margin-bottom: 0;
}

.about-section strong {
  display: block;
  font-size: 13px;
  color: #1f2937;
  margin-bottom: 4px;
}

.about-section p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #6b7280;
}

.modal-tab-content > p {
  font-size: 13px;
  line-height: 1.5;
  color: #4b5563;
  margin: 0 0 20px 0;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  z-index: 10;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.modal-start-btn {
  margin: 0 24px 24px;
  width: calc(100% - 48px);
  padding: 14px;
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.modal-start-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

/* Mobile responsive styles - Modern bottom bar */
@media (max-width: 480px) {
  /* Map fills screen with space for slim bottom bar */
  #map {
    bottom: 0;
    height: calc(100% - 56px);
    height: calc(100dvh - 56px - env(safe-area-inset-bottom, 0px));
  }

  /* Slim modern bottom bar */
  #controls {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    border-radius: 0;
    box-shadow: 0 -1px 0 rgba(0,0,0,0.08);
    background: #fff;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overflow: visible;
  }

  /* Hide the header on mobile */
  .panel-header {
    display: none;
  }

  /* Controls row - filter and radius side by side */
  .controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
  }

  .controls-row .section {
    padding: 0;
    border: none;
    flex: 1;
    min-width: 0;
  }

  #amenity-filter-section {
    flex: 1.2;
  }

  #radius-section {
    flex: 1;
  }

  .section-title,
  .hint {
    display: none;
  }

  /* Filter dropdown - pill style */
  .filter-dropdown {
    position: relative;
    z-index: 100;
  }

  .filter-btn {
    width: 100%;
    padding: 0 12px;
    font-size: 13px;
    height: 40px;
    min-height: 40px;
    border-radius: 10px;
    background: #f5f5f5;
    border: none;
    font-weight: 500;
    color: #374151;
  }

  .filter-btn:active {
    background: #ebebeb;
  }

  /* Radius control - segmented toggle */
  .radius-toggle {
    background: #f0f0f0;
    border-radius: 10px;
    height: 40px;
    padding: 3px;
  }

  .radius-opt {
    font-size: 13px;
    border-radius: 8px;
    padding: 0;
    line-height: 34px;
  }

  .radius-opt:active {
    background: rgba(255, 255, 255, 0.5);
  }

  /* Hide legend on mobile - keep UI minimal */
  .legend-section {
    display: none;
  }

  /* Mode toggle on mobile - full-width above filter row */
  .mode-section {
    padding: 6px 12px 0 !important;
    border: none !important;
  }

  .mode-toggle {
    height: 36px;
    padding: 3px;
    border-radius: 10px;
    background: #f0f0f0;
  }

  .mode-opt {
    font-size: 12px;
    border-radius: 8px;
    padding: 0;
    gap: 3px;
  }

  .mode-opt svg {
    width: 12px;
    height: 12px;
  }

  .hood-stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .cw-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-content.citywide-content {
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  /* Info button - top left floating on mobile */
  .info-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    right: auto;
    transform: none;
    width: 40px;
    height: 40px;
    background: #fff;
    color: #6b7280;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    z-index: 10;
  }

  .info-btn:active {
    background: #f5f5f5;
  }

  /* Filter popup - bottom sheet */
  .filter-popup {
    max-height: 60vh;
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
    padding: 0 16px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    z-index: 200;
  }

  .filter-popup::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 12px auto 16px;
  }

  .filter-item {
    padding: 14px 12px;
    font-size: 15px;
    min-height: 48px;
    border-radius: 8px;
  }

  .filter-type-pill {
    padding: 4px 10px;
  }

  .filter-item:active {
    background: #f5f5f5;
  }

  .filter-item input {
    width: 22px;
    height: 22px;
    min-width: 22px;
  }

  .select-all-btn {
    padding: 14px;
    font-size: 14px;
    min-height: 48px;
    border-radius: 8px;
    margin-bottom: 8px;
  }

  /* Radius info - floating card above bottom bar */
  #radius-info {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 12px);
    transform: none;
    min-width: 0;
    padding: 14px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  }

  .radius-count {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
  }

  .radius-breakdown {
    gap: 6px 14px;
  }

  .radius-type {
    font-size: 12px;
  }

  .percentile-value {
    font-size: 36px;
  }

  .percentile-breakdown {
    justify-content: flex-start;
    gap: 3px 8px;
    max-height: 118px;
  }

  /* Modal - modern bottom sheet */
  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
  }

  .modal-header {
    padding: 20px 20px 16px;
  }

  .modal-title h2 {
    font-size: 17px;
  }

  .modal-tabs {
    padding: 0 20px;
  }

  .modal-tab {
    padding: 12px 0;
    font-size: 13px;
  }

  .modal-tab-content {
    padding: 20px;
    max-height: calc(90vh - 220px);
    overflow-y: auto;
  }

  .howto-list li {
    margin-bottom: 16px;
  }

  .howto-list strong,
  .about-section strong {
    font-size: 13px;
  }

  .howto-list p,
  .about-section p,
  .modal-tab-content > p {
    font-size: 13px;
    line-height: 1.6;
  }

  .modal-start-btn {
    margin: 0 20px 20px;
    width: calc(100% - 40px);
    padding: 14px;
    font-size: 15px;
    border-radius: 12px;
  }

  .modal-close {
    top: 14px;
    right: 14px;
    width: 30px;
    height: 30px;
  }

  /* Hide tooltip on touch */
  #tooltip {
    display: none !important;
  }

  /* Map controls - top right */
  .maplibregl-ctrl-top-right {
    top: 12px !important;
    right: 12px !important;
  }

  .maplibregl-ctrl-group {
    margin: 0 !important;
    border-radius: 10px !important;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12) !important;
  }

  .maplibregl-ctrl-group button {
    width: 40px !important;
    height: 40px !important;
  }
}

/* Tablet adjustments */
@media (min-width: 481px) and (max-width: 768px) {
  #controls {
    width: 290px;
  }

  #radius-info {
    max-width: 320px;
  }

  .modal-content {
    max-width: 420px;
  }
}

/* Small phones - even more compact */
@media (max-width: 360px) {
  .controls-row {
    gap: 8px;
    padding: 8px 10px;
  }

  .filter-btn {
    font-size: 12px;
    padding: 0 10px;
    height: 36px;
    min-height: 36px;
  }

  .radius-toggle {
    height: 36px;
    padding: 2px;
  }

  .radius-opt {
    font-size: 11px;
    line-height: 32px;
  }

  #map {
    height: calc(100% - 52px);
    height: calc(100dvh - 52px - env(safe-area-inset-bottom, 0px));
  }

  #radius-info {
    bottom: calc(52px + env(safe-area-inset-bottom, 0px) + 10px);
  }
}

/* Touch-friendly improvements for all touch devices */
@media (hover: none) and (pointer: coarse) {
  /* Hide tooltip on touch */
  #tooltip {
    display: none !important;
  }

  /* Prevent text selection on interactive elements */
  .filter-btn,
  .filter-item,
  .select-all-btn,
  .modal-tab,
  .info-btn,
  .radius-opt {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
}
