/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #06060f;
  font-family: 'Inter', system-ui, sans-serif;
  color: #e0e0e0;
  cursor: crosshair;
}

canvas {
  display: block;
}

/* ===== LABEL OVERLAY CANVAS ===== */
#label-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* ===== LOADING SCREEN ===== */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #06060f;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 1s ease;
}

#loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
}

.loading-skull {
  font-size: 64px;
  animation: pulse 2s ease-in-out infinite;
  margin-bottom: 24px;
}

.loading-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 16px;
}

.loading-counter {
  font-family: 'Space Mono', monospace;
  font-size: 48px;
  font-weight: 700;
  background: linear-gradient(135deg, #ff6b35, #d32f2f, #9c27b0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.loading-subtext {
  font-size: 13px;
  color: #666;
  letter-spacing: 2px;
  margin-bottom: 32px;
}

.loading-bar-container {
  width: 300px;
  height: 2px;
  background: #1a1a2e;
  border-radius: 1px;
  margin: 0 auto;
  overflow: hidden;
}

.loading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff6b35, #d32f2f);
  border-radius: 1px;
  transition: width 0.1s ease;
}

/* ===== INTRO OVERLAY ===== */
#intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  transition: opacity 1.5s ease;
}

#intro-overlay.fade-out {
  opacity: 0;
}

/* Running counter at top */
#intro-counter-wrap {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 110;
  background: rgba(6, 6, 15, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 16px 32px;
}

.intro-counter-label {
  font-size: 10px;
  letter-spacing: 4px;
  color: #666;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.intro-counter-value {
  font-family: 'Space Mono', monospace;
  font-size: clamp(28px, 5vw, 56px);
  font-weight: 700;
  background: linear-gradient(135deg, #ff6b35, #d32f2f);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Milestone card at bottom */
.intro-milestone {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  background: rgba(6, 6, 15, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px 48px;
  z-index: 110;
  white-space: nowrap;
}

.intro-milestone-year {
  font-family: 'Space Mono', monospace;
  font-size: clamp(36px, 6vw, 56px);
  font-weight: 700;
  color: #ff6b35;
  line-height: 1;
  margin-bottom: 6px;
}

.intro-milestone-title {
  font-size: clamp(16px, 2.5vw, 24px);
  font-weight: 600;
  color: #e0e0e0;
  margin-bottom: 6px;
}

.intro-milestone-sub {
  font-size: clamp(12px, 1.5vw, 15px);
  color: #888;
  line-height: 1.5;
}

.intro-skip-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: #444;
  letter-spacing: 1px;
  z-index: 110;
}

/* ===== HUD ===== */
#hud {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  transition: opacity 1s ease;
}

.hud-panel {
  pointer-events: auto;
  background: rgba(10, 10, 20, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
}

#hud-top-left {
  position: absolute;
  top: 20px;
  left: 20px;
  padding: 20px 24px;
  min-width: 240px;
}

.hud-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 5px;
  color: #ff6b35;
  margin-bottom: 4px;
}

.hud-subtitle {
  font-size: 12px;
  font-weight: 300;
  color: #777;
  letter-spacing: 1px;
}

.hud-divider {
  height: 1px;
  background: linear-gradient(90deg, rgba(255,107,53,0.3), transparent);
  margin: 12px 0;
}

.hud-stat-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #666;
  margin-bottom: 4px;
}

.hud-stat-value {
  font-family: 'Space Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, #ff6b35, #d32f2f);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===== BAND CONTROL ===== */
.band-control {
  margin-top: 4px;
}

.band-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
}

#band-size-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  color: #e0e0e0;
  outline: none;
  transition: border-color 0.2s ease;
  width: 100%;
}

#band-size-input::placeholder {
  color: #444;
  font-size: 11px;
}

#band-size-input:focus {
  border-color: rgba(255, 107, 53, 0.5);
}

.band-reset-btn {
  background: rgba(255, 80, 80, 0.15);
  border: 1px solid rgba(255, 80, 80, 0.25);
  border-radius: 6px;
  color: #ff6b6b;
  font-size: 12px;
  padding: 5px 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  line-height: 1;
}

.band-reset-btn:hover {
  background: rgba(255, 80, 80, 0.3);
}

.band-hint {
  display: block;
  font-size: 9px;
  color: #444;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

/* ===== PER-CAPITA TOGGLE ===== */
.percapita-control {
  margin-top: 2px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  gap: 10px;
}

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 14px;
  height: 14px;
  background: #666;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: rgba(0, 229, 255, 0.2);
  border-color: rgba(0, 229, 255, 0.4);
}

