/*
 * Area page search and filters. Bundles the Hyd Tahoma face (Wine Tahoma) so search fields and filters keep
 * Windows-era metrics, scopes --desktop-font to these controls, and styles the collection search field with its
 * in-flow result list, the memory tools row (mode switch, year and month selects) on the Area page and the
 * matching tools on the Places page. Works with hyd-collection-search.js.
 */

/* Bundled Wine Tahoma gives search and filters consistent Windows-era metrics. */
@font-face {
  font-family: 'Hyd Tahoma';
  src: url('fonts/WineTahoma-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/*
 * Scoped font token: inside these controls --desktop-font starts with the Hyd Tahoma face, then falls back to
 * Tahoma and Hyd Ubuntu.
 */
html[data-theme]
  #world
  :is(
    #area .area-finder,
    #area > .memory-tools,
    #places .map-memory-tools,
    #places .destination-search,
    #place-search-results
  ) {
  --desktop-font: 'Hyd Tahoma',Tahoma,'Hyd Ubuntu',sans-serif;
  font-family: var(--desktop-font);
}

/* Area collections and Places filters share control metrics. Search results stay
   in the area window's flow, above its filters, instead of covering the media. */
html[data-theme] #world #area .area-finder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 6px 12px;
  align-items: center;
  padding: 8px 12px;
}

html[data-theme] #world #area .area-finder > input {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  height: 32px;
  min-height: 32px;
  margin: 0;
  font: 13px/1.3 var(--desktop-font);
}

html[data-theme] #world #area .area-finder > .hyd-cat-slot {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
  height: 40px;
}

/* --- Collection search results (an in-flow list under the field) --- */
html[data-theme] #world #area #area-collection-results {
  position: static;
  grid-column: 1/-1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  max-height: min(260px, 45dvh);
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 4px;
  margin: 0;
  background: #f4f5f6;
  color: #252c32;
  border: 1px solid #7d8993;
  border-radius: 3px;
  box-shadow: inset 0 1px 2px #0002;
  scrollbar-gutter: stable;
}

html[data-theme] #world #area #area-collection-results[hidden] {
  display: none;
}

html[data-theme] #world #area #area-collection-results .discovery-result {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  grid-template-rows: auto auto;
  gap: 2px 10px;
  align-content: center;
  align-items: center;
  width: 100%;
  min-width: 0;
  min-height: 58px;
  padding: 7px 9px;
  margin: 0;
  text-align: left;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 2px;
  box-shadow: none;
  font: 13px/1.3 var(--desktop-font);
  white-space: normal;
}

html[data-theme] #world #area #area-collection-results .discovery-result > :is(img, svg) {
  grid-column: 1;
  grid-row: 1/3;
  align-self: center;
  width: 48px;
  height: 36px;
  margin: 0;
  object-fit: cover;
  border-radius: 2px;
}

html[data-theme] #world #area #area-collection-results .discovery-result > span {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  font: inherit;
  overflow-wrap: anywhere;
}

html[data-theme] #world #area #area-collection-results .discovery-result > small {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  margin: 0;
  color: inherit;
  opacity: 0.75;
  font: 12px/1.3 var(--desktop-font);
  overflow-wrap: anywhere;
}

html[data-theme]
  #world
  #area
  #area-collection-results
  .discovery-result:is(:hover, :focus-visible, [aria-selected='true']) {
  color: #fff;
  background: #427cb5;
  outline: 0;
}

html[data-theme] #world #area #area-collection-results > p {
  margin: 8px;
  font: 13px/1.4 var(--desktop-font);
}

/* --- Memory tools row --- */
html[data-theme] #world #area > .memory-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 10px;
}

html[data-theme] #world #area > .memory-tools label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0;
  font: 12px/1.3 var(--desktop-font);
}

