/* UNL scarlet and cream, with a warm stone neutral for buildings not using HCC.
   Building fills themselves come from map-config.yml; keep --scarlet/--stone in step with it. */
:root {
  --scarlet: #D00000;
  --scarlet-deep: #8A0000;
  --stone: #B8B1A5;
  --stone-deep: #8F887C;
  --cream: #FEFDFA;
  --ink: #1F1B17;
  --ink-muted: #6B645B;
  --hairline: #E6E0D4;
  --map-ground: #EFECE6;

  --font-body: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 27, 23, 0.08), 0 6px 20px rgba(31, 27, 23, 0.12);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

::selection {
  background: color-mix(in srgb, var(--scarlet) 22%, var(--cream));
  color: var(--ink);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Long/short label pairs: short ones on narrow maps (see the max-width: 560px block) */
.label-short {
  display: none;
}

body, html {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--map-ground);
}

#map {
  height: 100%;
  width: 100%;
  background: var(--map-ground);
  font-family: var(--font-body);
}

/* Muted street basemap so the buildings carry the color */
.tiles-campus {
  filter: grayscale(1) sepia(0.12) brightness(1.04) contrast(0.86);
}

/* Building-code tag: used for HCC in the title and each building's code in popups */
.code-tag {
  display: inline-block;
  padding: 0.18em 0.45em 0.14em;
  border-radius: 3px;
  background: var(--scarlet);
  color: var(--cream);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.78em;
  letter-spacing: 0.06em;
  line-height: 1.1;
  vertical-align: 0.12em;
}

.code-tag.is-other {
  background: var(--stone);
  color: var(--ink);
}

/* Title card */
.panel {
  position: absolute;
  top: 16px;
  left: 16px;
  /* Above Leaflet's control corners (1000); the card comes before the map in the DOM */
  z-index: 1010;
  width: 340px;
  max-width: calc(100% - 32px);
  /* Room for the open Buildings list, which scrolls inside the card */
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  padding: 16px 18px 14px;
  background: var(--cream);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--scarlet);
}

.panel-eyebrow {
  font-size: 11px;
  font-weight: 600;
  font-stretch: 112%;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.panel-title {
  /* On very narrow maps the Buildings button wraps under the title instead of breaking it */
  white-space: nowrap;
  font-size: 24px;
  font-weight: 750;
  font-stretch: 78%;
  line-height: 1.1;
  letter-spacing: -0.005em;
}

.panel-summary {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.45;
}

.panel-summary strong {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--scarlet);
}

.panel-summary.is-error {
  color: var(--scarlet-deep);
}

.legend {
  list-style: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--ink);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.swatch-hcc {
  background: var(--scarlet);
  box-shadow: inset 0 0 0 1px var(--scarlet-deep);
}

.swatch-other {
  background: color-mix(in srgb, var(--stone) 60%, var(--map-ground));
  box-shadow: inset 0 0 0 1px var(--stone-deep);
}

.panel-updated {
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-muted);
}

.panel-updated:empty {
  display: none;
}

/* Buildings list toggle, beside the title */
.browse-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 28px;
  padding: 0 7px 0 9px;
  border: 0;
  border-radius: 6px;
  background: var(--hairline);
  color: var(--ink);
  font: 600 12px var(--font-body);
  cursor: pointer;
}

.browse-toggle[hidden] {
  display: none;
}

.browse-toggle:hover {
  background: color-mix(in srgb, var(--stone) 45%, var(--cream));
}

.browse-toggle .chevron {
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.browse-toggle[aria-expanded="true"] {
  background: var(--ink);
  color: var(--cream);
}

.browse-toggle[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.browse {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 12px -18px -14px;
  border-top: 1px solid var(--hairline);
  scrollbar-width: thin;
  scrollbar-color: var(--stone) transparent;
}

.browse-group ul {
  list-style: none;
  padding-bottom: 6px;
}

.browse-campus {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 18px 4px;
  background: var(--cream);
  font-size: 12px;
  font-weight: 700;
  font-stretch: 90%;
  color: var(--ink);
}

.browse-count {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-muted);
}

.browse-group button {
  display: grid;
  grid-template-columns: 4.6em 1fr;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  min-height: 30px;
  padding: 5px 18px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 500 13px/1.3 var(--font-body);
  text-align: left;
  cursor: pointer;
}

.browse-group button .code-tag {
  justify-self: start;
  font-size: 10.5px;
  vertical-align: baseline;
}

.browse-group button:hover {
  background: color-mix(in srgb, var(--hairline) 70%, var(--cream));
}

.browse-group button[aria-current="true"] {
  background: color-mix(in srgb, var(--scarlet) 8%, var(--cream));
}

.browse-group button:focus-visible {
  outline: 2px solid var(--scarlet);
  outline-offset: -2px;
}

/* Off-screen campus pointers (updateCampusPointers in index.js) */
.campus-pointers {
  position: absolute;
  inset: 0;
  z-index: 800;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
}

.campus-pointer {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 16px 6px 6px;
  border: 0;
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 0 0 1px rgba(31, 27, 23, 0.06), var(--shadow);
  font-family: var(--font-body);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  animation: cp-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  transition: box-shadow 0.2s;
}

.campus-pointer[hidden] {
  display: none;
}

/* Arrow on the side facing the campus */
.campus-pointer.is-right {
  flex-direction: row-reverse;
  padding: 6px 6px 6px 16px;
}

.campus-pointer:hover {
  box-shadow: 0 0 0 1px rgba(31, 27, 23, 0.08), 0 2px 4px rgba(31, 27, 23, 0.1), 0 10px 28px rgba(31, 27, 23, 0.2);
}

.campus-pointer:focus-visible {
  outline: 2px solid var(--scarlet);
  outline-offset: 2px;
}

.cp-arrow {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--scarlet);
  color: var(--cream);
  transform: rotate(var(--angle, 0deg));
}

