/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #8b949e;
  --accent:   #58a6ff;

  --af: #e6a817;
  --an: #74c476;
  --as: #fd7f28;
  --eu: #4393c3;
  --na: #d9534f;
  --oc: #20b2aa;
  --sa: #9b59b6;

  --sidebar-w: 280px;
}

html, body { height: 100%; width: 100%; overflow: hidden; font-family: system-ui, -apple-system, sans-serif; }

/* ── Layout ── */
body { display: flex; background: var(--bg); color: var(--text); font-size: 14px; }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#map {
  flex: 1;
  height: 100vh;
  position: relative;
}

/* ── Sidebar header ── */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4393c3, #9b59b6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.sidebar-header p {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.3;
}

/* ── Panel sections ── */
.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.section-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 10px;
}

/* ── Section title row (title + toggle) ── */
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title-row .section-title {
  margin-bottom: 0;
}

.toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.toggle-btn svg { width: 14px; height: 14px; transition: transform 0.22s ease; }
.toggle-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.toggle-btn.collapsed svg { transform: rotate(-90deg); }

/* ── Continent buttons ── */
.continent-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.cont-btn {
  padding: 8px 6px;
  border-radius: 6px;
  border: 1.5px solid transparent;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.cont-btn:hover { border-color: var(--accent); color: var(--accent); }
.cont-btn.active { color: #fff; border-color: transparent; }

/* Color each button */
.cont-btn[data-id="AF"]        { border-color: var(--af); color: var(--af); }
.cont-btn[data-id="AF"]:hover,
.cont-btn[data-id="AF"].active { background: var(--af); color: #000; border-color: var(--af); }

.cont-btn[data-id="AN"]        { border-color: var(--an); color: var(--an); }
.cont-btn[data-id="AN"]:hover,
.cont-btn[data-id="AN"].active { background: var(--an); color: #000; border-color: var(--an); }

.cont-btn[data-id="AS"]        { border-color: var(--as); color: var(--as); }
.cont-btn[data-id="AS"]:hover,
.cont-btn[data-id="AS"].active { background: var(--as); color: #000; border-color: var(--as); }

.cont-btn[data-id="EU"]        { border-color: var(--eu); color: var(--eu); }
.cont-btn[data-id="EU"]:hover,
.cont-btn[data-id="EU"].active { background: var(--eu); color: #fff; border-color: var(--eu); }

.cont-btn[data-id="NA"]        { border-color: var(--na); color: var(--na); }
.cont-btn[data-id="NA"]:hover,
.cont-btn[data-id="NA"].active { background: var(--na); color: #fff; border-color: var(--na); }

.cont-btn[data-id="OC"]        { border-color: var(--oc); color: var(--oc); }
.cont-btn[data-id="OC"]:hover,
.cont-btn[data-id="OC"].active { background: var(--oc); color: #000; border-color: var(--oc); }

.cont-btn[data-id="SA"]        { border-color: var(--sa); color: var(--sa); }
.cont-btn[data-id="SA"]:hover,
.cont-btn[data-id="SA"].active { background: var(--sa); color: #fff; border-color: var(--sa); }

/* ── Tiling segmented toggle ── */
.seg-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.seg-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 4px;
  border: none;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn strong { font-size: 13px; font-weight: 700; }
.seg-btn em { font-size: 10px; font-style: normal; opacity: 0.85; }
.seg-btn:not(.active):hover { color: var(--text); background: rgba(255,255,255,0.05); }
.seg-btn.active { background: rgba(88,166,255,0.14); color: var(--accent); }

/* ── Tool buttons ── */
.tool-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.tool-btn, .upload-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  line-height: 1.3;
}

.tool-btn svg, .upload-btn svg {
  width: 20px;
  height: 20px;
}

.tool-btn:hover, .upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(88,166,255,0.06);
}

.tool-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(88,166,255,0.12);
  box-shadow: 0 0 0 2px rgba(88,166,255,0.2);
}

.upload-btn { cursor: pointer; }

.clear-btn {
  width: 100%;
  padding: 7px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 2px;
}

.clear-btn:hover {
  border-color: #f85149;
  color: #f85149;
  background: rgba(248,81,73,0.06);
}

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-card {
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1.5px solid var(--border);
}

.stat-card.inside { border-color: rgba(88,166,255,0.4); background: rgba(88,166,255,0.06); }
.stat-card.total  { border-color: var(--border); background: var(--bg); }

.stat-num {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stat-card.inside .stat-num { color: var(--accent); }

.stat-lbl {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.tile-list-header { margin-bottom: 6px; }

/* ── Stats group sub-labels ── */
.stats-group-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 6px;
  opacity: 0.85;
}
#aoi-results .stats-group-label { margin-top: 14px; }

/* ── On-land stat card ── */
.stat-card.land { border-color: rgba(116,196,118,0.4); background: rgba(116,196,118,0.06); }
.stat-card.land .stat-num { color: #74c476; }

/* ── Tile list header row (title + long/short toggle) ── */
.tile-list-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  margin-bottom: 6px;
}

/* ── Long / Short name pill toggle (mirrors the 2D/3D pills) ── */
.name-toggle-pills {
  display: flex;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}
.name-pill {
  padding: 3px 9px;
  font-size: 10.5px;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.04em;
  line-height: 1.4;
}
.name-pill + .name-pill { border-left: 1px solid var(--border); }
.name-pill.active { background: var(--accent); color: #fff; }
.name-pill:not(.active):hover { color: var(--text); background: rgba(255,255,255,0.07); }

/* ── Truncation ellipsis row ── */
#tile-list li.tile-ellipsis {
  color: var(--accent);
  font-style: italic;
  text-align: center;
  background: none;
  border: none;
  padding: 4px 0;
  letter-spacing: 0.05em;
}

/* ── Sampling row (input + copy) ── */
.sampling-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
}
.sampling-row label { font-size: 11px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.sampling-row input[type="number"] {
  width: 68px;
  padding: 4px 6px;
  border-radius: 5px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}
.sampling-row input[type="number"]:focus { outline: none; border-color: var(--accent); }
.sampling-row .unit { font-size: 11px; color: var(--muted); }

#btn-copy-tiles {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
#btn-copy-tiles svg { width: 12px; height: 12px; }
#btn-copy-tiles:hover { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,0.06); }
#btn-copy-tiles.copied { border-color: #74c476; color: #74c476; background: rgba(116,196,118,0.06); }

#tile-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* No max-height: truncation keeps count manageable (6 + ellipsis + 3) */
}

#tile-list li {
  font-size: 11.5px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  padding: 5px 8px;
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}

/* ── Export button ── */
.export-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, #4393c3, #9b59b6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.export-btn svg { width: 18px; height: 18px; }
.export-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.export-btn:active { transform: translateY(0); }

/* ── Sidebar footer ── */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-footer a { color: var(--accent); text-decoration: none; }
.sidebar-footer .footer-credit a:hover { text-decoration: underline; }

/* Buy me a coffee button */
.kofi-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, #4393c3, #9b59b6);
  color: #fff !important;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.kofi-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.kofi-btn:hover { opacity: 0.92; transform: translateY(-1px); text-decoration: none !important; }
.kofi-btn:active { transform: translateY(0); }

.footer-author {
  display: block;
  font-size: 11px;
  color: var(--muted);        /* "Made by" — same muted gray as the grid-data credit */
  margin-bottom: 4px;
}
.author-name {
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  /* Name only — same blue→purple gradient as the Buy-me-a-coffee button */
  background: linear-gradient(135deg, #4393c3, #9b59b6);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.author-name:hover { text-decoration: underline; text-decoration-color: #4393c3; }
.footer-credit { display: block; }

/* ── Graticule HTML labels ── */
#graticule-labels-html {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}
.graticule-label {
  position: absolute;
  font: 10.5px 'SF Mono', 'Fira Code', monospace;
  color: var(--text);
  letter-spacing: 0.02em;
  padding: 1px 4px;
  background: rgba(13, 17, 23, 0.6);
  border-radius: 3px;
  white-space: nowrap;
  user-select: none;
}

/* Country hover tooltip */
#country-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: rgba(13,17,23,0.93);
  border: 1px solid var(--accent);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  white-space: nowrap;
}
body.mode-country .maplibregl-canvas { cursor: pointer !important; }

/* In country mode the stats are just a tile count + list — hide the
   land breakdown and the AOI sub-grid (redundant for a picked country). */
body.mode-country .stat-card.land { display: none; }
body.mode-country .stats-grid { grid-template-columns: 1fr; }
body.mode-country #aoi-results > .stats-grid,
body.mode-country #aoi-results > .stats-group-label { display: none; }

/* ── Snapshot: temporarily expand the map to full width for a complete capture ── */
body.capturing #sidebar { display: none; }
body.capturing #globe-wrap { left: 0; }

/* ── Camera-shutter flash ── */
#snapshot-flash {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  background: #ffffff;
  opacity: 0;
}
#snapshot-flash.flash { animation: shutter 0.45s ease-out; }
@keyframes shutter {
  0%   { opacity: 0; }
  12%  { opacity: 0.85; }
  100% { opacity: 0; }
}

/* ── Live coordinate readout ── */
#coord-readout {
  position: fixed;
  bottom: 8px;
  left: calc(var(--sidebar-w) + 12px);
  z-index: 15;
  font: 11px 'SF Mono', 'Fira Code', monospace;
  color: var(--text);
  background: rgba(13, 17, 23, 0.72);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  letter-spacing: 0.02em;
  pointer-events: none;
  backdrop-filter: blur(4px);
  transition: left 0.28s ease;
}
body.sidebar-collapsed #coord-readout { left: 46px; }

/* ── Hint banner ── */
#hint-banner {
  position: fixed;
  bottom: 32px;
  left: calc(var(--sidebar-w) + 50%);
  transform: translateX(-50%);
  background: rgba(13,17,23,0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 24px;
  backdrop-filter: blur(8px);
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

/* ── Loader ── */
#loader {
  position: fixed;
  top: 56px;
  left: calc(var(--sidebar-w) + 16px);
  background: rgba(13,17,23,0.9);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 200;
  backdrop-filter: blur(8px);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── MapLibre overrides ── */
.maplibregl-ctrl-attrib { font-size: 10px !important; }
.maplibregl-canvas { cursor: grab; }
.maplibregl-canvas:active { cursor: grabbing; }
.drawing .maplibregl-canvas { cursor: crosshair !important; }
#globe-wrap.drawing canvas  { cursor: crosshair !important; }

/* ── Scrollbar styling ── */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Sidebar collapse ── */
#sidebar {
  transition: width 0.28s ease, min-width 0.28s ease;
}

body.sidebar-collapsed #sidebar {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
}

/* ── Sidebar toggle tab ── */
#sidebar-toggle {
  position: fixed;
  left: var(--sidebar-w);
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  width: 18px;
  height: 52px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.28s ease, color 0.15s, background 0.15s;
}

#sidebar-toggle:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}

#sidebar-toggle svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transition: transform 0.28s ease;
}

/* When collapsed: tab moves to left edge; chevron flips to point right */
body.sidebar-collapsed #sidebar-toggle {
  left: 0;
  border-radius: 0 8px 8px 0;
}

