/* Maps by Funk — Atlas
   Brand tokens from brand.site/e0a52cd7-927b-4732-8572-c76a88b819c8 */

:root {
  --teal: #67cba6;
  --teal-deep: #468a71;
  --slate: #33444e;
  --off-white: #f4f4f4;
  --near-black: #111517;

  /* Derived surfaces — slate darkened/lightened, never a neutral grey */
  --bg: #1a2429;
  --surface: #23323a;
  --surface-hi: #2c3e47;
  --line: #3b4f59;
  --text: var(--off-white);
  --text-dim: #9db0ba;
  --text-faint: #6f8794;

  --header-h: 58px;
  --panel-w: 384px;

  --f-display: "Lexend Deca", "Segoe UI", sans-serif;
  --f-body: "Manrope", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-body);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ---------- header ---------- */

.header {
  height: var(--header-h);
  background: var(--near-black);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  position: relative;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

a.brand {
  color: inherit;
  text-decoration: none;
}

.badge-preview {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal);
  border: 1px solid var(--teal-deep);
  padding: 2px 6px;
  border-radius: 3px;
}

.brand svg {
  width: 26px;
  height: 26px;
  display: block;
}

.wordmark {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.wordmark em {
  font-style: normal;
  color: var(--teal);
}

.search {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.search input {
  width: 100%;
  height: 34px;
  padding: 0 32px 0 34px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--text);
  font: inherit;
}

.search input::placeholder {
  color: var(--text-faint);
}

.search input:focus {
  border-color: var(--teal);
  outline: none;
}

.search .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  stroke: var(--text-faint);
  fill: none;
  stroke-width: 2;
  pointer-events: none;
}

.search .clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  line-height: 1;
}

.search .clear:hover {
  background: var(--surface-hi);
  color: var(--text);
}

.badge-sample {
  margin-left: auto;
  flex-shrink: 0;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--near-black);
  background: var(--teal);
  padding: 4px 9px;
  border-radius: 3px;
}

/* ---------- layout ---------- */

.app {
  display: flex;
  height: calc(100% - var(--header-h));
}

.map-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
}

.overlay-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 7px;
  pointer-events: none;
}

.creators {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
}

/* Only the top countries render as chips now, so the row wraps normally; the
 * long tail lives in the picker. */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
}

/* Creator chips read as the primary switch: larger, display face, and a
 * teal edge so they are not mistaken for one more country. */
.chip.chip-creator {
  height: 30px;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 12.5px;
  border-color: var(--teal-deep);
  color: var(--text);
}

.chip {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(17, 21, 23, 0.82);
  backdrop-filter: blur(6px);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--teal-deep);
  color: var(--text);
}

.chip[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--near-black);
  font-weight: 700;
}

.chip.chip-more {
  border-style: dashed;
  color: var(--text);
}

.chip-more .caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.8;
}

.chip-more[aria-expanded="true"] {
  border-style: solid;
  border-color: var(--teal);
}

/* ---------- picker ---------- */

