:root {
  --bg: #0c1116;
  --panel: rgba(17, 24, 33, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #f4f7fb;
  --muted: #b7c0cc;
  --accent-yellow: #f8f4b4;
  --accent-orange: #f4a261;
  --accent-red: #e63946;
  --accent-purple: #5a189a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

#map {
  height: 100%;
  width: 100%;
  filter: saturate(0.95);
}

.hidden {
  display: none !important;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  background: rgba(7, 10, 14, 0.68);
  color: var(--text);
  backdrop-filter: blur(2px);
}

.status-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 650;
  background: rgba(20, 31, 43, 0.95);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
}

.status-banner.error {
  background: rgba(92, 24, 32, 0.95);
  border-color: rgba(230, 57, 70, 0.55);
}

#right-rail {
  position: absolute;
  top: 24px;
  right: 24px;
  bottom: 24px;
  width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 600;
  min-height: 0;
}

.panel {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  padding: 24px;
  color: var(--text);
  animation: fadeIn 0.6s ease-out;
  pointer-events: auto;
}

#left-panel {
  position: absolute;
  top: 24px;
  left: 24px;
  width: 340px;
}

.title-block h1 {
  font-size: 20px;
  line-height: 1.25;
  margin: 0 0 10px;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.2px;
}

.context-box {
  margin-top: 18px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.context-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin: 6px 0;
}

.context-row strong {
  color: var(--text);
}

.toggles {
  margin-top: 18px;
  display: grid;
  gap: 12px;
}

.toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.slider {
  position: relative;
  width: 42px;
  height: 22px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  transition: background 0.2s ease;
}

.slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}

.toggle input:checked + .slider {
  background: rgba(248, 244, 180, 0.5);
}

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

.toggle input:focus-visible + .slider {
  outline: 2px solid rgba(248, 244, 180, 0.9);
  outline-offset: 2px;
}

.toggle-label {
  color: var(--text);
  font-weight: 500;
}

.legend {
  margin-top: 22px;
}

.legend-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}

.legend-bar {
  margin-top: 10px;
  height: 160px;
  width: 12px;
  border-radius: 999px;
  background: linear-gradient(
    180deg,
    var(--accent-purple) 0%,
    var(--accent-red) 35%,
    var(--accent-orange) 65%,
    var(--accent-yellow) 100%
  );
}

.legend-labels {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.legend-call {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(244, 162, 97, 0.7);
  border: 1px solid rgba(248, 244, 180, 0.65);
  box-shadow: 0 0 8px rgba(244, 162, 97, 0.45);
}

.detail-panel {
  width: 100%;
  flex: 1 1 auto;
  max-height: none;
  min-height: 0;
  overflow: auto;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

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

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-zip {
  font-size: 28px;
  font-weight: 700;
}

.detail-name {
  font-size: 15px;
  font-weight: 600;
  margin-top: 2px;
}

.detail-name.is-empty {
  display: none;
}


.score-badge {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--accent-purple);
  color: #fff;
  text-align: center;
  transition: background 0.3s ease;
}

.score-value {
  font-size: 26px;
  font-weight: 700;
}

.score-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score-strip {
  margin-top: 18px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.score-strip-title {
  font-size: 12px;
  color: var(--muted);
}

.score-strip-value {
  font-size: 18px;
  font-weight: 600;
  margin: 6px 0 10px;
}

.score-strip-bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.score-strip-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent-purple);
  transition: width 0.7s ease;
}

.factors {
  margin-top: 20px;
}

.factors-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin-bottom: 12px;
}

.factor {
  margin-bottom: 12px;
}

.factor-label {
  font-size: 13px;
  margin-bottom: 6px;
}

.factor-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.factor-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent-orange);
  transition: width 0.7s ease;
}

.ai-box {
  margin-top: 18px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(90, 24, 154, 0.16);
  border: 1px solid rgba(90, 24, 154, 0.35);
}

.ai-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.ai-box p {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.rank-panel {
  width: 100%;
  max-height: 260px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 0 0 auto;
  min-height: 0;
}

.rank-panel.expanded {
  flex: 1 1 auto;
  max-height: none;
}

.rank-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.rank-title {
  font-size: 14px;
  font-weight: 600;
}

.rank-subtitle {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.9px;
}

.rank-toggle {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: border 0.2s ease, transform 0.2s ease;
}

.rank-toggle:hover {
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.rank-list {
  display: grid;
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
  flex: 1 1 auto;
  min-height: 0;
}

.rank-item {
  display: grid;
  grid-template-columns: 24px 1fr 64px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: border 0.2s ease, transform 0.2s ease;
}

.rank-item:hover {
  border-color: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
}

.rank-item.active {
  border-color: rgba(248, 244, 180, 0.6);
}

.rank-number {
  font-size: 12px;
  color: var(--muted);
}

.rank-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rank-zip {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.rank-borough {
  font-size: 11px;
  color: var(--muted);
}

.rank-score {
  font-size: 14px;
  font-weight: 600;
  text-align: right;
}

.rank-score span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

#footer {
  position: absolute;
  left: 24px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  z-index: 600;
}

.leaflet-container {
  background: #0b1217;
}

.zip-shape {
  transition: fill 0.2s ease, stroke 0.2s ease, fill-opacity 0.2s ease;
}

.leaflet-tooltip.zip-tooltip {
  background: rgba(15, 20, 26, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.call-point {
  filter: drop-shadow(0 0 6px rgba(244, 162, 97, 0.35));
  cursor: pointer;
  transition: opacity 0.2s ease, fill-opacity 0.2s ease;
}

.call-point:hover {
  filter: drop-shadow(0 0 10px rgba(248, 244, 180, 0.6));
}

.leaflet-popup.call-popup .leaflet-popup-content-wrapper {
  background: rgba(15, 20, 26, 0.95);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.leaflet-popup.call-popup .leaflet-popup-tip {
  background: rgba(15, 20, 26, 0.95);
}

.call-popup-content {
  display: grid;
  gap: 4px;
  min-width: 180px;
}

.call-popup-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.call-popup-row {
  display: grid;
  gap: 2px;
}

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

.call-popup-value {
  font-size: 12px;
  color: var(--text);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  #left-panel {
    width: 300px;
    left: 16px;
    top: 16px;
  }

  #right-rail {
    right: 16px;
    top: 16px;
    bottom: 16px;
    width: 360px;
  }

  .rank-panel {
    max-height: 240px;
  }

  #footer {
    left: 16px;
  }
}

@media (max-width: 720px) {
  #app {
    overflow-x: hidden;
    overflow-y: auto;
  }

  #left-panel {
    position: relative;
    width: auto;
    margin: 16px;
  }

  #map {
    height: calc(100% - 280px);
  }

  #right-rail {
    position: relative;
    width: auto;
    margin: 0 16px 24px;
    top: auto;
    right: auto;
    bottom: auto;
    gap: 16px;
  }

  .detail-panel,
  .rank-panel {
    max-height: none;
  }

  #footer {
    position: relative;
    margin: 16px;
  }
}
