:root {
  color-scheme: light;
  color: #294331;
  background: #faf5e8;
  font-family: system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.map-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem 1.15rem;
  padding: .85rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid #c6baa0;
  background: linear-gradient(112deg, #fffaf0, #f4ecd8);
}

h1 {
  margin: 0;
  font: 600 clamp(1.55rem, 4vw, 2.05rem)/1.12 Georgia, serif;
}

#household-hint {
  display: flex;
  align-items: center;
  gap: .35rem;
  margin: 0;
  color: #485e4c;
  font-size: .83rem;
  line-height: 1.3;
}
#household-hint svg {
  width: 1.3rem;
  height: 1.3rem;
  flex: none;
  fill: #cc9d83;
  stroke: #624b3f;
  stroke-width: 2.6;
  stroke-linejoin: round;
}

.map-frame {
  position: relative;
  min-height: 20rem;
  isolation: isolate;
}

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

.map-tools {
  position: absolute;
  z-index: 1001;
  top: .65rem;
  right: .65rem;
  display: flex;
  align-items: flex-start;
  gap: .4rem;
}

.map-tools button {
  display: block;
  color: inherit;
  font: 600 .875rem/1.2 system-ui, sans-serif;
  min-height: 44px;
  padding: .8rem;
  border: 1px solid #a99b7f;
  border-radius: .45rem;
  background: #fffaf0;
  cursor: pointer;
}

#map:focus-visible { outline-offset: -3px; }
:focus-visible { outline: 3px solid #3b6652; outline-offset: 2px; }

#map .leaflet-control-zoom a {
  width: 44px;
  height: 44px;
  line-height: 44px;
  color: #294331;
  background: #fffaf0;
}

#map .leaflet-control-zoom .leaflet-disabled { color: #6d6b60; }
#map .leaflet-control-attribution { background: #fffaf0ef; color: #384437; }
#map .leaflet-control-attribution a { color: #234f62; }

.map-label {
  pointer-events: none;
  user-select: none;
}

.map-label span {
  display: block;
  width: max-content;
  transform: translate(-50%, -50%) rotate(var(--angle, 0deg));
  color: #3b382c;
  white-space: nowrap;
  text-shadow: 1px 0 #fff9e9, -1px 0 #fff9e9, 0 1px #fff9e9, 0 -1px #fff9e9;
}

.map-label--street span {
  font: 650 11px/1.15 system-ui, sans-serif;
  letter-spacing: .015em;
}

.map-label--house span { font: 650 10px/1.1 system-ui, sans-serif; }

#map-status {
  position: absolute;
  z-index: 1001;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 85%;
  padding: .7rem 1rem;
  border-radius: .4rem;
  background: #fffaf0;
}

.map-label--context span { color: #665f53; font-weight: 500; }

/* Raster paper stays in the background; map pigments and washes move with the map. */
:root {
  --paper-grain: url('../assets/illustrations/watercolor/paper.png');
  --landmark-serif: 'Iowan Old Style', Charter, Georgia, serif;
  --map-sans: 'Avenir Next', system-ui, sans-serif;
  --street-label-font: 650 11px/1.15 var(--map-sans);
  --house-label-font: 650 11px/1.1 var(--map-sans);
  font-family: var(--map-sans);
}

.map-header {
  color: #30482d;
  background: linear-gradient(110deg, #fffaf2d0, #f3e5c5a0), var(--paper-grain) #f5ecd6;
  border-color: #ccbea0;
}

h1 { font-family: 'Iowan Old Style', Charter, Georgia, serif; }

#map {
  background-color: #f4edd8;
  background-image: var(--paper-grain);
  cursor: grab;
}

#map.leaflet-dragging, #map.leaflet-drag-target { cursor: grabbing; }

#map .paint-lake { fill: url('#watercolor-lake') #a8c4cd; }
#map .paint-woods { fill: url('#watercolor-woods') #aebe92; }
#map .paint-green { fill: url('#watercolor-green') #cbd3a3; }
#map .paint-building-0 { fill: url('#watercolor-building-0') #cc9d83; }
#map .paint-building-1 { fill: url('#watercolor-building-1') #d6b578; }
#map .paint-building-2 { fill: url('#watercolor-building-2') #a9b891; }
#map .paint-building-3 { fill: url('#watercolor-building-3') #a9bdc0; }
#map .paint-building-4 { fill: url('#watercolor-building-4') #c9ac92; }


.map-label span {
  color: #343728;
  text-shadow: 1px 0 #fff9e8, -1px 0 #fff9e8, 0 1px #fff9e8, 0 -1px #fff9e8;
}

.map-label--street span { font: var(--street-label-font); letter-spacing: normal; }
.map-label--house span { font: var(--house-label-font); }
.map-label--context span { color: #665d4c; }
.map-label--landmark span {
  font: italic 600 13px/1.15 var(--landmark-serif);
  color: #3f5540;
}
.map-label--water span { color: #3d6071; }
.map-label--landmark .map-label-lines {
  line-height: 1.04;
  text-align: center;
}


.leaflet-house-labels-pane {
  opacity: 0;
  visibility: hidden;
  transition: opacity 140ms ease, visibility 0s linear 140ms;
}

.leaflet-house-labels-pane.house-labels-visible {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

@media (prefers-reduced-motion: reduce) {
  .leaflet-house-labels-pane { transition: none; }
}

@media (max-width: 760px), (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  body {
    height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .map-header {
    gap: .25rem .6rem;
    padding: calc(.4rem + env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right))
      .45rem max(.75rem, env(safe-area-inset-left));
  }

  .map-header h1 { font-size: clamp(1.2rem, 5.7vw, 1.4rem); }
  #household-hint { font-size: .77rem; }
  .map-frame { min-height: 0; }
  .map-tools { right: max(.65rem, calc(env(safe-area-inset-right) + .25rem)); }
  #map .leaflet-left { left: env(safe-area-inset-left); }
  #map .leaflet-bottom { bottom: env(safe-area-inset-bottom); }
  #map .leaflet-right { right: env(safe-area-inset-right); }
}

@media (orientation: landscape) and (max-width: 760px),
       (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .map-header:has(#household-search:not([hidden])) {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
  }

  .map-header h1, #household-hint { grid-column: 1; }
  #household-search { grid-area: 1 / 2 / span 2; width: 100%; }
}