html[data-theme] #world #area > .memory-tools :is(button, select) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 0;
  height: 32px;
  min-height: 32px;
  padding: 4px 10px;
  margin: 0;
  font: 13px/1.3 var(--desktop-font);
  white-space: normal;
}

html[data-theme] #world #area > .memory-tools .memory-mode-switch {
  align-items: stretch;
  flex: 0 0 auto;
  margin: 0;
  min-width: 0;
}

html[data-theme] #world #area > .memory-tools .memory-mode-switch > button {
  min-width: 82px;
  border-radius: 0;
}

html[data-theme] #world #area > .memory-tools > span {
  margin: 0 0 0 auto;
  font: 12px/1.4 var(--desktop-font);
}

/* Selects draw their own chevron from gradients, so the native arrow is removed (appearance: none). */
html[data-theme] #world :is(#area > .memory-tools, #places .map-memory-tools) select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image:
    linear-gradient(45deg, transparent 50%, #384b5c 50%),
    linear-gradient(135deg, #384b5c 50%, transparent 50%), linear-gradient(#fff, #e7edf2);
  background-position:
    calc(100% - 14px) center,
    calc(100% - 10px) center,
    0 0;
  background-size:
    4px 4px,
    4px 4px,
    100% 100%;
  background-repeat: no-repeat;
  line-height: 1.3;
}

/*
 * Touch and small screens: 44px fields and 16px text, so iOS Safari does not zoom in when a field is focused.
 */
@media (max-width: 700px), (any-pointer: coarse) {
  html[data-theme] #world #area .area-finder > input {
    height: 44px;
    min-height: 44px;
    font-size: 16px;
  }

  html[data-theme] #world #area #area-collection-results .discovery-result {
    min-height: 60px;
    font-size: 16px;
  }

  html[data-theme] #world #area #area-collection-results .discovery-result > small {
    font-size: 12px;
  }

  html[data-theme] #world #area > .memory-tools :is(button, select) {
    height: 44px;
    min-height: 44px;
    font-size: 16px;
    line-height: 1.25;
  }

  html[data-theme] #world #area > .memory-tools label {
    font-size: 12px;
  }

  html[data-theme] #world #area > .memory-tools .memory-mode-switch > button {
    min-width: 110px;
  }
}

/* Phone layout (700px and below): the memory tools stack into a two-column grid. */
@media (max-width: 700px) {
  html[data-theme] #world #area .area-finder {
    gap: 6px 8px;
    padding: 8px;
  }

  html[data-theme] #world #area > .memory-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 8px;
    padding: 8px;
  }

  html[data-theme] #world #area > .memory-tools .memory-mode-switch {
    display: flex;
    grid-column: 1/-1;
    width: 100%;
    box-sizing: border-box;
  }

  html[data-theme] #world #area > .memory-tools .memory-mode-switch > button {
    flex: 1 1 0;
    min-width: 0;
  }

  html[data-theme] #world #area > .memory-tools > label {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  html[data-theme] #world #area > .memory-tools select {
    width: 100%;
  }

  html[data-theme] #world #area > .memory-tools > button {
    width: 100%;
    padding: 4px 6px;
  }

  html[data-theme] #world #area > .memory-tools > span {
    grid-column: 1/-1;
    margin: 0;
  }

  html[data-theme] #world #places .map-memory-tools > label {
    flex-direction: column;
    align-items: stretch;
    font-size: 12px;
  }

  html[data-theme] #world #places .map-memory-tools .memory-mode-switch {
    padding-right: 0;
    border-right: 0;
  }

  html[data-theme] #world #places .map-memory-tools .memory-mode-switch > button {
    width: 50%;
  }
}

/* Symmetric padding keeps date selections centred independently of the chevron. */
html[data-theme]
  #world
  :is(#area > .memory-tools, #places .map-memory-tools)
  :is(#collection-year, #collection-month, #map-memory-year, #map-memory-month) {
  text-align: center;
  text-align-last: center;
  padding-inline: 28px;
}
