:root {
  /* Ocean / panels / gold / text — aligned to the Civ-style reference */
  --ocean: #16222e;
  --ocean-deep: #101a24;
  --panel: #1e2a38;
  --panel-2: #243343;
  --gold: #c9a45c;
  --gold-soft: rgba(201,164,92,0.30);
  --text: #f8f0d8;
  --muted: #93a3b3;
  --line: rgba(201,164,92,0.22);

  /* Five yields (reference palette) */
  --food: #6fbf73;
  --prod: #e09145;
  --gold-y: #e6c25a;
  --sci: #5aa9d6;
  --cult: #9b7cc4;

  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; background: var(--ocean-deep); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Malay", sans-serif; }

/* ---------- Top bar ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 48px; z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: linear-gradient(180deg, rgba(24,36,48,0.96), rgba(18,28,38,0.92));
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.04em; font-size: 16px; }
.brand-emblem { color: var(--gold); }
.spacer { flex: 1; }

.stats { display: flex; align-items: center; gap: 10px; }
.stat-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 10px; font-size: 13px; color: var(--text);
}
.stat-badge .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.stat-badge .val { font-weight: 700; }
.stat-badge .lbl { color: var(--muted); font-size: 11px; }
.stat-badge.placeholder { opacity: 0.45; }

.lang-switch { display: flex; gap: 4px; }
.lang-switch button {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 13px;
}
.lang-switch button.active { color: var(--text); border-color: var(--gold); background: rgba(201,164,92,0.12); }

/* ---------- Map canvas ---------- */
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

/* ---------- Tooltip ---------- */
#tooltip {
  position: absolute; z-index: 30; background: rgba(20,30,40,0.96); border: 1px solid var(--gold-soft);
  border-radius: 8px; padding: 8px 11px; font-size: 12.5px; line-height: 1.5; pointer-events: none; display: none;
  max-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
#tooltip .tt-title { font-weight: 700; color: var(--text); }
#tooltip .tt-sub { color: var(--muted); }
#tooltip .tt-hint { color: var(--gold); }

/* ---------- Feature detail card ---------- */
#feature-card {
  position: absolute; z-index: 32; background: rgba(20,30,40,0.97); border: 1px solid var(--gold-soft);
  border-radius: 10px; padding: 12px 14px; width: 272px; max-width: 78vw;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5); font-size: 12.5px; line-height: 1.5;
}
#feature-card .fc-close {
  position: absolute; top: 8px; right: 8px; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; width: 24px; height: 24px; cursor: pointer; font-size: 13px;
}
#feature-card .fc-close:hover { color: var(--text); }
.fc-title { font-weight: 700; color: var(--text); padding-right: 26px; margin-bottom: 8px; }
.fc-rows { display: flex; flex-direction: column; gap: 5px; }
.fc-row { display: flex; gap: 8px; }
.fc-row .fr-lbl { flex: 0 0 76px; color: var(--muted); }
.fc-row .fr-val { flex: 1; color: var(--text); word-break: break-word; }
.fc-row .fr-val a { color: var(--gold); text-decoration: none; word-break: break-all; }
.fc-row .fr-val a:hover { text-decoration: underline; }
.fc-desc { margin-top: 8px; }
.fc-desc-text { font-size: 12px; color: var(--text); line-height: 1.55; margin: 0 0 5px; }
.fc-desc-src { font-size: 10.5px; color: var(--gold); text-decoration: none; }
.fc-desc-src:hover { text-decoration: underline; }
.fc-note { font-size: 11px; color: var(--muted); line-height: 1.5; margin-top: 8px; }
.fc-action {
  margin-top: 10px; width: 100%; background: var(--panel-2); color: var(--gold);
  border: 1px solid var(--gold-soft); border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 12.5px;
}
.fc-action:hover { background: rgba(201,164,92,0.12); }

/* ---------- Bottom layer bar ---------- */
#layerbar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20;
  display: flex; gap: 6px; background: rgba(20,30,40,0.92); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px;
}
.layer-btn {
  display: flex; align-items: center; gap: 6px; background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px;
}
.layer-btn .ico { font-size: 13px; }
.layer-btn.active { color: var(--text); background: var(--panel-2); border-color: var(--gold-soft); }
.layer-btn.placeholder { opacity: 0.4; }

/* ---------- Right city panel ---------- */
#citypanel {
  position: absolute; top: 48px; right: 0; bottom: 0; width: 380px; z-index: 25;
  background: linear-gradient(180deg, var(--panel), #18232f); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform 0.22s ease; overflow-y: auto;
  box-shadow: -10px 0 30px rgba(0,0,0,0.35);
}
#citypanel.open { transform: translateX(0); }