/* A few nudges toward the campus when a pointer appears, and continuously on hover */
.cp-arrow svg {
  animation: cp-nudge 1.2s cubic-bezier(0.45, 0, 0.55, 1) 0.4s 3;
}

.campus-pointer:hover .cp-arrow svg {
  animation-iteration-count: infinite;
}

.cp-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.15;
}

.cp-name {
  font-size: 14px;
  font-weight: 750;
  font-stretch: 82%;
}

.cp-count {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.cp-count:empty {
  display: none;
}

@keyframes cp-in {
  from {
    opacity: 0;
    scale: 0.85;
  }
}

@keyframes cp-nudge {
  50% {
    translate: 3px 0;
  }
}

/* Out of the way while a popup is open */
body.popup-open .campus-pointers {
  opacity: 0;
  visibility: hidden;
}

/* Taller hit areas on touch without making the controls look heavier */
@media (pointer: coarse) {
  .browse-toggle {
    position: relative;
  }

  .browse-toggle::after {
    content: "";
    position: absolute;
    inset: -8px 0;
  }

  .browse-group button {
    min-height: 40px;
  }
}

/* Base layer switcher (map-config.yml: display.show_layers_control) */
.controls {
  position: absolute;
  bottom: 28px;
  right: 10px;
  z-index: 1000;
  display: flex;
  padding: 3px;
  gap: 2px;
  background: var(--cream);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls:empty {
  display: none;
}

.controls button {
  padding: 6px 12px;
  cursor: pointer;
  border: 0;
  background: transparent;
  border-radius: 6px;
  font: 500 13px var(--font-body);
  color: var(--ink);
}

.controls button:hover {
  background: var(--hairline);
}

.controls button.active {
  background: var(--ink);
  color: var(--cream);
}

.controls button:focus-visible,
.full-map-link:focus-visible,
.leaflet-bar a:focus-visible,
.leaflet-popup-close-button:focus-visible,
.browse-toggle:focus-visible {
  outline: 2px solid var(--scarlet);
  outline-offset: 2px;
}

.leaflet-container:focus-visible {
  outline: 2px solid var(--scarlet);
  outline-offset: -2px;
}

.bp-name:focus {
  outline: none;
}

/* Leaflet chrome */
.leaflet-bar {
  border: 0 !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}

.leaflet-bar a {
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  background: var(--cream);
  color: var(--ink);
  border-bottom-color: var(--hairline);
}

.leaflet-bar a:hover {
  background: var(--hairline);
  color: var(--ink);
}

.leaflet-control-attribution {
  background: rgba(254, 253, 250, 0.8) !important;
  color: var(--ink-muted);
  font-size: 10px;
}

.leaflet-control-attribution a {
  color: var(--ink-muted);
}

/* Hover label */
.building-tooltip {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: var(--cream);
  font: 600 12px var(--font-body);
  box-shadow: 0 2px 8px rgba(31, 27, 23, 0.25);
}

.building-tooltip::before {
  display: none;
}

/* Building popup */
.building-popup .leaflet-popup-content-wrapper {
  padding: 0;
  border-radius: var(--radius);
  background: var(--cream);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.building-popup .leaflet-popup-content {
  margin: 0;
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
}

.building-popup .leaflet-popup-tip {
  background: var(--cream);
  box-shadow: none;
}

.building-popup a.leaflet-popup-close-button {
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font: 400 20px/24px var(--font-body);
  color: var(--ink-muted);
}

.building-popup a.leaflet-popup-close-button:hover {
  background: var(--hairline);
  color: var(--ink);
}

.bp-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 14px 44px 12px 16px;
}

/* The name comes first in the DOM; the code tag shows above it */
.bp-head .code-tag {
  order: -1;
  font-size: 12px;
  vertical-align: baseline;
}

/* Long department lists scroll (maxHeight in preparePopup) */
.building-popup .leaflet-popup-scrolled {
  border: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--stone) transparent;
}

.bp-name {
  margin-top: 6px;
  font-size: 19px;
  font-weight: 750;
  font-stretch: 82%;
  line-height: 1.15;
}

.building-popup .bp-status {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.bp-depts {
  list-style: none;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--hairline);
  display: grid;
  gap: 7px;
}

.bp-depts li {
  position: relative;
  padding-left: 18px;
  color: var(--ink-muted);
}

/* Hollow ring for departments not using HCC, filled scarlet for those that do */
.bp-depts li::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 0.38em;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--stone-deep);
}

