/*
  Standalone styling for /maps/viewer/. The page is deliberately not built by
  Tailwind: it is a full-viewport application served straight out of static/,
  the same way /maps/interactive/ is, so it carries its own small stylesheet
  rather than pulling in the site bundle.

  Type and colour follow the site: Source Serif for prose, Playfair Display for
  headings, and the orange/indigo palette used across b00k.club.
*/

/*
  Declared to match css/input.css byte for byte — same families, same URLs,
  same formats. A reader arriving from a b00k.club page already has these in
  cache, so the map costs them nothing extra; any deviation would fetch a
  second copy of a font they already hold.
*/
@supports (font-variation-settings: normal) {
  @font-face {
    font-family: 'Source Serif';
    font-style: normal;
    src: url('/font/Source_Serif_4/SourceSerif4Variable-Roman.ttf.woff') format('truetype-variations');
    font-display: swap;
  }
  @font-face {
    font-family: 'Source Serif';
    font-style: italic;
    src: url('/font/Source_Serif_4/SourceSerif4Variable-Italic.ttf.woff') format('truetype-variations');
    font-display: swap;
  }
  @font-face {
    font-family: 'Playfair Display';
    font-style: normal;
    font-weight: 400 900;
    src: url('/font/Playfair_Display/PlayfairDisplay-VariableFont_wght.ttf') format('truetype-variations');
    font-display: swap;
  }
}

:root {
  --ink: rgb(47 41 41);
  --ink-soft: rgb(94 86 82);
  --paper: rgb(255 251 245);
  --paper-veil: rgb(255 251 245 / 0.94);
  --edge: rgb(47 41 41 / 0.18);
  --accent: rgb(130 60 39);
  --shadow: 0 2px 10px rgb(28 25 23 / 0.18);
  --radius: 3px;
  --font-serif: 'Source Serif', Georgia, serif;
  --font-display: 'Playfair Display', Georgia, serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-serif);
  color: var(--ink);
  background: rgb(70 110 171);
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: rgb(70 110 171);
}

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

/* ---------------------------------------------------------------- chrome */

.chrome {
  position: absolute;
  z-index: 1000;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  padding-top: max(0.6rem, env(safe-area-inset-top));
}

.chrome--top {
  inset: 0 0 auto 0;
  background: linear-gradient(to bottom, rgb(255 251 245 / 0.92), rgb(255 251 245 / 0));
  pointer-events: none;
}

.chrome > * {
  pointer-events: auto;
}

.titles {
  min-width: 0;
}

#map-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 3.2vw, 1.5rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 0.1rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.tools {
  display: flex;
  flex-shrink: 0;
  gap: 0.4rem;
  align-items: flex-start;
}

.button {
  display: inline-flex;
  align-items: center;
  height: 2rem;
  padding: 0 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  background: var(--paper-veil);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.button:hover,
.button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------------------------------------------------------------- search */

.search {
  position: relative;
}

#search-input {
  width: min(17rem, 42vw);
  height: 2rem;
  padding: 0 0.55rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--paper-veil);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#search-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.results {
  position: absolute;
  inset: 2.2rem 0 auto 0;
  max-height: min(60vh, 26rem);
  padding: 0.15rem;
  margin: 0;
  overflow-y: auto;
  list-style: none;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.results li > button {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  width: 100%;
  padding: 0.3rem 0.45rem;
  font: inherit;
  font-size: 0.87rem;
  color: inherit;
  text-align: left;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: 2px;
}

.results li > button:hover,
.results li > button:focus-visible,
.results li[aria-selected='true'] > button {
  background: rgb(130 60 39 / 0.1);
  outline: none;
}

.results .kind {
  flex-shrink: 0;
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--ink-soft);
  text-transform: lowercase;
}

