/* Styles for the app's screens. */

/* Simple pages: not found, a load error, loading, and placeholders. */
.message-page {
  display: grid;
  gap: var(--space-4);
  max-width: var(--page-max-width);
  margin-inline: auto;
  padding-top: var(--space-6);
}

.message-page__title:focus {
  outline: none;
}

.message-page__text {
  color: var(--color-text-muted);
}

.message-page__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

/* The password screen, before the app starts. */
.lock-screen {
  display: grid;
  gap: var(--space-4);
  max-width: var(--page-max-width);
  margin-inline: auto;
  padding-top: var(--space-6);
}

.lock-screen__title:focus {
  outline: none;
}

.lock-screen__text {
  color: var(--color-text-muted);
}

.lock-screen__error {
  color: var(--color-error);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.lock-screen__error:empty {
  display: none;
}

/*
 * Home: the map fills the whole screen, under the notch and home indicator, and the
 * routed view becomes a click-through overlay. Only the overlay's own controls are
 * padded for the safe areas.
 */
.map {
  position: fixed;
  inset: 0;
  z-index: var(--z-map);
}

.map[hidden] {
  display: none;
}

.app[data-route='home'] {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  min-height: 0;
  padding: 0;
  pointer-events: none;
}

.app[data-route='home'] > * {
  pointer-events: auto;
}

.app[data-route='home'] > .map-header,
.app[data-route='home'] > .map-notices {
  pointer-events: none;
}

/* The app's name, with the progress pill under it. Only the pills themselves take taps. */
.map-header {
  position: absolute;
  top: calc(var(--safe-top) + var(--space-3));
  left: calc(var(--safe-left) + var(--space-3));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  max-width: calc(100% - var(--safe-left) - var(--safe-right) - var(--space-3) * 2 - var(--tap-target) - var(--space-3));
}

.map-header > * {
  max-width: 100%;
  pointer-events: auto;
}

.map-header__title,
.progress-pill,
.map .leaflet-control-zoom,
.map .locate-control,
.surprise-bar,
.filter-chip,
.surprise-menu {
  background: var(--glass-bg);
  box-shadow: var(--glass-hairline), var(--shadow-md);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
}

.map-header__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--map-pill-height);
  padding-inline: var(--space-3) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-md);
  line-height: var(--map-pill-height);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* A small red mark before the name, after the red of the City's arms. */
.map-header__title::before {
  content: '';
  flex: none;
  width: var(--space-2);
  height: var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

/* "3 / 8 seen": a secondary way into the list, so it's smaller than the map's own controls. */
.progress-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--map-pill-height);
  padding-inline: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
  line-height: var(--line-height-tight);
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
}

.progress-pill[hidden] {
  display: none;
}

.progress-pill::before {
  content: '';
  position: absolute;
  inset: calc((var(--tap-target) - var(--map-pill-height)) / -2) 0;
}

.progress-pill:active {
  background: var(--glass-bg-strong);
}

.progress-ring {
  flex: none;
  width: var(--progress-ring-size);
  height: var(--progress-ring-size);
  /* Start the arc at twelve o'clock. */
  transform: rotate(-90deg);
}

.progress-ring circle {
  fill: none;
  stroke-width: 3.5;
}

.progress-ring__track {
  stroke: var(--color-progress-track);
}

.progress-ring__value {
  stroke: var(--color-progress);
  stroke-dasharray: 0 100;
}

