:root {
  --panel-bg: #ffffff;
  --panel-border: #e7e5e4;
  --text: #1c1917;
  --text-muted: #78716c;
  --accent: #ea580c;
  --accent-soft: #fff7ed;
  --accent-border: #fed7aa;
  --star: #f59e0b;
  --danger: #b91c1c;
  --surface: #f5f5f4;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  /* Nothing on the page scrolls, so kill the rubber-band on iOS. */
  overscroll-behavior: none;
}

/* The lightbox scrolls nothing; the page behind it must not scroll either. */
body.is-locked {
  overflow: hidden;
}

/*
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. dvh tracks Safari's collapsing toolbar, so the map
 * is neither cropped nor scrollable as the bar hides.
 */
#map {
  height: 100%;
  height: 100dvh;
}

/* ---------------------------------------------------------------- the panel */

.panel {
  width: 280px;
  margin: 10px;
  /* Landscape on a notched phone puts the display cutout to one side. */
  margin-top: max(10px, env(safe-area-inset-top));
  margin-left: max(10px, env(safe-area-inset-left));
  background-color: var(--panel-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 6px rgba(28, 25, 23, 0.16), 0 8px 24px rgba(28, 25, 23, 0.12);
  font-family: var(--font);
  color: var(--text);
  overflow: hidden;
}

/*
 * Touch defaults for every control in the panel: no grey tap flash, no
 * 300ms double-tap-to-zoom delay, and no text selection or callout when a
 * press turns into a drag.
 */
.panel button {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.panel__toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

/* Hover styling only where a pointer can hover — otherwise it sticks on tap. */
@media (hover: hover) {
  .panel__toggle:hover {
    background-color: var(--surface);
  }
}

.panel__chevron {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--text-muted);
  transition: transform 150ms ease;
}

.panel.is-collapsed .panel__chevron {
  transform: rotate(-90deg);
}

.panel__title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.panel__count {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background-color: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.panel__count:empty {
  display: none;
}

.panel__body {
  padding: 0 12px 12px;
  border-top: 1px solid var(--panel-border);
}

.panel.is-collapsed .panel__body {
  display: none;
}

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

.field {
  padding-top: 10px;
}

.field__label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field__input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background-color: #fff;
  font: inherit;
  font-size: 12px;
  color: var(--text);
}

@media (hover: hover) {
  .field__input:hover {
    border-color: #d6d3d1;
  }
}

.field__input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ------------------------------------------------------------------ chip row */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.chips:empty {
  display: none;
}

.chip {
  flex: none;
  padding: 3px 9px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background-color: #fff;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

@media (hover: hover) {
  .chip:hover {
    border-color: #d6d3d1;
    color: var(--text);
  }
}

.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chip.is-active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ------------------------------------------------------------- photo thumbs */

/*
 * The plate glyph sits underneath every thumbnail and only shows through when
 * the photo is missing, so a card never collapses to an empty box.
 */
.place__thumb,
.gallery__thumb,
.infowindow__thumb {
  position: relative;
  display: block;
  flex: none;
  overflow: hidden;
  border-radius: 8px;
  background-color: var(--surface);
  color: #a8a29e;
}

.thumb__fallback {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44%;
  height: 44%;
  transform: translate(-50%, -50%);
  opacity: 0;
}

.is-empty > .thumb__fallback {
  opacity: 1;
}

.place__thumb img,
.gallery__thumb img,
.infowindow__thumb img {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* -------------------------------------------------------------- place cards */

.places {
  max-height: min(46vh, 340px);
  margin-top: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.places:empty {
  display: none;
}

.place {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.place + .place {
  margin-top: 2px;
}

@media (hover: hover) {
  .place:hover {
    background-color: var(--surface);
  }
}

.place:active {
  background-color: #e7e5e4;
}

.place:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.place.is-selected {
  background-color: var(--accent-soft);
  border-color: var(--accent-border);
}

.place__thumb {
  width: 44px;
  height: 44px;
}

.place__meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.place__name {
  font-size: 12px;
  font-weight: 600;
  /* Restaurant names run long; one line keeps the list scannable. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place.is-selected .place__name {
  color: var(--accent);
}

.place__sub {
  color: var(--text-muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place__rating {
  flex: none;
  color: var(--star);
  font-size: 9px;
  letter-spacing: 0.5px;
}

/* ------------------------------------------------------- selected place info */

.detail {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background-color: var(--accent-soft);
}

.detail__head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.detail__head > div {
  min-width: 0;
  flex: 1;
}

.detail__name {
  font-size: 13px;
  font-weight: 600;
}

.detail__rating {
  color: var(--star);
  font-size: 10px;
  letter-spacing: 1px;
}

.detail__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}

.detail__close svg {
  width: 12px;
  height: 12px;
}

@media (hover: hover) {
  .detail__close:hover {
    background-color: #ffedd5;
    color: var(--text);
  }
}

.detail__address {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
  text-decoration: none;
}

.detail__address:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ------------------------------------------------------------------ gallery */

.gallery {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-bottom: 2px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.gallery__item {
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: zoom-in;
}

.gallery__item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.gallery__thumb {
  width: 72px;
  height: 56px;
}

/* -------------------------------------------------------------- visit notes */

.visits {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.visit + .visit {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--accent-border);
}

.visit__head {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.visit__date {
  font-size: 11px;
  font-weight: 600;
}

.visit__rating {
  color: var(--star);
  font-size: 9px;
  letter-spacing: 0.5px;
}

.visit__note {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
}

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

.status {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
}

.status[data-tone="error"] {
  color: var(--danger);
}

/* -------------------------------------------------------------- info windows */

.infowindow {
  display: flex;
  gap: 10px;
  max-width: 260px;
  font-family: var(--font);
  color: var(--text);
}

.infowindow__thumb {
  width: 64px;
  height: 64px;
}

.infowindow__body {
  min-width: 0;
}

.infowindow__heading {
  font-size: 13px;
  font-weight: 600;
}

.infowindow__rating {
  color: var(--star);
  font-size: 10px;
  letter-spacing: 1px;
}

.infowindow__address,
.infowindow__meta {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
}

/* ----------------------------------------------------------------- lightbox */

.lightbox {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: env(safe-area-inset-top) 8px calc(8px + env(safe-area-inset-bottom));
  background-color: rgba(28, 25, 23, 0.88);
}

.lightbox[hidden] {
  display: none;
}

.lightbox__figure {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.lightbox__image {
  max-width: 100%;
  /* Leaves room for the caption under the photo on a short screen. */
  max-height: 78dvh;
  object-fit: contain;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.06);
}

.lightbox__caption {
  max-width: 60ch;
  color: #e7e5e4;
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.lightbox__caption:empty {
  display: none;
}

.lightbox__nav,
.lightbox__close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .lightbox__nav:hover,
  .lightbox__close:hover {
    background-color: rgba(255, 255, 255, 0.24);
  }
}

.lightbox__nav {
  width: 44px;
  height: 44px;
  font-size: 26px;
  line-height: 1;
}

.lightbox__nav[hidden] {
  display: none;
}

.lightbox__close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  width: 36px;
  height: 36px;
}

.lightbox__close svg {
  width: 16px;
  height: 16px;
}

/* ------------------------------------------------- short screens (landscape) */

/*
 * A phone on its side is ~400px tall: the list has to give way or the panel
 * runs off the bottom of the map.
 */
@media (min-width: 641px) and (max-height: 520px) {
  .places {
    max-height: 26vh;
  }
}

/* ------------------------------------------------------------ phones: sheet */

/*
 * On a phone the map is the whole point, so the panel drops to the bottom as
 * a sheet with two states. Peek keeps the selected place's photos and notes in
 * thumb reach; expanding brings up the search field and the full list. JS moves
 * the element out of the map's control layer at this same breakpoint, which is
 * what lets it be position: fixed here.
 */
@media (max-width: 640px) {
  .panel {
    position: fixed;
    z-index: 3;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    width: auto;
    max-width: none;
    max-height: 85vh;
    max-height: 85dvh;
    margin: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -1px 3px rgba(28, 25, 23, 0.1),
      0 -10px 30px rgba(28, 25, 23, 0.16);
    transition: transform 160ms ease;
  }

  .panel__toggle {
    position: relative;
    min-height: 48px;
    padding: 16px 16px 12px;
    /* The header is the drag surface, so it owns vertical gestures. */
    touch-action: none;
  }

  /* Grab handle, the standard affordance for "this sheet moves". */
  .panel__toggle::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    width: 36px;
    height: 4px;
    margin-left: -18px;
    border-radius: 999px;
    background-color: #d6d3d1;
  }

  .panel__title {
    font-size: 15px;
  }

  .panel__count {
    padding: 2px 9px;
    font-size: 12px;
  }

  /* One scroll container per sheet: the body scrolls, the list inside it does
     not, so a drag never has to pick between two nested scrollers. */
  .panel__body {
    flex: 1;
    min-height: 0;
    padding: 0 16px calc(14px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .places {
    max-height: none;
    overflow: visible;
  }

  /* Peek state: the chevron points up because tapping it opens the sheet. */
  .panel.is-collapsed .panel__chevron {
    transform: rotate(180deg);
  }

  .panel.is-collapsed .panel__body {
    display: block;
  }

  .panel.is-collapsed .field,
  .panel.is-collapsed .chips,
  .panel.is-collapsed .places {
    display: none;
  }

  .panel.is-collapsed .detail {
    margin-top: 12px;
  }

  /* ---- targets sized for a thumb (44px) and type sized for a phone ---- */

  .field__label {
    font-size: 12px;
  }

  .field__input {
    padding: 11px 12px;
    /* 16px keeps iOS from zooming the page when the field takes focus. */
    font-size: 16px;
  }

  .chips {
    gap: 6px;
    margin-top: 10px;
  }

  .chip {
    min-height: 40px;
    padding: 4px 16px;
    font-size: 13px;
  }

  .detail {
    padding: 10px 12px;
  }

  .detail__name {
    font-size: 15px;
  }

  .detail__rating,
  .visit__rating,
  .place__rating {
    font-size: 11px;
  }

  .detail__address,
  .visit__note,
  .visit__date {
    font-size: 12px;
  }

  .detail__close {
    width: 32px;
    height: 32px;
  }

  .gallery__thumb {
    width: 88px;
    height: 68px;
  }

  .status {
    font-size: 13px;
  }

  .place {
    gap: 12px;
    padding: 8px 6px;
  }

  .place__thumb {
    width: 48px;
    height: 48px;
  }

  .place__name {
    font-size: 14px;
  }

  .place__sub {
    font-size: 12px;
  }

  .infowindow {
    max-width: 240px;
  }

  .lightbox__image {
    max-height: 72dvh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .panel__chevron {
    transition: none;
  }
}