body.sidebar-collapsed #sidebar-toggle svg {
  transform: rotate(180deg);
}

/* Reposition floating UI elements when sidebar is hidden */
body.sidebar-collapsed #hint-banner {
  left: 50%;
}

body.sidebar-collapsed #loader {
  left: 24px;
}

/* ── Top-left control bar (flex row: view toggle · country · home · snapshot) ── */
#topbar-left {
  position: fixed;
  top: 16px;
  left: calc(var(--sidebar-w) + 16px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: left 0.28s ease;
}
body.sidebar-collapsed #topbar-left { left: 34px; }

/* 2D / 3D view toggle */
#view-toggle-wrap {
  display: flex;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
}
.view-toggle-pill {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  letter-spacing: 0.06em;
  line-height: 1;
}
.view-toggle-pill + .view-toggle-pill { border-left: 1px solid var(--border); }
.view-toggle-pill.active { background: var(--accent); color: #fff; }
.view-toggle-pill:not(.active):hover { color: var(--text); background: rgba(255,255,255,0.07); }

#layers-menu-wrap {
  position: relative;
}

#layers-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 96px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  z-index: 25;
}

.layer-menu-item {
  width: 100%;
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.layer-menu-item:last-child { border-bottom: 0; }
.layer-menu-item:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.layer-menu-item.active {
  color: var(--accent);
  background: rgba(88,166,255,0.10);
}
.layer-menu-item.active::after {
  content: "";
  width: 5px;
  height: 5px;
  background: currentColor;
}
body.mode-3d #layers-menu-wrap { display: none; }

/* Country-mode pill (labelled toggle next to 2D/3D) */
.topbar-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.topbar-pill svg { width: 15px; height: 15px; }
.topbar-pill:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.topbar-pill.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

/* Home / snapshot icon buttons */
.topbar-icon-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.topbar-icon-btn svg { width: 15px; height: 15px; }
.topbar-icon-btn:hover { color: var(--accent); background: rgba(88,166,255,0.1); border-color: rgba(88,166,255,0.45); }

/* ── Floating AOI toolbar ── */
#aoi-toolbar {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  transition: left 0.28s ease;
}

