:root {
  --bg: #15171c;
  --panel: rgba(24, 27, 33, 0.88);
  --line: rgba(255, 255, 255, 0.10);
  --text: #e9e6df;
  --muted: #a39f95;
  --accent: #e2aa4f;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
canvas#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; cursor: grab; }
canvas#map.dragging { cursor: grabbing; }
canvas#map.hot { cursor: pointer; }

button {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line);
  border-radius: 8px; min-width: 34px; height: 34px; cursor: pointer; padding: 0 10px;
}
button:hover { background: rgba(255, 255, 255, 0.14); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

#title { position: fixed; top: calc(var(--nav-h) + 12px); left: 16px; pointer-events: none; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7); max-width: calc(100vw - 32px); }
#title .name { font-size: 20px; font-weight: 600; letter-spacing: 0.02em; }
#title .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

#legend { position: fixed; top: calc(var(--nav-h) + 112px); left: 16px; width: 230px; max-height: calc(100vh - var(--nav-h) - 238px); display: flex; flex-direction: column; }
#legend.collapsed #nation-list { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 8px 8px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.panel-head button { min-width: 26px; height: 26px; padding: 0; }
#nation-list { list-style: none; margin: 0; padding: 0 4px 6px; overflow-y: auto; }
#nation-list li { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 14px; }
#nation-list li:hover { background: rgba(255, 255, 255, 0.08); }
#nation-list li.on { background: rgba(226, 170, 79, 0.18); }
#nation-list .sw { width: 16px; height: 16px; border-radius: 4px; flex: none; border: 1px solid rgba(255, 255, 255, 0.25); background-size: cover; background-position: center; }
#nation-list .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nation-list .ar { color: var(--muted); font-size: 12px; }

#info { position: fixed; top: calc(var(--nav-h) + 12px); right: 16px; width: min(340px, calc(100vw - 32px)); max-height: calc(100vh - var(--nav-h) - 140px); overflow-y: auto; padding: 0; background: none; border: none; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
#info .close { position: absolute; top: 8px; right: 8px; min-width: 28px; height: 28px; padding: 0; font-size: 18px; line-height: 1; }
#info h2 { margin: 0 28px 2px 0; font-size: 20px; line-height: 1.2; }
#info .kind { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 10px; }
#info .flag { width: 100%; max-height: 120px; object-fit: contain; border-radius: 6px; border: 1px solid var(--line); margin-bottom: 12px; background: rgba(255, 255, 255, 0.04); }
#info dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px; font-size: 14px; }
#info dt { color: var(--muted); }
#info dd { margin: 0; }
#info p { font-size: 14px; line-height: 1.5; margin: 0 0 12px; white-space: pre-wrap; }
#info .facts { font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
#info .tags span { display: inline-block; font-size: 12px; padding: 2px 8px; margin: 0 4px 4px 0; border-radius: 99px; background: rgba(255, 255, 255, 0.08); }
#info .link { color: var(--accent); cursor: pointer; text-decoration: underline; }

#tools { position: fixed; right: 16px; bottom: 112px; display: flex; flex-direction: column; gap: 6px; }
#tools button { font-size: 18px; background: var(--panel); }

#timeline { position: fixed; left: 16px; right: 16px; bottom: 16px; padding: 10px 14px 8px; }
.tl-row { display: flex; align-items: center; gap: 8px; }
#tl-prev { transform: none; }
#tl-prev, #tl-next { font-size: 20px; line-height: 1; }
#tl-prev { direction: ltr; }
#tl-track { position: relative; flex: 1; height: 34px; margin: 0 10px; cursor: pointer; touch-action: none; }
#tl-line { position: absolute; left: 0; right: 0; top: 50%; height: 2px; background: rgba(255, 255, 255, 0.25); transform: translateY(-50%); border-radius: 2px; }
.tl-dot { position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: #4a4d55; border: 2px solid #9b9ca2; }
.tl-dot:hover { border-color: #fff; }
.tl-dot.on { background: var(--accent); border-color: #fff; width: 16px; height: 16px; margin: -8px 0 0 -8px; }
#tl-label { display: flex; justify-content: space-between; gap: 16px; font-size: 13px; padding: 2px 4px 0; }
#tl-label .y { font-weight: 600; color: var(--accent); }
#tl-label .n { color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tl-label .a { color: var(--muted); }

#tip { position: fixed; pointer-events: none; background: rgba(15, 16, 20, 0.92); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; font-size: 13px; z-index: 5; white-space: nowrap; }
#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(21, 23, 28, 0.7); font-size: 15px; color: var(--muted); z-index: 10; transition: opacity 0.25s; }
#loading.off { opacity: 0; pointer-events: none; }
#search { position: fixed; top: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%); width: min(420px, calc(100vw - 32px)); z-index: 4; }
#search-input { width: 100%; height: 38px; border-radius: 19px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; padding: 0 16px; outline: none; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35); }
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--muted); }
#search-results { list-style: none; margin: 6px 0 0; padding: 4px; max-height: 50vh; overflow-y: auto; }
#search-results li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
#search-results li.on, #search-results li:hover { background: rgba(255, 255, 255, 0.10); }
#search-results .sw { width: 14px; height: 14px; border-radius: 4px; flex: none; border: 1px solid rgba(255, 255, 255, 0.3); }
#search-results .sw.pl { border-radius: 50%; }
#search-results .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search-results .sub { color: var(--muted); font-size: 12px; white-space: nowrap; }
#search-results .none { color: var(--muted); cursor: default; }
#title { max-width: 30vw; }

.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8, 9, 12, 0.55); z-index: 8; padding: 16px; }
.modal-box { width: min(980px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 16px 18px 18px; }
.modal-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.modal-head h2 { margin: 0 8px 0 0; font-size: 20px; }
.modal-head .close { margin-left: auto; font-size: 20px; line-height: 1; min-width: 32px; padding: 0; }
.tabs { display: flex; gap: 2px; background: rgba(255, 255, 255, 0.06); padding: 2px; border-radius: 9px; }
.tabs button { border: 0; background: transparent; height: 28px; font-size: 13px; border-radius: 7px; }
.tabs button.on { background: rgba(226, 170, 79, 0.9); color: #1b1408; font-weight: 600; }
.chart-wrap { position: relative; height: min(340px, 42vh); }
#chart { width: 100%; height: 100%; display: block; cursor: crosshair; }
#chart-tip { position: absolute; pointer-events: none; background: rgba(15, 16, 20, 0.95); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; min-width: 150px; z-index: 2; }
#chart-tip .th { color: var(--accent); font-weight: 600; margin-bottom: 3px; }
#chart-tip .row { display: flex; align-items: center; gap: 7px; justify-content: space-between; }
#chart-tip .row span.l { display: flex; align-items: center; gap: 6px; }
#chart-tip i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
#chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 4px; font-size: 13px; }
#chart-legend .lchip { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; padding: 2px 6px; border-radius: 6px; }
#chart-legend .lchip:hover { background: rgba(255, 255, 255, 0.08); }
#chart-legend .lchip.off { opacity: 0.4; text-decoration: line-through; }
#chart-legend .lchip i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
#stats h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
#ranking .bar { display: grid; grid-template-columns: 150px 1fr 110px; gap: 10px; align-items: center; padding: 3px 4px; border-radius: 6px; cursor: pointer; font-size: 13.5px; }
#ranking .bar:hover { background: rgba(255, 255, 255, 0.07); }
#ranking .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ranking .track { height: 12px; background: rgba(255, 255, 255, 0.07); border-radius: 6px; overflow: hidden; }
#ranking .fill { height: 100%; border-radius: 6px; }
#ranking .val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.spark { margin: 0 0 12px; }
.spark .lab { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.spark svg { width: 100%; height: 48px; display: block; overflow: visible; }

[hidden] { display: none !important; }

@media (max-width: 760px) {
  #title { display: none; }
  #ranking .bar { grid-template-columns: 100px 1fr 80px; }
  #legend { top: auto; bottom: 124px; left: 12px; width: 200px; max-height: 38vh; }
  #info { top: auto; bottom: 124px; right: 12px; left: 12px; width: auto; max-height: 45vh; }
  #tools { bottom: 124px; right: 12px; }
  #legend:not(.collapsed) ~ #tools { display: none; }
}

/* Map mode selector: a drop-down (icon + name) at the top left, above the legend. */
#modes { position: fixed; top: calc(var(--nav-h) + 64px); left: 16px; width: 230px; z-index: 5; }
#mode-btn { width: 100%; height: 36px; display: flex; align-items: center; gap: 9px; padding: 0 10px; background: transparent; border-color: transparent; text-align: left; font-size: 14px; }
#mode-btn .ml { flex: 1; }
#mode-btn .caret { color: var(--muted); }
#modes.open #mode-btn { background: rgba(255, 255, 255, 0.08); }
#mode-list { list-style: none; margin: 0; padding: 4px; border-top: 1px solid var(--line); }
#mode-list li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px; cursor: pointer; }
#mode-list li:hover { background: rgba(255, 255, 255, 0.08); }
#mode-list li.on { background: rgba(226, 170, 79, 0.18); }
#mode-list .mt { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#mode-list .md { color: var(--muted); font-size: 12px; }
#mode-list kbd { font: inherit; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.mi { display: inline-flex; color: var(--accent); }
#nation-list li.none { color: var(--muted); cursor: default; font-size: 13px; }
#nation-list li.none:hover { background: none; }
#nation-list li.war { align-items: flex-start; }
#nation-list li.war .sw { margin-top: 3px; }
#nation-list .wn { font-size: 14px; }
#nation-list .ws { color: var(--muted); font-size: 12px; white-space: normal; line-height: 1.3; }
/* ---- Encyclopedia-style infobox. The colours come from the snapshot's age (--ib-* are set in applyInfoTheme). */
#info { --ib-paper: rgba(24, 27, 33, 0.94); --ib-ink: #e9e6df; --ib-head: #3a3a3a; --ib-sub: #1e2229; --ib-line: rgba(255, 255, 255, 0.12); --ib-link: #e2aa4f; }
#info .close { color: var(--ib-ink); z-index: 2; background: transparent; border-color: transparent; }
#info .close:hover { background: rgba(0, 0, 0, 0.12); }
.ib { background: var(--ib-paper); color: var(--ib-ink); border: 1px solid var(--ib-line); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35); font-size: 13.5px; line-height: 1.4; overflow: hidden; }
.ib-title { background: var(--ib-head); text-align: center; font-weight: 700; font-size: 17px; padding: 7px 34px 7px 12px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.ib-sub { background: var(--ib-sub); text-align: center; padding: 4px 10px; font-size: 13px; }
.ib-img { padding: 8px 10px 4px; text-align: center; }
.ib-img img { max-width: 100%; max-height: 130px; border: 1px solid var(--ib-line); background: rgba(255, 255, 255, 0.04); }
.ib-cap { font-size: 12px; padding-top: 3px; }
.ib-row { display: grid; grid-template-columns: 96px 1fr; gap: 0 10px; padding: 4px 10px; }
.ib-row:first-of-type { border-top: 0; }
.ib-row .k { font-weight: 700; }
.ib-row .v { overflow-wrap: anywhere; }
.ib-head { background: var(--ib-head); text-align: center; font-weight: 700; font-size: 14.5px; padding: 4px 10px; margin-top: 6px; }
.ib-cols { display: grid; grid-template-columns: 1fr 1fr; }
.ib-cols > div { padding: 5px 10px; min-width: 0; }
.ib-cols > div + div { border-left: 1px solid var(--ib-line); }
.ib-line { padding: 1px 0; overflow-wrap: anywhere; }
.chip { display: inline-block; width: 22px; height: 14px; border: 1px solid rgba(255, 255, 255, 0.28); margin-right: 6px; vertical-align: -2px; background-size: cover; background-position: center; flex: none; }
.ib-p { margin: 0; padding: 8px 10px 4px; white-space: pre-wrap; }
.ib-facts { padding: 6px 10px 8px; font-size: 12px; opacity: 0.75; border-top: 1px solid var(--ib-line); margin-top: 6px; }
.ib-tags { padding: 4px 10px 8px; }
.ib-tags span { display: inline-block; font-size: 12px; padding: 1px 8px; margin: 0 4px 4px 0; border: 1px solid var(--ib-line); border-radius: 99px; }
#info .ib .link { color: var(--ib-link); cursor: pointer; text-decoration: none; }
#info .ib .link:hover { text-decoration: underline; }
.ib .spark { padding: 4px 10px; }
.ib .spark .lab { display: flex; justify-content: space-between; font-size: 12px; color: inherit; }
.ib .spark svg { width: 100%; height: 40px; display: block; }

.ib-events { padding: 5px 10px 6px; }
.ib .ib-dim { opacity: 0.65; font-size: 12px; }

/* ================================================================================================
   TDG Empire look: the same palette and fonts as the website (tdgwebsite/assets/style.css).
   Headings, buttons and labels in Cinzel, text in Crimson Text, warm near-black panels with a gold accent, deep red
   primary buttons and square corners. (Without internet the fonts fall back to Georgia.)
   ================================================================================================ */
:root {
  --bg: #0d0c0b; --panel: rgba(23, 21, 19, 0.92); --line: #3a322a; --text: #e8e0d2; --muted: #9a8f7e;
  --accent: #c9a24b; --red: #9b2226; --radius: 0px;
  font-family: 'Crimson Text', Georgia, 'Times New Roman', serif;
}
body { font-size: 16px; }
button { font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.04em; font-size: 13px; background: rgba(201, 162, 75, 0.06); border: 1px solid var(--line); border-radius: 0; color: var(--text); }
button:hover { background: rgba(201, 162, 75, 0.16); border-color: var(--accent); color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); }
.panel { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--red); border-radius: 0; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55); }
#title .name { font-family: 'Cinzel', Georgia, serif; font-weight: 700; letter-spacing: 0.08em; color: var(--accent); font-size: 21px; text-transform: uppercase; }
#title .sub { font-style: italic; color: var(--muted); font-size: 15px; }
.panel-head { font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.12em; color: var(--accent); font-size: 12px; }
#nation-list li, #search-results li, #mode-list li { border-radius: 0; font-size: 16px; }
#nation-list li:hover, #search-results li:hover, #mode-list li:hover { background: rgba(201, 162, 75, 0.10); }
#nation-list li.on, #search-results li.on, #mode-list li.on { background: rgba(201, 162, 75, 0.18); box-shadow: inset 2px 0 0 var(--accent); }
#nation-list .sw, #search-results .sw { border-radius: 0; border-color: rgba(232, 224, 210, 0.35); }
#nation-list .ar, #nation-list .ws, #mode-list .md, #search-results .sub { color: var(--muted); }
#search-input { font-family: 'Crimson Text', Georgia, serif; font-size: 16px; border-radius: 0; background: rgba(23, 21, 19, 0.94); border: 1px solid var(--line); border-bottom: 2px solid var(--red); box-shadow: 0 6px 22px rgba(0, 0, 0, 0.5); }
#search-input:focus { border-color: var(--accent); border-bottom-color: var(--accent); }
#mode-btn { font-size: 13px; }
#mode-list kbd { border-radius: 0; font-family: 'Cinzel', Georgia, serif; }
#tools button { background: var(--panel); border-radius: 0; }
#timeline { border-top: 3px solid var(--red); }
#tl-label .y { font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.06em; color: var(--accent); }
#tl-label .n { font-style: italic; }
#tl-line { background: rgba(201, 162, 75, 0.35); border-radius: 0; }
.tl-dot { background: #2a231c; border-color: #8a6f2f; }
.tl-dot:hover { border-color: var(--accent); }
.tl-dot.on { background: var(--accent); border-color: #f1dca0; }
#tip, #chart-tip { border-radius: 0; background: rgba(13, 12, 11, 0.95); border-color: var(--line); font-family: 'Crimson Text', Georgia, serif; font-size: 15px; }
#loading { background: rgba(13, 12, 11, 0.85); font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.1em; color: var(--accent); }
.modal { background: rgba(8, 7, 6, 0.7); }
.modal-head h2 { font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.08em; color: var(--accent); }
.tabs { background: rgba(201, 162, 75, 0.06); border-radius: 0; border: 1px solid var(--line); }
.tabs button { border-radius: 0; font-size: 12px; }
.tabs button.on { background: var(--red); color: #fff; border: 0; font-weight: 700; }
#stats h3 { font-family: 'Cinzel', Georgia, serif; color: var(--accent); letter-spacing: 0.12em; }
#chart-legend .lchip { border-radius: 0; white-space: nowrap; flex: none; font-size: 15px; }
#chart-legend .lchip i { border-radius: 0; }
#ranking .bar { font-size: 15px; border-radius: 0; }
#ranking .track, #ranking .fill { border-radius: 0; }
#ranking .bar:hover { background: rgba(201, 162, 75, 0.10); }

/* the infobox */
.ib { border-radius: 0; border-top: 3px solid var(--red); font-size: 15.5px; line-height: 1.35; box-shadow: 0 10px 34px rgba(0, 0, 0, 0.6); }
.ib-title { font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.08em; color: var(--accent); font-size: 17px; }
.ib-sub { font-style: italic; color: var(--muted); }
.ib-head { font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.1em; color: var(--accent); font-size: 13px; }
.ib-row .k { font-family: 'Cinzel', Georgia, serif; font-size: 12px; letter-spacing: 0.06em; color: var(--muted); font-weight: 500; padding-top: 2px; }
.ib-tags span { border-radius: 0; }
.ib-img img { border-radius: 0; }
#info .close:hover { background: rgba(201, 162, 75, 0.15); }
#info .ib .link { color: var(--accent); }


/* Top bar: the same navbar as tdgempire.com. index.html fetches the live one from the site (nav.php, built from config.php)
   and replaces the fallback below it; the map UI sits underneath it. */
:root { --nav-h: 68px; }
.tdg-nav {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  box-sizing: border-box; height: var(--nav-h); padding: 0 1.5rem;
  background: rgba(13, 12, 11, .92); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  font: 19px/1.6 'Crimson Text', Georgia, serif; color: var(--text);
}
.tdg-nav a { color: inherit; text-decoration: none; }
.tdg-nav a.tdg-brand { display: flex; align-items: center; gap: .6rem; font: 700 1.1rem 'Cinzel', serif; letter-spacing: .06em; color: var(--accent); }
.tdg-brand img { height: 42px; width: 42px; }
.tdg-nav nav { display: flex; align-items: center; gap: 1.5rem; }
.tdg-nav nav a:not(.tdg-btn) { color: var(--muted); transition: color .2s; }
.tdg-nav nav a:not(.tdg-btn):hover, .tdg-nav nav a[aria-current=page] { color: var(--accent); }
.tdg-btn { display: inline-block; background: var(--red); color: #fff !important; border: 1px solid #c0393e; padding: .4rem .9rem; font: .8rem 'Cinzel', serif; letter-spacing: .06em; transition: background .2s; }
.tdg-btn:hover { background: #b22d33; }
.tdg-burger { display: none; background: none; border: 0; color: var(--accent); font-size: 1.6rem; cursor: pointer; }
@media (max-width: 760px) {
  .tdg-nav { padding: 0 1rem; }
  .tdg-burger { display: block; }
  .tdg-nav nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: flex-start; gap: .9rem; padding: 1rem; background: rgba(13, 12, 11, .97); border-bottom: 1px solid var(--line); }
  .tdg-nav.open nav { display: flex; }
}
