:root {
  --bg: #0b1622;
  --panel: rgba(15, 24, 36, 0.95);
  --panel-2: rgba(24, 35, 50, 0.9);
  --edge: #7d6337;
  --edge-soft: rgba(169, 141, 85, 0.28);
  --gold: #e2c37a;
  --gold-dim: #a98d55;
  --text: #eee6d3;
  --muted: #a49d8c;
  --accent: #6cc0e5;
  --serif: Cinzel, Georgia, serif;
  --sans: "Source Sans 3", system-ui, sans-serif;
  --top: 56px;
  --panel-w: 440px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 14px/1.4 var(--sans); }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
canvas#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
canvas#map.dragging { cursor: grabbing; }

/* ---------------------------------------------------------------- top bar */
#topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--top); display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: linear-gradient(180deg, rgba(9, 16, 26, 0.98), rgba(9, 16, 26, 0.88)); border-bottom: 1px solid var(--edge); z-index: 20; }
.emblem { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--gold); background: radial-gradient(#25406b, #13223b);
  color: var(--gold); font-size: 18px; cursor: pointer; flex: none; box-shadow: 0 0 10px rgba(226,195,122,.35); }
.brand h1 { font: 700 19px var(--serif); letter-spacing: .14em; margin: 0; color: var(--gold); text-transform: uppercase; }
.brand .sub { font-size: 11px; color: var(--muted); }
.natstats { display: flex; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.stat { display: flex; align-items: center; gap: 5px; background: none; border: 0; padding: 4px 8px; border-radius: 6px; font-weight: 700; font-size: 15px; cursor: pointer; white-space: nowrap; }
.stat:hover { background: rgba(255,255,255,.06); }
.stat span { font-size: 15px; }
.c-people { color: #e8e2d2; } .c-gold { color: #f1d36b; } .c-green { color: #8fd16a; } .c-red { color: #ef8a6a; } .c-amber { color: #e0a35a; }
.search { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.35); border: 1px solid var(--gold-dim); border-radius: 18px; padding: 4px 10px; }
.search input { width: 230px; background: none; border: 0; color: var(--text); font: inherit; outline: none; }
.search kbd { font: 11px var(--sans); border: 1px solid var(--muted); border-radius: 3px; padding: 0 4px; color: var(--muted); }
.top-btn { background: var(--panel-2); border: 1px solid var(--edge); color: var(--gold); border-radius: 6px; padding: 6px 12px; cursor: pointer; font: 600 13px var(--serif); white-space: nowrap; }

/* ---------------------------------------------------------------- advisor panel */
#panel { position: fixed; top: var(--top); left: 0; bottom: 0; width: var(--panel-w); background: var(--panel); border-right: 1px solid var(--edge);
  z-index: 10; display: flex; flex-direction: column; box-shadow: 8px 0 24px rgba(0,0,0,.4); }