.toggle-switch input:checked + .toggle-slider::before {
  left: 18px;
  background: #00e5ff;
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
}

/* ===== REPLAY BUTTON ===== */
.replay-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #777;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 0.5px;
}

.replay-btn:hover {
  background: rgba(255, 107, 53, 0.1);
  border-color: rgba(255, 107, 53, 0.25);
  color: #ff6b35;
}

.replay-icon {
  font-size: 14px;
  display: inline-block;
  transition: transform 0.4s ease;
}

.replay-btn:hover .replay-icon {
  transform: rotate(-360deg);
}

/* ===== COLOR FILTER PANEL ===== */
#color-filter-panel {
  position: absolute;
  top: 20px;
  left: 290px;
  padding: 14px 18px;
  max-width: 340px;
}

.color-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.color-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  color: #888;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.color-chip:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.15);
  color: #bbb;
}

.color-chip.active {
  border-color: var(--chip-active-color, rgba(255, 107, 53, 0.5));
  background: var(--chip-active-bg, rgba(255, 107, 53, 0.12));
  color: var(--chip-active-text, #ff6b35);
  box-shadow: 0 0 12px var(--chip-active-glow, rgba(255, 107, 53, 0.15));
}

.color-chip .chip-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 8px rgba(255, 255, 255, 0.03);
  flex-shrink: 0;
}

.color-chip.active .chip-emoji {
  background: var(--chip-active-bg, rgba(255, 107, 53, 0.18));
  border-color: var(--chip-active-color, rgba(255, 107, 53, 0.4));
  color: var(--chip-active-text, #ff6b35);
}

/* Color Legend */
.color-legend {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  animation: fadeIn 0.3s ease;
}

.legend-title {
  font-size: 9px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 6px;
}

.legend-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: #888;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-pct {
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  color: #666;
  margin-left: auto;
}

/* ===== YEAR TOOLTIP ===== */
#year-tooltip {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 20px 24px;
  pointer-events: none;
  background: rgba(10, 10, 20, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 107, 53, 0.15);
  border-radius: 12px;
  text-align: right;
  transition: opacity 0.3s ease;
  min-width: 180px;
}

.tooltip-year {
  font-family: 'Space Mono', monospace;
  font-size: 36px;
  font-weight: 700;
  color: #ff6b35;
  line-height: 1;
}

.tooltip-deaths {
  font-family: 'Space Mono', monospace;
  font-size: 20px;
  font-weight: 600;
  color: #e0e0e0;
  margin-top: 4px;
}

.tooltip-label {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 2px;
}

.tooltip-rate {
  font-size: 12px;
  color: #888;
  margin-top: 8px;
}

/* ===== BOTTOM CONTROLS ===== */
#hud-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  font-size: 11px;
  color: #555;
  letter-spacing: 1px;
  white-space: nowrap;
}

.hud-sep {
  margin: 0 8px;
  color: #333;
}

/* ===== COMPARISON PANEL ===== */
#comparison-panel {
  position: absolute;
  bottom: 60px;
  left: 20px;
  padding: 14px 18px;
  max-width: 420px;
}

.comp-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.comp-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  color: #888;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.comp-chip:hover {
  background: rgba(0, 229, 255, 0.08);
  border-color: rgba(0, 229, 255, 0.2);
  color: #bbb;
}

.comp-chip.active {
  background: rgba(0, 229, 255, 0.12);
  border-color: rgba(0, 229, 255, 0.4);
  color: #00e5ff;
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.15);
}

.comp-chip .chip-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid rgba(0, 229, 255, 0.2);
  box-shadow: inset 0 0 8px rgba(0, 229, 255, 0.06);
  flex-shrink: 0;
}

.comp-chip.active .chip-emoji {
  background: rgba(0, 229, 255, 0.18);
  border-color: rgba(0, 229, 255, 0.45);
  color: #8ff6ff;
}

.chip-num {
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  color: #555;
  margin-left: 2px;
}

.comp-chip.active .chip-num {
  color: rgba(0, 229, 255, 0.6);
}

/* ===== COMPARISON INFO CARD ===== */
#comp-info-card {
  position: fixed;
  bottom: 60px;
  right: 20px;
  max-width: 360px;
  padding: 20px 24px;
  background: rgba(6, 8, 18, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 229, 255, 0.15);
  border-radius: 14px;
  z-index: 55;
  animation: fadeInUp 0.4s ease;
  pointer-events: auto;
}