/* toolbar uses right:16px — no sidebar-collapsed adjustment needed */

.aoi-btn {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
  flex-shrink: 0;
}

.aoi-btn svg { width: 14px; height: 14px; pointer-events: none; }

.aoi-btn:hover {
  color: var(--accent);
  background: rgba(88,166,255,0.08);
  border-color: rgba(88,166,255,0.4);
}

.aoi-btn.active {
  color: var(--accent);
  background: rgba(88,166,255,0.12);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(88,166,255,0.2);
}

.aoi-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.aoi-clear-btn:hover {
  color: #f85149;
  background: rgba(248,81,73,0.08);
  border-color: rgba(248,81,73,0.4);
}

.aoi-divider {
  width: 1px;
  height: 14px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

/* ── 3D Globe overlay ── */
#globe-wrap {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  background: #080c14;
  z-index: 8;
  transition: left 0.28s ease;
}

body.sidebar-collapsed #globe-wrap {
  left: 0;
}

/* ─────────────────────────────────────────────────────────────
   Homogeneous console redesign shared with BBoxer / Open SAR Triad
   ───────────────────────────────────────────────────────────── */

:root {
  --bg:        oklch(0.15 0.008 250);
  --surface:   oklch(0.182 0.009 250);
  --bg-3:      oklch(0.225 0.011 250);
  --border:    oklch(0.31 0.012 250);
  --border-2:  oklch(0.42 0.014 250);
  --text:      oklch(0.93 0.008 250);
  --text-2:    oklch(0.71 0.011 250);
  --muted:     oklch(0.54 0.012 250);
  --accent:    oklch(0.83 0.135 82);
  --accent-2:  oklch(0.83 0.135 82 / 0.16);
  --accent-3:  oklch(0.83 0.135 82 / 0.45);
  --red:       oklch(0.65 0.20 25);
  --land:      var(--text);
  --shadow:    0 18px 50px -24px oklch(0 0 0 / 0.85);
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --font-cond: 'IBM Plex Sans Condensed', 'IBM Plex Mono', sans-serif;
  --sidebar-w: 320px;
}