.progress-pill__chevron {
  flex: none;
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  fill: none;
  stroke: var(--color-text-muted);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Leaflet overrides, so the map matches the app's tokens and clears the safe areas. */
.map.leaflet-container {
  background: var(--color-bg);
  font-family: var(--font-sans);
}

.map:focus-visible {
  outline-offset: -3px;
}

.map .leaflet-tile-pane {
  filter: var(--map-tile-filter);
}

.map .leaflet-top {
  top: var(--safe-top);
}

.map .leaflet-bottom {
  bottom: var(--safe-bottom);
}

.map .leaflet-left {
  left: var(--safe-left);
}

.map .leaflet-right {
  right: var(--safe-right);
}

.map .leaflet-top .leaflet-control {
  margin-top: var(--space-3);
}

.map .leaflet-right .leaflet-control {
  margin-right: var(--space-3);
}

.map .leaflet-control-zoom {
  border: none;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.map .leaflet-control-zoom a {
  width: var(--tap-target);
  height: var(--tap-target);
  border-bottom-color: var(--color-bar-border);
  background: transparent;
  color: var(--color-text);
  font-size: var(--font-size-lg);
  line-height: var(--tap-target);
}

.map .leaflet-control-zoom a:active {
  background: var(--color-button-bg);
}

.map .leaflet-control-zoom a.leaflet-disabled {
  background: transparent;
}

.map .leaflet-control-zoom a:focus-visible {
  outline-offset: -3px;
}

.map .leaflet-control-attribution {
  margin: 0;
  border-top-left-radius: var(--radius-sm);
  background: var(--map-control-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-tight);
  padding: var(--space-1) var(--space-2);
}

.map .leaflet-control-attribution a {
  color: inherit;
}

/* The credits, folded to one short line with an ⓘ that shows the rest (see map.js). */
.map .map-credits {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  max-width: calc(100vw - var(--safe-left) - var(--safe-right));
  padding-right: var(--space-1);
}

.map-credits__full {
  flex: 1 1 auto;
  min-width: 0;
}

.map-credits__toggle {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: none;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* The visible ⓘ is small, so its tap area reaches out to a full tap target. */
.map-credits__toggle::before {
  content: '';
  position: absolute;
  inset: calc((var(--tap-target) - var(--icon-size-lg)) / -2);
}

.map-credits__toggle svg {
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.map-credits--open .map-credits__toggle {
  color: var(--color-text);
}

/* Shown on the map when places.json can't be loaded. Sits above the attribution. */
.map-message {
  position: absolute;
  left: calc(var(--safe-left) + var(--space-3));
  right: calc(var(--safe-right) + var(--space-3));
  bottom: calc(var(--safe-bottom) + var(--space-7));
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
}

.map-message p {
  flex: 1;
}

.map-message .button {
  flex: none;
}

/*
 * Place pins. Leaflet sizes the outer element to the 44px tap target; the coloured dot
 * inside is smaller so neighbouring pins don't crowd each other at City-wide zoom.
 */
.place-pin {
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.place-pin:focus-visible {
  outline: none;
}

.place-pin__dot {
  display: grid;
  position: relative;
  place-items: center;
  width: var(--pin-dot-size);
  height: var(--pin-dot-size);
  border: var(--pin-border-width) solid var(--color-surface);
  border-radius: var(--radius-pill);
  /* A faint top light over the category colour, so the pin reads as a raised button. */
  background: linear-gradient(180deg, rgb(255 255 255 / 0.18), rgb(0 0 0 / 0.1)), var(--category-color);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.2), 0 4px 10px rgb(0 0 0 / 0.22);
  color: var(--color-text-on-accent);
  transition: transform var(--duration-fast) var(--easing-standard),
    filter var(--duration-fast) var(--easing-standard), opacity var(--duration-fast) var(--easing-standard);
}

.place-pin:hover .place-pin__dot,
.place-pin:active .place-pin__dot {
  transform: scale(1.12);
}

.place-pin:focus-visible .place-pin__dot {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.place-pin__dot > svg {
  width: var(--pin-glyph-size);
  height: var(--pin-glyph-size);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Seen: faded, with a tick badge, so the difference doesn't rely on colour alone. */
.place-pin--seen .place-pin__dot {
  filter: var(--pin-seen-filter);
  opacity: var(--pin-seen-opacity);
  box-shadow: var(--shadow-sm);
}

.place-pin__tick {
  display: none;
  position: absolute;
  top: calc(var(--pin-tick-size) / -3);
  right: calc(var(--pin-tick-size) / -3);
  place-items: center;
  width: var(--pin-tick-size);
  height: var(--pin-tick-size);
  border-radius: var(--radius-pill);
  background: var(--color-text);
  color: var(--color-surface);
  box-shadow: 0 0 0 1.5px var(--color-surface);
}

.place-pin--seen .place-pin__tick {
  display: grid;
}

.place-pin__tick svg {
  width: var(--pin-tick-glyph-size);
  height: var(--pin-tick-glyph-size);
  fill: none;
  stroke: currentColor;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The pin whose card is open stands out, at full strength even if seen. */
.place-pin--selected .place-pin__dot,
.place-pin--selected:hover .place-pin__dot,
.place-pin--selected:active .place-pin__dot {
  transform: scale(var(--pin-selected-scale));
  filter: none;
  opacity: 1;
  box-shadow: 0 0 0 3px var(--category-color), 0 0 0 9px rgb(255 255 255 / 0.55), var(--shadow-lg);
}

/* Category colours, for pins and labels. */
[data-category] { --category-color: var(--color-accent); }
[data-category='roads'] { --category-color: var(--cat-roads); }
[data-category='pubs'] { --category-color: var(--cat-pubs); }
[data-category='monuments'] { --category-color: var(--cat-monuments); }
[data-category='artefacts'] { --category-color: var(--cat-artefacts); }
[data-category='buildings'] { --category-color: var(--cat-buildings); }
[data-category='churches'] { --category-color: var(--cat-churches); }
[data-category='ancient'] { --category-color: var(--cat-ancient); }
[data-category='plaques'] { --category-color: var(--cat-plaques); }

.map-outside {
  fill: var(--map-outside-shade);
  fill-opacity: 1;
}

.map-boundary {
  stroke: var(--map-boundary-color);
  stroke-opacity: var(--map-boundary-opacity);
  stroke-width: var(--map-boundary-width);
}

/* The user's location: a blue dot with a white ring, a soft halo and a faint accuracy circle. */
.user-location {
  display: grid;
  place-items: center;
  pointer-events: none;
}

.user-location__dot {
  width: var(--user-dot-size);
  height: var(--user-dot-size);
  border: 3px solid var(--color-surface);
  border-radius: var(--radius-pill);
  background: var(--color-location);
  box-shadow: 0 0 0 6px var(--color-location-halo), var(--shadow-md);
}

.user-location__accuracy {
  fill: var(--color-location-accuracy);
  fill-opacity: 1;
  stroke: none;
}

/* Locate button, stacked under the zoom buttons. */
.map .locate-control {
  border: none;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.locate-button {
  display: grid;
  place-items: center;
  width: var(--tap-target);
  height: var(--tap-target);
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  touch-action: manipulation;
}

.locate-button:active {
  background: var(--color-button-bg);
}

.locate-button:focus-visible {
  outline-offset: -3px;
}

.locate-button svg {
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}

.locate-button[data-state='locating'],
.locate-button[data-state='on'] {
  color: var(--color-location);
}

.locate-button[data-state='on'] svg {
  fill: currentColor;
}

.locate-button[data-state='denied'],
.locate-button[data-state='unavailable'] {
  color: var(--color-text-muted);
}

/*
 * Messages near the top of the map, under the header's two pills: the home-screen app's
 * own (update, offline, Add to Home Screen), then a short-lived notice, e.g. when location
 * is off. Taps go through the gaps to the map.
 */
.map-notices {
  position: absolute;
  top: calc(var(--safe-top) + var(--space-3) + var(--map-pill-height) * 2 + var(--space-2) + var(--space-3));
  left: calc(var(--safe-left) + var(--space-3));
  right: calc(var(--safe-right) + var(--space-3) + var(--tap-target) + var(--space-3));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
}

.map-notices > * {
  max-width: 100%;
  pointer-events: auto;
}

.map-notices > [hidden] {
  display: none;
}

.map-notice {
  align-self: stretch;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-text);
  color: var(--color-surface);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
}

/* A new version is ready. Gentle: a small pill, not a dialog. */
.update-banner__button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: 0 var(--space-4) 0 var(--space-3);
  border: none;
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  touch-action: manipulation;
}

.update-banner__button:hover {
  background: var(--color-surface-muted);
}

.update-banner__button svg {
  color: var(--color-accent);
}

.update-banner__button:disabled {
  cursor: progress;
}

.update-banner__button svg,
.offline-notice svg {
  flex: none;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Subtle, and taps go straight through it to the map. */
.offline-notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--map-control-bg);
  color: var(--color-text-muted);
  box-shadow: var(--shadow-sm);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-tight);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
}

.map-notices > .offline-notice {
  pointer-events: none;
}

.offline-notice svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
}

/* iOS has no install prompt, so Safari users get these directions once. */
.install-hint {
  display: flex;
  align-items: flex-start;
  gap: var(--space-1);
  padding: var(--space-3) 0 var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
}

.install-hint__body {
  display: grid;
  gap: var(--space-1);
  flex: 1;
  min-width: 0;
}

.install-hint__title {
  font-size: var(--font-size-md);
}

.install-hint__text {
  color: var(--color-text-muted);
}

.install-hint__text b {
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
}

/* The Share glyph sits in the line of text, as it looks in Safari's toolbar. */
.install-hint__share {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.2em;
  fill: none;
  stroke: var(--color-text);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.install-hint__close {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tap-target);
  height: var(--tap-target);
  margin-top: calc(var(--space-3) * -1);
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
}

.install-hint__close svg {
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/*
 * Bottom sheets over the map (the place card and the all-seen message). They slide up
 * from below the screen; reduced motion makes that instant (see base.css).
 */
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-sheet);
  display: grid;
  gap: var(--space-3);
  width: 100%;
  max-width: var(--sheet-max-width);
  margin-inline: auto;
  padding: var(--space-5) calc(var(--safe-right) + var(--space-5)) calc(var(--safe-bottom) + var(--space-4))
    calc(var(--safe-left) + var(--space-5));
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--color-surface);
  box-shadow: var(--glass-hairline), 0 -8px 40px rgb(22 24 29 / 0.16);
  transform: translateY(100%);
  transition: transform var(--duration-normal) var(--easing-sheet);
  /* A safety net for very long content: the sheet scrolls rather than run off the top. */
  max-height: calc(100% - var(--safe-top) - var(--space-4));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet.is-open {
  transform: none;
}

.sheet[hidden] {
  display: none;
}

.place-card__top,
.all-seen__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  /* The close button's tap area reaches into the padding, so the label lines up with the title. */
  margin: calc(var(--space-2) * -1) calc(var(--space-2) * -1) calc(var(--space-2) * -1) 0;
}

.place-card__top-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Only on random suggestions. Up top, so it never sits where a thumb reaches for directions. */
.skip-button {
  gap: var(--space-1);
  padding-inline: var(--space-4) var(--space-3);
}

.skip-button[hidden] {
  display: none;
}

.skip-button .button__icon {
  fill: currentColor;
}

.category-label {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-1);
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
  border-radius: var(--radius-pill);
  /* The text stays in the main text colour, so contrast never depends on the tint. */
  background: color-mix(in srgb, var(--category-color) 12%, transparent);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
}