.comp-info-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.comp-info-title {
  font-size: 13px;
  font-weight: 700;
  color: #00e5ff;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.comp-info-stat {
  font-family: 'Space Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  color: #e0e0e0;
  line-height: 1.4;
  margin-bottom: 10px;
}

.comp-info-stat em {
  font-style: normal;
  color: #00e5ff;
}

.comp-info-detail {
  font-size: 12px;
  color: #777;
  line-height: 1.6;
}

.comp-info-detail strong {
  color: #aaa;
  font-weight: 600;
}

.comp-info-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: #555;
  font-size: 14px;
  cursor: pointer;
  padding: 8px;
  min-width: 32px;
  min-height: 32px;
  line-height: 1;
  transition: color 0.2s;
  touch-action: manipulation;
}

.comp-info-close:hover {
  color: #aaa;
}

/* ===== INFO DRAWER ===== */
.info-toggle-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(10, 10, 20, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #888;
  font-size: 18px;
  cursor: pointer;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  pointer-events: auto;
}

.info-toggle-btn:hover {
  background: rgba(255, 107, 53, 0.15);
  border-color: rgba(255, 107, 53, 0.3);
  color: #ff6b35;
  transform: scale(1.05);
}

.info-drawer {
  position: fixed;
  bottom: 70px;
  right: 20px;
  width: 340px;
  max-height: 60vh;
  background: rgba(6, 8, 18, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  z-index: 65;
  overflow-y: auto;
  animation: fadeInUp 0.35s ease;
  pointer-events: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.info-drawer::-webkit-scrollbar {
  width: 4px;
}
.info-drawer::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

.info-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 0;
}

.info-drawer-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #ff6b35;
  text-transform: uppercase;
}

.info-drawer-close-btn {
  background: none;
  border: none;
  color: #555;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}
.info-drawer-close-btn:hover {
  color: #aaa;
}

.info-drawer-body {
  padding: 16px 20px 20px;
  font-size: 12px;
  line-height: 1.7;
  color: #999;
}

.info-drawer-body p {
  margin-bottom: 8px;
}
.info-drawer-body strong {
  color: #ccc;
}

.info-drawer-body h4 {
  font-size: 10px;
  font-weight: 700;
  color: #888;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.info-drawer-body ul {
  list-style: none;
  padding: 0;
  margin-bottom: 4px;
}

.info-drawer-body li {
  position: relative;
  padding-left: 14px;
  margin-bottom: 4px;
  font-size: 11px;
}

.info-drawer-body li::before {
  content: '›';
  position: absolute;
  left: 0;
  color: #ff6b35;
  font-weight: 700;
}

.info-drawer-body a {
  color: #ff6b35;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 107, 53, 0.2);
  transition: border-color 0.2s;
}

.info-drawer-body a:hover {
  border-color: #ff6b35;
}

.info-drawer-divider {
  height: 1px;
  background: linear-gradient(90deg, rgba(255,107,53,0.2), transparent);
  margin: 12px 0;
}

.info-drawer-footer {
  font-size: 10px;
  color: #555;
  text-align: center;
  margin-top: 4px;
}

/* ===== PER-CAPITA BADGE ===== */
.percapita-badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #00e5ff;
  background: rgba(0, 229, 255, 0.1);
  border: 1px solid rgba(0, 229, 255, 0.2);
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: 6px;
  animation: fadeIn 0.3s ease;
}

/* ===== SEARCH & RANDOM ===== */
.search-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#dot-search-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: #fff;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  padding: 6px 8px;
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
}

#dot-search-input:focus {
  border-color: #00e5ff;
}

