﻿:root {
  --bg: #081318;
  --panel: rgba(11, 24, 31, 0.9);
  --line: rgba(186, 215, 219, 0.14);
  --text: #edf3f1;
  --muted: #9cb3b6;
  --accent: #d56a3f;
  --accent-2: #49a99a;
  --accent-3: #7db6d3;
  --soft: #12222a;
  --shadow: 0 22px 55px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(213, 106, 63, 0.22), transparent 24%),
    radial-gradient(circle at bottom right, rgba(73, 169, 154, 0.18), transparent 28%),
    linear-gradient(180deg, #102028 0%, var(--bg) 100%);
  font-family: Georgia, "Times New Roman", serif;
}

button,
input,
table,
.meta-note,
.lead,
.detail-empty,
.detail-topline,
.mini-legend,
.stats-grid,
.search-box,
.summary-strip,
svg text {
  font-family: "Segoe UI", Arial, sans-serif;
}

.app-shell {
  width: calc(100% - 24px);
  max-width: 1720px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 12px 0;
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(540px, 1.28fr);
  gap: 14px;
  align-items: start;
}

.left-column,
.right-column {
  display: grid;
  gap: 0;
  align-content: start;
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.map-panel,
.detail-panel {
  padding: 18px;
}

.map-panel {
  height: auto;
}

.eyebrow,
.section-label {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.74rem;
  color: var(--accent);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.4rem, 4.2vw, 4.3rem);
  line-height: 0.96;
  max-width: 11ch;
}

h2 {
  margin-bottom: 0;
  font-size: 1.8rem;
  line-height: 1.1;
}

.lead {
  color: var(--muted);
  line-height: 1.65;
  margin-bottom: 14px;
}

.meta-note {
  color: var(--muted);
  margin-bottom: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  margin-bottom: 8px;
}

.panel-header.compact {
  margin-bottom: 4px;
}

.map-frame {
  position: relative;
  height: auto;
  min-height: 320px;
  isolation: isolate;
}

.map-source-note {
  margin: 6px 4px 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.map-action {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1000;
  border: 1px solid rgba(125, 182, 211, 0.2);
  background: linear-gradient(180deg, rgba(18, 35, 44, 0.96), rgba(11, 24, 31, 0.92));
  color: var(--text);
  border-radius: 999px;
  padding: 10px 15px;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  transition: transform 0.22s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.22s ease;
  pointer-events: auto;
}

.map-action:hover {
  transform: scale(1.04);
  border-color: rgba(213, 106, 63, 0.34);
  color: var(--accent);
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 1px solid rgba(125, 182, 211, 0.14);
  border-radius: 999px;
  background: rgba(16, 31, 39, 0.88);
  margin-left: auto;
}

.lang-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.22s ease, background-color 0.22s ease, color 0.22s ease;
}

.lang-btn.is-active {
  background: var(--accent-3);
  color: #071217;
}

.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 1px solid rgba(125, 182, 211, 0.14);
  border-radius: 999px;
  background: rgba(16, 31, 39, 0.88);
}

.mode-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.22s ease, background-color 0.22s ease, color 0.22s ease;
}

.mode-btn:hover,
.lang-btn:hover {
  transform: scale(1.06);
}

.mode-btn:active,
.lang-btn:active,
.map-action:active {
  transform: scale(0.97);
}

.mode-btn.is-active {
  background: var(--accent-3);
  color: #071217;
}

.map-container {
  background: linear-gradient(180deg, rgba(15, 31, 39, 0.96), rgba(9, 21, 28, 0.88));
  border: 1px solid rgba(186, 215, 219, 0.1);
  border-radius: 20px;
  padding: 0;
  height: 100%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  overflow: hidden;
  position: relative;
}

.map-container::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 30% 20%, rgba(9, 16, 22, 0.12), transparent 38%),
    linear-gradient(180deg, rgba(3, 8, 12, 0.1), rgba(3, 8, 12, 0.26));
  z-index: 400;
}

.map-container .leaflet-container {
  width: 100%;
  height: 100%;
  border-radius: 20px;
}

.map-container .leaflet-tile-pane {
  filter: brightness(0.6) saturate(0.82) contrast(1.02);
}

.leaflet-control-attribution {
  font-size: 0.68rem;
}

.map-point {
  animation: point-scale 2.8s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center center;
  filter: drop-shadow(0 0 10px rgba(125, 182, 211, 0.45));
  will-change: transform;
}

.map-point.is-active {
  animation-duration: 1.9s;
  filter: drop-shadow(0 0 14px rgba(213, 106, 63, 0.8));
}

@keyframes point-scale {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.045);
  }
}

.hidden {
  display: none;
}

.detail-empty {
  color: var(--muted);
  line-height: 1.6;
}

.detail-panel {
  height: auto;
  overflow: visible;
}

.top-controls-row {
  margin-bottom: 6px;
  align-items: center;
}

.detail-title-block {
  margin-top: 2px;
  margin-bottom: 12px;
}

.detail-title-block h2 {
  font-size: 2.2rem;
  line-height: 0.98;
  margin: 0;
}