.category-label__glyph {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--icon-size-2xl);
  height: var(--icon-size-2xl);
  border-radius: var(--radius-pill);
  background: var(--category-color);
  color: var(--color-text-on-accent);
}

.category-label__glyph svg {
  width: var(--icon-size-xs);
  height: var(--icon-size-xs);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tap-target);
  height: var(--tap-target);
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  touch-action: manipulation;
}

.icon-button svg {
  width: var(--icon-circle-size);
  height: var(--icon-circle-size);
  padding: calc((var(--icon-circle-size) - var(--icon-size-sm)) / 2);
  border-radius: var(--radius-pill);
  background: var(--color-button-bg);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.place-card__title {
  font-size: var(--font-size-2xl);
}

/* A very long name or teaser is cut short on the card, so the card stays compact over the
   map. The history page shows them in full. */
.place-card__title,
.place-card__teaser {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

/* Focus is moved here for screen readers when the card opens; a ring would just be noise. */
.place-card__title:focus {
  outline: none;
}

.place-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
  margin-top: calc(var(--space-2) * -1);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.place-card__walk::before {
  content: '·';
  margin-right: var(--space-2);
}

.place-card__walk[hidden] {
  display: none;
}

.place-card__teaser {
  line-height: var(--line-height-body);
}

.place-card__directions .button,
.place-card__bottom .button,
.place-card__history,
.surprise-button,
.all-seen__actions--pair .button {
  white-space: nowrap;
}

.place-card__directions,
.place-card__bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: var(--space-3);
}

.place-card__directions .button {
  padding-inline: var(--space-3);
}

.button__icon {
  flex: none;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.seen-button--seen,
.seen-button--seen:hover {
  background: var(--color-success-soft);
  color: var(--color-success);
}

.place-card__history {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: var(--tap-target);
  border-radius: var(--radius-pill);
  font-weight: var(--font-weight-bold);
  text-decoration: none;
}

.place-card__history:active {
  background: var(--color-accent-soft);
}

/*
 * Surprise me: the main action, centred at the bottom of the map within thumb reach and
 * clear of the home indicator and the map attribution. The small button beside it opens
 * a menu of less common picks.
 */
.surprise-bar {
  position: absolute;
  left: 0;
  right: 0;
  /* The map credits can open to two or three lines on a phone, so the bar sits above them, like .map-message. */
  bottom: calc(var(--safe-bottom) + var(--space-7));
  display: flex;
  gap: var(--space-2);
  width: calc(100% - var(--safe-left) - var(--safe-right) - var(--space-3) * 2);
  max-width: var(--sheet-max-width);
  margin-inline: auto;
  padding: var(--space-2);
  border-radius: var(--radius-pill);
  box-shadow: var(--glass-hairline), var(--shadow-lg);
}

.surprise-bar[hidden] {
  display: none;
}

.surprise-button {
  flex: 1;
  min-height: var(--button-large-height);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  letter-spacing: -0.01em;
}

.surprise-button .button__icon {
  width: var(--icon-size-xl);
  height: var(--icon-size-xl);
  stroke-width: 2.25;
}

/* The round buttons either side of Surprise me: Filter and More. */
.round-button {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: var(--button-large-height);
  height: var(--button-large-height);
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--color-button-bg);
  color: var(--color-text);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--duration-fast) var(--easing-standard),
    transform var(--duration-fast) var(--easing-standard);
}