.random-btn {
  background: rgba(0, 229, 255, 0.1);
  border: 1px solid rgba(0, 229, 255, 0.3);
  border-radius: 4px;
  color: #00e5ff;
  font-size: 11px;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.random-btn:hover {
  background: rgba(0, 229, 255, 0.2);
}

/* ===== PERSON INFO CARD ===== */
#person-info-card {
  position: fixed;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  width: 320px;
  padding: 20px 24px;
  background: rgba(10, 15, 25, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(150, 130, 255, 0.3);
  border-radius: 14px;
  z-index: 56;
  animation: fadeIn 0.4s ease;
  pointer-events: auto;
}

.person-info-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.person-info-title {
  font-size: 11px;
  font-weight: 700;
  color: #9682ff;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.person-info-id {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: #888;
  margin-left: auto;
  margin-right: 24px;
}

.person-name {
  font-family: 'Space Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.person-demographics {
  font-size: 12px;
  color: #aaa;
  margin-bottom: 16px;
}

.person-demographics strong {
  color: #00e5ff;
}

.person-extra {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.person-detail-row {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  font-size: 11px;
  color: #cfcfd8;
  line-height: 1.35;
}

.person-detail-label {
  color: #888;
  min-width: 62px;
  flex-shrink: 0;
}

.person-detail-value {
  color: #f2f2f7;
  font-weight: 600;
}

.person-disclaimer {
  font-size: 9px;
  color: #666;
  line-height: 1.4;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 12px;
}

/* ===== UTILITIES ===== */
.hidden {
  display: none !important;
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.05); opacity: 1; }
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ================================================================
   MOBILE RESPONSIVE (max-width: 768px)
   ================================================================ */
@media (max-width: 768px) {
  :root {
    --safe-bottom: max(10px, env(safe-area-inset-bottom));
    --safe-top: max(10px, env(safe-area-inset-top));
  }

  button,
  input,
  .color-chip,
  .comp-chip {
    touch-action: manipulation;
  }

  /* --- Loading Screen --- */
  .loading-skull { font-size: 40px; }
  .loading-text { font-size: 12px; letter-spacing: 4px; }
  .loading-counter { font-size: 20px; }
  .loading-subtext { font-size: 10px; }

  /* --- Intro Counter --- */
  #intro-counter-wrap {
    top: calc(var(--safe-top) + 6px);
    padding: 10px 20px;
    max-width: calc(100vw - 20px);
  }
  .intro-counter-label {
    font-size: 8px;
    letter-spacing: 3px;
  }
  .intro-counter-value {
    font-size: clamp(22px, 6vw, 36px);
  }

  /* --- Intro Milestone Card --- */
  .intro-milestone {
    bottom: 50px;
    padding: 16px 24px;
    max-width: 90vw;
    white-space: normal;
  }
  .intro-milestone-year {
    font-size: clamp(28px, 8vw, 40px);
  }
  .intro-milestone-title {
    font-size: clamp(14px, 3.5vw, 18px);
  }
  .intro-milestone-sub {
    font-size: clamp(11px, 2.5vw, 13px);
  }
  .intro-skip-hint {
    bottom: 10px;
    font-size: 10px;
  }

  /* --- HUD Top-Left Panel --- */
  #hud-top-left {
    top: calc(var(--safe-top) + 4px);
    left: 10px;
    right: 10px;
    padding: 12px 14px;
    min-width: 0;
    max-width: 360px;
    max-height: 42vh;
    overflow-y: auto;
    scrollbar-width: thin;
  }
  .hud-title {
    font-size: 9px;
    letter-spacing: 3px;
  }
  .hud-subtitle {
    display: none;
  }
  .hud-stat-value {
    font-size: 16px;
  }
  .hud-stat-label {
    font-size: 8px;
    letter-spacing: 1.5px;
  }
  .hud-divider {
    margin: 8px 0;
  }
  .search-controls {
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
  }
  #dot-search-input,
  .random-btn {
    min-height: 34px;
    font-size: 12px;
  }
  .replay-btn {
    min-height: 34px;
  }

  /* --- Band Control (hide on mobile for clean UI) --- */
  .band-control {
    display: none;
  }

  /* --- Per-Capita Toggle --- */
  .percapita-control .band-hint {
    display: none;
  }

  /* --- Color Filter Panel --- */
  #color-filter-panel {
    position: absolute;
    top: auto;
    bottom: calc(var(--safe-bottom) + 74px);
    left: 10px;
    right: 10px;
    max-width: none;
    padding: 10px 12px;
    background: rgba(8, 10, 20, 0.82);
  }
  .color-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .color-chips::-webkit-scrollbar {
    display: none;
  }
  .color-chip {
    flex-shrink: 0;
    padding: 7px 10px;
    font-size: 10px;
  }
  .color-chip .chip-emoji {
    width: 20px;
    height: 20px;
    font-size: 12px;
  }
  .color-legend {
    display: none !important;
  }

  /* --- Year Tooltip --- */
  #year-tooltip {
    display: none !important;
  }

  /* --- Bottom HUD --- */
  #hud-bottom {
    display: none;
  }

  /* --- Comparison Panel --- */
  #comparison-panel {
    bottom: var(--safe-bottom);
    left: 10px;
    right: 10px;
    max-width: none;
    padding: 10px 12px;
    background: rgba(8, 10, 20, 0.86);
  }
  .comp-chips {
    gap: 4px;
    margin-top: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .comp-chips::-webkit-scrollbar {
    display: none;
  }
  .comp-chip {
    padding: 7px 10px;
    font-size: 10px;
    flex-shrink: 0;
  }
  .comp-chip .chip-emoji {
    width: 20px;
    height: 20px;
    font-size: 12px;
  }
  .chip-num {
    font-size: 8px;
  }

  /* --- Comparison Info Card --- */
  #comp-info-card {
    bottom: auto;
    top: calc(var(--safe-top) + 58px);
    right: 10px;
    left: 10px;
    max-width: none;
    padding: 14px 16px;
    max-height: 36vh;
    overflow-y: auto;
  }
  .comp-info-icon {
    font-size: 24px;
    margin-bottom: 4px;
  }
  .comp-info-title {
    font-size: 11px;
    letter-spacing: 1.5px;
  }
  .comp-info-stat {
    font-size: 14px;
  }
  .comp-info-detail {
    font-size: 11px;
  }
  .comp-info-close {
    top: 8px;
    right: 10px;
    font-size: 18px;
    padding: 8px;
    min-width: 38px;
    min-height: 38px;
  }

  /* --- Person Info Card --- */
  #person-info-card {
    top: calc(var(--safe-top) + 58px);
    bottom: calc(var(--safe-bottom) + 130px);
    right: 10px;
    left: 10px;
    width: auto;
    transform: none !important;
    padding: 14px 16px;
    max-height: none;
    overflow-y: auto;
  }
  .person-info-title {
    font-size: 10px;
    letter-spacing: 1.5px;
  }
  .person-info-id {
    font-size: 10px;
    margin-right: 28px;
  }
  .person-name {
    font-size: 18px;
    margin-bottom: 6px;
  }
  .person-demographics {
    font-size: 11px;
    margin-bottom: 12px;
  }
  .person-extra {
    margin-bottom: 10px;
    gap: 5px;
  }
  .person-detail-row {
    font-size: 10px;
    gap: 5px;
  }
  .person-detail-label {
    min-width: 58px;
  }
  .person-disclaimer {
    font-size: 8px;
    padding-top: 10px;
  }

  /* --- Info Drawer --- */
  .info-toggle-btn {
    bottom: calc(var(--safe-bottom) + 2px);
    right: 14px;
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
  .info-drawer {
    bottom: calc(var(--safe-bottom) + 46px);
    right: 10px;
    left: 10px;
    width: auto;
    max-height: 58vh;
  }

  /* --- Replay (hide label on mobile) --- */
  .replay-btn {
    font-size: 10px;
    padding: 6px 10px;
  }
}