.cp-header { padding: 18px 18px 12px; border-bottom: 1px solid var(--line); }
.cp-kicker { font-size: 11px; letter-spacing: 0.18em; color: var(--gold); text-transform: uppercase; }
.cp-title { font-size: 26px; font-weight: 800; letter-spacing: 0.02em; margin: 4px 0 2px; }
.cp-sub { color: var(--muted); font-size: 13px; }
.cp-desc { margin: 10px 18px 0; }
.cp-desc-text { font-size: 12.5px; color: var(--text); line-height: 1.55; margin: 0 0 5px; }
.cp-desc-src { font-size: 10.5px; color: var(--gold); text-decoration: none; }
.cp-desc-src:hover { text-decoration: underline; }
.cp-close {
  position: absolute; top: 14px; right: 14px; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 15px;
}
.cp-close:hover { color: var(--text); }

.cp-badges { display: flex; gap: 10px; margin: 14px 18px 0; }
.cp-badge {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
}
.cp-badge .b-val { font-size: 18px; font-weight: 800; }
.cp-badge .b-lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }

.cp-tabs { display: flex; gap: 4px; margin: 16px 18px 0; border-bottom: 1px solid var(--line); }
.cp-tab {
  background: transparent; border: none; color: var(--muted); padding: 9px 10px; cursor: pointer; font-size: 12.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.cp-tab.active { color: var(--text); border-bottom-color: var(--gold); }

.cp-body { padding: 14px 18px 24px; }
.cp-section { margin-bottom: 18px; }
.cp-section h4 { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); margin-bottom: 10px; }

.meter-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.meter-row .m-name { width: 120px; color: var(--text); }
.meter-row .m-bar { flex: 1; height: 8px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.meter-row .m-fill { height: 100%; border-radius: 5px; }
.meter-row .m-val { width: 64px; text-align: right; color: var(--muted); font-size: 12px; }

.cp-note { font-size: 11.5px; color: var(--muted); line-height: 1.55; margin-top: 10px; }
.cp-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.spec-chip { font-size: 12px; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); }
.chip-strong { color: var(--food); background: rgba(111,191,115,0.12); }
.chip-weak { color: var(--muted); background: rgba(147,163,179,0.12); }
#cp-body .meter-row .m-val { width: 96px; }

/* ---------- Resources list ---------- */
.res-group { margin: 10px 0; }
.res-group-label { display: block; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); margin-bottom: 6px; }
.res-item { display: flex; align-items: center; gap: 8px; margin: 5px 0; font-size: 13px; }
.res-ico { width: 18px; text-align: center; flex: 0 0 18px; }
.res-name { color: var(--text); }

/* ---------- Status hint ---------- */
.status {
  position: absolute; right: 16px; bottom: 16px; z-index: 10;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-size: 12px; color: var(--muted); max-width: 38%;
}

/* ---------- Almanac: sources & gaps ---------- */
.almanac-btn {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  border-radius: 8px; width: 30px; height: 30px; flex: 0 0 30px;
  font-size: 15px; cursor: pointer;
}
.almanac-btn:hover { color: var(--text); border-color: var(--gold-soft); background: rgba(201,164,92,0.12); }

.almanac { position: fixed; inset: 0; z-index: 50; }
.almanac-mask { position: absolute; inset: 0; background: rgba(8,14,20,0.72); }
.almanac-dialog {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(880px, 92vw); max-height: 82vh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--panel), #18232f);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.almanac-dialog .cp-close { top: 14px; right: 14px; }
.almanac-h { font-size: 22px; font-weight: 800; letter-spacing: 0.02em; margin: 4px 0 2px; padding: 18px 22px 0; }
.almanac-body { padding: 14px 22px 22px; overflow-y: auto; }
.almanac-section { margin-bottom: 22px; }
.almanac-section h4 {
  font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 10px;
}
.src-card {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
  padding: 12px 14px; margin: 10px 0;
}
.src-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.src-org { font-weight: 700; font-size: 14px; color: var(--text); }
.src-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); margin: 6px 0; }
.src-meta b { color: var(--gold); font-weight: 600; }
.src-desc { font-size: 12.5px; color: var(--text); line-height: 1.55; margin: 6px 0; }
.src-link { font-size: 12px; color: var(--gold); text-decoration: none; word-break: break-all; }
.src-link:hover { text-decoration: underline; }
.gap-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; }
.gap-item { font-size: 12.5px; color: var(--muted); line-height: 1.5; padding-left: 16px; position: relative; }
.gap-item::before { content: "·"; position: absolute; left: 4px; color: var(--gold); }
.rule-list { list-style: none; }
.rule-list li { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 7px 0; padding-left: 18px; position: relative; }
.rule-list li::before { content: "–"; position: absolute; left: 2px; color: var(--gold); }

/* ---------- Advisors panel ---------- */
#advisor-panel {
  position: absolute; top: 48px; right: 0; bottom: 0; width: 380px; z-index: 25;
  background: linear-gradient(180deg, var(--panel), #18232f); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform 0.22s ease; overflow-y: auto;
  box-shadow: -10px 0 30px rgba(0,0,0,0.35);
}
#advisor-panel.open { transform: translateX(0); }
#advisor-panel .cp-close { top: 14px; right: 14px; }