.round-button:active {
  background: var(--color-button-bg-active);
  transform: scale(0.94);
}

.round-button svg {
  width: var(--icon-size-xl);
  height: var(--icon-size-xl);
}

.surprise-more svg {
  fill: currentColor;
}

.filter-button svg,
.filter-chip svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* A filter is on: tinted, with a dot, so it doesn't rely on colour alone. */
.filter-button--active {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.filter-button--active::after {
  content: '';
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: var(--filter-dot-size);
  height: var(--filter-dot-size);
  border: 2px solid var(--color-surface);
  border-radius: var(--radius-pill);
  background: var(--color-accent);
}

/* The active filter, above the bar's Filter button. Tap it to change, × to clear. */
.filter-chip {
  position: absolute;
  left: 0;
  bottom: calc(100% + var(--space-2));
  display: flex;
  align-items: center;
  max-width: 100%;
  border-radius: var(--radius-pill);
}

.filter-chip[hidden] {
  display: none;
}

.filter-chip__open,
.filter-chip__clear {
  display: flex;
  align-items: center;
  min-height: var(--tap-target);
  border: none;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  touch-action: manipulation;
}

.filter-chip__open {
  gap: var(--space-2);
  min-width: 0;
  padding: 0 var(--space-1) 0 var(--space-4);
  border-radius: var(--radius-pill) 0 0 var(--radius-pill);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.filter-chip__open svg {
  flex: none;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  color: var(--color-accent);
}

.filter-chip__text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.filter-chip__clear {
  justify-content: center;
  flex: none;
  width: var(--tap-target);
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  color: var(--color-text-muted);
}

.filter-chip__clear svg {
  width: var(--icon-circle-size-small);
  height: var(--icon-circle-size-small);
  padding: calc((var(--icon-circle-size-small) - var(--icon-size-xs)) / 2);
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
  stroke-width: 2.5;
}

.filter-chip__open:focus-visible,
.filter-chip__clear:focus-visible {
  outline-offset: -3px;
}

.surprise-more[aria-expanded='true'] {
  background: var(--color-button-bg-active);
}

.surprise-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + var(--space-2));
  min-width: min(100%, 18rem);
  padding: var(--space-1);
  border-radius: var(--radius-lg);
  background: var(--glass-bg-strong);
  box-shadow: var(--glass-hairline), var(--shadow-lg);
}

.surprise-menu[hidden] {
  display: none;
}

.surprise-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.surprise-menu__item:hover,
.surprise-menu__item:active {
  background: var(--color-button-bg);
}

.surprise-menu__item:focus-visible {
  outline-offset: -3px;
}

.surprise-menu__item .button__icon {
  flex: none;
  color: var(--color-text-muted);
}

/* Everything seen (R6). */
.all-seen__badge {
  display: grid;
  place-items: center;
  width: var(--button-large-height);
  height: var(--button-large-height);
  border-radius: var(--radius-pill);
  background: var(--color-success-soft);
  color: var(--color-success);
}

.all-seen__badge svg {
  width: var(--icon-size-badge);
  height: var(--icon-size-badge);
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
}

/* Nothing to pick because of the filter: a funnel, in neutral colours, instead of the star. */
.all-seen__funnel,
.all-seen--filtered .all-seen__star {
  display: none;
}

.all-seen--filtered .all-seen__funnel {
  display: block;
}

.all-seen--filtered .all-seen__badge {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
}

.all-seen__step {
  display: grid;
  gap: var(--space-3);
}

.all-seen__step[hidden] {
  display: none;
}

.all-seen__title {
  font-size: var(--font-size-xl);
}

.all-seen__title:focus {
  outline: none;
}

.all-seen__text {
  color: var(--color-text-muted);
  line-height: var(--line-height-body);
}

.all-seen__actions {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.all-seen__actions--pair {
  grid-template-columns: 1fr 1fr;
}

/*
 * Filter sheet. Its middle scrolls on short screens, so the title and Done stay in reach.
 */
.filter-sheet {
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow-y: visible;
}

.filter-sheet__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: calc(var(--space-2) * -1) calc(var(--space-2) * -1) 0 0;
}

.filter-sheet__title {
  font-size: var(--font-size-xl);
}

.filter-sheet__title:focus {
  outline: none;
}

.filter-sheet__body {
  display: grid;
  gap: var(--space-4);
  /* Room for focus rings, which would otherwise be clipped by the scroller. */
  margin: 0 calc(var(--space-1) * -1);
  padding: var(--space-1);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.filter-sheet__heading {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.filter-status {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
  padding: 0;
  border: none;
}

.filter-status legend {
  padding: 0;
  margin-bottom: var(--space-2);
}

/* Seen / Unseen / Both: native radios, drawn as a segmented control. */
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
}

.segmented__option {
  position: relative;
  display: grid;
  place-items: center;
  min-height: calc(var(--tap-target) - var(--space-1) * 2);
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  touch-action: manipulation;
}

.segmented__option:has(:checked) {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.segmented__option:has(:focus-visible),
.filter-option:has(:focus-visible) {
  outline: 3px solid var(--color-focus);
  outline-offset: 0;
}

/* The inputs stay in place (for VoiceOver's focus ring position) but invisible. */
.segmented__input,
.filter-option__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.filter-categories {
  display: grid;
  gap: var(--space-1);
}

.filter-categories__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.filter-categories__shortcuts {
  display: flex;
  margin-right: calc(var(--space-3) * -1);
}

.text-button {
  min-width: var(--tap-target);
  min-height: var(--tap-target);
  padding: 0 var(--space-3);
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-accent);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  touch-action: manipulation;
}

.text-button:focus-visible {
  outline-offset: -3px;
}

.filter-categories__list {
  display: grid;
  padding: 0;
  list-style: none;
}

.filter-option {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-target);
  padding: var(--space-1) var(--space-1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: manipulation;
}

.filter-option:active {
  background: var(--color-surface-muted);
}

.filter-option__name {
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-tight);
}

