:root {
  --bg: #e9eff5;
  --space: radial-gradient(circle at 50% 45%, #f7fafd 0%, #dfe8f1 60%, #cfdbe7 100%);
  --panel: rgba(255, 255, 255, 0.78);
  --panel-solid: #ffffff;
  --line: rgba(0, 0, 0, 0.08);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --chip: rgba(0, 0, 0, 0.05);
  --chip-hover: rgba(0, 0, 0, 0.09);
  --card-bg: #f5f5f7;
  --accent: #f59e0b;
  --accent-ink: color-mix(in srgb, var(--accent) 70%, #000);
  --radius: 20px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --shadow: 0 12px 40px rgba(15, 30, 60, 0.14), 0 2px 6px rgba(15, 30, 60, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #03050a;
    --space: radial-gradient(circle at 50% 45%, #13203f 0%, #070b16 55%, #020308 100%);
    --panel: rgba(30, 30, 34, 0.78);
    --panel-solid: #1c1c20;
    --line: rgba(255, 255, 255, 0.1);
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --chip: rgba(255, 255, 255, 0.08);
    --chip-hover: rgba(255, 255, 255, 0.14);
    --card-bg: #26262b;
    --accent-ink: color-mix(in srgb, var(--accent) 75%, #fff);
    --shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }

.glass {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  box-shadow: var(--shadow);
}

#map { position: fixed; inset: 0; background: var(--space); }

/* ---------- Flags ---------- */
.flag { display: inline-block; line-height: 1; font-style: normal; }
img.flag { width: 1.15em; height: 1.15em; vertical-align: -0.2em; }

/* ---------- Masthead ---------- */
.masthead {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 5;
  max-width: min(480px, calc(100vw - 32px));
  padding: 16px 18px 14px;
  border-radius: var(--radius);
}
.masthead-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.masthead h1 {
  margin: 0;
  font: 800 30px/1 var(--display);
  letter-spacing: -0.02em;
}
.masthead h1 span { font-weight: 500; color: var(--muted); font-size: 0.75em; }
.chips-toggle {
  flex: none;
  border: 0;
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--chip);
  font-size: 13px;
  font-weight: 600;
}
.chips-toggle:hover { background: var(--chip-hover); }
.chev { display: inline-block; margin-left: 2px; font-size: 10px; }

/* Collapsed: every chip in one horizontally scrolling row. */
.region-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -4px;
  padding: 0 4px 2px;
  mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.region-chips::-webkit-scrollbar { display: none; }
.chip-group, .chip-row { display: contents; }
.chip-group h3 { display: none; }

/* Expanded: all countries, wrapped and grouped by continent. */
.region-chips.is-expanded {
  display: block;
  max-height: min(60dvh, 520px);
  overflow-y: auto;
  overflow-x: hidden;
  mask-image: none;
  scrollbar-width: thin;
}
.region-chips.is-expanded .chip-group { display: block; margin-bottom: 10px; }
.region-chips.is-expanded .chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.region-chips.is-expanded .chip-group h3 {
  display: block;
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.chip {
  flex: none;
  border: 1px solid transparent;
  background: var(--chip);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.chip:hover { background: var(--chip-hover); }
.chip[aria-current="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }

/* ---------- Pins ---------- */
.marker { cursor: pointer; transition: opacity 0.2s; }
.marker[style*="opacity: 0;"] { pointer-events: none; } /* far side of the globe */
.pin {
  --accent: #f59e0b;
  position: relative;
  display: grid;
  justify-items: center;
  padding: 0 0 7px;
  border: 0;
  background: none;
  transform: scale(var(--pin-scale, 1));
  transition: transform 0.18s cubic-bezier(.2,.8,.2,1);
  transform-origin: 50% 100%;
}
.pin-face {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 23px;
  border-radius: 50%;
  background: var(--panel-solid);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--accent), 0 6px 14px rgba(0, 0, 0, 0.28);
}
/* the little pointer under the bubble */
.pin::after {
  content: "";
  position: absolute;
  bottom: 1px;
  left: 50%;
  width: 10px;
  height: 10px;
  background: var(--accent);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 0 0 3px 0;
  z-index: -1;
}
.pin-count {
  position: absolute;
  top: -5px;
  right: -7px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: 700 11px/19px -apple-system, system-ui, sans-serif;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.pin-label {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.pin:hover, .pin:focus-visible, .pin.is-active { transform: scale(max(1, calc(var(--pin-scale, 1) * 1.18))); }
.pin:hover .pin-label, .pin:focus-visible .pin-label, .pin.is-active .pin-label { opacity: 1; }
.pin:focus-visible { outline: none; }
.pin:focus-visible .pin-face { box-shadow: 0 0 0 2px var(--accent), 0 0 0 6px color-mix(in srgb, var(--accent) 35%, transparent); }
.marker:has(.pin:hover), .marker:has(.pin.is-active) { z-index: 3; }

/* MapLibre controls */
.maplibregl-ctrl-group { background: var(--panel) !important; backdrop-filter: blur(20px); border-radius: 12px !important; box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-group button + button { border-top-color: var(--line) !important; }
@media (prefers-color-scheme: dark) {
  .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
}
.maplibregl-ctrl-attrib { background: var(--panel) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }

/* ---------- Region panel (first click) ---------- */
.region-panel {
  position: fixed;
  z-index: 6;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: min(440px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  overflow: hidden;
  transform: translateX(calc(100% + 32px));
  transition: transform 0.4s cubic-bezier(.2,.8,.2,1);
}
.region-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--accent);
}
.region-panel.is-open { transform: none; }

.region-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 20px 18px 8px;
}
.region-emoji {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  font-size: 30px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.region-head h2 { margin: 0; font: 800 24px/1.1 var(--display); }
.local-term { margin: 2px 0 0; color: var(--accent-ink); font-weight: 600; font-size: 14px; }
.region-intro { margin: 4px 18px 14px; color: var(--muted); font-size: 14px; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: var(--chip);
  color: var(--muted);
  font-size: 13px;
}
.icon-btn:hover { background: var(--chip-hover); color: var(--text); }

.unc-grid {
  list-style: none;
  margin: 0;
  padding: 0 18px 18px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  overflow-y: auto;
}
.area-head {
  grid-column: 1 / -1;
  margin: 6px 0 -4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent-ink);
}
.area-head:first-child { margin-top: 0; }
.unc-card {
  display: block;
  width: 100%;
  padding: 0;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card-bg);
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}
.unc-card:hover, .unc-card:focus-visible { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.12), 0 0 0 2px var(--accent); outline: none; }
.thumb {
  position: relative;
  aspect-ratio: 4 / 5;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 20%, color-mix(in srgb, var(--accent) 45%, transparent), transparent 60%),
    radial-gradient(circle at 80% 90%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 70%),
    color-mix(in srgb, var(--accent) 10%, var(--card-bg));
}
.thumb video, .thumb img:not(.flag) { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-emoji { font-size: 54px; filter: drop-shadow(0 6px 12px rgba(0,0,0,.2)); transition: transform 0.3s; }
.unc-card:hover .thumb-emoji { transform: scale(1.12) rotate(-6deg); }
.thumb-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  backdrop-filter: blur(6px);
}
.thumb-badge.is-missing { background: rgba(0,0,0,.35); }
.play-glyph {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
}
.unc-card h3 { margin: 0; padding: 10px 12px 12px; font: 700 14px/1.25 var(--display); }

/* ---------- Viewer (second click) ---------- */
.viewer {
  width: min(1040px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.viewer::backdrop { background: rgba(10, 14, 24, 0.45); backdrop-filter: blur(6px); }
.viewer-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  max-height: calc(100dvh - 40px);
}
.stage {
  background: #000;
  display: grid;
  place-items: center;
  min-height: 420px;
}
.stage iframe, .stage video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  background: #000;
}
.stage.is-vertical iframe, .stage.is-vertical video {
  width: auto;
  height: min(78dvh, 740px);
  aspect-ratio: 9 / 16;
  max-width: 100%;
}

.stage-empty {
  width: 100%;
  height: 100%;
  padding: 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  color: #f5f5f7;
  background:
    radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--accent) 35%, transparent), transparent 55%),
    #15161a;
}
.stage-empty .big-emoji { font-size: 64px; line-height: 1; }
.stage-empty h3 { margin: 0; font: 800 22px/1.2 var(--display); }
.stage-empty p { margin: 0; color: #a1a1a6; }
.search-links { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.search-links a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  background: rgba(255,255,255,.06);
  color: #f5f5f7;
  text-decoration: none;
}
.search-links a:hover { border-color: var(--accent); }
.search-links .q { color: #a1a1a6; font-size: 13px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.link-out {
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 32px;
  text-align: center;
  color: #f5f5f7;
}
.link-out a {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

.viewer-info {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
}
.viewer-top { display: flex; justify-content: space-between; align-items: center; }
.badge {
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
}
.viewer h2 { margin: 0; font: 800 24px/1.15 var(--display); }
.viewer-desc { margin: 0; }
.tags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { padding: 2px 9px; border-radius: 999px; background: var(--chip); color: var(--muted); font-size: 12px; }
.viewer-meta { margin: 0; color: var(--muted); font-size: 13px; }
.viewer-meta a { color: var(--accent-ink); }

.more-label { margin: 0 0 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.clip-strip {
  list-style: none;
  margin: 0;
  padding: 0 0 4px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.clip-thumb {
  position: relative;
  flex: none;
  width: 112px;
  aspect-ratio: 16 / 9;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  background: var(--card-bg);
  display: grid;
  place-items: center;
  font-size: 24px;
}
.clip-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.clip-thumb[aria-current="true"] { border-color: var(--accent); }
.clip-thumb:hover { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.clip-by {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 6px 3px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.viewer-nav button {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--chip);
  font-size: 13px;
  font-weight: 600;
}
.viewer-nav button:hover { border-color: var(--accent); }
.viewer-nav button:disabled { opacity: 0.35; cursor: default; border-color: var(--line); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .masthead { top: 10px; left: 10px; right: 10px; max-width: none; padding: 12px 14px 10px; }
  .masthead h1 { font-size: 24px; }

  .region-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 64dvh;
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(105%);
  }
  .region-panel.is-open { transform: none; }

  .viewer { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  /* Plain stacking: a grid row would squeeze a tall (vertical) video down to the stage's min-height. */
  .viewer-body { display: block; max-height: 100dvh; height: 100%; overflow-y: auto; }
  .viewer-info { border-left: 0; overflow: visible; }
  .stage { min-height: 280px; }
  .stage.is-vertical iframe, .stage.is-vertical video { height: 70dvh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
