/*
 * hyd-pocket-places.css
 *
 * Pocket Places (hyd-pocket-places.js). On phones the Places page becomes a full-height map navigator: a title
 * bar, a search row, the map filling the screen, a column of round buttons along the map edge, and a bottom
 * sheet (a dialog) holding the filters, route options and note tools. hyd-pocket-places.js builds the sheet and
 * the edge column and moves the existing controls into them while the phone media list matches (phone width, or
 * a touch screen at most 450px tall: a phone on its side), adding the pocket-places class to #places; the rules
 * here only style that result. Buttons and fields are sized for 44px touch targets.
 */

/* The same Places controls, arranged as a pocket navigator on phones only. */
#world #places .pocket-place-filters:not([open]),
#world #places .pocket-filters[hidden],
#world #places .pocket-map-edge[hidden] {
  display: none;
}

/*
 * Phone layout, upright or sideways. This media list is the matchMedia query in hyd-pocket-places.js. The
 * html[data-theme] prefix adds specificity so these rules take over from the desktop Places styles.
 */
@media (max-width: 620px), (pointer: coarse) and (max-height: 450px) {
  /* --- Page frame, title bar and close button --- */
  html[data-theme] #world #places.pocket-places {
    padding: 0;
    margin: 0;
    height: 100dvh;
    min-height: 0;
    animation: none;
  }

  html[data-theme] #world #places.pocket-places .places-browser {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    overflow: hidden;
  }

  html[data-theme] #world #places.pocket-places .places-heading {
    height: 44px;
    min-height: 44px;
    padding: 0 56px;
    border-radius: 0;
  }

  html[data-theme] #world #places.pocket-places .finder-close {
    width: 44px;
    height: 44px;
    min-height: 44px;
    left: 0;
    background: none;
    border: 0;
    box-shadow: none;
    font-size: 24px;
  }

  html[data-theme] #world #places.pocket-places .hyd-cat-slot-places {
    display: none;
  }

  /* --- Search row --- */
  html[data-theme] #world #places.pocket-places .map-tools {
    flex: none;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 7px max(8px,env(safe-area-inset-right)) 7px max(8px,env(safe-area-inset-left));
  }

  html[data-theme] #world #places.pocket-places .destination-search {
    flex: 1 1 0;
    gap: 0;
    align-items: center;
    position: relative;
  }

  html[data-theme] #world #places.pocket-places .destination-picker {
    display: block;
    min-width: 0;
  }

  html[data-theme] #world #places.pocket-places .destination-picker > span {
    display: none;
  }

  /*
   * Search field: 16px text keeps iOS Safari from zooming in when the field is focused. The submit button
   * inside it is a 44px target.
   */
  html[data-theme] #world #places.pocket-places #area-search {
    height: 44px;
    min-height: 44px;
    font-size: 16px;
    padding-right: 44px;
  }

  html[data-theme] #world #places.pocket-places #place-search-submit {
    position: absolute;
    right: 0;
    top: 0;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    font-size: 12px;
    padding: 0;
    border: 0;
    border-left: 1px solid #829ab1;
    border-radius: 0 5px 5px 0;
    background: transparent;
    box-shadow: none;
  }

  html[data-theme] #world #places.pocket-places .map-tools > .pocket-filters:not([hidden]) {
    flex: 0 0 66px;
    width: 66px;
    min-width: 44px;
    min-height: 44px;
    height: 44px;
    font-size: 13px;
  }

  /* --- Map --- */
  html[data-theme] #world #places.pocket-places #places-areas,
  html[data-theme] #world #places.pocket-places .atlas-stage {
    flex: 1;
    display: flex;
    min-height: 0;
    padding: 0;
    margin: 0;
  }

  html[data-theme] #world #places.pocket-places .map-wrap {
    flex: 1;
    height: 100%;
    min-height: 0;
    margin: 0;
    border-radius: 0;
  }

  html[data-theme] #world #places.pocket-places #area-map {
    height: 100%;
    min-height: 0;
  }

  html[data-theme] #world #places.pocket-places .map-compass {
    display: none;
  }

  /* --- Map-edge button column --- */
  html[data-theme] #world #places .pocket-map-edge {
    position: absolute;
    right: max(8px,env(safe-area-inset-right));
    top: 10px;
    z-index: 800;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  html[data-theme] #world #places .pocket-map-edge button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    margin: 0;
    padding: 0;
    border: 1px solid #829ab1;
    border-radius: 50%;
    background: linear-gradient(#fff, #d3e0ed);
    color: #254662;
    box-shadow:
      inset 0 1px #fff,
      0 2px 4px #28476440;
    font-size: 0;
  }

  html[data-theme] #world #places .pocket-map-edge {
    align-items: flex-end;
  }

  html[data-theme] #world #places .pocket-map-edge .map-note-leave {
    display: flex;
    gap: 5px;
    width: auto;
    min-width: 44px;
    max-width: 126px;
    padding: 0 9px;
    border-radius: 4px;
  }

  html[data-theme] #world #places .pocket-map-edge .map-note-button-copy {
    display: none;
  }

  html[data-theme] #world #places .pocket-map-edge .pocket-note-label {
    display: inline;
    font: 12px/1.2 var(--desktop-font);
    white-space: nowrap;
  }

  html[data-theme] #world #places .pocket-map-edge #map-reset span {
    font-size: 25px;
  }

  html[data-theme] #world #places .pocket-map-edge #map-memory-shuffle span {
    display: none;
  }

  /* A shuffle scoped to a route or a destination names that scope, like the note button. */
  html[data-theme] #world #places .pocket-map-edge #map-memory-shuffle[data-scope] {
    display: flex;
    gap: 5px;
    width: auto;
    min-width: 44px;
    max-width: 140px;
    padding: 0 9px;
    border-radius: 4px;
  }

  html[data-theme] #world #places .pocket-map-edge #map-memory-shuffle[data-scope] span {
    display: inline;
    font: 12px/1.2 var(--desktop-font);
    white-space: nowrap;
  }

  html[data-theme] #world #places .pocket-map-edge svg,
  html[data-theme] #world #places .pocket-map-edge img {
    width: 25px;
    height: 25px;
    margin: 0;
  }

  /* --- Zoom control, popups and search results --- */
  html[data-theme] #world #places.pocket-places .leaflet-control-zoom a {
    width: 44px;
    height: 44px;
    line-height: 44px;
  }

  /* A popup owns the map controls until it is dismissed. */
  html[data-theme]
    #world
    #places.pocket-places
    .map-wrap:has(.leaflet-popup)
    :is(.pocket-map-edge, .leaflet-control-zoom) {
    visibility: hidden;
  }

  html[data-theme] #world #places.pocket-places .leaflet-popup-close-button {
    width: 44px;
    height: 44px;
    line-height: 44px;
  }

  html[data-theme] #world #places.pocket-places .leaflet-popup-content {
    padding-right: 24px;
  }

  html[data-theme] #world #places.pocket-places #place-search-results {
    max-width: calc(100% - 16px);
  }

  /* The route count line stays on screen: a strip between the search row and the map, its text
     lined up with the search text (row padding, then the field's 1px border and 9px padding). */
  html[data-theme] #world #places.pocket-places #route-selection-status {
    flex: none;
    padding: 6px max(8px, env(safe-area-inset-right)) 6px
      calc(max(8px, env(safe-area-inset-left)) + 10px);
    font-size: 12px;
  }

  /* The place result bar runs along the map's bottom edge, above the map credit, and above the
     minimised player's card where the card meets it (--mini-player-lift, hyd-world.js). */
  html[data-theme] #world #places.pocket-places .place-selection {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(26px + var(--mini-player-lift, 0px));
    width: auto;
    max-width: none;
    gap: 8px;
    padding: 6px 6px 6px 10px;
  }

  html[data-theme] #world #places.pocket-places #place-selection-play {
    height: 44px;
    min-height: 44px;
    min-width: 96px;
  }

  html[data-theme] #world #places.pocket-places #place-search-results button {
    min-height: 44px;
    font-size: 14px;
  }

  /* --- Filter bottom sheet --- */
  html[data-theme] #world #places .pocket-place-filters {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-width: 620px;
    max-height: calc(100dvh - max(12px,env(safe-area-inset-top)));
    margin: 0 auto;
    padding: 0;
    border: 1px solid #536c88;
    border-radius: 8px 8px 0 0;
    background: #dae6f1;
    color: #254967;
    box-shadow: 0 -4px 24px #17263b55;
    font: 14px var(--desktop-font);
    overflow: hidden;
  }

  html[data-theme] #world #places .pocket-place-filters[open] {
    display: flex;
    flex-direction: column;
    animation: pocket-places-sheet 0.18s ease-out;
  }

  html[data-theme] #world #places .pocket-place-filters::backdrop {
    background: #17263b66;
  }

  html[data-theme] #world #places .pocket-filters-heading {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    min-height: 48px;
    background:
      repeating-linear-gradient(0deg, #ffffff24 0 1px, transparent 1px 3px),
      linear-gradient(#e8f3ff, #bfd3e7);
    border-bottom: 1px solid #8aa1ba;
    box-shadow: inset 0 1px #fff;
  }

  html[data-theme] #world #places .pocket-filters-heading h2 {
    font:
      400 15px 'Hyd Minar',var(--desktop-font);
    margin: 0;
  }

  html[data-theme] #world #places .pocket-filters-close {
    position: absolute;
    left: 0;
    top: 2px;
    width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
    font-size: 24px;
    color: inherit;
  }

  html[data-theme] #world #places .pocket-filters-body {
    overflow: auto;
    overscroll-behavior: contain;
    padding-bottom: max(12px,env(safe-area-inset-bottom));
  }

  /* --- Controls moved into the sheet --- */
  html[data-theme] #world #places .pocket-place-filters .map-memory-tools {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 12px;
    gap: 12px 8px;
  }

  html[data-theme] #world #places .pocket-place-filters .memory-mode-switch {
    grid-column: 1/-1;
    width: 100%;
    min-width: 0;
    gap: 0;
    padding: 0;
    border: 0;
  }

  html[data-theme] #world #places .pocket-place-filters .memory-mode-switch > button {
    flex: 1;
    min-width: 0;
  }

  html[data-theme] #world #places .pocket-place-filters :is(button, select, input, summary) {
    min-height: 44px;
    font-size: 16px;
  }

  html[data-theme] #world #places .pocket-place-filters :is(button, select) {
    height: 44px;
  }

  html[data-theme] #world #places .pocket-place-filters .map-memory-tools label {
    display: grid;
    gap: 5px;
    min-width: 0;
    font-size: 13px;
  }

  html[data-theme] #world #places .pocket-place-filters label:has(#map-memory-area) {
    display: none;
  }

  html[data-theme] #world #places .pocket-place-filters .map-memory-tools select {
    width: 100%;
    max-width: none;
  }

  html[data-theme] #world #places .pocket-place-filters #map-memory-clear {
    grid-column: 1/-1;
    width: 100%;
    margin: 0;
  }

  html[data-theme] #world #places .pocket-place-filters .map-notes-toolbar {
    margin: 0;
    padding: 8px 12px;
    gap: 8px;
    display: flex;
    flex-wrap: wrap;
  }

  html[data-theme] #world #places .pocket-place-filters .map-notes-toggle {
    display: flex;
    align-items: center;
    min-height: 44px;
    width: 100%;
    font-size: 16px;
  }

  html[data-theme] #world #places .pocket-place-filters .map-notes-toggle span {
    font: inherit;
  }

  html[data-theme] #world #places .pocket-place-filters .map-notes-toggle input {
    width: 22px;
    min-height: 22px;
    height: 22px;
    margin: 0 8px 0 0;
  }

  html[data-theme] #world #places .pocket-place-filters .map-notes-count {
    flex-basis: 100%;
    margin: 0;
  }

  html[data-theme] #world #places .pocket-place-filters .route-options {
    padding: 0 12px 8px;
  }

  html[data-theme] #world #places .pocket-place-filters .route-options summary {
    display: flex;
    align-items: center;
    width: 100%;
    font-size: 14px;
  }

  html[data-theme] #world #places .pocket-place-filters .route-from-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 80px;
    gap: 8px;
  }

  html[data-theme] #world #places .pocket-place-filters .route-from-search label {
    grid-column: 1/-1;
  }

  html[data-theme] #world #places .pocket-place-filters .route-from-search input {
    flex: 1 1 75%;
    height: 44px;
    font-size: 16px;
  }

  html[data-theme] #world #places .pocket-place-filters .route-from-search button {
    width: 100%;
    min-width: 44px;
  }

  html[data-theme] #world #places .pocket-place-filters #route-from-clear {
    grid-column: 1/-1;
    width: 100%;
  }

  html[data-theme] #world #places .pocket-place-filters #place-search-results {
    position: fixed;
    z-index: 1;
  }

  /* --- Note chooser and note dialog --- */
  html[data-theme] #world #places.pocket-places .map-note-chooser {
    position: absolute;
    left: 8px;
    right: 60px;
    bottom: max(28px,env(safe-area-inset-bottom));
    z-index: 900;
    max-height: 55%;
    overflow: auto;
    box-shadow: 0 2px 8px #17263b55;
  }

  html[data-theme] #world #places.pocket-places .atlas-stage {
    position: relative;
  }

  html[data-theme] #world #places.pocket-places .map-note-chooser button {
    min-height: 44px;
    font-size: 14px;
  }

  html[data-theme] #world #hyd-map-note {
    max-height: calc(100dvh - max(12px,env(safe-area-inset-top)) - max(12px,env(safe-area-inset-bottom)));
  }

  html[data-theme] #world #hyd-map-note .map-note-titlebar {
    min-height: 48px;
    grid-template-columns: 44px 1fr 44px;
  }

  html[data-theme] #world #hyd-map-note .map-note-close {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    border: 0;
    background: none;
    box-shadow: none;
    font-size: 24px;
  }

  html[data-theme] #world #hyd-map-note :is(input:not([type='checkbox']), textarea, select) {
    font-size: calc(16 * var(--px));
    min-height: 44px;
  }

  html[data-theme] #world #hyd-map-note .map-note-form button {
    min-height: 44px;
    font-size: calc(14 * var(--px));
  }

  /* --- Top menu peek button --- */
  html[data-theme] #world.places-menu-reveal .desktop-menu-peek {
    height: 44px;
    min-height: 44px;
    width: 44px;
    left: auto;
    right: max(8px,env(safe-area-inset-right));
    translate: 0;
  }

  html[data-theme] #world.places-menu-reveal > .shell nav button {
    min-height: 44px;
    min-width: 44px;
  }
}