[data-theme="paper"] {
  --bg:        oklch(0.95 0.006 95);
  --surface:   oklch(0.975 0.005 95);
  --bg-3:      oklch(0.915 0.008 95);
  --border:    oklch(0.83 0.012 95);
  --border-2:  oklch(0.70 0.014 95);
  --text:      oklch(0.27 0.012 255);
  --text-2:    oklch(0.44 0.013 255);
  --muted:     oklch(0.57 0.012 255);
  --accent:    oklch(0.58 0.155 52);
  --accent-2:  oklch(0.58 0.155 52 / 0.14);
  --accent-3:  oklch(0.58 0.155 52 / 0.5);
  --red:       oklch(0.55 0.20 25);
  --land:      var(--text);
  --shadow:    0 18px 50px -28px oklch(0 0 0 / 0.35);
}

html,
body {
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] {
  display: none !important;
}

#sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  scrollbar-color: var(--border) transparent;
  position: relative;
}

#sidebar::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 3px, oklch(1 0 0 / .008) 3px 4px);
}

#sidebar > * { position: relative; z-index: 1; }
#sidebar::-webkit-scrollbar { width: 9px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border: 3px solid var(--surface); border-radius: 0; }

.sidebar-header {
  align-items: flex-start;
  gap: 10px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--border);
}

.logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 0;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.logo-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.logo-bbox {
  position: absolute;
  left: 11px;
  top: 12px;
  width: 18px;
  height: 15px;
  border: 1.5px solid var(--accent);
  box-shadow:
    0 0 0 1px oklch(0 0 0 / .5),
    inset 0 0 0 999px oklch(from var(--accent) l c h / .08);
}

.logo-bbox::before,
.logo-bbox::after {
  content: "";
  position: absolute;
  width: 3px;
  height: 3px;
  background: var(--accent);
  box-shadow:
    15px 0 0 var(--accent),
    0 12px 0 var(--accent),
    15px 12px 0 var(--accent);
}

.logo-bbox::before {
  left: -2px;
  top: -2px;
}

.logo-bbox::after {
  display: none;
}

.sidebar-brand {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  display: flex;
  flex-direction: column;
  max-width: 139px;
}

.sidebar-header h1 {
  font-family: var(--font-cond);
  font-size: 18px;
  line-height: 1;
  letter-spacing: .01em;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: .08em;
  white-space: nowrap;
}

.header-sep { color: var(--accent); font-weight: 600; }
.sidebar-header p {
  margin-top: auto;
  padding-top: 7px;
  color: var(--text-2);
  font-size: 9.5px;
  letter-spacing: .04em;
  line-height: 1.35;
}

.header-right {
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
  padding-top: 0;
}

.theme-toggle,
#view-toggle-wrap,
.name-toggle-pills,
.seg-toggle {
  display: flex;
  border: 1px solid var(--border-2);
  border-radius: 0;
  background: var(--bg-3);
  overflow: hidden;
  box-shadow: none;
}

.theme-toggle {
  height: 22px;
  border-color: var(--border);
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: .08em;
}

.theme-toggle button,
.view-toggle-pill,
.name-pill,
.seg-btn {
  appearance: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  cursor: pointer;
}

.theme-toggle button {
  padding: 0 7px;
  font: inherit;
  text-transform: uppercase;
}

.theme-toggle button + button,
.view-toggle-pill + .view-toggle-pill,
.name-pill + .name-pill,
.seg-btn + .seg-btn {
  border-left: 1px solid var(--border);
}

.theme-toggle button[aria-pressed="true"],
.view-toggle-pill.active,
.name-pill.active,
.seg-btn.active {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}

.theme-toggle button:hover:not([aria-pressed="true"]),
.view-toggle-pill:not(.active):hover,
.name-pill:not(.active):hover,
.seg-btn:not(.active):hover {
  color: var(--text);
  background: oklch(1 0 0 / .07);
}

.panel-section {
  padding: 16px 20px 18px;
  border-bottom: 1px solid var(--border);
}

.section-title,
.mod-h {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
}