#explorer-panel {
  position: absolute; top: 48px; right: 0; bottom: 0; width: 380px; z-index: 25;
  background: linear-gradient(180deg, var(--panel), #18232f); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform 0.22s ease; overflow-y: auto;
  box-shadow: -10px 0 30px rgba(0,0,0,0.35);
}
#explorer-panel.open { transform: translateX(0); }
#explorer-panel .cp-close { top: 14px; right: 14px; }
.exp-controls { display: flex; gap: 10px; margin: 14px 18px 0; }
.exp-axis { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.exp-axis select { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; font-size: 12.5px; }
#exp-scatter { display: block; margin: 12px 18px 0; width: 344px; height: 190px; background: rgba(10,18,26,0.5); border: 1px solid var(--line); border-radius: 10px; }
.exp-list { margin: 10px 18px 18px; display: flex; flex-direction: column; }
.exp-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.exp-row:hover { background: var(--panel-2); }
.exp-row .rk { width: 22px; color: var(--muted); font-size: 12px; text-align: right; }
.exp-row .rn { flex: 1; min-width: 0; }
.exp-row .rn .rn-name { color: var(--text); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-row .rn .rn-sub { color: var(--muted); font-size: 11px; }
.exp-row .rv { color: var(--gold-y); font-size: 13px; font-weight: 700; white-space: nowrap; }

.ad-selector { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 14px 18px 0; }
.ad-pick {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 4px; cursor: pointer; color: var(--muted); font-size: 11px;
}
.ad-pick .ad-ico { font-size: 17px; }
.ad-pick.active { color: var(--text); border-color: var(--gold-soft); background: rgba(201,164,92,0.12); }
.ad-pick.pending { opacity: 0.55; }

.ad-body { padding: 14px 18px 24px; }
.ad-section { margin-bottom: 18px; }
.ad-section h4 {
  font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); margin-bottom: 10px;
}
.ad-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.ad-stat {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
}
.ad-stat .s-val { font-size: 18px; font-weight: 800; }
.ad-stat .s-lbl { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.ad-rank { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ad-rank:hover { background: var(--panel-2); }
.ad-rank .rk { width: 22px; color: var(--muted); font-size: 12px; text-align: right; }
.ad-rank .rn { flex: 1; min-width: 0; }
.ad-rank .rn .rn-name { color: var(--text); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-rank .rn .rn-sub { color: var(--muted); font-size: 11px; }
.ad-rank .rv { color: var(--gold-y); font-size: 13px; font-weight: 700; white-space: nowrap; }

.ad-note { font-size: 11.5px; color: var(--muted); line-height: 1.55; margin-top: 10px; }
.ad-gap { font-size: 12px; color: var(--muted); line-height: 1.5; padding: 8px 0; }

/* ---------- Responsive: placed after panel base rules so width overrides win ---------- */
@media (max-width: 720px) {
  #citypanel, #advisor-panel, #explorer-panel { width: 100%; }
  #exp-scatter { width: calc(100% - 36px); }
  .gap-grid { grid-template-columns: 1fr; }
  .almanac-dialog { width: 96vw; max-height: 88vh; }

  /* compact top bar: drop badge labels, shrink buttons and gaps */
  #topbar { gap: 8px; padding: 0 10px; height: 44px; }
  .brand { font-size: 14px; gap: 6px; }
  .stats { gap: 6px; min-width: 0; }
  .stats .lbl { display: none; }
  .stat-badge { padding: 4px 7px; font-size: 12px; gap: 5px; }
  .almanac-btn { width: 28px; height: 28px; flex: 0 0 28px; font-size: 14px; }
  .lang-switch { gap: 2px; }
  .lang-switch button { padding: 4px 7px; font-size: 12px; }

  /* layer bar: icon-only, horizontally scrollable so it never overflows */
  #layerbar {
    left: 8px; right: 8px; transform: none; max-width: calc(100vw - 16px);
    overflow-x: auto; scrollbar-width: none;
  }
  #layerbar::-webkit-scrollbar { display: none; }
  .layer-btn { padding: 7px 9px; gap: 0; }
  .layer-btn .lb-label { display: none; }

  /* panel meter rows: narrow name/value columns on small screens */
  .meter-row { font-size: 12px; gap: 8px; }
  .meter-row .m-name { width: 88px; }
  #cp-body .meter-row .m-val { width: 64px; }
}

@media (max-width: 480px) {
  #topbar { gap: 6px; padding: 0 8px; }
  #brand-text { display: none; }
  .stat-badge .val { font-size: 12px; }
  /* keep only the population badge; yield badges collapse to avoid top-bar crowding */
  .stats .stat-badge:nth-child(n+2) { display: none; }
  .almanac-btn { width: 26px; height: 26px; flex: 0 0 26px; }
  .lang-switch button { padding: 3px 5px; font-size: 11px; }
  .cp-badges { gap: 8px; }
  .cp-badge { padding: 8px 10px; }
  .cp-badge .b-val { font-size: 16px; }
}
