:root {
  --page: #ebe5da;
  --surface: rgba(252, 250, 246, 0.94);
  --ink: #2a251f;
  --ink-2: #6f6558;
  --ink-3: #9a9082;
  --line: rgba(42, 37, 31, 0.12);
  --accent: #d0562f;
  --accent-ink: #fff;
  --shadow: 0 1px 2px rgba(42, 37, 31, 0.06), 0 8px 28px rgba(42, 37, 31, 0.12);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --c-ee: #6f9fb0;
  --c-merc: #d2b27a;
  --c-street: #b8aa98;
  --c-globe: #8fb3a3;
  --c-off: rgba(42, 37, 31, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }

#street, #base, #overlay { position: fixed; inset: 0; width: 100%; height: 100%; }
#street { z-index: 0; visibility: hidden; background: var(--page); }
#base { z-index: 1; pointer-events: none; }
#overlay { z-index: 2; cursor: grab; touch-action: none; outline: none; }
#overlay.dragging { cursor: grabbing; }
#overlay.on-ghost { cursor: move; }
#overlay.on-country { cursor: pointer; }

.panel, .topbar .search, .card, .modes .seg, .hud, .zoom, .tooltip, .toast {
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

/* Top bar */
.topbar {
  position: fixed; z-index: 10; top: 16px; left: 16px;
  display: flex; flex-direction: column; gap: 10px; width: min(340px, calc(100vw - 32px));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--ink-2); font-size: 12.5px; }
.brand { pointer-events: none; text-shadow: 0 0 6px var(--page), 0 0 12px var(--page); }
.brand-row { display: flex; align-items: center; gap: 10px; }
.about-btn {
  pointer-events: auto; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 3px 11px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); cursor: pointer; text-shadow: none;
  box-shadow: 0 1px 2px rgba(42, 37, 31, 0.06);
}
.about-btn:hover, .about-btn[aria-expanded="true"] { color: var(--ink); background: #fff; }
.about-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.search { position: relative; border-radius: 12px; display: flex; align-items: center; }
.search svg { width: 18px; height: 18px; margin-left: 12px; fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 10px 12px 10px 8px; outline: none;
}
.search input::placeholder { color: var(--ink-3); }
.search:focus-within { border-color: rgba(208, 86, 47, 0.5); }
#suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 50vh; overflow: auto;
}
#suggest li {
  display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
#suggest li small { color: var(--ink-3); }
#suggest li[aria-selected="true"], #suggest li:hover { background: rgba(42, 37, 31, 0.06); }