.results .empty {
  padding: 0.4rem 0.45rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* ---------------------------------------------------------------- panels */

.panel {
  position: absolute;
  z-index: 1000;
  background: var(--paper-veil);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel--layers {
  top: 3.4rem;
  right: 0.75rem;
  padding: 0.5rem 0.7rem;
}

.panel--layers fieldset {
  padding: 0;
  margin: 0;
  border: 0;
}

.panel--layers legend {
  padding: 0 0 0.3rem;
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel--layers label {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.12rem 0;
  font-size: 0.85rem;
  cursor: pointer;
}

.panel--legend {
  right: 0.75rem;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  max-width: 12rem;
  overflow: hidden;
}

.panel__heading {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  width: 100%;
  padding: 0.35rem 0.6rem;
  font: inherit;
  font-size: 0.72rem;
  color: var(--ink-soft);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  background: none;
  border: 0;
}

.panel__heading::after {
  margin-left: auto;
  content: '▾';
}

.panel__heading[aria-expanded='false']::after {
  content: '▸';
}

.legend-items {
  max-height: min(40vh, 20rem);
  padding: 0 0.6rem 0.5rem;
  margin: 0;
  overflow-y: auto;
  list-style: none;
}

.legend-items li {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.82rem;
  line-height: 1.5;
}

.legend-items .swatch {
  flex-shrink: 0;
  width: 0.7rem;
  height: 0.7rem;
  border: 1px solid rgb(17 17 17 / 0.55);
}

/* ------------------------------------------------------------ map layers */

.map-overlay {
  /* The overlay spans the whole map, so it must not swallow drags. Only the
     shapes a reader can actually click opt back into pointer events. */
  pointer-events: none;
}

.map-overlay #burgIcons use,
.map-overlay #anchors use,
.map-overlay #markers > svg,
.map-overlay #labels text,
.map-overlay #searoutes path,
.map-overlay #roads path,
.map-overlay #trails path {
  pointer-events: auto;
  cursor: pointer;
}

/* Layer visibility is toggled through each group's own `style.display`, because
   the generator bakes inline display values into some layers when it saves. */

/* --------------------------------------------------------------- popups */

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
}

.leaflet-popup-content {
  width: min(22rem, 78vw) !important;
  margin: 0.7rem 0.85rem;
  font-family: var(--font-serif);
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink);
}

.popup__name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
}

.popup__kind {
  margin: 0.05rem 0 0;
  font-size: 0.73rem;
  color: var(--ink-soft);
  text-transform: lowercase;
}

.popup__body {
  max-height: 40vh;
  margin-top: 0.5rem;
  overflow-y: auto;
}

.popup__body > :first-child {
  margin-top: 0;
}

.popup__body > :last-child {
  margin-bottom: 0;
}

.popup__body p {
  margin: 0 0 0.5rem;
}

.popup__body .poem {
  margin: 0 0 0.1rem;
  padding-left: 0.8rem;
  text-indent: -0.8rem;
  font-style: italic;
}

.popup__body a {
  color: var(--accent);
}

.popup__body img {
  max-width: 100%;
  height: auto;
}

/* ------------------------------------------------------------- controls */

.leaflet-control-attribution {
  font-family: var(--font-serif);
  font-size: 0.7rem;
}

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

.scale-bar {
  padding: 0.15rem 0.4rem;
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--ink);
  text-align: center;
  background: var(--paper-veil);
  border: 1px solid var(--edge);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}

.scale-bar__rule {
  height: 0.3rem;
  border: 1px solid var(--ink);
  border-top: 0;
}

/* --------------------------------------------------------------- status */

.status,
.fallback {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1200;
  padding: 0.7rem 1.1rem;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
}

.fallback {
  max-width: 28rem;
  text-align: center;
}

.status[hidden] {
  display: none;
}

.status--error {
  border-color: var(--accent);
}

@media (max-width: 40rem) {
  .chrome--top {
    flex-wrap: wrap;
  }

  #map-title {
    font-size: 1.05rem;
  }

  .subtitle {
    display: none;
  }

  #search-input {
    width: min(15rem, 55vw);
  }

  .panel--legend {
    max-width: 9rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .leaflet-fade-anim .leaflet-tile,
  .leaflet-zoom-anim .leaflet-zoom-animated {
    transition: none !important;
  }
}
