:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: #f9f3fa;
  background: #0e0b11;
  --bg: #151019;
  --surface: #201722;
  --raised: #2b1b2d;
  --line: #382b3c;
  --muted: #b9aabd;
  --accent: #ff82c1;
  --hot: #ff4ca4;
  --peach: #ffbd98;
  --sunset: linear-gradient(115deg, #f657aa, #ff83bd 58%, #ffc19a);
  --map-control: #17101bea;
  --header-height: 72px;
  --panel-width: 314px;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button { color: inherit; background: transparent; border: 0; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
:where(button, input, a, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
svg[aria-hidden="true"] { display: block; width: 20px; height: 20px; flex: none; }
i { display: inline-flex; font-style: normal; }

.topbar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: clamp(12px, 2.5vw, 34px);
  height: var(--header-height);
  padding: 0 25px;
  border-bottom: 1px solid #4f2c47;
  background: radial-gradient(ellipse at 0 0, #3c1832 0%, transparent 33%), #110d15;
}
.brand { display: flex; align-items: center; gap: 12px; width: calc(var(--panel-width) - 34px); flex: none; }
.brand img { filter: drop-shadow(0 3px 12px #ff48993b); }
.brand b {
  display: block;
  font-family: "Archivo Black", Inter, "Segoe UI", sans-serif;
  font-size: 25px;
  font-weight: 950;
  font-style: italic;
  line-height: .95;
  letter-spacing: -.7px;
}
.brand small { display: block; margin-top: 6px; color: #e3adc9; font-size: 10px; font-weight: 750; letter-spacing: 2.3px; }
.tabs { display: flex; align-items: stretch; gap: 4px; height: 100%; }
.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 2px 15px 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 650;
  font-size: 15px;
}
.tab svg { width: 18px; height: 18px; }
.tab:hover { color: #fff; background: #2a1a2b; }
.tab.active { color: #ffd4e9; border-color: var(--hot); background: linear-gradient(0deg,#a62e702f,transparent 65%); }
.tab.active i { color: var(--accent); }
.tab span {
  padding: 2px 6px;
  border-radius: 6px;
  background: #392339;
  color: #ffd5e9;
  font: 12px ui-monospace, Consolas, monospace;
}
.save-status { display: flex; align-items: center; gap: 7px; margin-left: auto; color: var(--muted); font-size: 13px; }
.save-status svg { width: 16px; height: 16px; color: var(--accent); }
.language-select {
  flex: none;
  max-width: 8rem;
  min-height: 36px;
  padding: 0 .5rem;
  border: 1px solid #55394f;
  border-radius: 7px;
  background: #201522;
  color: #f9eaf5;
  font-size: .875rem;
}

.workspace {
  position: relative;
  display: flex;
  overflow: hidden;
  height: calc(100vh - var(--header-height));
  height: calc(100dvh - var(--header-height));
}
.sidebar {
  z-index: 3;
  width: var(--panel-width);
  flex: 0 0 var(--panel-width);
  overflow: auto;
  border-right: 1px solid #5a3250;
  background: radial-gradient(ellipse 105% 42% at 0 0,#35172d, transparent), var(--bg);
  box-shadow: 14px 0 34px #12091c38;
  scrollbar-width: thin;
  scrollbar-color: #5f405b transparent;
}
#panel-content {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: clamp(21px, 3.8vh, 34px) 22px 22px;
}
.sidebar h1 { font-size: clamp(27px, 4.5vh, 35px); font-weight: 850; letter-spacing: -.04em; line-height: 1.08; overflow-wrap: anywhere; }
.sidebar h2 { color: #dec5d9; font-size: 13px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.panel-title, .back-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.back-row { margin-bottom: 15px; }
.back-button, .panel-close {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 0;
  color: #e1cadd;
  font-size: 14px;
}
.back-button:hover, .panel-close:hover { color: var(--accent); }
.back-button svg { width: 15px; height: 15px; }
.panel-close { display: none; }
.lede { margin-top: 10px; color: var(--muted); font-size: 15px; line-height: 1.55; }

.stats { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; margin: clamp(14px, 3vh, 22px) 0; }
.stat {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px 5px;
  padding: 12px 11px;
  border: 1px solid #502b49;
  border-radius: 9px;
  background: linear-gradient(150deg,#3a1d37,#211622 62%);
}
.stat i { color: var(--accent); }
.stat:nth-child(2) i { color: var(--peach); }
.stat svg { width: 17px; height: 17px; }
.stat strong { font-size: 26px; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; }
.stat small { grid-column: 1 / -1; color: #d4c0d0; font-size: 13px; overflow-wrap: anywhere; }
.regions { padding-top: clamp(13px,2.7vh,20px); border-top: 1px solid var(--line); }
.regions h2, .instructions h2 { margin-bottom: 10px; }
.region {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: clamp(7px,1.2vh,11px) 9px;
  border-radius: 7px;
  color: #efdbeb;
  text-align: left;
  font-size: 15px;
}
.region svg { width: 16px; height: 16px; color: #be89ae; }
.region:hover { background: var(--raised); }
.region.current { color: #ffe4f2; background: #48223c; box-shadow: inset 2px 0 var(--hot); }
.region.current svg { color: var(--accent); }
.instructions { padding-top: clamp(14px,3vh,25px); margin-top: auto; }
.instructions h2 { padding-top: 15px; border-top: 1px solid var(--line); }
.instructions div { display: flex; align-items: center; gap: 11px; margin-top: 10px; }
.instructions div > i {
  display: grid;
  place-items: center;
  flex: 0 0 33px;
  height: 33px;
  border: 1px solid #53314b;
  border-radius: 7px;
  background: #342033;
  color: #ffc3e1;
}
.instructions svg { width: 17px; height: 17px; }
.instructions p > * { display: block; }
.instructions b { font-size: 14px; font-weight: 650; }
.instructions span { margin-top: 2px; color: var(--muted); font-size: 13px; }

.map-wrap { position: relative; flex: 1; min-width: 0; isolation: isolate; background: #355769; }
#map { position: absolute; z-index: 0; inset: 0; background: #355769; font-family: inherit; touch-action: none; }
#map:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.leaflet-tile-pane { filter: saturate(.8) brightness(.87) contrast(1.06); }
.leaflet-container .leaflet-interactive { outline: none; }
.district-label { background: none; border: 0; text-align: center; pointer-events: none !important; }
.district-label span {
  display: inline-block;
  transform: translate(-50%,-50%);
  color: #fff1fb;
  text-align: center;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: .11em;
  text-transform: uppercase;
  text-shadow: 0 1px 4px #140917, -1px 0 2px #241128, 1px 0 2px #241128;
}
.district-label.major span { font-size: 18px; letter-spacing: .16em; }

.panel-toggle, .map-tools, .compass {
  position: absolute;
  border: 1px solid #794361;
  border-radius: 9px;
  background: var(--map-control);
  color: #ffe2f1;
  box-shadow: 0 4px 18px #1107194d;
}
.panel-toggle { display: grid; place-items: center; top: 17px; left: 17px; width: 44px; height: 44px; }
.panel-toggle[aria-expanded="false"] { color: var(--accent); }
.panel-toggle:hover, .map-tools button:hover { background: #3b1e35; color: #fff; }
.compass {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  top: 17px;
  right: 17px;
  width: 43px;
  height: 60px;
  pointer-events: none;
}
.compass b { color: #ffd0e7; font: 600 12px ui-monospace, Consolas, monospace; }
.compass svg { width: 20px; height: 29px; }
.needle-light { fill: #ffc4e0; }
.needle-dark { fill: #a85486; }
.map-tools { display: flex; flex-direction: column; overflow: hidden; right: 17px; bottom: 47px; }
.map-tools button { display: grid; place-items: center; width: 42px; height: 42px; }
.map-tools button + button { border-top: 1px solid #4e2f4a; }
.map-tools button:last-child svg { width: 17px; height: 17px; }
.map-tools button:focus-visible { outline-offset: -4px; }
.map-foot {
  position: absolute;
  right: 14px;
  bottom: 9px;
  left: 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  font-size: 12px;
}
.map-foot > span { padding: 4px 7px; border-radius: 4px; color: #fce8f5; background: #1a1020e8; }
.map-foot a { color: inherit; pointer-events: auto; text-underline-offset: 2px; }
.map-foot #scale { flex: none; width: max-content; text-align: center; border-bottom: 2px solid #ffc4e0; border-radius: 2px; font: 12px ui-monospace, Consolas, monospace; }

.detail-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; color: var(--accent); font-size: 14px; }
.detail-head svg { width: 17px; height: 17px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 20px 0 9px; }
.section-title span { color: var(--muted); font: 13px ui-monospace, Consolas, monospace; }
.primary, .secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 11px;
  padding: 10px 8px;
  border: 1px solid #633c5a;
  border-radius: 8px;
  color: #ffeaf7;
  font-weight: 650;
  font-size: 15px;
}
.primary { color: #250f21; background: var(--sunset); border-color: transparent; }
.primary:hover { filter: brightness(1.09); }
.secondary:hover, .journal-link:hover { background: var(--raised); }
.primary svg, .secondary svg { width: 17px; height: 17px; }
.empty { margin-top: 8px; padding: 14px 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-size: 15px; line-height: 1.55; }
.journal-list { list-style: none; margin: 0; padding: 0; }
.journal-link { display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 3px; text-align: left; border-top: 1px solid var(--line); }
.journal-link > i { color: var(--accent); }
.journal-link > i svg { width: 18px; height: 18px; }
.journal-link small { display: block; margin-top: 3px; color: var(--muted); }
.journal-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 9px; }
.journal-tabs button { padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
.journal-tabs .on { background: #44243d; color: #ffd9ed; border-color: #865475; }

#notice, #load-failure {
  position: absolute;
  bottom: 46px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 85%;
  padding: 10px 13px;
  border: 1px solid #875475;
  border-radius: 8px;
  background: #211427f5;
  box-shadow: 0 3px 18px #130b204d;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}
#load-failure { bottom: 50%; pointer-events: auto; }
#load-failure button { color: var(--accent); text-decoration: underline; }
.mobile-grip { display: none; }

@media (max-width: 970px) {
  :root { --panel-width: 268px; }
  .topbar { padding-inline: 17px; }
  #panel-content { padding-inline: 17px; }
}
@media (max-width: 850px) {
  .save-status { display: none; }
  .language-select { max-width: 7rem; margin-left: auto; }
}
@media (max-width: 700px) {
  :root { --header-height: 59px; }
  .topbar { gap: 8px; padding-inline: 12px; }
  .brand { width: auto; gap: 7px; }
  .brand img { width: 32px; height: 32px; }
  .brand b { font-size: 18px; }
  .brand small { font-size: 9px; letter-spacing: 1.3px; margin-top: 4px; }
  .tabs { margin-left: auto; gap: 0; }
  .tab { padding-inline: 7px; font-size: 14px; gap: 5px; }
  .tab svg { width: 16px; height: 16px; }
  .tab span { font-size: 10px; }
  .language-select { margin-left: 0; }
  .sidebar {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    display: none;
    width: 100%;
    max-height: 58%;
    border: 1px solid #723e65;
    border-radius: 15px 15px 0 0;
    box-shadow: 0 -8px 30px #13061f66;
  }
  .sidebar.open { display: block; }
  .mobile-grip { display: block; margin: 6px auto 0; width: 32px; height: 3px; border-radius: 4px; background: #9d698e; }
  #panel-content { min-height: 0; padding: 12px 16px max(17px,env(safe-area-inset-bottom)); }
  .sidebar h1 { font-size: 25px; }
  .panel-close { display: grid; place-items: center; flex: 0 0 36px; height: 34px; border: 1px solid var(--line); border-radius: 7px; }
  .lede { margin-top: 7px; font-size: 14px; }
  .stats { margin: 12px 0; }
  .stat { padding: 9px 12px; }
  .stat strong { font-size: 23px; }
  .panel-toggle { top: 11px; left: 11px; }
  .compass { top: 11px; right: 11px; }
  .map-tools { right: 11px; bottom: 45px; }
  .map-foot { left: 8px; right: 8px; font-size: 10px; }
  #notice { z-index: 2; top: 66px; bottom: auto; }
}
@media (max-width: 520px) {
  .brand > div { display: none; }
  .language-select { max-width: 5rem; padding-inline: .25rem; }
}
@media (max-width: 360px) {
  .topbar { gap: 5px; padding-inline: 8px; }
  .tab svg { display: none; }
}