.filter-option__count {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
}

/* No places in this category with the current seen choice: still choosable, but quieter. */
.filter-option--empty .category-label__glyph,
.filter-option--empty .filter-option__name {
  opacity: 0.5;
}

.filter-option__check {
  display: grid;
  place-items: center;
  width: var(--checkbox-size);
  height: var(--checkbox-size);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: transparent;
}

.filter-option__check svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.filter-option:has(:checked) .filter-option__check {
  border-color: var(--category-color);
  background: var(--category-color);
  color: var(--color-text-on-accent);
}

/*
 * History page (#/place/<id>). It scrolls as a normal page, with a slim bar at the top for
 * Back and the main actions in a bar stuck to the bottom, within thumb reach. Both bars
 * run edge to edge and pad themselves for the safe areas.
 */
.app:has(> .history-page) {
  padding: 0;
}

.history-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  /* A soft wash of the category's colour behind the header, fading into the page. */
  background: linear-gradient(
      180deg,
      color-mix(in srgb, var(--category-color) 14%, var(--color-bg)) 0,
      var(--color-bg) 24rem
    )
    no-repeat;
}

/* The slim bar with a Back control at the top of the history and list pages. */
.page-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-overlay);
  padding: calc(var(--safe-top) + var(--space-1)) calc(var(--safe-right) + var(--space-2)) var(--space-1)
    calc(var(--safe-left) + var(--space-2));
  border-bottom: 1px solid var(--color-bar-border);
  background: var(--color-bar-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
}

.page-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--tap-target);
  min-width: var(--tap-target);
  padding-inline: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  touch-action: manipulation;
}

.page-back svg {
  width: var(--icon-size-2xl);
  height: var(--icon-size-2xl);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-photo {
  width: 100%;
  max-width: var(--page-max-width);
  margin-inline: auto;
}

.history-photo[hidden] {
  display: none;
}

.history-photo__image {
  width: 100%;
  aspect-ratio: var(--photo-aspect-ratio);
  object-fit: cover;
  background: var(--color-surface-muted);
}

.history-photo__credit {
  padding: var(--space-1) calc(var(--safe-right) + var(--space-4)) 0 calc(var(--safe-left) + var(--space-4));
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-tight);
}

.history-photo__credit a {
  display: inline-flex;
  align-items: center;
  /* The caption is small text, but its link still gets a full-size tap area. */
  min-height: var(--tap-target);
  color: inherit;
}

.history-page__body {
  flex: 1;
  display: grid;
  align-content: start;
  gap: var(--space-6);
  width: 100%;
  max-width: var(--page-max-width);
  margin-inline: auto;
  padding: var(--space-5) calc(var(--safe-right) + var(--space-4)) var(--space-7) calc(var(--safe-left) + var(--space-4));
}

.history-page__header {
  display: grid;
  gap: var(--space-2);
}

.history-page__header .category-label {
  justify-self: start;
  margin-top: 0;
  margin-bottom: var(--space-2);
}

.history-page__title {
  font-size: var(--font-size-3xl);
  line-height: 1.1;
}

.history-page__title:focus {
  outline: none;
}

.history-page__era {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.history-page__standfirst {
  margin-top: var(--space-2);
  font-size: var(--font-size-standfirst);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-body);
}

.history-section {
  display: grid;
  gap: var(--space-3);
}

.history-section h2 {
  font-size: var(--font-size-xl);
}

.history-section[hidden],
.look-for[hidden] {
  display: none;
}

.look-for {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-5);
  border: 1px solid var(--color-callout-border);
  border-radius: var(--radius-lg);
  background: var(--color-callout-bg);
}

.look-for__title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-lg);
}

/* The eye sits in its own little disc, like an app icon for "look here". */
.look-for__icon {
  flex: none;
  width: var(--icon-circle-size);
  height: var(--icon-circle-size);
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--color-callout-border);
  fill: none;
  stroke: var(--color-callout-icon);
  stroke-width: 2;
  stroke-linejoin: round;
}

.look-for__text {
  font-size: var(--font-size-reading);
  line-height: var(--line-height-reading);
}

/* The history text itself. */
.prose {
  font-size: var(--font-size-reading);
  line-height: var(--line-height-reading);
}

.prose > * + * {
  margin-top: var(--space-4);
}

.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  margin-top: var(--space-5);
  font-size: var(--font-size-md);
}

.prose ul,
.prose ol {
  padding-left: var(--space-5);
}

.prose blockquote {
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-border);
  color: var(--color-text-muted);
}

.facts,
.sources {
  padding-inline: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.facts {
  display: grid;
  grid-template-columns: minmax(6.5rem, auto) 1fr;
  margin: 0;
}

/* The card's edge does the job of the last row's rule. */
.facts dt:nth-last-child(2),
.facts dd:last-child {
  border-bottom: none;
}

.facts dt,
.facts dd {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

.facts dt {
  padding-right: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-body);
  /* Lines the smaller label up with the first line of the value. */
  padding-top: calc(var(--space-3) + 0.125rem);
}

.facts dd {
  margin: 0;
}

.history-access__text {
  line-height: var(--line-height-body);
}

.sources {
  display: grid;
  list-style: none;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-body);
}

/* Each source is a full-width row, so even a short title is an easy tap. */
.sources a {
  display: flex;
  align-items: center;
  min-height: var(--tap-target);
  padding-block: var(--space-2);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
}