.tray-toggle {
  appearance: none;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.tray-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.tray-toggle:hover .ttl,
.tray-toggle:hover .chev {
  color: var(--text);
}

.section-title .ix,
.mod-h .ix { color: var(--accent); font-weight: 600; }
.section-title .ttl,
.mod-h .ttl { color: var(--text-2); }
.section-title .rule,
.mod-h .rule { flex: 1; height: 1px; background: var(--border); }

.section-title .meta,
.mod-h .meta {
  color: var(--muted);
  font-size: 9.5px;
  letter-spacing: .12em;
  white-space: nowrap;
}

.section-title .chev,
.mod-h .chev {
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
  transform: translateY(-2px) rotate(45deg);
  transition: transform .16s ease;
  flex: 0 0 7px;
}

.tray-section.is-collapsed {
  padding-bottom: 16px;
}

.tray-section.is-collapsed .section-title,
.tray-section.is-collapsed .mod-h {
  margin-bottom: 0;
}

.tray-section.is-collapsed .chev {
  transform: translateY(2px) rotate(-135deg);
}

.section-hint,
.stats-group-label {
  color: var(--muted);
  font-family: var(--font-mono);
  letter-spacing: .03em;
}

.seg-btn {
  padding: 7px 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.stat-card,
#tile-list li {
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--bg);
}

#aoi-results,
#tile-list-wrap {
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  background: oklch(from var(--bg-3) l c h / .45);
}

#tile-list-wrap {
  padding-top: 9px;
}

.tile-list-header-row {
  gap: 8px;
  margin-top: 0;
  margin-bottom: 8px;
}

.tile-list-header-row + .tile-list-header-row {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

#tile-list {
  gap: 3px;
  margin-top: 8px;
}

#tile-list li {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  background: var(--surface);
  border-color: var(--border);
  border-left: 2px solid var(--accent);
  border-radius: 0;
}

#tile-list li.tile-ellipsis {
  color: var(--muted);
  background: transparent;
  border: 0;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.stat-card.inside {
  border-color: var(--accent-3);
  background: var(--accent-2);
}

.stat-card.land {
  border-color: var(--border);
  background: var(--bg);
}

.stat-num {
  font-family: var(--font-mono);
  color: var(--text);
}
.stat-card.inside .stat-num { color: var(--accent); }
.stat-card.land .stat-num { color: var(--text); }

.stat-lbl,
.sampling-row label,
.sampling-row .unit {
  color: var(--muted);
  font-family: var(--font-mono);
}

.sampling-row input[type="number"],
#btn-copy-tiles,
.export-btn {
  border-radius: 0;
  border: 1px solid var(--border-2);
  background: var(--bg-3);
  color: var(--text);
  font-family: var(--font-mono);
}

.sampling-row input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-2);
}

#btn-copy-tiles:hover,
.export-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-2);
  transform: none;
  opacity: 1;
}

#btn-copy-tiles.copied {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-2);
}

.export-btn {
  padding: 9px 14px;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: 10.5px;
  font-weight: 600;
}

.sidebar-footer {
  padding: 14px 20px 15px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  letter-spacing: .06em;
}

.footer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.footer-author {
  margin: 0;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer .author-name {
  color: var(--text-2);
  background: none;
  -webkit-text-fill-color: currentColor;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.sidebar-footer .author-name:hover {
  color: var(--text);
  text-decoration-color: var(--text-2);
}

.footer-icons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-footer .footer-icon-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text-2);
  text-decoration: none;
  transition: color .15s, border-color .15s, background .15s;
}

.sidebar-footer .footer-icon-link svg { width: 15px; height: 15px; }
.sidebar-footer .footer-icon-link:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-2);
}

.sidebar-footer .footer-support {
  display: inline-block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  text-decoration: none;
}

.sidebar-footer .footer-support:hover { color: var(--text-2); }
.footer-credit {
  display: none;
  color: var(--muted);
  font-size: 9.5px;
}
.footer-credit a { color: var(--text-2); border-bottom: 1px solid var(--border-2); }
.footer-credit a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.kofi-btn { display: none; }