#panel-body { overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: var(--edge) transparent; }
.adv-tabs { position: sticky; top: 0; z-index: 2; display: flex; gap: 6px; align-items: center; padding: 10px 12px; background: rgba(13, 21, 32, .97); border-bottom: 1px solid var(--edge-soft); }
.adv-tab { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--edge); background: radial-gradient(#3a3324, #1d1a14); cursor: pointer; font-size: 15px; padding: 0; flex: none; }
.adv-tab.on { border: 2px solid var(--gold); box-shadow: 0 0 10px rgba(226,195,122,.6); }
.adv-tab.council { border-radius: 6px; width: 38px; }
.adv-close { margin-left: auto; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--muted); background: none; cursor: pointer; font-size: 18px; line-height: 1; }
.panel-head { padding: 18px 20px 12px; border-bottom: 1px solid var(--edge-soft); background: linear-gradient(180deg, rgba(60,48,24,.25), transparent); }
.panel-head h2 { font: 700 26px var(--serif); color: var(--gold); margin: 2px 0 6px; letter-spacing: .04em; }
.panel-head p { margin: 0; color: #d9d1bf; }
.adv-head { display: flex; gap: 14px; align-items: center; }
.kicker { font: 600 11px var(--serif); letter-spacing: .18em; color: var(--gold-dim); text-transform: uppercase; }
.medal { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex: none; font-size: 21px;
  background: radial-gradient(circle at 35% 30%, #f3dc9a, #b48a3c 60%, #6d5122); border: 2px solid #3a2c12; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.medal.big { width: 64px; height: 64px; font-size: 30px; }
.council-group { font: 600 12px var(--serif); letter-spacing: .16em; color: var(--gold-dim); text-transform: uppercase; padding: 16px 20px 6px; }
.council-card { display: flex; gap: 14px; align-items: center; width: calc(100% - 32px); margin: 6px 16px; padding: 12px 14px; text-align: left;
  background: linear-gradient(90deg, rgba(56,46,26,.55), rgba(22,32,44,.6)); border: 1px solid var(--edge-soft); border-radius: 8px; cursor: pointer; }
.council-card:hover { border-color: var(--gold); }
.council-card .role { display: block; font: 600 10.5px var(--serif); letter-spacing: .16em; color: var(--gold-dim); text-transform: uppercase; }
.council-card .cname { display: block; font: 700 19px var(--serif); color: #f2e7c9; }
.council-card .cdesc { display: block; font-size: 13px; color: #c9c1ae; }
.panel-foot { color: var(--muted); font-size: 12px; padding: 12px 20px 24px; }

/* dashboards */
.dash { padding: 4px 0 24px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px 16px 4px; }
.kpi { background: var(--panel-2); border: 1px solid var(--edge-soft); border-radius: 8px; padding: 10px 10px 8px; min-width: 0; }
.kpi[data-lens] { cursor: pointer; } .kpi[data-lens]:hover { border-color: var(--gold); }
.kpi-label { font: 600 10px var(--serif); letter-spacing: .12em; color: var(--gold-dim); text-transform: uppercase; }
.kpi-value { font: 700 21px var(--serif); color: #f3e8c8; margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 11.5px; color: var(--muted); }
.dash-section { padding: 14px 16px 6px; border-top: 1px solid rgba(169,141,85,.12); margin-top: 10px; }
.dash-section h3 { font: 700 16px var(--serif); color: #f1e4c1; margin: 2px 0 4px; }
.dash-desc { color: #bdb5a2; font-size: 12.5px; margin: 0 0 8px; }
.lens-chip { background: none; border: 1px solid var(--gold-dim); color: var(--gold); border-radius: 12px; padding: 2px 10px; font-size: 11.5px; cursor: pointer; margin-bottom: 8px; }
.lens-chip:hover { background: rgba(226,195,122,.12); }
.bars { display: flex; flex-direction: column; gap: 2px; }
.bar-row { display: grid; grid-template-columns: 22px minmax(90px, 1.2fr) 1fr auto; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 4px; cursor: pointer; }
.bar-row:hover, .bar-row.hot, tr.hot, .faith-row.hot { background: rgba(226,195,122,.14); }
.bar-rank { color: var(--muted); font-size: 11px; text-align: right; }
.bar-label { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-label small { display: block; color: var(--muted); font-size: 10.5px; }
.bar-track { height: 10px; background: rgba(255,255,255,.05); border-radius: 2px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 2px; }
.bar-value { font-size: 12.5px; font-weight: 600; text-align: right; white-space: nowrap; }
.bar-value small { color: var(--muted); font-weight: 400; }
.more { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px 4px; font-size: 12.5px; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th { font: 600 10.5px var(--serif); letter-spacing: .08em; color: var(--gold-dim); text-transform: uppercase; text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--edge-soft); cursor: pointer; white-space: nowrap; }
.tbl td { padding: 5px 6px; border-bottom: 1px solid rgba(255,255,255,.04); }
.tbl tr[data-prov], .tbl tr[data-hex], .tbl tr[data-fly], .tbl tr[data-island] { cursor: pointer; }
.tbl tr:hover td { background: rgba(226,195,122,.08); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .rank { color: var(--muted); width: 22px; }
.wide .tbl { font-size: 11.5px; }
.cols { display: flex; align-items: flex-end; gap: 3px; padding: 8px 0 18px; }
.col { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.col-bar { width: 80%; border-radius: 2px 2px 0 0; min-height: 1px; }
.col-x { position: absolute; bottom: -16px; font-size: 10px; color: var(--muted); }
.stack { display: flex; height: 12px; border-radius: 3px; overflow: hidden; background: rgba(255,255,255,.05); }
.stack span { display: block; height: 100%; }
.stack-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; margin: 6px 0 10px; color: #d6cdb8; }
.stack-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; }
.faith-rows { display: flex; flex-direction: column; gap: 3px; }
.faith-row { display: grid; grid-template-columns: 150px 1fr; gap: 8px; align-items: center; font-size: 12px; cursor: pointer; padding: 1px 4px; border-radius: 3px; }
.faith-row span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pair-bars { display: flex; flex-direction: column; gap: 4px; }
.pair { display: grid; grid-template-columns: 90px 1fr 46px 1fr 46px; gap: 6px; align-items: center; font-size: 12.5px; cursor: pointer; padding: 2px 4px; border-radius: 3px; }
.pair:hover { background: rgba(226,195,122,.1); }
.pair b { text-align: right; font-size: 12px; }
.pair-track { height: 8px; background: rgba(255,255,255,.05); border-radius: 2px; overflow: hidden; }
.pair-track span { display: block; height: 100%; }
.p-people { background: #c76b8f; } .p-land { background: #6f9a3e; }
.pair-legend { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.pair-legend span { display: inline-block; width: 10px; height: 8px; margin: 0 3px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip-res { background: var(--panel-2); border: 1px solid var(--edge-soft); border-radius: 12px; padding: 2px 9px; font-size: 12px; }
.sources ul { padding-left: 18px; margin: 4px 0 10px; font-size: 12px; line-height: 1.5; }
.caveats li { color: #cfc6b2; }

/* ---------------------------------------------------------------- legend & toolbar */
#legend { position: fixed; left: calc(var(--panel-w) + 14px); bottom: 62px; z-index: 8; width: 330px; background: var(--panel); border: 1px solid var(--edge);
  border-radius: 8px; padding: 10px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.45); }
body.panel-closed #legend { left: 14px; }
.lg-title { font: 700 14px var(--serif); color: var(--gold); margin-bottom: 6px; }
.lg-bar { position: relative; height: 12px; border-radius: 3px; cursor: crosshair; }
.lg-band { position: absolute; top: -3px; bottom: -3px; border: 2px solid #fff; border-radius: 3px; pointer-events: none; }
.lg-ticks { display: flex; justify-content: space-between; font-size: 11px; color: #d8d0bd; margin-top: 3px; }
.lg-cats { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.lg-cat { font-size: 12.5px; cursor: pointer; } .lg-cat i { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.lg-src { font-size: 11px; color: var(--muted); margin-top: 6px; }
.lg-hint { font-size: 10.5px; color: #8b8576; margin-top: 2px; font-style: italic; }
.lg-ov { font-size: 11.5px; color: #d9cfb6; margin-top: 6px; border-top: 1px solid var(--edge-soft); padding-top: 6px; }

#toolbar { position: fixed; right: 14px; bottom: 14px; z-index: 12; display: flex; gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--edge);
  border-radius: 10px; padding: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.45); max-width: calc(100vw - var(--panel-w) - 28px); }
#quick-lenses { display: flex; gap: 6px; }
.tb-btn { background: var(--panel-2); border: 1px solid var(--edge-soft); border-radius: 6px; padding: 6px 10px; cursor: pointer; white-space: nowrap; font-size: 13px; }
.tb-btn:hover { border-color: var(--gold-dim); }
.tb-btn.on { border-color: var(--gold); color: var(--gold); background: rgba(80,64,30,.5); }
.tb-lens { color: var(--gold); border-color: var(--gold-dim); }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; border-radius: 9px; background: var(--gold); color: #1a1408; font-size: 11px; font-weight: 700; margin-left: 4px; }
.popover { position: fixed; right: 14px; bottom: 66px; z-index: 15; background: var(--panel); border: 1px solid var(--edge); border-radius: 10px; padding: 14px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.55); }
.popover h2 { font: 700 15px var(--serif); letter-spacing: .14em; color: var(--gold); text-transform: uppercase; margin: 0 0 10px; }
#map-menu label { display: flex; gap: 8px; align-items: center; padding: 3px 0; cursor: pointer; }
#map-menu input { accent-color: var(--gold); }
.hint { margin-top: 8px; font-size: 11px; color: var(--muted); }
#lens-chooser { width: min(760px, calc(100vw - 28px)); max-height: calc(100vh - 140px); overflow-y: auto; }
.chooser-head { display: flex; justify-content: space-between; align-items: center; }
.chooser-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 18px; }
.chooser-group .kicker { margin: 6px 0 6px; }
.lens-btn { display: flex; align-items: center; gap: 8px; width: 100%; margin-bottom: 6px; background: var(--panel-2); border: 1px solid var(--edge-soft); border-radius: 6px;
  padding: 7px 10px 9px; cursor: pointer; text-align: left; position: relative; }
.lens-btn:hover { border-color: var(--gold-dim); }
.lens-btn.on { border: 2px solid var(--gold); background: rgba(80,64,30,.45); }
.lens-ico { width: 22px; text-align: center; }
.lens-swatch { position: absolute; left: 10px; right: 10px; bottom: 3px; height: 3px; border-radius: 2px; }
.close { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }
.chooser-head .close { position: static; }

/* ---------------------------------------------------------------- inspector, tooltip, minimap */
#inspector { position: fixed; top: calc(var(--top) + 12px); right: 12px; width: 310px; max-height: calc(100% - var(--top) - 230px); overflow-y: auto; z-index: 11;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 8px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.insp-title { font: 700 17px var(--serif); color: var(--gold); padding-right: 22px; }
.insp-sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.insp-lens { margin: 8px 0; padding: 6px 8px; border-left: 4px solid; background: rgba(255,255,255,.04); border-radius: 3px; font-size: 13px; }
.insp-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px dashed rgba(169,141,85,.16); font-size: 13px; }
.insp-row span:first-child { color: var(--muted); }
.insp-row span:last-child { text-align: right; }
.insp-section { margin-top: 10px; }
.insp-section h3 { font: 700 11.5px var(--serif); letter-spacing: .12em; color: var(--gold-dim); margin: 0 0 3px; text-transform: uppercase; }
.yields { display: flex; gap: 12px; font-weight: 700; }
.y-food { color: #8fd16a; } .y-prod { color: #e0a35a; } .y-gold { color: #f1d36b; }
.chip { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
#tooltip { position: fixed; pointer-events: none; z-index: 30; background: rgba(8,14,22,.96); border: 1px solid var(--gold-dim); padding: 6px 9px; border-radius: 5px; font-size: 12.5px; max-width: 270px; }
.tip-lens { color: var(--gold); }
#minimap-wrap { position: fixed; right: 14px; bottom: 66px; z-index: 9; background: var(--panel); border: 1px solid var(--edge); border-radius: 8px; padding: 5px; }
#minimap { display: block; width: 300px; height: 120px; cursor: pointer; }
.pill { position: fixed; left: 14px; top: calc(var(--top) + 12px); z-index: 12; background: var(--panel); color: var(--gold); border: 1px solid var(--edge); border-radius: 16px; padding: 6px 14px; font: 600 13px var(--serif); cursor: pointer; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; font: 20px var(--serif); letter-spacing: .1em; color: var(--gold); background: var(--bg); z-index: 50; }

@media (max-width: 1280px) {
  .natstats .stat:nth-child(n+6) { display: none; }
}
@media (max-width: 1100px) {
  :root { --panel-w: 380px; }
  .brand .sub, .search kbd { display: none; }
  .search input { width: 150px; }
  #quick-lenses .tb-btn:nth-child(n+3) { display: none; }
  #minimap-wrap { display: none; }
}
@media (max-width: 900px) {
  :root { --top: 50px; }
  .natstats { display: none; }
  .brand h1 { font-size: 16px; }
  .search { flex: 1; } .search input { width: 100%; }
  .top-btn { padding: 5px 8px; font-size: 0; } .top-btn::first-letter { font-size: 16px; }
  #panel { top: auto; bottom: 0; width: 100%; height: 52vh; border-right: 0; border-top: 1px solid var(--edge); }
  #legend { left: 16px !important; right: 16px; width: auto; bottom: calc(52vh + 10px); }
  body.panel-closed #legend { bottom: 66px; }
  #toolbar { left: 16px; right: 16px; max-width: none; bottom: calc(52vh + 10px); justify-content: space-between; }
  #legend { bottom: calc(52vh + 62px); }
  body.panel-closed #toolbar { bottom: 14px; }
  #quick-lenses { display: none; }
  #inspector { top: calc(var(--top) + 8px); left: 16px; right: 16px; width: auto; max-height: 36vh; }
  .kpis { grid-template-columns: 1fr 1fr 1fr; padding: 10px 12px 0; }
  .kpi-value { font-size: 17px; }
  #legend { padding: 8px 10px; }
  #legend .lg-src, #legend .lg-hint, #legend .lg-ov { display: none; }
  .adv-tabs { overflow-x: auto; scrollbar-width: none; }
  .popover { left: 16px; right: 16px; bottom: auto; top: calc(var(--top) + 8px); width: auto !important; max-height: 70vh; overflow-y: auto; }
}