.sources li + li {
  border-top: 1px solid var(--color-border);
}

/* Streets (S4): "On Cheapside" under a place's facts, and a street's places, as list rows. */
.on-street,
.street-places__list {
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.on-street[hidden] {
  display: none;
}

.street-places__list {
  padding: 0;
  list-style: none;
  overflow: hidden;
}

.street-places__list li + li {
  border-top: 1px solid var(--color-border);
}

.on-street,
.street-place {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-tight);
  text-decoration: none;
  overflow-wrap: anywhere;
  touch-action: manipulation;
}

.on-street:active,
.street-place:active {
  background: var(--color-surface-muted);
}

.on-street:focus-visible,
.street-place:focus-visible {
  outline-offset: -3px;
}

.on-street__name {
  font-weight: var(--font-weight-bold);
}

.on-street__chevron,
.street-place__chevron {
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
  fill: none;
  stroke: var(--color-text-muted);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-actions {
  position: sticky;
  bottom: 0;
  z-index: var(--z-overlay);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  padding: var(--space-3) max(calc(var(--safe-right) + var(--space-4)), calc((100% - var(--page-max-width)) / 2 + var(--space-4)))
    calc(var(--safe-bottom) + var(--space-3)) max(calc(var(--safe-left) + var(--space-4)), calc((100% - var(--page-max-width)) / 2 + var(--space-4)));
  border-top: 1px solid var(--color-bar-border);
  background: var(--color-bar-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
}

.history-actions .button {
  min-height: calc(var(--tap-target) + var(--space-1));
  padding-inline: var(--space-2);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
  text-align: center;
}

/* The Back control's partners on the right of the top bar: Ask, and the chat's buttons. */
.page-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.page-topbar__actions {
  display: flex;
  gap: var(--space-1);
}

.topbar-button,
.topbar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-width: var(--tap-target);
  min-height: var(--tap-target);
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--color-accent);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.topbar-link {
  padding-inline: var(--space-3);
}

.topbar-button[hidden] {
  display: none;
}

.topbar-button:active,
.topbar-link:active {
  background: var(--color-button-bg);
}

.topbar-button svg,
.topbar-link svg {
  width: var(--icon-size-2xl);
  height: var(--icon-size-2xl);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar-link svg {
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
}

/* On the history page, after the write-up: the way into the chat. */
.chat-invite {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-3) var(--space-4);
  align-items: start;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.chat-invite__icon {
  display: grid;
  place-items: center;
  width: var(--icon-circle-size);
  height: var(--icon-circle-size);
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.chat-invite__icon svg {
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}

.chat-invite__text {
  display: grid;
  gap: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.chat-invite__title {
  color: var(--color-text);
  font-size: var(--font-size-lg);
}

.chat-invite__button {
  grid-column: 1 / -1;
}

/*
 * Chat (#/place/<id>/chat). Like the history page it scrolls as a normal page, with the
 * question box stuck to the bottom within thumb reach.
 */
.app:has(> .chat-page) {
  padding: 0;
}

.chat-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(
      180deg,
      color-mix(in srgb, var(--category-color) 10%, var(--color-bg)) 0,
      var(--color-bg) 14rem
    )
    no-repeat;
}

.chat-page__body {
  flex: 1;
  display: grid;
  align-content: start;
  gap: var(--space-5);
  width: 100%;
  max-width: var(--page-max-width);
  margin-inline: auto;
  padding: var(--space-4) calc(var(--safe-right) + var(--space-4)) var(--space-5) calc(var(--safe-left) + var(--space-4));
}

.chat-header {
  display: grid;
  gap: var(--space-1);
}

.chat-header__eyebrow,
.chat-header__model {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.chat-header__title {
  font-size: var(--font-size-2xl);
  line-height: 1.1;
}

.chat-header__title:focus {
  outline: none;
}

.chat-settings {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  /* Clear of the sticky top bar when scrolled into view. */
  scroll-margin-top: calc(var(--safe-top) + var(--tap-target) + var(--space-4));
}

.chat-settings[hidden] {
  display: none;
}

.chat-settings__title {
  font-size: var(--font-size-lg);
}

.chat-settings__intro,
.field__hint {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.field {
  display: grid;
  gap: var(--space-1);
}

.field[hidden] {
  display: none;
}

.field__label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
}

.field__input {
  width: 100%;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-sm);
  background: var(--color-input-bg);
  /* 16px or more, or iOS zooms the page in when the field is focused. */
  font-size: var(--font-size-md);
}

.field__select {
  position: relative;
}

.field__select select {
  appearance: none;
  padding-right: var(--space-6);
}

/* A chevron drawn in CSS, since the select's own arrow is gone with appearance: none. */
.field__select::after {
  content: '';
  position: absolute;
  top: 50%;
  right: var(--space-4);
  width: var(--space-2);
  height: var(--space-2);
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: translateY(-75%) rotate(45deg);
  pointer-events: none;
}

.chat-settings__error {
  color: var(--color-error);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
}

.chat-settings__error:empty {
  display: none;
}

.chat-settings__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chat-settings__actions .button[hidden] {
  display: none;
}

.chat-intro {
  display: grid;
  gap: var(--space-3);
}

.chat-intro[hidden],
.chat-log[hidden] {
  display: none;
}

.chat-intro__text {
  color: var(--color-text-muted);
}

.chat-suggestions {
  display: grid;
  gap: var(--space-2);
  padding: 0;
  list-style: none;
}

.chat-suggestion {
  width: 100%;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-weight: var(--font-weight-medium);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--duration-fast) var(--easing-standard);
}

.chat-suggestion:active {
  background: var(--color-surface-muted);
  transform: scale(0.98);
}

.chat-log {
  display: grid;
  gap: var(--space-5);
  padding: 0;
  list-style: none;
}

.chat-message--user {
  justify-self: end;
  max-width: 85%;
}

.chat-bubble {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  background: var(--color-chat-user-bg);
  color: var(--color-chat-user-text);
  white-space: pre-wrap;
}

.chat-message--assistant {
  display: grid;
  gap: var(--space-3);
}

.chat-prose > * + * {
  margin-top: var(--space-3);
}

.chat-thinking {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
}

.chat-thinking__dots {
  display: inline-flex;
  gap: var(--space-1);
}

.chat-thinking__dots span {
  width: var(--thinking-dot-size);
  height: var(--thinking-dot-size);
  border-radius: var(--radius-pill);
  background: currentColor;
  animation: thinking var(--duration-thinking) var(--easing-standard) infinite;
}

.chat-thinking__dots span:nth-child(2) {
  animation-delay: calc(var(--duration-thinking) / 8);
}

.chat-thinking__dots span:nth-child(3) {
  animation-delay: calc(var(--duration-thinking) / 4);
}

@keyframes thinking {
  0%,
  60%,
  100% {
    opacity: 0.3;
  }

  30% {
    opacity: 1;
  }
}

.chat-meta {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.chat-meta svg {
  width: var(--icon-size-xs);
  height: var(--icon-size-xs);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.chat-sources {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: calc(var(--space-2) * -1);
  padding: 0;
  list-style: none;
}

/* Small chips, but each still a full-height tap target. */
.chat-sources a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  max-width: 100%;
  padding-inline: var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-button-bg);
  color: var(--color-text);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-problem {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-error-soft);
  color: var(--color-error);
  font-weight: var(--font-weight-medium);
}

.chat-problem__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.button--small {
  min-height: var(--tap-target);
  padding-inline: var(--space-4);
  background: var(--color-surface);
  font-size: var(--font-size-sm);
}

.chat-composer {
  position: sticky;
  bottom: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) max(calc(var(--safe-right) + var(--space-4)), calc((100% - var(--page-max-width)) / 2 + var(--space-4)))
    calc(var(--safe-bottom) + var(--space-3)) max(calc(var(--safe-left) + var(--space-4)), calc((100% - var(--page-max-width)) / 2 + var(--space-4)));
  border-top: 1px solid var(--color-bar-border);
  background: var(--color-bar-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
}

.chat-composer[hidden] {
  display: none;
}

.chat-composer__input {
  flex: 1;
  min-height: var(--tap-target);
  max-height: var(--composer-max-height);
  /* Centres one line of text in the tap-target height (less the 1px border). */
  padding: calc(var(--space-2) + 1px) var(--space-4);
  border: 1px solid var(--color-input-border);
  border-radius: calc(var(--tap-target) / 2);
  background: var(--color-input-bg);
  font-size: var(--font-size-md);
  line-height: var(--line-height-body);
  resize: none;
}

.chat-composer__send {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--tap-target);
  height: var(--tap-target);
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--color-accent-gradient);
  color: var(--color-text-on-accent);
  box-shadow: var(--shadow-accent);
  cursor: pointer;
  touch-action: manipulation;
}

