:root {
  --bg: #0d1b2b;
  --panel: #13223a;
  --panel-2: #182a45;
  --panel-3: #1e3353;
  --line: #2b4366;
  --line-soft: rgba(120, 160, 210, 0.16);
  --gold: #d9b45a;
  --gold-2: #f2d48a;
  --gold-dim: #9c7f3c;
  --text: #e8e2d0;
  --muted: #9aa8bc;
  --faint: #6c7c92;
  --good: #7fcf7a;
  --bad: #ef7b6b;
  --food: #8fd16a;
  --prod: #f2994a;
  --gold-y: #f2c94c;
  --sci: #56b4f2;
  --cul: #c08cf2;
  --serif: 'Cinzel', 'Trajan Pro', 'Cormorant SC', 'Palatino Linotype', Palatino, Georgia, serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--gold-2); }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#map:active { cursor: grabbing; }

/* ---------- loading ---------- */
#loading { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; background: var(--bg); z-index: 50; font-family: var(--serif); letter-spacing: .08em; color: var(--gold); transition: opacity .5s; }
#loading.done { opacity: 0; pointer-events: none; }
.spin { width: 44px; height: 44px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- top bar ---------- */
#topbar { position: absolute; top: 0; left: 0; right: 0; height: 44px; display: flex; align-items: center; gap: 6px; padding: 0 10px; background: linear-gradient(#1a2c47, #101d31); border-bottom: 1px solid var(--gold-dim); box-shadow: 0 3px 12px rgba(0,0,0,.5); z-index: 20; }
#topbar .emblem { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, #3a5a8a, #13223a); border: 1.5px solid var(--gold); color: #fff; font-size: 15px; flex: none; }
#topbar .brand { font-family: var(--serif); letter-spacing: .16em; text-transform: uppercase; color: var(--gold-2); font-weight: 700; margin: 0 6px 0 2px; }
#topbar .stats { display: flex; gap: 2px; align-items: center; overflow: hidden; flex: 1; min-width: 0; }
#topbar .stat { display: flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 6px; font-weight: 600; font-size: 14px; white-space: nowrap; cursor: help; }
#topbar .stat:hover { background: rgba(255,255,255,.06); }
#topbar .stat svg { width: 16px; height: 16px; }
#topbar .right { display: flex; gap: 6px; align-items: center; flex: none; }
.search { position: relative; }
.search input { width: 210px; height: 30px; border-radius: 15px; border: 1px solid var(--line); background: #0b1626; color: var(--text); padding: 0 30px 0 30px; font: inherit; }
.search input:focus { outline: none; border-color: var(--gold); }
.search .ic { position: absolute; left: 10px; top: 7px; width: 16px; height: 16px; opacity: .7; }
.search kbd { position: absolute; right: 8px; top: 6px; font-size: 11px; color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.search-results { position: absolute; top: 36px; right: 0; width: 320px; max-height: 60vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 30; }
.search-results .item { padding: 8px 12px; display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
.search-results .item:hover, .search-results .item.active { background: var(--panel-3); }
.search-results .item small { color: var(--muted); }
.icon-btn { width: 32px; height: 30px; display: grid; place-items: center; border-radius: 6px; border: 1px solid var(--line); background: #0f1c30; }
.icon-btn:hover { border-color: var(--gold); }
.icon-btn.active { background: linear-gradient(#5b4820, #3a2e14); border-color: var(--gold); }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- panels ---------- */
.panel { position: absolute; top: 44px; bottom: 0; width: 400px; background: linear-gradient(180deg, var(--panel), #0f1b2e); border: 1px solid var(--line); box-shadow: var(--shadow); z-index: 15; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
#left { left: 0; border-left: none; }
#right { right: 0; border-right: none; width: 440px; }
.panel .close { position: absolute; right: 10px; top: 10px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: #0b1626; display: grid; place-items: center; z-index: 3; }
.panel .close:hover { border-color: var(--gold); }
.panel h1, .panel h2, .panel h3 { font-family: var(--serif); font-weight: 700; margin: 0; letter-spacing: .05em; }
.panel h1 { font-size: 26px; color: #fff; }
.panel h2 { font-size: 15px; color: var(--gold); text-transform: uppercase; letter-spacing: .12em; display: flex; align-items: center; gap: 8px; }
.panel h2::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--gold-dim), transparent); }
.panel h3 { font-size: 13px; color: var(--gold-2); text-transform: uppercase; letter-spacing: .1em; }
.sec { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.kicker { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.note { font-size: 11.5px; color: var(--faint); line-height: 1.45; margin-top: 8px; }
.good { color: var(--good); } .bad { color: var(--bad); }

.head { display: flex; gap: 14px; align-items: center; padding: 16px; padding-right: 50px; background: radial-gradient(circle at 0 0, rgba(217,180,90,.12), transparent 60%); }
.pop-hex { width: 64px; height: 72px; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #fff; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.badge { display: inline-flex; gap: 6px; align-items: center; padding: 3px 10px; border-radius: 12px; border: 1px solid var(--gold-dim); background: rgba(0,0,0,.25); font-family: var(--serif); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--gold-2); }
.chip { display: inline-block; padding: 1px 7px; border-radius: 4px; border: 1px solid var(--line); font-size: 11px; color: var(--muted); margin-right: 4px; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cards.three { grid-template-columns: 1fr 1fr 1fr; }
.card { background: rgba(0,0,0,.22); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.card .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.card .val { font-size: 20px; font-weight: 700; color: #fff; margin-top: 2px; }
.card .sub { font-size: 12px; color: var(--muted); }

.ranks { display: flex; justify-content: space-around; gap: 6px; margin-top: 4px; }
.rank { text-align: center; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.medal { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 4px; font-weight: 800; font-size: 13px; color: #2a1d05; border: 2px solid rgba(255,255,255,.35); box-shadow: inset 0 -4px 8px rgba(0,0,0,.3), 0 2px 6px rgba(0,0,0,.4); }
.medal.g { background: radial-gradient(circle at 35% 30%, #fff1b8, #d9a93a 60%, #9b7420); }
.medal.s { background: radial-gradient(circle at 35% 30%, #ffffff, #b8c2cf 60%, #7a8696); }
.medal.b { background: radial-gradient(circle at 35% 30%, #ffd8b0, #c47d43 60%, #87512a); color: #fff; }

.tabs { display: flex; gap: 2px; padding: 0 10px; position: sticky; top: 0; background: #101d31; z-index: 2; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: none; padding: 10px 8px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs button.active { color: var(--gold-2); border-bottom-color: var(--gold); }
.tabs button:hover { color: #fff; }

.bars .row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 5px 4px; border-radius: 5px; cursor: default; }
.bars .row:hover { background: rgba(255,255,255,.05); }
.bars .row .name { font-size: 13px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.bars .row .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .row .v { font-weight: 600; font-size: 13px; text-align: right; white-space: nowrap; }
.bars .row .bar { grid-column: 1 / 3; height: 5px; background: rgba(255,255,255,.07); border-radius: 3px; position: relative; overflow: visible; }
.bars .row .bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); }
.bars .row .bar b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #fff; opacity: .7; }
.bars .row .x { font-size: 11px; color: var(--muted); margin-left: 4px; }
.bars.clickable .row { cursor: pointer; }

table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.t th { text-align: right; font-weight: 600; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; padding: 6px 4px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); cursor: pointer; user-select: none; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t td { padding: 5px 4px; border-bottom: 1px solid rgba(255,255,255,.04); text-align: right; white-space: nowrap; }
table.t td.nm { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td, table.t tr.hl td { background: rgba(217,180,90,.1); }
table.t th.sorted { color: var(--gold-2); }

.figs { display: flex; flex-wrap: wrap; gap: 1px; margin: 6px 0; }
.figs .f { width: 13px; height: 20px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--muted); }
.legend-row i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.stack { display: flex; height: 16px; border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
.stack > div { height: 100%; }
.stack.us { height: 6px; opacity: .65; }

.standout { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--gold-dim); background: linear-gradient(90deg, rgba(217,180,90,.14), rgba(0,0,0,.1)); margin: 10px 0; }
.standout .ic { width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; background: #0b1626; border: 1px solid var(--gold-dim); font-size: 20px; flex: none; }

.district { display: flex; gap: 12px; padding: 10px; border-radius: var(--radius); background: rgba(0,0,0,.2); border: 1px solid var(--line); margin: 8px 0; }
.district .ic { width: 42px; height: 48px; flex: none; display: grid; place-items: center; font-size: 22px; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); }
.district b { color: #fff; }

.list-item { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 6px; border-bottom: 1px solid rgba(255,255,255,.05); cursor: pointer; border-radius: 4px; }
.list-item:hover { background: rgba(217,180,90,.08); }
.list-item .t1 { font-weight: 600; }
.list-item .t2 { font-size: 12px; color: var(--muted); }

/* ---------- lens bar ---------- */
#lensbar { position: absolute; bottom: 14px; right: 14px; display: flex; gap: 4px; padding: 5px; background: rgba(15,28,48,.92); border: 1px solid var(--gold-dim); border-radius: 10px; box-shadow: var(--shadow); z-index: 12; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 260px); }
#lensbar button { display: flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 7px; border: 1px solid transparent; background: transparent; font-size: 13px; font-weight: 500; white-space: nowrap; }
#lensbar button:hover { background: rgba(255,255,255,.06); }
#lensbar button.on { background: linear-gradient(#5b4820, #3a2e14); border-color: var(--gold); color: var(--gold-2); }
#lensbar button.toggle.on { background: rgba(217,180,90,.14); border-color: var(--gold-dim); color: var(--gold-2); }
#lensbar .count { background: var(--gold); color: #2a1d05; border-radius: 9px; font-size: 10.5px; font-weight: 800; padding: 0 6px; }
.menu { position: absolute; bottom: 52px; right: 0; width: 300px; max-height: 70vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 8px; z-index: 40; }
.menu .grp { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); padding: 8px 6px 4px; }
.menu button { width: 100%; text-align: left; justify-content: flex-start; }
.menu label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.menu label:hover { background: rgba(255,255,255,.05); }

/* ---------- legend ---------- */
#legend { position: absolute; top: 56px; right: 14px; width: 300px; background: rgba(15,28,48,.94); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; z-index: 11; box-shadow: var(--shadow); }
#legend .title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
#legend .title .x { margin-left: auto; }
#legend .ramp { height: 10px; border-radius: 5px; margin: 8px 0 4px; }
#legend .ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
#legend .desc { font-size: 11.5px; color: var(--faint); margin-top: 6px; line-height: 1.4; }
#legend .cats { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; font-size: 12px; margin-top: 6px; }
#legend .cats i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
body.right-open #legend { right: 454px; }
body.right-open #lensbar { right: 454px; max-width: calc(100% - 700px); }

/* ---------- tooltip ---------- */
#tooltip { position: absolute; pointer-events: none; z-index: 45; background: rgba(10,19,33,.96); border: 1px solid var(--gold-dim); border-radius: 8px; padding: 8px 10px; max-width: 300px; font-size: 12.5px; box-shadow: var(--shadow); line-height: 1.45; }
#tooltip b { color: #fff; }
#tooltip .tt-h { font-family: var(--serif); color: var(--gold-2); font-size: 14px; letter-spacing: .04em; }
#tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; }
#tooltip .tt-row span:first-child { color: var(--muted); }

/* ---------- minimap ---------- */
#minimap { position: absolute; left: 14px; bottom: 14px; width: 220px; height: 200px; border: 2px solid var(--gold-dim); border-radius: 8px; background: #0b1626; box-shadow: var(--shadow); z-index: 10; cursor: pointer; }
body.left-open #minimap { left: 414px; }

/* ---------- modal (help / almanac) ---------- */
#modal { position: absolute; inset: 0; background: rgba(4,8,14,.72); z-index: 60; display: grid; place-items: center; padding: 20px; }
#modal .box { width: min(860px, 100%); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--gold-dim); border-radius: 12px; box-shadow: var(--shadow); position: relative; }
#modal .box .close { position: sticky; float: right; top: 10px; margin: 10px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: #0b1626; }
#modal h1 { font-family: var(--serif); color: var(--gold-2); letter-spacing: .06em; margin: 0 0 8px; font-size: 26px; }
#modal h2 { font-family: var(--serif); color: var(--gold); font-size: 16px; letter-spacing: .1em; text-transform: uppercase; margin: 22px 0 8px; }
#modal .content { padding: 22px 26px; line-height: 1.55; }
#modal .src { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
#modal .src b { color: #fff; }

/* ---------- advisors ---------- */
.adv-nav { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #101d31; z-index: 3; flex-wrap: wrap; padding-right: 46px; }
.adv-nav button { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: #0b1626; display: grid; place-items: center; padding: 0; font-size: 14px; }
.adv-nav button.active { border-color: var(--gold); background: linear-gradient(#5b4820, #3a2e14); }
.adv-head { display: flex; gap: 14px; align-items: center; padding: 16px; border-bottom: 1px solid var(--line-soft); background: radial-gradient(circle at 0 0, rgba(217,180,90,.12), transparent 60%); }
.adv-portrait { width: 62px; height: 62px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 28px; background: radial-gradient(circle at 35% 30%, #f6dc8e, #b8862d 60%, #6d4c15); border: 2px solid #f2d48a; box-shadow: 0 3px 10px rgba(0,0,0,.5); }
.adv-card { display: flex; gap: 12px; padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: rgba(0,0,0,.2); cursor: pointer; margin: 8px 0; }
.adv-card:hover { border-color: var(--gold); background: rgba(217,180,90,.08); }
.adv-card .adv-portrait { width: 48px; height: 48px; font-size: 22px; }
.adv-card .role { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.adv-card .nm { font-family: var(--serif); font-size: 17px; color: var(--gold-2); }
.adv-card p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; background: transparent; padding: 5px 10px; font-size: 12.5px; color: var(--muted); }
.seg button.on { background: var(--panel-3); color: #fff; }
select, input[type=number], input[type=text].f { background: #0b1626; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font: inherit; font-size: 13px; }
.btn { border: 1px solid var(--line); background: #0b1626; border-radius: 6px; padding: 5px 10px; font-size: 12.5px; }
.btn:hover { border-color: var(--gold); }
.scatter { width: 100%; height: 300px; display: block; background: rgba(0,0,0,.2); border-radius: 8px; border: 1px solid var(--line); cursor: crosshair; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .panel, #right { width: 100%; top: auto; bottom: 0; height: 62vh; border-radius: 14px 14px 0 0; }
  #topbar .stat.opt { display: none; }
  .search input { width: 110px; padding-right: 8px; }
  .search kbd, #topbar .brand { display: none; }
  #minimap { display: none; }
  #lensbar { left: 8px; right: 8px; max-width: none; bottom: 8px; justify-content: center; }
  #legend { left: 8px; right: 8px; width: auto; top: 52px; }
  body.right-open #legend { right: 8px; }
  body.left-open #minimap { left: 8px; }
}

.map-hl, .map-hl td { background: rgba(242,212,138,.18) !important; outline: 1px solid rgba(242,212,138,.5); }

/* ---------- launch: name, stat labels, first-visit card, attribution ---------- */
#topbar .brand { display: flex; flex-direction: column; line-height: 1.05; white-space: nowrap; }
#topbar .brand small { font-family: var(--sans); font-size: 10px; letter-spacing: .04em; text-transform: none; color: var(--muted); font-weight: 500; }
#topbar .stat { display: grid; grid-template-columns: auto auto; column-gap: 5px; align-items: center; padding: 2px 8px; }
#topbar .stat svg { grid-row: span 2; }
#topbar .stat span { line-height: 1.1; }
#topbar .stat small { font-size: 10px; line-height: 1; color: var(--muted); font-weight: 500; }
#intro { position: absolute; left: 16px; bottom: 16px; width: min(400px, calc(100% - 24px)); background: rgba(12,22,38,.96); border: 1px solid var(--gold-dim); border-radius: 12px; padding: 16px 20px; z-index: 56; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
#intro h1 { font-family: var(--serif); font-size: 24px; color: #fff; margin: 4px 0 6px; font-weight: 600; }
#intro p { color: #cfd6e0; margin: 0 0 12px; line-height: 1.45; }
#intro .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#intro .row a { margin-left: auto; color: var(--gold-2); font-size: 13px; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #13223a; font-weight: 700; }
.btn.primary:hover { background: var(--gold-2); }
#intro .btn { font-size: 14px; padding: 7px 14px; }
body.intro-open #minimap { visibility: hidden; }
#attrib { position: absolute; right: 14px; bottom: 0; font-size: 10.5px; line-height: 14px; color: rgba(207,214,224,.7); z-index: 11; pointer-events: none; white-space: nowrap; }
@media (max-width: 760px) {
  #topbar .brand { display: flex; font-size: 13px; letter-spacing: .08em; }
  #topbar .brand small { display: none; }
  #topbar .stats { display: none; }
  #lensbar { bottom: 18px; }
  #attrib { right: 0; left: 0; text-align: center; font-size: 9.5px; }
  #intro { left: 12px; bottom: 76px; padding: 14px 16px; }
  #intro h1 { font-size: 20px; }
}