.picker {
  position: fixed;
  z-index: 50;
  width: 260px;
  max-height: min(380px, 70vh);
  display: flex;
  flex-direction: column;
  background: var(--near-black);
  border: 1px solid var(--teal-deep);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.picker-search {
  margin: 8px;
  height: 32px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.picker-search:focus {
  outline: none;
  border-color: var(--teal);
}

.picker-list {
  list-style: none;
  margin: 0;
  padding: 0 4px 6px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.picker-list button {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  text-align: left;
  font-size: 13px;
}

.picker-list button:hover,
.picker-list button:focus-visible {
  background: var(--surface-hi);
  color: var(--text);
  outline: none;
}

.picker-list button[aria-selected="true"] {
  color: var(--teal);
  font-weight: 700;
}

.picker-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-n {
  flex-shrink: 0;
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.picker-empty {
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text-faint);
}

.chip .n {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  font-size: 11px;
}

.basemap-switch {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 10;
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 16px;
  background: rgba(17, 21, 23, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
}

.basemap-switch .chip[aria-pressed="false"] {
  height: 24px;
  border: 0;
  background: transparent;
  backdrop-filter: none;
  font-size: 12px;
}

.basemap-switch .chip[aria-pressed="true"] {
  height: 24px;
  border: 0;
  font-size: 12px;
}

.basemap-switch .chip:hover {
  color: var(--text);
}

.basemap-switch .chip[aria-pressed="true"]:hover {
  color: var(--near-black);
}

/* ---------- side panel ---------- */

.panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.panel-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

/* `display: flex` would otherwise beat the hidden attribute and show an empty bar. */
.place-bar[hidden] {
  display: none;
}

.place-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 10px;
  background: rgba(103, 203, 166, 0.12);
  border: 1px solid var(--teal-deep);
  border-radius: 5px;
}

.place-pin {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 2px var(--near-black);
  flex-shrink: 0;
}

.place-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place-clear {
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 11.5px;
  padding: 2px 9px;
  border-radius: 3px;
}

.place-clear:hover {
  border-color: var(--teal);
  color: var(--text);
}

.sort {
  appearance: none;
  width: 100%;
  height: 30px;
  padding: 0 28px 0 10px;
  background: var(--surface-hi);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font-family: var(--f-body);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  /* Chevron drawn inline so no icon font or image request is needed. */
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 15px) 13px, calc(100% - 10px) 13px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.sort:hover {
  border-color: var(--teal-deep);
}

.sort:focus-visible {
  border-color: var(--teal);
}

.sort option {
  background: var(--near-black);
  color: var(--text);
}

.panel-head h2 {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.panel-head .count {
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Attribution and legal links, required by the YouTube API terms. */
.panel-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--text-faint);
}

.panel-foot a {
  color: inherit;
}

.panel-foot a:hover {
  color: var(--text);
}

.list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.card {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
  padding: 8px;
  background: var(--surface-hi);
  border: 1px solid transparent;
  border-radius: 6px;
}

.card:hover {
  border-color: var(--teal-deep);
}

.card.is-active {
  border-color: var(--teal);
  background: #33474f;
}

.thumb {
  position: relative;
  display: block;
  width: 112px;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  overflow: hidden;
  background: var(--slate);
  align-self: start;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease, filter 0.2s ease;
}

/* Diamond motif stands in when a thumbnail is missing. */
.thumb.is-fallback {
  background:
    repeating-linear-gradient(135deg, rgba(103, 203, 166, 0.16) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(45deg, rgba(103, 203, 166, 0.16) 0 2px, transparent 2px 9px),
    linear-gradient(150deg, var(--teal-deep) 0%, var(--slate) 62%);
}

/* Play affordance: always faintly present, so the thumbnail reads as playable
 * before you hover it. */
.thumb .play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(17, 21, 23, 0.62);
  display: grid;
  place-items: center;
  opacity: 0.78;
  transition: opacity 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.thumb .play svg {
  width: 16px;
  height: 16px;
  fill: var(--off-white);
  margin-left: 2px;
}

.thumb:hover .play,
.thumb:focus-visible .play {
  opacity: 1;
  background: var(--teal);
  transform: scale(1.08);
}

.thumb:hover .play svg,
.thumb:focus-visible .play svg {
  fill: var(--near-black);
}

.thumb:hover img {
  filter: brightness(0.82);
}

.thumb .dur {
  position: absolute;
  right: 3px;
  bottom: 3px;
  background: rgba(17, 21, 23, 0.86);
  color: var(--off-white);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  padding: 1px 4px;
  border-radius: 2px;
}

.card-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-main {
  all: unset;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  min-width: 0;
}

.card-main:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  border-radius: 2px;
}

.card-title {
  font-weight: 700;
  font-size: 13px;
  line-height: 1.32;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-main:hover .card-title {
  color: var(--teal);
}

.card-loc {
  font-size: 11.5px;
  color: var(--teal);
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.card-loc span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

.card-meta {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.card-watch {
  flex-shrink: 0;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--near-black);
  background: var(--teal);
  text-decoration: none;
  padding: 3px 9px;
  border-radius: 3px;
}

.card-watch:hover {
  background: var(--off-white);
}

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.empty strong {
  display: block;
  color: var(--text-dim);
  font-family: var(--f-display);
  margin-bottom: 4px;
}

/* ---------- popup ---------- */

.maplibregl-popup-content {
  background: var(--near-black);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0;
  overflow: hidden;
  width: 246px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.maplibregl-popup-tip {
  border-top-color: var(--near-black) !important;
  border-bottom-color: var(--near-black) !important;
}

.maplibregl-popup-close-button {
  color: var(--text-dim);
  font-size: 18px;
  padding: 2px 7px;
}

.maplibregl-popup-close-button:hover {
  background: transparent;
  color: var(--teal);
}

.pop-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: var(--slate);
}

.pop-thumb.is-fallback {
  background:
    repeating-linear-gradient(135deg, rgba(103, 203, 166, 0.16) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(45deg, rgba(103, 203, 166, 0.16) 0 2px, transparent 2px 9px),
    linear-gradient(150deg, var(--teal-deep) 0%, var(--slate) 62%);
}

.pop-thumb.is-fallback::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 22px;
  height: 22px;
  background: var(--teal);
  opacity: 0.9;
  transform: rotate(45deg);
  border-radius: 3px;
}

.pop-body {
  padding: 9px 11px 11px;
}

.pop-title {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 13px;
  line-height: 1.3;
  margin: 0 0 3px;
  color: var(--off-white);
}

.pop-loc {
  font-size: 11.5px;
  color: var(--teal);
  margin: 0 0 2px;
}

.pop-source {
  font-size: 10px;
  color: var(--text-faint);
  margin: 0 0 9px;
}

.pop-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--teal);
  color: var(--near-black);
  text-decoration: none;
  font-weight: 700;
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 4px;
}

.pop-link:hover {
  background: var(--off-white);
}

/* ---------- country labels ----------
   DOM markers rather than a MapLibre symbol layer, so they use the real brand
   typeface. text-shadow stands in for the SDF halo. */

.country-label {
  font-family: var(--f-display);
  font-weight: 700;
  color: #eaf7f1;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.04;
  white-space: nowrap;
  cursor: pointer;
  text-shadow:
    0 0 3px var(--near-black),
    0 0 7px var(--near-black),
    0 1px 2px var(--near-black);
}

.cl-name {
  font-size: 0.72em;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.cl-count {
  font-size: 1.12em;
  font-variant-numeric: tabular-nums;
}

.country-label.is-hidden {
  /* visibility, not display — the element must keep layout so it stays
     measurable for the next collision pass. */
  visibility: hidden;
  pointer-events: none;
}

.country-label:hover {
  color: var(--teal);
}

.country-label.is-selected {
  color: var(--teal);
}

/* Video title beside its dot. Same DOM-marker approach, same brand face. */
.pin-label {
  font-family: var(--f-body);
  font-weight: 700;
  font-size: 11.5px;
  line-height: 1.2;
  color: var(--off-white);
  background: rgba(17, 21, 23, 0.72);
  border: 1px solid rgba(103, 203, 166, 0.35);
  border-radius: 3px;
  padding: 2px 6px;
  margin: 0;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(3px);
}

.pin-label:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.pin-label.is-active {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--near-black);
}

.pin-label.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

/* ---------- hover preview ---------- */

.hover-popup {
  pointer-events: none; /* never steals a click from the map */
  z-index: 5;
}

.hover-popup .maplibregl-popup-content {
  width: 290px;
  padding: 0;
  background: var(--near-black);
  border: 1px solid var(--teal-deep);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

.hc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px 7px;
  border-bottom: 1px solid var(--line);
}

.hc-heading {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 13px;
  color: var(--teal);
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hc-sub {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.hc-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--slate);
  overflow: hidden;
}

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

.hc-thumb.is-fallback {
  background:
    repeating-linear-gradient(135deg, rgba(103, 203, 166, 0.16) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(45deg, rgba(103, 203, 166, 0.16) 0 2px, transparent 2px 9px),
    linear-gradient(150deg, var(--teal-deep) 0%, var(--slate) 62%);
}

.hc-lead {
  padding: 8px 11px 6px;
}

.hc-lead-title {
  font-weight: 700;
  font-size: 12.5px;
  line-height: 1.32;
  color: var(--off-white);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hc-lead-meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* ---------- attribution ---------- */

.maplibregl-ctrl-attrib {
  background: rgba(17, 21, 23, 0.8) !important;
  font-size: 10px;
}

.maplibregl-ctrl-attrib a {
  color: var(--text-faint);
}

/* ---------- mobile ---------- */

@media (max-width: 760px) {
  /* The header is one non-wrapping flex row. On a phone its contents have to
     be allowed to shrink, or they push the whole page sideways and every view
     inherits a horizontal scrollbar. */
  .header {
    gap: 10px;
    padding: 0 12px;
  }

  .brand .wordmark {
    display: none;
  }

  .search {
    flex: 1 1 auto;
    min-width: 0;
  }

  .header-right {
    min-width: 0;
    gap: 8px;
  }

  .dev {
    min-width: 0;
  }

  .dev select {
    max-width: 96px;
  }

  .app {
    flex-direction: column;
  }

  .map-wrap {
    flex: 1 1 52%;
  }

  .panel {
    width: 100%;
    flex: 1 1 48%;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .badge-sample {
    display: none;
  }

  /* Wrapped chip rows covered most of the map on a phone. Each row becomes one
     line that scrolls sideways instead; the picker hangs off <body>, so the
     row's overflow cannot clip it. */
  .creators,
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    pointer-events: auto;
    margin: 0 -12px;
    padding: 0 12px;
  }

  .creators::-webkit-scrollbar,
  .filters::-webkit-scrollbar {
    display: none;
  }

  .creators > *,
  .filters > * {
    flex-shrink: 0;
  }

  .search {
    max-width: none;
  }
}

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