.chat-composer__send:active {
  filter: brightness(0.94);
  transform: scale(0.94);
}

.chat-composer__send svg {
  width: var(--icon-size-xl);
  height: var(--icon-size-xl);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* While an answer streams, the button stops it: a filled square, as in other chat apps. */
.chat-composer.is-busy .chat-composer__send {
  background: var(--color-text);
  box-shadow: none;
}

.chat-composer.is-busy .chat-composer__send svg {
  fill: currentColor;
  stroke: none;
}

/*
 * List and progress (#/list). A normal scrolling page with the same top bar as the history
 * page: the progress summary first, then the places.
 */
.app:has(> .list-page) {
  padding: 0;
}

.list-page {
  min-height: 100vh;
  min-height: 100dvh;
}

.list-page__body {
  display: grid;
  gap: var(--space-5);
  width: 100%;
  max-width: var(--page-max-width);
  margin-inline: auto;
  padding: var(--space-5) calc(var(--safe-right) + var(--space-4)) calc(var(--safe-bottom) + var(--space-7))
    calc(var(--safe-left) + var(--space-4));
}

.list-page__title {
  font-size: var(--font-size-3xl);
  line-height: 1.1;
}

.list-page__title:focus {
  outline: none;
}

.progress-summary {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-4) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.progress-summary__kind {
  display: grid;
  gap: var(--space-3);
}

.progress-summary__kind[hidden] {
  display: none;
}

.progress-summary__count {
  color: var(--color-text-muted);
  font-size: var(--font-size-lg);
  line-height: var(--line-height-tight);
}

.progress-summary__count strong {
  margin-right: var(--space-1);
  color: var(--color-text);
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--letter-spacing-display);
  line-height: 1;
}

.progress-bar {
  height: var(--progress-bar-height);
  border-radius: var(--radius-pill);
  background: var(--color-progress-track);
  overflow: hidden;
}

.progress-bar--small {
  height: var(--progress-bar-height-small);
}

.progress-bar__fill {
  display: block;
  width: calc(var(--progress, 0) * 100%);
  height: 100%;
  border-radius: inherit;
  background: var(--color-progress);
}

.category-progress {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3) var(--space-4);
  margin-top: var(--space-1);
  padding: var(--space-4) 0 0;
  border-top: 1px solid var(--color-border);
  list-style: none;
}

.category-progress__item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: var(--space-2);
  row-gap: var(--space-1);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
}

.category-progress__name {
  font-weight: var(--font-weight-medium);
}

.category-progress__count {
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.category-progress .progress-bar {
  grid-column: 1 / -1;
}

.category-progress .progress-bar__fill {
  background: var(--category-color);
}

.list-places {
  display: grid;
  gap: var(--space-4);
}

/* The search box (S6). 16px text, so Safari doesn't zoom in when it's tapped. */
.list-search {
  position: relative;
}

.list-search__icon {
  position: absolute;
  top: 50%;
  left: var(--space-3);
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  transform: translateY(-50%);
  fill: none;
  stroke: var(--color-text-muted);
  stroke-width: 2.5;
  stroke-linecap: round;
  pointer-events: none;
}

.list-search__input {
  width: 100%;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3) var(--space-2) calc(var(--space-3) + var(--icon-size-md) + var(--space-2));
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-pill);
  background: var(--color-input-bg);
  font-size: var(--font-size-md);
  -webkit-appearance: none;
  appearance: none;
}