@media (max-width: 420px) {
  #hud-top-left {
    max-width: none;
    max-height: 38vh;
    padding: 10px 12px;
  }

  .hud-title {
    font-size: 8px;
    letter-spacing: 2px;
  }

  .hud-stat-value {
    font-size: 14px;
  }

  .color-chip,
  .comp-chip {
    padding: 6px 9px;
    font-size: 9px;
  }

  .chip-num {
    display: none;
  }

  #color-filter-panel,
  #comparison-panel {
    left: 8px;
    right: 8px;
    padding: 9px 10px;
  }

  #person-info-card,
  #comp-info-card,
  .info-drawer {
    left: 8px;
    right: 8px;
  }

  #person-info-card {
    bottom: calc(var(--safe-bottom) + 120px);
  }
  .person-detail-row {
    font-size: 9px;
    line-height: 1.3;
  }
  .person-detail-label {
    min-width: 54px;
  }
}

/* Landscape phones — tighter layout */
@media (max-height: 480px) and (orientation: landscape) {
  #intro-counter-wrap {
    top: 8px;
    padding: 6px 14px;
  }
  .intro-counter-value {
    font-size: 20px;
  }
  .intro-milestone {
    bottom: 30px;
    padding: 10px 20px;
  }
  .intro-milestone-year {
    font-size: 24px;
  }
  .intro-milestone-title {
    font-size: 13px;
  }
  .intro-milestone-sub {
    font-size: 11px;
  }
  #hud-top-left {
    padding: 8px 10px;
    max-width: 150px;
  }
  #comparison-panel {
    bottom: 30px;
  }
}