#sidebar-toggle {
  width: 22px;
  height: 46px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  transition: left .28s ease, color .15s, border-color .15s;
}
#sidebar-toggle:hover { color: var(--accent); border-color: var(--accent); background: var(--surface); }
body.sidebar-collapsed #sidebar-toggle { border-radius: 0; }

#topbar-left,
#aoi-toolbar {
  gap: 1px;
}

#view-toggle-wrap,
.topbar-pill,
.topbar-icon-btn,
#aoi-toolbar,
#loader,
#coord-readout,
#hint-banner,
#country-tooltip {
  border-radius: 0;
  border: 1px solid var(--border);
  background: oklch(from var(--surface) l c h / .9);
  color: var(--text-2);
  box-shadow: var(--shadow);
  font-family: var(--font-mono);
  backdrop-filter: blur(6px);
}

.view-toggle-pill {
  height: 30px;
  padding: 0 13px;
  font-size: 11px;
  letter-spacing: .08em;
}

.topbar-pill,
.topbar-icon-btn {
  height: 32px;
  box-shadow: var(--shadow);
}

.topbar-pill {
  padding: 0 13px;
  font-size: 11px;
  letter-spacing: .04em;
}

.topbar-pill:hover,
.topbar-icon-btn:hover {
  color: var(--accent);
  background: var(--accent-2);
  border-color: var(--accent-3);
}

.topbar-pill.active {
  color: var(--accent);
  background: var(--accent-2);
  border-color: var(--accent);
}

.topbar-icon-btn {
  width: 32px;
  color: var(--muted);
}

#aoi-toolbar {
  padding: 3px;
}

.aoi-btn {
  width: 30px;
  height: 30px;
  border-radius: 0;
  border: 1px solid transparent;
  color: var(--muted);
}

.aoi-btn:hover {
  color: var(--accent);
  background: var(--accent-2);
  border-color: var(--accent-3);
}

.aoi-btn.active {
  color: var(--accent);
  background: var(--accent-2);
  border-color: var(--accent);
  box-shadow: none;
}

.aoi-clear-btn:hover {
  color: var(--red);
  background: oklch(from var(--red) l c h / .08);
  border-color: oklch(from var(--red) l c h / .4);
}

.aoi-divider { background: var(--border); height: 16px; }

.graticule-label {
  border-radius: 0;
  color: var(--text-2);
  background: oklch(from var(--surface) l c h / .62);
  font: 10px var(--font-mono);
  letter-spacing: .04em;
}

.maplibregl-ctrl-attrib,
.maplibregl-ctrl-scale {
  font-family: var(--font-mono) !important;
  border-radius: 0 !important;
}

.maplibregl-ctrl-group {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 !important;
}

.maplibregl-ctrl-group button {
  color: var(--muted) !important;
}

.maplibregl-ctrl-group button:hover {
  background: oklch(1 0 0 / .07) !important;
  color: var(--text) !important;
}

#globe-wrap { background: var(--bg); }

@media (max-width: 760px) {
  :root { --sidebar-w: 100vw; }
  .sidebar-header { padding: 14px 16px; }
  .logo-mark { width: 40px; height: 40px; }
  .sidebar-header h1 { font-size: 18px; }
  .theme-toggle { height: 24px; }
  .theme-toggle button { padding: 0 8px; }
  .panel-section { padding: 13px 14px 15px; }
  body:not(.sidebar-collapsed) #topbar-left,
  body:not(.sidebar-collapsed) #aoi-toolbar,
  body:not(.sidebar-collapsed) #coord-readout,
  body:not(.sidebar-collapsed) #tour-help-btn {
    display: none;
  }
  body:not(.sidebar-collapsed) #sidebar-toggle {
    left: calc(100vw - 22px);
  }
  body.sidebar-collapsed #topbar-left {
    left: 16px;
  }
}