.list-search__input::placeholder {
  color: var(--color-text-muted);
}

.list-status {
  min-width: 0;
  padding: 0;
  border: none;
}

.segmented__count {
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.list-places__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.list-places__title {
  font-size: var(--font-size-xl);
}

/* A native select, so iOS shows its own picker, drawn as a pill. */
.list-sort {
  position: relative;
  flex: none;
}

.list-sort__select {
  min-height: var(--tap-target);
  padding: 0 calc(var(--space-3) + var(--icon-size-lg)) 0 calc(var(--space-3) + var(--icon-size-2xl));
  border: none;
  border-radius: var(--radius-pill);
  background: var(--color-button-bg);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  touch-action: manipulation;
}

.list-sort__icon,
.list-sort__sort-icon {
  position: absolute;
  top: 50%;
  right: var(--space-3);
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  transform: translateY(-50%);
  fill: none;
  stroke: var(--color-text-muted);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.list-sort__sort-icon {
  right: auto;
  left: var(--space-3);
}

.list-places__groups {
  display: grid;
  gap: var(--space-5);
}

.place-group {
  display: grid;
  gap: var(--space-2);
}

.place-group__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-inline: var(--space-1);
  font-size: var(--font-size-md);
}

.place-list {
  padding: 0;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  list-style: none;
  overflow: hidden;
}

/* Inset rules, starting after the glyph, as in iOS lists. */
.place-list > li + li {
  border-top: 1px solid var(--color-border);
  margin-left: calc(var(--space-4) + var(--list-glyph-size) + var(--space-3));
}

.place-list > li + li > .place-row {
  margin-left: calc((var(--space-4) + var(--list-glyph-size) + var(--space-3)) * -1);
}

.place-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-target);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  color: var(--color-text);
  text-decoration: none;
  touch-action: manipulation;
}

.place-row:active {
  background: var(--color-surface-muted);
}

.place-row:focus-visible {
  outline-offset: -3px;
}

.place-row__glyph {
  align-self: start;
  width: var(--list-glyph-size);
  height: var(--list-glyph-size);
}

.place-row__glyph svg {
  width: var(--icon-size-md);
  height: var(--icon-size-md);
}

.place-row__text {
  display: grid;
  /* Lets a long name or teaser wrap instead of pushing the row wider than the list. */
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-1);
}

.place-row__name {
  overflow-wrap: anywhere;
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
}

/* "Short": a street entry with a paragraph rather than a full history page. */
.place-row__short {
  display: inline-block;
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  line-height: 1.5;
  vertical-align: 0.1em;
}

.place-row__teaser {
  display: -webkit-box;
  overflow: hidden;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.place-row__seen {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-success);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-tight);
}

.place-row__seen svg {
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.place-row__chevron {
  width: var(--icon-size-lg);
  height: var(--icon-size-lg);
  fill: none;
  stroke: var(--color-text-muted);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.list-places__empty {
  max-width: none;
  padding: var(--space-5) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text-muted);
  text-align: center;
}

.list-places__empty[hidden] {
  display: none;
}

/*
 * Narrow phones (iPhone SE 1st generation and similar, 320px wide). Paired buttons drop to
 * smaller text so their labels stay on one line, and the bar's round buttons shrink to
 * leave Surprise me room, still keeping a full tap target.
 */
@media (max-width: 359px) {
  .surprise-bar {
    --button-large-height: 3rem;
  }

  .surprise-button {
    padding-inline: var(--space-3);
    font-size: var(--font-size-md);
  }

  .place-card__directions .button,
  .place-card__bottom .button,
  .place-card__history,
  .all-seen__actions--pair .button {
    padding-inline: var(--space-2);
    font-size: var(--font-size-sm);
  }

  .history-actions {
    gap: var(--space-1);
    padding-inline: calc(var(--safe-left) + var(--space-3)) calc(var(--safe-right) + var(--space-3));
  }

  .history-actions .button {
    padding-inline: var(--space-1);
    /* Bold is a little too wide for "Mark as seen" on one line at this width. */
    font-weight: var(--font-weight-medium);
  }

  /* "Apple" and "Google" are enough beside each other; the links' labels still say Maps. */
  .history-actions__maps {
    display: none;
  }

  .category-progress {
    grid-template-columns: minmax(0, 1fr);
  }
}

/*
 * Landscape on a phone: a sheet across the bottom would cover most of the short screen,
 * including the place it's about. Sheets dock to the bottom left instead, leaving the map
 * on the right clear, and app.js pans the place into that clear area.
 */
@media (orientation: landscape) and (max-height: 500px) {
  .sheet {
    left: calc(var(--safe-left) + var(--space-3));
    right: auto;
    bottom: calc(var(--safe-bottom) + var(--space-3));
    width: min(var(--sheet-max-width), 55%);
    max-height: calc(100% - var(--safe-top) - var(--safe-bottom) - var(--space-3) * 2);
    gap: var(--space-2);
    margin: 0;
    padding: var(--space-3) var(--space-4) var(--space-4);
    border-radius: var(--radius-lg);
    transform: translateY(calc(100% + var(--space-3) + var(--safe-bottom)));
  }

  .sheet.is-open {
    transform: none;
  }

  /* The card stays clear of the header's pills; anything that doesn't fit scrolls. */
  .place-card {
    max-height: calc(
      100% - var(--safe-top) - var(--safe-bottom) - var(--space-3) * 2 - var(--space-2) * 2 - var(--map-pill-height) * 2
    );
  }

  .place-card__title,
  .place-card__teaser {
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
}