/* Country card */
.card {
  position: fixed; z-index: 10; top: 16px; right: 16px; width: 280px;
  border-radius: var(--radius); padding: 18px 18px 14px;
}
.card h2 { margin: 0; font-size: 22px; line-height: 1.2; padding-right: 28px; }
.card dl { margin: 14px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.card dl .wide { grid-column: 1 / -1; }
.card dt { font-size: 11.5px; color: var(--ink-3); }
.card dd { margin: 1px 0 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card dd .sub { display: block; font-weight: 400; font-size: 13px; color: var(--ink-2); }
.card-actions { display: flex; gap: 8px; margin-top: 16px; }
.card-note { margin: 12px 0 0; font-size: 11.5px; color: var(--ink-3); }
.card-close { position: absolute; top: 10px; right: 10px; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; cursor: pointer;
  font-weight: 500; transition: background 0.15s, transform 0.1s;
}
.btn:hover { background: #f6f2ec; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #bd4b27; }
.btn:focus-visible, .icon-btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border: 0; background: transparent;
  border-radius: 9px; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: rgba(42, 37, 31, 0.07); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* Projection switch */
.modes {
  position: fixed; z-index: 10; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center;
}
.seg { display: flex; padding: 4px; border-radius: 12px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 7px 16px; border-radius: 9px; cursor: pointer; white-space: nowrap;
  color: var(--ink-2); font-weight: 500; transition: background 0.2s, color 0.2s;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"] { background: var(--ink); color: #fff; }
.ghost-clear { box-shadow: var(--shadow); }

/* Projection status HUD */
.hud {
  position: fixed; z-index: 10; left: 16px; bottom: 20px; width: 240px; border-radius: 12px; padding: 10px 12px;
  font-size: 12.5px;
}
.hud-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
#hud-proj { font-weight: 600; }
.mono { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); }
/* The padding gives the thin bar a comfortable click/drag target */
.track { position: relative; padding: 7px 0; margin: 2px 0 0; cursor: pointer; touch-action: none; outline: none; }
.track-bar { position: relative; height: 6px; border-radius: 3px; overflow: hidden; background: var(--c-off); }
.track-bar i { position: absolute; top: 0; bottom: 0; }
.knob {
  position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: #fff; border: 2px solid var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s; pointer-events: none;
}
.track:hover .knob, .track:active .knob { transform: scale(1.15); }
.track:focus-visible .knob { outline: 2px solid var(--accent); outline-offset: 2px; }
.track-legend { position: relative; height: 14px; color: var(--ink-3); font-size: 10.5px; }
.track-legend span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.tuner { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.tuner summary { cursor: pointer; color: var(--ink-2); font-size: 12px; list-style: none; }
.tuner summary::before { content: "▸ "; }
.tuner[open] summary::before { content: "▾ "; }
.tuner label { display: grid; grid-template-columns: 74px 1fr 30px; align-items: center; gap: 6px; margin-top: 6px; color: var(--ink-2); font-size: 11.5px; }
.tuner input { width: 100%; accent-color: var(--accent); }
.tuner output { font-family: var(--mono); font-size: 11px; text-align: right; }

/* Zoom buttons */
.zoom {
  position: fixed; z-index: 10; right: 16px; bottom: 44px; border-radius: 12px; padding: 3px;
  display: flex; flex-direction: column; gap: 2px;
}

.attrib {
  position: fixed; z-index: 10; right: 16px; bottom: 12px; font-size: 10.5px; color: var(--ink-2);
  background: rgba(252, 250, 246, 0.7); padding: 2px 8px; border-radius: 6px;
}
.attrib a { color: inherit; text-decoration: none; }
.attrib a:hover { text-decoration: underline; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; padding: 6px 10px; border-radius: 9px; font-size: 13px;
  white-space: nowrap; transform: translate(14px, 14px);
}
.tooltip b { font-weight: 600; margin-right: 6px; }
.tooltip span { color: var(--ink-2); font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; z-index: 20; left: 50%; bottom: 76px; transform: translateX(-50%);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; max-width: calc(100vw - 32px); text-align: center;
}

.loading {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; color: var(--ink-2);
  background: var(--page); transition: opacity 0.4s;
}
.loading.done { opacity: 0; pointer-events: none; }

.maplibregl-ctrl-attrib { display: none; }

/* About panel: a drawer so the text lives in the page (for readers and search engines) without covering the map by default */
.about {
  position: fixed; z-index: 25; top: 0; right: 0; bottom: 0; width: min(460px, 100vw);
  background: #fcfaf6; border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(42, 37, 31, 0.14);
  overflow-y: auto; overscroll-behavior: contain; outline: none;
  transform: translateX(100%); visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;
}
.about.open { transform: none; visibility: visible; transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
.about article { padding: 28px 28px 40px; max-width: 62ch; }
.about-close { position: sticky; top: 12px; float: right; margin: 12px 12px 0 0; background: #fcfaf6; }
.about h2 { font-size: 22px; line-height: 1.25; margin: 0 0 12px; letter-spacing: -0.01em; }
.about h2#faq { margin-top: 32px; font-size: 19px; }
.about h3 { font-size: 15.5px; margin: 26px 0 8px; }
.about p, .about li { font-size: 14.5px; line-height: 1.62; color: #3d362e; }
.about p { margin: 0 0 10px; }
.about .lead { font-size: 15.5px; color: var(--ink); }
.about ul { padding-left: 20px; margin: 0; }
.about li { margin-bottom: 6px; }
.about a { color: var(--accent); }
.about details { border-top: 1px solid var(--line); padding: 10px 0; }
.about details:last-of-type { border-bottom: 1px solid var(--line); }
.about summary { cursor: pointer; font-weight: 600; font-size: 14.5px; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.about summary::after { content: "+"; color: var(--ink-3); font-weight: 400; }
.about details[open] summary::after { content: "−"; }
.about details p { margin: 8px 0 2px; }
.about-credits { margin-top: 28px !important; font-size: 12.5px !important; color: var(--ink-3) !important; }
@media (prefers-reduced-motion: reduce) { .about, .about.open { transition: none; } }

@media (max-width: 720px) {
  .brand p { display: none; }
  .brand h1 { font-size: 17px; }
  .card {
    top: auto; bottom: 72px; left: 12px; right: 12px; width: auto; padding: 14px 16px 12px;
  }
  .card-note { display: none; }
  .hud { top: 108px; bottom: auto; left: 16px; width: 240px; padding: 8px 10px; }
  .hud-row { white-space: nowrap; }
  .btn { white-space: nowrap; }
  .hud .tuner, .track-legend { display: none; }
  /* Keep only the share button on phones (pinch replaces the zoom buttons) */
  .zoom { top: 108px; bottom: auto; right: 16px; }
  #zoom-in, #zoom-out, #zoom-home { display: none; }
  .about article { padding: 20px 20px 32px; }
  .modes { bottom: 30px; }
  .card { bottom: 86px; }
  .seg button { padding: 7px 12px; }
  .attrib { left: 12px; right: 12px; bottom: 4px; text-align: center; font-size: 9.5px; background: none; }
}