.detail-hero {
  padding: 18px 22px;
  margin-bottom: 14px;
  border: 1px solid rgba(125, 182, 211, 0.14);
  border-radius: 24px;
  background:
    radial-gradient(circle at top right, rgba(213, 106, 63, 0.16), transparent 34%),
    linear-gradient(180deg, rgba(17, 34, 42, 0.96), rgba(10, 20, 26, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  min-height: 154px;
}

.detail-compare {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  align-items: center;
  min-height: 112px;
}

#detail-content[data-mode="age"] .detail-compare {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.compare-metric {
  padding: 6px 8px;
  min-width: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  text-align: center;
}

.compare-metric-foreign {
  border-right: 1px solid rgba(186, 215, 219, 0.14);
  padding-right: 20px;
}

.compare-metric-spanish {
  padding-left: 20px;
}

.compare-metric-tertiary {
  padding-left: 20px;
  border-left: 1px solid rgba(186, 215, 219, 0.14);
}

.compare-label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  color: var(--muted);
}

.compare-value {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.9rem, 5.6vw, 4.35rem);
  line-height: 0.82;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  margin-top: 6px;
}

.compare-sub {
  margin: 0;
  margin-top: 4px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
  display: none;
}

.detail-visuals {
  display: grid;
  grid-template-columns: minmax(260px, 0.84fr) minmax(280px, 1.16fr);
  gap: 14px;
  align-items: stretch;
}

.visual-card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.025));
  min-height: 218px;
}

.visual-card-chart {
  display: grid;
  place-items: center;
  padding: 14px;
}

.visual-card-breakdown {
  padding: 18px;
}

.donut-wrap {
  width: 228px;
  height: 228px;
  position: relative;
  margin: 0 auto;
}

.donut {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(var(--accent-2) 0deg 180deg, #d9dbd9 180deg 360deg);
  position: relative;
  box-shadow:
    0 18px 36px rgba(0, 0, 0, 0.26),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.donut::after {
  content: "";
  position: absolute;
  inset: 24%;
  border-radius: 50%;
  background:
    radial-gradient(circle at top, rgba(125, 182, 211, 0.09), transparent 42%),
    #102028;
  box-shadow: inset 0 0 0 1px var(--line);
}

.mini-legend,
.stat-label,
.stat-sub {
  color: var(--muted);
}

.mini-legend {
  display: grid;
  gap: 12px;
  height: 100%;
  align-content: center;
}

.legend-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid rgba(186, 215, 219, 0.1);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.legend-row-soft {
  background: rgba(255, 255, 255, 0.02);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.03);
}

.legend-copy {
  display: grid;
  gap: 3px;
}

.legend-copy span {
  color: var(--text);
  font-weight: 600;
}

.legend-copy small {
  color: var(--muted);
  font-size: 0.8rem;
}

.legend-row strong {
  font-size: 1.12rem;
  color: var(--text);
}

.stats-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02));
  min-height: 146px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.stat-label {
  font-size: 0.8rem;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-size: clamp(1.9rem, 3vw, 2.5rem);
  line-height: 0.95;
  margin-bottom: 4px;
}

.stat-sub {
  font-size: 0.86rem;
  line-height: 1.45;
}

.stat-value-row {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.stat-percent {
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--accent-3);
}

.search-box {
  display: grid;
  gap: 6px;
  min-width: 240px;
}

.search-box span {
  font-size: 0.84rem;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.summary-card strong {
  display: block;
  font-size: 1.5rem;
  line-height: 1.05;
  margin-top: 10px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.03);
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

tr.is-active {
  background: rgba(213, 106, 63, 0.16);
}

tr:hover {
  background: rgba(125, 182, 211, 0.08);
  cursor: pointer;
}

.cell-name {
  font-weight: 600;
}

.cell-code {
  display: block;
  margin-top: 4px;
  font-size: 0.84rem;
  color: var(--muted);
}

.empty-row td {
  color: var(--muted);
}

.map-error,
.debug-block {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #7a2f1f;
  background: rgba(213, 106, 63, 0.08);
  border: 1px solid rgba(213, 106, 63, 0.22);
  border-radius: 16px;
  padding: 14px;
  white-space: pre-wrap;
  overflow: auto;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
    width: min(100% - 16px, 1720px);
  }

  .detail-visuals,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .visual-card {
    min-height: auto;
  }

  .map-panel,
  .detail-panel {
    height: auto;
  }

  .map-frame {
    height: auto;
    min-height: 360px;
  }

  .map-container {
    height: min(62vh, 520px);
    min-height: 320px;
  }

  .map-container .leaflet-tile-pane {
    filter: none;
  }

  .map-svg {
    height: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 16px, 1380px);
    padding-top: 10px;
  }

  .hero-panel,
  .map-panel,
  .detail-panel,
  .table-panel {
    padding: 16px;
  }

  .panel,
  .map-container,
  .table-wrap,
  .stat-card,
  .summary-card {
    border-radius: 18px;
  }

  .panel-header {
    flex-direction: column;
  }

  .detail-hero,
  .visual-card-breakdown,
  .visual-card-chart {
    padding: 18px;
  }

  .detail-compare {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  #detail-content[data-mode="age"] .detail-compare {
    grid-template-columns: 1fr;
  }

  .compare-metric-foreign {
    border-right: 0;
    border-bottom: 1px solid rgba(186, 215, 219, 0.14);
    padding-right: 8px;
    padding-bottom: 14px;
  }

  .compare-metric-spanish {
    padding-left: 8px;
    padding-top: 14px;
  }

  .compare-metric-tertiary {
    border-left: 0;
    border-top: 1px solid rgba(186, 215, 219, 0.14);
    padding-left: 8px;
    padding-top: 14px;
  }

  .donut-wrap {
    width: 214px;
    height: 214px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }
}