.bp-depts li.is-hcc {
  color: var(--ink);
  font-weight: 600;
}

.bp-depts li.is-hcc::before {
  background: var(--scarlet);
  box-shadow: none;
}

.bp-extra {
  padding: 10px 16px 14px;
  border-top: 1px solid var(--hairline);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 12.5px;
}

.bp-extra dt {
  color: var(--ink-muted);
}

/* Embed mode (see setupEmbedMode in index.js) */
.embed-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  background: rgba(31, 27, 23, 0.5);
  color: var(--cream);
  font-size: 18px;
  font-weight: 600;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.embed-hint.visible {
  opacity: 1;
}

.leaflet-container a.full-map-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px 7px 11px;
  background: var(--cream);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font: 600 12px var(--font-body);
  color: var(--ink);
  text-decoration: none;
}

.leaflet-container a.full-map-link:hover {
  background: var(--hairline);
}

/* Compact title card for iframes and phones */
body.embed .panel {
  top: 10px;
  left: 10px;
  width: 272px;
  max-height: calc(100% - 20px);
  padding: 11px 13px 10px;
}

body.embed .panel-eyebrow,
body.embed .panel-updated {
  display: none;
}

body.embed .panel-head {
  margin-top: 0;
}

body.embed .panel-title {
  font-size: 18px;
}

body.embed .panel-summary {
  margin-top: 6px;
  font-size: 12.5px;
}

body.embed .legend {
  margin-top: 8px;
  padding-top: 8px;
  gap: 4px;
  font-size: 12px;
}

body.embed .browse {
  margin: 10px -13px -10px;
}

body.embed .browse-campus,
body.embed .browse-group button {
  padding-inline: 13px;
}

@media (max-width: 560px) {
  .panel,
  body.embed .panel {
    top: 10px;
    left: 10px;
    right: 58px;
    width: auto;
    max-width: none;
    max-height: calc(100% - 20px);
    padding: 11px 13px 10px;
  }

  .panel-eyebrow,
  .panel-updated {
    display: none;
  }

  .panel-head {
    margin-top: 0;
  }

  .panel-title {
    font-size: 18px;
  }

  .panel-summary {
    margin-top: 6px;
    font-size: 12.5px;
  }

  /* One legend row, to keep the card short on phones */
  .legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    margin-top: 8px;
    padding-top: 8px;
    font-size: 12px;
  }

  .legend li {
    gap: 6px;
  }

  .label-long {
    display: none;
  }

  .label-short {
    display: inline;
  }

  .browse {
    margin: 10px -13px -10px;
  }

  .browse-campus,
  .browse-group button {
    padding-inline: 13px;
  }

  /* Compact on phones so the pointers cover less of the campus: name only (the count stays for
     screen readers) */
  .campus-pointer {
    min-height: 40px;
    gap: 8px;
    padding: 4px 14px 4px 4px;
  }

  .campus-pointer.is-right {
    padding: 4px 4px 4px 14px;
  }

  .cp-arrow {
    width: 32px;
    height: 32px;
  }

  .cp-name {
    font-size: 13px;
  }

  .cp-count {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

.panel,
.leaflet-top.leaflet-right,
.leaflet-container a.full-map-link {
  transition: opacity 0.2s, visibility 0.2s;
}

/* Small maps: while a popup is open, the controls step aside so they don't cover it */
@media (max-width: 560px), (max-height: 480px) {
  body.popup-open .leaflet-top.leaflet-right,
  body.popup-open .leaflet-container a.full-map-link {
    opacity: 0;
    visibility: hidden;
  }
}

/* Not enough height to pan popups below the title card, so get it out of the way */
@media (max-height: 480px) {
  body.popup-open .panel {
    opacity: 0;
    visibility: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .embed-hint,
  .panel,
  .leaflet-top.leaflet-right,
  .leaflet-container a.full-map-link,
  .campus-pointers,
  .campus-pointer,
  .browse-toggle .chevron {
    transition: none;
  }

  .campus-pointer,
  .cp-arrow svg {
    animation: none;
  }
}
