/* Minimalist classroom vibe */
:root{
  --bg: #141414;
  --panel: rgba(255,255,255,0.92);
  --panel-border: rgba(0,0,0,0.10);
  --ink: #1b1f24;
  --muted: rgba(0,0,0,0.62);
  --title-red: #c1121f;
  --shadow: 0 10px 28px rgba(0,0,0,0.12);
}

*{ box-sizing: border-box; }
html,body{ height:100%; margin:0; background:var(--bg); color:var(--ink); font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; }

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

#title-wrap{
  position:absolute;
  top:14px; left:16px;
  z-index: 30;
  pointer-events:none;
}
#title{
  margin:0;
  display:inline-block;
  font-family: "Rock Salt", Inter, sans-serif;
  color: var(--title-red);
  font-size: clamp(20px, 3vw, 40px);
  letter-spacing: 0.5px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.06);
}
#title::after{
  content:"";
  display:block;
  height: 4px;
  width: 100%;
  margin-top: 8px;
  background: var(--title-red);
  border-radius: 999px;
  transform: rotate(-1.2deg);
  opacity: 0.95;
}

#map-wrap{
  position:absolute; inset:0;
  padding-top: 68px; /* room for title */
  z-index: 10;
}

#svg{
  width:100%;
  height:100%;
  display:block;
}

.loading{
  position:absolute;
  left: 16px;
  top: 76px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  z-index: 40;
  font-weight: 600;
}

/* State styling */
.state{
  stroke: rgba(0,0,0,0.14);
  stroke-width: 1;
  cursor: pointer;
  transition: filter 140ms ease, opacity 140ms ease, stroke 140ms ease;
}
.state:hover{
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.20));
  stroke: rgba(0,0,0,0.30);
}
.state.dimmed{
  opacity: 0.14;
  pointer-events: none;
}

/* Popup */
.popup{
  position:absolute;
  z-index: 60;
  min-width: 260px;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(7px);
  display:none;
}
.popup[aria-hidden="false"]{ display:block; }

.popup-inner{ padding: 12px 12px 10px; }
.popup-head{
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.popup-state{
  font-weight: 800;
  font-size: 16px;
  line-height: 1.1;
}
.icon-btn{
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor:pointer;
  color: rgba(0,0,0,0.65);
}
.icon-btn:hover{ color: rgba(0,0,0,0.9); }

.badge{
  display:inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
}

.popup-block{ margin-top: 10px; }
.popup-label{
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.popup-quote{
  font-size: 14px;
  font-weight: 650;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.04);
}
.popup-translation{
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.03);
  color: rgba(0,0,0,0.75);
}
.popup-types{
  display:flex;
  flex-wrap: wrap;
  gap: 6px;
}
.type-pill{
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.06);
}

/* Legend */
#legend{
  position:absolute;
  right: 14px;
  bottom: 14px;
  width: min(320px, calc(100vw - 28px));
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  z-index: 50;
  overflow:hidden;
}
#legend-header{
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 12px 12px;
  cursor:pointer;
  user-select:none;
}
#legend-header:focus{ outline: 2px solid rgba(193,18,31,0.35); outline-offset: -2px; }
.legend-title{ font-weight: 900; }
.legend-toggle{ color: rgba(0,0,0,0.55); font-weight: 800; }

#legend-body{ padding: 0 12px 12px; }
#legend.minimized #legend-body{ display:none; }
#legend.minimized .legend-toggle{ transform: rotate(-90deg); }

.legend-items{
  display:flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.legend-item{
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: 12px;
  cursor:pointer;
  border: 1px solid rgba(0,0,0,0.06);
  background: rgba(255,255,255,0.55);
}
.legend-item:hover{ border-color: rgba(0,0,0,0.12); }
.swatch{
  width: 14px; height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.20);
  flex: 0 0 auto;
}
.legend-item .label{
  font-weight: 650;
  font-size: 13px;
}
.legend-item.selected{
  box-shadow: 0 0 0 2px rgba(193,18,31,0.22) inset;
}
.legend-item.dim{
  opacity: 0.55;
}

.btn-quiet{
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(0,0,0,0.03);
  cursor: pointer;
  font-weight: 700;
  color: rgba(0,0,0,0.72);
}
.btn-quiet:hover{ background: rgba(0,0,0,0.05); }

.legend-footer{
  display:flex;
  justify-content:flex-end;
  margin-top: 8px;
}
.btn-link{
  border:0;
  background: transparent;
  cursor:pointer;
  font-weight: 700;
  color: rgba(0,0,0,0.60);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 12px;
}
.btn-link:hover{ color: rgba(0,0,0,0.85); }

/* Modal */
.modal-backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,0.35);
  display:none;
  align-items:center;
  justify-content:center;
  z-index: 80;
  padding: 18px;
}
.modal-backdrop[aria-hidden="false"]{ display:flex; }

.modal{
  width: min(520px, 96vw);
  background: rgba(255,255,255,0.96);
  border-radius: 16px;
  border: 1px solid rgba(0,0,0,0.10);
  box-shadow: var(--shadow);
  overflow:hidden;
}
.modal-head{
  display:flex;
  justify-content: space-between;
  align-items:center;
  padding: 12px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.modal-title{ font-weight: 900; }
.modal-body{ padding: 12px 14px 14px; color: rgba(0,0,0,0.78); }
.sources-list{ margin: 0; padding-left: 18px; }
.sources-list li{ margin: 8px 0; line-height: 1.35; }
.made-with{ margin-top: 12px; font-weight: 700; color: rgba(0,0,0,0.65); }
.made-with a{ color: rgba(0,0,0,0.75); }
.made-with a:hover{ color: rgba(0,0,0,0.95); }

/* Attribution */
#attribution{
  position:absolute;
  left: 16px;
  bottom: 14px;
  z-index: 45;
  font-size: 11px;
  color: rgba(0,0,0,0.55);
  background: rgba(255,255,255,0.62);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 999px;
  padding: 6px 10px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}
#attribution .dot{ padding: 0 6px; opacity: 0.7; }

/* Mobile orientation gate */
#rotate-gate{
  display:none;
  position:fixed;
  inset:0;
  background: var(--bg);
  z-index: 9999;
  align-items:center;
  justify-content:center;
  padding: 18px;
}
.rotate-card{
  width: min(520px, 96vw);
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px 16px;
  text-align:center;
}
.rotate-title{ font-family: "Rock Salt", Inter, sans-serif; color: var(--title-red); font-size: 22px; }
.rotate-sub{ margin-top: 6px; color: rgba(0,0,0,0.68); font-weight: 650; }

/* Gate triggers primarily for handheld devices */
@media (max-width: 900px) and (orientation: portrait){
  #rotate-gate{ display:flex; }
  #app{ display:none; }
}