/*
 * A phone on its side: the title bar and the search row share one 55px row (5px above and below the 44px
 * fields), so the map keeps the height (302px of map at 800x360). The title bar keeps its 44px close on the
 * left; the search row leaves the right corner to the menu peek button (8px + 44px + 8px), as the title bar
 * does upright.
 */
@media (pointer: coarse) and (max-height: 450px) {
  html[data-theme] #world #places.pocket-places .places-browser {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  html[data-theme] #world #places.pocket-places .places-browser > * {
    grid-column: 1 / -1;
  }

  html[data-theme] #world #places.pocket-places .places-browser > .places-heading {
    grid-column: 1;
    grid-row: 1;
    height: auto;
    padding: 0 12px 0 52px;
  }

  html[data-theme] #world #places.pocket-places .places-browser > .map-tools {
    grid-column: 2;
    grid-row: 1;
    padding-block: 5px;
    padding-right: calc(max(8px, env(safe-area-inset-right)) + 52px);
  }

  html[data-theme] #world #places.pocket-places .places-browser > #route-selection-status {
    grid-row: 2;
  }

  html[data-theme] #world #places.pocket-places .places-browser > #places-areas {
    grid-row: 3;
  }
}

/* Slide-up animation for the filter sheet (used by .pocket-place-filters[open] above, 0.18s). */
@keyframes pocket-places-sheet {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* Reduced motion and the on-page motion switch: the sheet appears without sliding. */
@media (prefers-reduced-motion: reduce) {
  #world #places .pocket-place-filters[open] {
    animation: none;
  }
}

.motion-off #world #places .pocket-place-filters[open] {
  animation: none;
}
