@layer theme {
  :root {
    --font-family-base:
      'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI',
      'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;

    --f4: 1rem;
    --f5: 0.875rem;
    --f6: 0.75rem;
    --f7: 0.625rem;

    --s5: 2rem;
    --s6: 3rem;

    --br-sm: 6px;
    --br-base: 10px;
    --br-lg: 20px;
    --br-full: 9999px;

    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    --primaryH: 207;
    --primaryS: 55%;
    --primaryL: 62%;

    --borderH: 207;
    --borderS: 55%;
    --borderL: 80%;
  }

  :root {
    --header-height: 56px;
    --footer-height: 64px;
    --main-padding: 0;
  }

  html {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  /* ── Map page height chain ──────────────────────────────────────────────── */

  /* Fix body height when map is visible so map fills remaining space */
  body:has(r-home) {
    height: 100dvh;
    overflow: hidden;
  }

  body:has(r-home) > main {
    overflow: hidden;
  }

  r-home {
    display: block;
    height: 100%;
    overflow: hidden;
  }

  /* Centred spinner shown in `main` until the router mounts the first view. */
  .boot-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  m-map {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1;
    padding-bottom: var(--footer-height);
    box-sizing: border-box;
  }

  m-map[hidden],
  header[hidden] {
    display: none;
  }

  m-map #map {
    height: calc(100% + var(--header-height) + var(--footer-height));
    width: 100%;
    margin-top: calc(-1 * var(--header-height));
    margin-bottom: calc(-1 * var(--footer-height));
    /* Shown until the first tiles render; matches the style's background
       layer (mapBackground() in layers.ts) so there's no colour flash. */
    background-color: hsl(47, 26%, 88%);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]) m-map #map,
    :root:not([data-theme]) m-mini-map {
      background-color: hsl(220, 15%, 12%);
    }
  }

  :root[data-theme='dark'] m-map #map,
  :root[data-theme='dark'] m-mini-map {
    background-color: hsl(220, 15%, 12%);
  }

  m-map #map canvas {
    z-index: 1;
  }

  m-map .maplibregl-marker {
    z-index: 5;
  }

  m-map .maplibregl-popup {
    z-index: 100;
  }

  m-map > .download-btn {
    z-index: 10;
  }

  m-map .maplibregl-ctrl-top-left,
  m-map .maplibregl-ctrl-top-right {
    padding-top: var(--header-height);
    z-index: 10;
  }

  m-map .maplibregl-ctrl-bottom-left,
  m-map .maplibregl-ctrl-bottom-right {
    padding-bottom: var(--footer-height);
    z-index: 10;
  }

  m-map .maplibregl-ctrl-group {
    margin-top: var(--header-height);
    margin-bottom: var(--footer-height);
  }

  m-map .maplibregl-ctrl-attrib {
    margin-bottom: var(--footer-height);
  }

  /* MapLibre's built-in controls (zoom, geolocate, attribution) hardcode a
     white button and dark icon glyphs baked into maplibre-gl.css — there's
     no theme hook to recolour them individually. Inverting the whole group
     is safe here (unlike the popups below): every pixel in it is either the
     white surface or a monochrome icon, so invert+hue-rotate turns both into
     a dark surface with a light icon without distorting anything. The user
     location dot (blue, outside this group) is untouched. */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]) m-map .maplibregl-ctrl-group,
    :root:not([data-theme]) m-map .maplibregl-ctrl-attrib,
    :root:not([data-theme]) m-mini-map .maplibregl-ctrl-group,
    :root:not([data-theme]) m-mini-map .maplibregl-ctrl-attrib {
      filter: invert(1) hue-rotate(180deg);
    }
  }

  :root[data-theme='dark'] m-map .maplibregl-ctrl-group,
  :root[data-theme='dark'] m-map .maplibregl-ctrl-attrib,
  :root[data-theme='dark'] m-mini-map .maplibregl-ctrl-group,
  :root[data-theme='dark'] m-mini-map .maplibregl-ctrl-attrib {
    filter: invert(1) hue-rotate(180deg);
  }

  m-map .download-btn {
    position: absolute;
    bottom: calc(var(--footer-height) + var(--s4));
    left: var(--s3);
    padding: var(--s2) var(--s4);
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--br-base);
    font-size: var(--f4);
    font-weight: var(--fw-medium);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10;
    transition: opacity var(--transition-fast);
    height: 3em;
  }

  m-map .download-btn:hover {
    opacity: 0.9;
  }

  /* Map options. Top-left, clearing the header the map sits under. Just the
     icon until opened, so the map stays uncluttered. */
  m-map .map-menu {
    position: absolute;
    top: var(--s3);
    left: var(--s3);
    z-index: 10;
  }

  /* The map runs under the header where a route mounts one (the list view);
     on the map route the header is empty, so there's nothing to clear. */
  body:has(header > *) m-map .map-menu {
    top: calc(var(--header-height) + var(--s3));
  }

  m-map .map-menu-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    /* Tracks the app theme (`--background`/`--body`) rather than a fixed
       light surface, so the control matches the rest of the chrome instead
       of staying a light chip against a dark map. */
    background: color-mix(in srgb, var(--background) 92%, transparent);
    color: var(--body);
    border: none;
    border-radius: var(--br-base);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    transition: opacity var(--transition-fast);
  }

  m-map .map-menu-button:hover {
    opacity: 0.85;
  }

  m-map .map-menu-panel {
    position: absolute;
    top: calc(100% + var(--s2));
    left: 0;
    min-width: 240px;
    padding: var(--s2);
    background: color-mix(in srgb, var(--background) 97%, transparent);
    color: var(--body);
    border-radius: var(--br-base);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  }

  m-map .map-menu-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    padding: var(--s2);
    font-size: var(--f5);
    cursor: pointer;
  }

  m-map .map-menu-row > span {
    display: flex;
    flex-direction: column;
  }

  m-map .map-menu-hint {
    font-size: var(--f6);
    opacity: 0.6;
  }

  m-map .map-menu-zoom {
    margin: 0;
    padding: var(--s2);
    border-top: 1px solid color-mix(in srgb, currentColor 12%, transparent);
    font-size: var(--f6);
    opacity: 0.6;
  }

  m-map .map-menu-row select {
    font-size: var(--f5);
    color: inherit;
    background: var(--background);
    border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
    border-radius: var(--br-sm);
    padding: var(--s1) var(--s2);
  }

  m-map .map-menu-lists {
    padding: var(--s2);
    border-top: 1px solid color-mix(in srgb, currentColor 12%, transparent);
    font-size: var(--f5);
  }

  m-map .map-menu-lists summary {
    cursor: pointer;
  }

  m-map .map-menu-list-option {
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s2) var(--s2) var(--s2) var(--s4);
    font-size: var(--f5);
    cursor: pointer;
  }

  /* MapLibre popups hardcode a white background (maplibre-gl.css), so both
     the surface and the text need an explicit, theme-aware colour instead of
     the library's fixed #fff/inherited body text — the tip triangle below
     gets the same treatment so it doesn't stay a white sliver on a dark
     popup. Not done with a blanket filter: unlike the ctrl-group icons,
     popups can contain real photo thumbnails, which a filter would invert.
     `!important`: this whole file lives in `@layer theme`, and maplibre-gl.css
     is unlayered — unlayered rules always beat layered ones regardless of
     source order, so without it the background stayed stuck at the library's
     `#fff` while the text below (which the library doesn't set) still
     switched to the dark theme's light body colour, leaving white-on-white. */
  m-map .maplibregl-popup-content,
  .maplibregl-popup-content {
    background: var(--background) !important;
  }

  m-map .maplibregl-popup-content,
  m-map .maplibregl-popup-content a,
  .maplibregl-popup-content,
  .maplibregl-popup-content a {
    color: var(--body);
  }

  .maplibregl-popup-content input,
  .maplibregl-popup-content textarea {
    color: var(--body);
    background: var(--background);
  }

  .maplibregl-popup-anchor-top .maplibregl-popup-tip,
  .maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
  .maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
    border-bottom-color: var(--background) !important;
  }

  .maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
  .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
  .maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
    border-top-color: var(--background) !important;
  }

  .maplibregl-popup-anchor-left .maplibregl-popup-tip {
    border-right-color: var(--background) !important;
  }

  .maplibregl-popup-anchor-right .maplibregl-popup-tip {
    border-left-color: var(--background) !important;
  }

  /* Popup bodies (m-bookmark-add-popup / m-bookmark-view-popup). MapLibre
     mounts popup content inside the map element's light DOM, so ordinary
     page classes reach it — no inline styles needed. */
  .bm-popup {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .bm-popup--add {
    min-width: 180px;
  }

  .bm-popup-address {
    margin: 0;
    font-size: 0.75em;
    opacity: 0.6;
    word-break: break-word;
    max-width: 220px;
  }

  .bm-popup input[type='text'] {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  .bm-popup-save {
    width: 100%;
  }

  .bm-popup-thumbs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
  }

  .bm-popup-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 3px;
    cursor: pointer;
    display: block;
  }

  .bm-popup-link {
    font-size: 0.8em;
  }

  /* ── Icons ────────────────────────────────────────────────────────────── */

  /* Monochrome icons painted as a mask so they inherit `currentColor`. An
     SVG in an `<img>` is a separate document and can't be recoloured from
     here, which is why it stayed black when the theme went dark. See
     `utils/icon.ts`. */
  .icon {
    display: inline-block;
    flex: none;
    width: 1em;
    height: 1em;
    background-color: currentColor;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
  }

  /* ── Header ───────────────────────────────────────────────────────────── */

  header {
    border-bottom: 1px solid currentColor;
    /* Civility lays out `body` as a grid with `header` as a grid item, whose
       default `min-width: auto` sizes it to the nowrap h1's full text width —
       pushing the header actions off-screen instead of letting the title
       ellipsize. */
    min-width: 0;
  }

  ui-header-content,
  m-header,
  m-bookmark-header,
  m-bookmarks-header,
  m-list-header {
    display: flex;
    align-items: center;
    gap: var(--s2);
    height: var(--header-height);
    padding: 0 var(--container-padding);
  }

  /* The share dialog is a header child for lifecycle reasons only; keep it
     out of the flex row. */
  m-bookmark-header civ-share-dialog,
  m-list-header civ-share-dialog {
    display: contents;
  }

  m-bookmark-header .bm-icon-btn {
    width: 34px;
    height: 34px;
  }

  m-list-header .list-view-count {
    font-size: var(--f5);
    opacity: 0.6;
    white-space: nowrap;
  }

  ui-header-content h1,
  m-header h1,
  m-bookmark-header h1,
  m-bookmarks-header h1,
  m-list-header h1 {
    flex: 1;
    margin: 0;
    font-size: var(--f4);
    font-weight: var(--fw-semibold);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  ui-header-content .header-back,
  m-header .header-back,
  m-bookmark-header .header-back,
  m-list-header .header-back {
    background: transparent;
    border: none;
    padding: var(--s1);
    color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
  }

  m-header .header-back .icon,
  m-bookmark-header .header-back .icon,
  m-list-header .header-back .icon {
    width: 20px;
    height: 20px;
  }

  ui-header-content .header-actions,
  m-header .header-actions,
  m-bookmark-header .header-actions,
  m-bookmarks-header .header-actions,
  m-list-header .header-actions {
    display: flex;
    align-items: center;
    gap: var(--s2);
  }

  /* Reserves a little room for the title so the header-actions row (which
     never shrinks — see `.bm-icon-btn`) starts folding into the overflow
     menu before the title is squeezed to nothing. */
  m-bookmark-header h1 {
    min-width: 3rem;
  }

  /* A trigger + panel used wherever actions collapse behind a
     `more-vertical` button: the bookmarks list toolbar, the list detail
     header, and the bookmark detail header once it runs out of room. */
  .header-menu {
    position: relative;
  }

  .header-menu-panel {
    position: absolute;
    top: calc(100% + var(--s2));
    right: 0;
    min-width: 180px;
    padding: var(--s1);
    display: flex;
    flex-direction: column;
    background: color-mix(in srgb, var(--primary) 6%, var(--background));
    color: var(--body);
    border-radius: var(--br-base);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    z-index: 20;
  }

  .header-menu-item {
    display: flex;
    align-items: center;
    gap: var(--s2);
    width: 100%;
    padding: var(--s2);
    background: transparent;
    border: none;
    border-radius: var(--br-sm);
    color: inherit;
    font-size: var(--f5);
    text-align: left;
    cursor: pointer;
  }

  .header-menu-item:hover {
    background: color-mix(in srgb, currentColor 8%, transparent);
  }

  .header-menu-item--danger {
    color: var(--error);
  }

  /* ── Fixed bottom tab bar ──────────────────────────────────────────────── */

  footer[fixed] {
    padding: 0;
    height: var(--footer-height);
  }

  ui-bottom-bar .icon {
    width: 24px;
    height: 24px;
  }

  /* ── Page host elements ────────────────────────────────────────────────── */

  r-search,
  r-settings,
  r-settings-downloads,
  r-settings-about,
  r-bookmarks {
    display: block;
    padding: var(--s4) var(--s3);
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    box-sizing: border-box;
  }

  /* ── Generic settings sections ──────────────────────────────────────────── */

  r-settings section,
  r-settings-downloads section,
  r-settings-about section {
    margin-bottom: var(--s5);
  }

  r-settings h2,
  r-settings-downloads h2,
  r-settings-about h2 {
    font-size: var(--f4);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--s3);
  }

  r-settings section > p,
  r-settings-downloads section > p,
  r-settings-about section > p {
    opacity: 0.6;
    margin-bottom: var(--s3);
    font-size: var(--f5);
  }

  /* A select sitting in the same row layout as the settings toggles. */
  .settings-select {
    width: auto;
    min-width: 8rem;
    margin: 0;
  }

  /* ── Settings nav links (to sub-pages) ────────────────────────────────── */

  .settings-nav-list {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
  }

  .settings-nav-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s3);
    border: 1px solid currentColor;
    border-radius: var(--br-base);
    text-decoration: none;
    color: inherit;
    font-weight: var(--fw-medium);
    font-size: var(--f5);
    transition: opacity var(--transition-fast);
  }

  .settings-nav-link:hover {
    opacity: 0.7;
  }

  .settings-nav-link-meta {
    font-size: var(--f6);
    opacity: 0.5;
    font-weight: var(--fw-normal);
    margin-top: 2px;
  }

  /* ── Data actions (import/export) ────────────────────────────────────── */

  .action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    padding: var(--s3);
    border: 1px solid currentColor;
    border-radius: var(--br-base);
    text-decoration: none;
    color: inherit;
    font-weight: var(--fw-medium);
    transition: opacity var(--transition-base);
    width: 100%;
    box-sizing: border-box;
    background: transparent;
    font-size: var(--f5);
  }

  .action:hover {
    opacity: 0.7;
    transform: none;
  }

  .action--danger {
    color: var(--error);
    border-color: var(--error);
  }

  /* An .action sized to its content — for buttons sitting inside a row. */
  .action--compact {
    width: auto;
    padding: var(--s2) var(--s3);
  }

  /* ── civ-sync-input component ─────────────────────────────────────────────── */

  civ-sync-input form {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
  }

  civ-sync-input label {
    display: flex;
    flex-direction: column;
    gap: var(--s1);
    cursor: default;
    border: none;
    padding: 0;
    font-weight: var(--fw-normal);
    border-radius: 0;
    background: none;
  }

  civ-sync-input label span {
    font-size: var(--f6);
    opacity: 0.7;
  }

  civ-sync-input label input {
    width: 100%;
    box-sizing: border-box;
  }

  civ-sync-input .ui-sync-input__error {
    font-size: var(--f6);
    color: hsl(var(--errorH), var(--errorS), var(--errorL));
    margin: 0;
  }

  civ-sync-input .ui-sync-input__error code {
    font-family: var(--font-family-mono);
    font-size: var(--f7);
    opacity: 0.8;
  }

  civ-sync-input .ui-sync-input__status {
    display: flex;
    align-items: baseline;
    gap: var(--s3);
    margin-bottom: var(--s3);
  }

  civ-sync-input .ui-sync-input__status small {
    opacity: 0.6;
  }

  civ-sync-input .ui-sync-input__indicator {
    font-weight: var(--fw-medium);
  }

  civ-sync-input .ui-sync-input__indicator--ok {
    color: hsl(var(--successH), var(--successS), var(--successL));
  }

  civ-sync-input .ui-sync-input__indicator--syncing {
    opacity: 0.7;
  }

  civ-sync-input .ui-sync-input__actions {
    display: flex;
    align-items: center;
    gap: var(--s3);
    flex-wrap: wrap;
  }

  civ-sync-input .ui-sync-input__actions .action {
    width: auto;
    padding: var(--s2) var(--s4);
  }

  /* ── civ-sync-state component ─────────────────────────────────────────────── */
  civ-store-import div {
    display: flex;
    gap: var(--s3);
    margin-bottom: var(--s3);
  }

  /* Shared dot shape — used by both badge and inline/detailed inner dot */
  .ui-sync-state--badge,
  .ui-sync-state__dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  /* Badge: the root span IS the dot */
  .ui-sync-state--badge {
    background: currentColor;
    opacity: 0.3;
  }

  /* Status colors — applied via modifier class on the wrapper */
  .ui-sync-state--ok .ui-sync-state__dot,
  .ui-sync-state--badge.ui-sync-state--ok {
    background: hsl(var(--successH), var(--successS), var(--successL));
    opacity: 1;
  }

  .ui-sync-state--syncing .ui-sync-state__dot,
  .ui-sync-state--badge.ui-sync-state--syncing {
    background: hsl(var(--primaryH), var(--primaryS), var(--primaryL));
    opacity: 0.7;
  }

  .ui-sync-state--error .ui-sync-state__dot,
  .ui-sync-state--badge.ui-sync-state--error {
    background: hsl(var(--errorH), var(--errorS), var(--errorL));
    opacity: 1;
  }

  .ui-sync-state--disconnected .ui-sync-state__dot,
  .ui-sync-state--badge.ui-sync-state--disconnected {
    background: currentColor;
    opacity: 0.3;
  }

  /* Inline variant */
  .ui-sync-state--inline {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    font-size: var(--f6);
  }

  /* Detailed variant */
  .ui-sync-state--detailed {
    display: flex;
    flex-direction: column;
    gap: var(--s1);
  }

  .ui-sync-state--detailed .ui-sync-state__row {
    display: flex;
    align-items: center;
    gap: var(--s2);
    font-weight: var(--fw-medium);
  }

  .ui-sync-state--detailed .ui-sync-state__meta {
    font-size: var(--f6);
    opacity: 0.6;
  }

  .ui-sync-state--detailed .ui-sync-state__error {
    font-size: var(--f6);
    color: hsl(var(--errorH), var(--errorS), var(--errorL));
    margin: 0;
  }

  .ui-sync-state--detailed .ui-sync-state__error code {
    font-family: var(--font-family-mono);
    font-size: var(--f7);
  }

  .settings-data-status--error {
    color: var(--error);
  }

  /* ── Downloads page ─────────────────────────────────────────────────────── */

  .tile-list {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
  }

  .tile-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    padding: var(--s3);
    border: 1px solid currentColor;
    border-radius: var(--br-base);
  }

  .tile-item-info {
    flex: 1;
    min-width: 0;
  }

  .tile-item-name {
    font-weight: var(--fw-semibold);
    font-size: var(--f5);
    display: block;
  }

  .tile-item-meta {
    font-size: var(--f6);
    opacity: 0.6;
    margin-top: 2px;
  }

  .tile-item-action {
    display: flex;
    align-items: center;
    gap: var(--s2);
    flex-shrink: 0;
  }

  .tile-status-cached {
    font-size: var(--f6);
    font-weight: var(--fw-medium);
    color: var(--success);
    white-space: nowrap;
  }

  /* ── Search page ────────────────────────────────────────────────────────── */

  .search-input-wrap {
    margin-bottom: var(--s3);
  }

  .search-input-wrap input[type='search'] {
    width: 100%;
    padding: var(--s2) var(--s3);
    border-radius: var(--br-full);
    font-size: var(--f5);
    box-sizing: border-box;
    margin: 0;
  }

  .search-section-title {
    font-size: var(--f6);
    font-weight: var(--fw-semibold);
    opacity: 0.45;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: var(--s3) 0 var(--s1) 0;
    padding: 0;
  }

  .search-history-list {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    max-width: 95vw;
    margin: auto;
  }

  .search-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s3) var(--s3);
    gap: var(--s3);
    cursor: pointer;
    background: transparent;
    border: 1px solid currentColor;
    border-radius: var(--br-base);
    color: inherit;
    text-align: left;
    font-size: var(--f5);
    width: 100%;
    min-width: 0;
    transition: opacity var(--transition-fast);
  }

  .search-history-item:hover {
    opacity: 0.6;
    transform: none;
  }

  .search-history-item > span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .search-empty {
    padding: var(--s5) var(--s3);
    text-align: center;
    opacity: 0.5;
    font-size: var(--f5);
  }

  .search-history-clear {
    display: flex;
    justify-content: flex-end;
    padding: var(--s1) 0 var(--s2);
  }

  /* ── Bookmarks page ─────────────────────────────────────────────────────── */

  .bm-empty {
    padding: var(--s5) var(--s3);
    text-align: center;
    opacity: 0.5;
    font-size: var(--f5);
  }

  .bm-empty--folder {
    padding: var(--s3);
  }

  .bm-folder {
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s3);
    border: 1px solid currentColor;
    border-radius: var(--br-base);
    color: inherit;
    text-decoration: none;
  }

  .bm-folder-name {
    flex: 1;
    font-weight: var(--fw-semibold);
    font-size: var(--f5);
  }

  .bm-folder-count {
    font-size: var(--f6);
    opacity: 0.5;
    flex-shrink: 0;
  }

  .bm-section {
    margin-bottom: var(--s2);
  }

  .bm-section-title {
    font-size: var(--f6);
    font-weight: var(--fw-semibold);
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--s2);
    padding: 0 var(--s3);
  }

  .bm-folder,
  .bm-section {
    max-width: 90vw;
    margin: var(--s2) auto var(--s2) auto;
  }

  .bm-item {
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s2) var(--s3);
  }

  /* The row body is the link to the bookmark's page; the trailing icon
     buttons stay separately clickable. */
  .bm-item-info {
    flex: 1;
    min-width: 0;
    display: block;
    color: inherit;
    text-decoration: none;
  }

  .bm-item-name {
    display: block;
    font-size: var(--f5);
    font-weight: var(--fw-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .bm-item-coords {
    display: block;
    font-size: var(--f6);
    opacity: 0.5;
    margin-top: 1px;
  }

  .bm-item-actions {
    display: flex;
    align-items: center;
    gap: var(--s1);
    flex-shrink: 0;
  }

  .bm-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--br-sm);
    cursor: pointer;
    opacity: 0.6;
    flex-shrink: 0;
    transition: opacity var(--transition-fast);
  }

  .bm-icon-btn:hover {
    opacity: 1;
    transform: none;
  }

  .bm-item-checkbox {
    flex-shrink: 0;
  }

  /* "Select" mode toolbar — select-all + count on the left, a
     `.header-menu`-style Actions dropdown on the right. */
  .bm-select-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s2);
    padding: var(--s2) var(--s3);
    max-width: 90vw;
    margin: 0 auto var(--s2) auto;
  }

  .bm-select-all {
    display: flex;
    align-items: center;
    gap: var(--s2);
    font-size: var(--f5);
    font-weight: var(--fw-medium);
  }

  .bm-select-actions {
    position: relative;
  }

  .bm-select-actions-btn {
    display: flex;
    align-items: center;
    gap: var(--s1);
    padding: var(--s1) var(--s2);
    background: transparent;
    border: 1px solid currentColor;
    border-radius: var(--br-sm);
    color: inherit;
    font-size: var(--f5);
    cursor: pointer;
  }

  .bm-select-actions-btn:hover {
    opacity: 0.7;
    transform: none;
  }

  .bm-select-actions-btn:disabled {
    opacity: 0.4;
    cursor: default;
  }

  .bm-select-actions .header-menu-panel {
    right: 0;
  }

  .bm-add-form {
    margin-top: var(--s3);
    padding: var(--s3);
    border: 1px solid currentColor;
    border-radius: var(--br-base);
    display: flex;
    flex-direction: column;
    gap: var(--s2);
  }

  .bm-coord-row {
    display: flex;
    gap: var(--s2);
  }

  .bm-coord-row input {
    flex: 1;
    min-width: 0;
  }

  .bm-form-actions {
    display: flex;
    gap: var(--s2);
  }

  .bm-btn-danger {
    margin-left: auto;
    color: var(--error);
  }

  /* ── Bookmark edit dialog ───────────────────────────────────────────────── */

  .bm-dialog {
    padding: var(--s4);
    min-width: min(320px, 90vw);
    display: flex;
    flex-direction: column;
    gap: var(--s3);
  }

  .bm-dialog-title {
    font-size: var(--f4);
    font-weight: var(--fw-semibold);
    margin: 0;
  }

  .bm-dialog form {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
  }

  .bm-dialog .bm-form-actions {
    margin-top: var(--s1);
  }

  .bm-dialog textarea {
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
    font-size: var(--f5);
  }

  .bm-dialog-coords {
    font-size: var(--f6);
    opacity: 0.5;
    margin: 0;
    font-variant-numeric: tabular-nums;
  }

  /* `<civ-share-link>`'s URL is one unbreakable token; without help it forces
     the flex row (and the dialog around it) wider than the viewport instead
     of wrapping, which is what forced the horizontal scroll. */
  civ-share-link {
    display: block;
    min-width: 0;
  }

  .civ-share-link {
    min-width: 0;
  }

  .civ-share-link__url {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .bm-export-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2);
  }

  .bm-scope-toggle {
    display: flex;
    gap: var(--s2);
  }

  .bm-scope-btn {
    flex: 1;
    padding: var(--s2);
    border: 1px solid currentColor;
    border-radius: var(--br-sm);
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    opacity: 0.7;
  }

  .bm-scope-btn:hover {
    opacity: 1;
  }

  .bm-scope-btn[aria-pressed='true'] {
    background: var(--success);
    border-color: transparent;
    color: white;
    opacity: 1;
  }

  .bm-image-thumb {
    position: relative;
    width: 80px;
    height: 80px;
    flex-shrink: 0;
  }

  .bm-image-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
    display: block;
  }

  .bm-image-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    padding: 0;
    line-height: 1;
    font-size: 14px;
    border-radius: 50%;
    cursor: pointer;
  }

  .bm-image-add {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border: 2px dashed currentColor;
    border-radius: 4px;
    font-size: 24px;
    opacity: 0.5;
    cursor: pointer;
    flex-shrink: 0;
  }

  .bm-image-add:hover {
    opacity: 1;
  }

  /* A lightbox isn't a card: drop the dialog's width cap, background and
     shadow so the photo itself is the surface, and darken the backdrop. */
  dialog:has(.bm-lightbox) {
    max-width: none;
    width: auto;
    background: transparent;
    box-shadow: none;
  }

  dialog:has(.bm-lightbox)::backdrop {
    opacity: 0.85;
  }

  .bm-lightbox {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .bm-lightbox img {
    max-width: 96vw;
    max-height: 90vh;
    object-fit: contain;
    display: block;
    border-radius: var(--br-sm);
    cursor: zoom-out;
  }

  /* ── Import confirmation dialog ─────────────────────────────────────────── */

  .bm-import-error {
    font-size: var(--f6);
    color: var(--error);
    margin: 0 0 var(--s3);
  }

  .bm-import-summary {
    font-size: var(--f5);
    opacity: 0.6;
    margin: 0;
  }

  .bm-import-group + .bm-import-group {
    border-top: 1px solid currentColor;
  }

  .bm-import-group-name {
    font-size: var(--f6);
    font-weight: var(--fw-semibold);
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
    padding: var(--s2) var(--s3) var(--s1);
  }

  .bm-import-item {
    padding: var(--s2) var(--s3);
    display: flex;
    flex-direction: column;
    gap: 1px;
  }

  .bm-import-item + .bm-import-item {
    border-top: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  }

  .bm-import-item--duplicate {
    opacity: 0.4;
  }

  .bm-import-dupe-badge {
    font-size: var(--f7);
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.7;
  }

  /* ── Welcome dialog ─────────────────────────────────────────────────────── */

  .welcome-dialog {
    padding: var(--s4);
    min-width: min(420px, 90vw);
    display: flex;
    flex-direction: column;
    gap: var(--s3);
  }

  .welcome-title {
    font-size: var(--f3);
    font-weight: var(--fw-semibold);
    margin: 0;
  }

  .welcome-intro {
    margin: 0;
    font-size: var(--f5);
    opacity: 0.75;
  }

  .welcome-section {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    padding-top: var(--s3);
    border-top: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  }

  .welcome-section h3 {
    margin: 0;
    font-size: var(--f4);
    font-weight: var(--fw-semibold);
  }

  .welcome-muted {
    margin: 0;
    font-size: var(--f6);
    opacity: 0.6;
  }

  .welcome-link {
    font-size: var(--f5);
    color: var(--primary);
    text-decoration: none;
    padding: var(--s1) 0;
    align-self: flex-start;
  }

  .welcome-link:hover {
    opacity: 0.7;
  }

  .welcome-done {
    margin: 0;
    font-size: var(--f6);
    color: var(--success);
    font-weight: var(--fw-medium);
  }

  .welcome-error {
    margin: 0;
    font-size: var(--f6);
    color: var(--error);
  }

  .welcome-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--s2);
  }

  .welcome-tile-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--s2);
  }

  .welcome-tile-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    padding: var(--s2) var(--s3);
    border: 1px solid currentColor;
    border-radius: var(--br-base);
  }

  .welcome-tile-label {
    font-size: var(--f5);
    font-weight: var(--fw-medium);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .welcome-tile-action {
    flex-shrink: 0;
  }

  @media (max-width: 768px) {
    input,
    textarea,
    select {
      font-size: 1rem;
    }
  }

  /* ── Public shared-location viewer (?id=&server=) ─────────────────────── */

  .share-view-loading {
    display: flex;
    justify-content: center;
    padding: var(--s6) 0;
  }

  .share-view {
    display: block;
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem;
  }

  /* Shared by the public share viewer and the bookmark detail page. Tall enough
     to be worth panning around in, without pushing the details below the fold. */
  m-mini-map {
    display: block;
    width: 100%;
    height: min(60vh, 380px);
    border-radius: var(--br-base);
    overflow: hidden;
    background: hsl(47, 26%, 88%);
  }

  m-mini-map .mini-map {
    width: 100%;
    height: 100%;
  }

  /* ── Bookmark detail page ──────────────────────────────────────────────── */

  /* Matches the other page hosts: centred column, page gutter, and room for
     the fixed tab bar. */
  .bookmark-page {
    display: block;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: var(--s3) var(--s3) calc(var(--footer-height) + var(--s4));
    box-sizing: border-box;
  }

  .bookmark-page-body {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
    padding: var(--s3) 0 0;
  }

  /* The name is already the header title; in the body it's a quieter anchor. */
  .bookmark-page-title {
    margin: 0;
    font-size: var(--f4);
    font-weight: var(--fw-semibold);
  }

  .bookmark-page-body > * {
    margin: 0;
  }

  /* A value with its copy button beside it. */
  .bookmark-page-field {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin: 0;
  }

  .bookmark-page-field > span:first-child {
    min-width: 0;
  }

  .bookmark-page-copy {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--br-sm);
    color: inherit;
    opacity: 0.55;
    cursor: pointer;
  }

  .bookmark-page-copy:hover {
    opacity: 1;
  }

  .bookmark-page-lists {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2);
    margin: 0;
  }

  .bookmark-page-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    padding: 0.15rem 0.55rem;
    border: 1px solid color-mix(in srgb, currentColor 25%, transparent);
    border-radius: var(--br-full);
    font-size: var(--f6);
    text-decoration: none;
    color: inherit;
  }

  .bookmark-page-chip-dot {
    width: 0.6em;
    height: 0.6em;
    border-radius: 50%;
  }

  /* Name, address and coordinates as one block; the verbs live in the header. */
  .bookmark-page-head-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
  }

  .bookmark-page-lists-field {
    border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
    border-radius: var(--br-base);
    padding: var(--s2) var(--s3);
  }

  .bookmark-page-lists-field legend {
    font-size: var(--f6);
    opacity: 0.6;
    padding: 0 var(--s2);
  }

  .bookmark-page-list-option {
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s2) 0;
    cursor: pointer;
  }

  .bookmark-page-list-option input {
    width: auto;
    margin: 0;
  }

  .bookmark-page-form {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
  }

  /* Header icon button in its "on" state (visited). */
  .bm-icon-btn--on {
    background: var(--success);
    color: white;
    border-radius: var(--br-sm);
  }

  /* Header icon button in its "on" state (favorite). */
  .bm-icon-btn--favorite-on {
    background: var(--pink);
    color: white;
    border-radius: var(--br-sm);
  }

  /* The heart badge shown next to a favorited location's name — the map
     popup, shared-list rows, and the owner's own bookmarks/detail pages. */
  .bm-favorite-badge {
    color: var(--pink);
    font-size: 0.9em;
    display: inline-flex;
    vertical-align: -0.1em;
  }

  /* The share icon shown next to a list/bookmark's name on `/bookmarks` when
     it currently has a live public link. */
  .bm-share-badge {
    opacity: 0.6;
    font-size: 0.9em;
    display: inline-flex;
    vertical-align: -0.1em;
  }

  .share-view-body {
    padding: 1rem 0.25rem;
  }

  .share-view-swatch,
  .bm-folder-swatch {
    display: inline-block;
    width: 0.7em;
    height: 0.7em;
    border-radius: 50%;
    vertical-align: baseline;
    flex-shrink: 0;
  }

  /* Sized to its own content so `@container` below can react to how much
     room is actually left once the title has taken its share. */
  .share-view-header {
    container-type: inline-size;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s2);
    margin-bottom: 0.35rem;
  }

  .share-view-actions {
    display: flex;
    flex-shrink: 0;
    gap: var(--s1);
  }

  .share-view-action-btn {
    display: flex;
    align-items: center;
    gap: 0.35em;
    padding: var(--s1) var(--s2);
    background: transparent;
    border: none;
    border-radius: var(--br-sm);
    color: inherit;
    font: inherit;
    font-weight: var(--fw-medium);
    white-space: nowrap;
    cursor: pointer;
    opacity: 0.75;
  }

  .share-view-action-btn:hover {
    opacity: 1;
    background: color-mix(in srgb, currentColor 8%, transparent);
  }

  /* Collapses to icon-only once the row is too tight for both buttons'
     labels and a long list title — the header itself is the query
     container, so this reacts to the title's actual length too. */
  @container (max-width: 380px) {
    .share-view-action-label {
      display: none;
    }
  }

  .share-view-list {
    list-style: none;
    margin: 0.5rem 0 1rem;
    padding: 0;
    display: flex;
    flex-direction: column;
  }

  .share-view-list-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    border-bottom: 1px solid color-mix(in srgb, currentColor 12%, transparent);
  }

  .share-view-list-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
    min-width: 0;
    text-align: left;
    background: transparent;
    border: none;
    padding: 0.6rem 0.25rem;
    cursor: pointer;
    color: inherit;
    font: inherit;
  }

  .share-view-list-item:hover {
    background: color-mix(in srgb, currentColor 5%, transparent);
  }

  .share-view-list-name {
    font-weight: var(--fw-medium);
  }

  .share-view-list-meta {
    font-size: 0.8em;
    opacity: 0.6;
    word-break: break-word;
  }

  .share-view-list-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 32px;
    height: 32px;
    margin-top: 0.4rem;
    background: transparent;
    border: none;
    border-radius: var(--br-sm);
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition-fast), transform
      var(--transition-fast);
  }

  .share-view-list-toggle:hover {
    opacity: 1;
  }

  .share-view-list-toggle[aria-expanded='true'] {
    transform: rotate(180deg);
  }

  .share-view-list-detail {
    flex: 1 1 100%;
    padding: 0 0.25rem 0.6rem;
  }

  .share-view-list-empty {
    list-style: none;
    opacity: 0.7;
    padding: 0.6rem 0.25rem;
  }

  .share-view-reset {
    margin-left: 0.5rem;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    text-decoration: underline;
    opacity: 0.8;
    cursor: pointer;
  }

  .share-view-reset:hover {
    opacity: 1;
  }

  .share-view-title {
    margin: 0;
    font-size: 1.25rem;
    min-width: 0;
    overflow-wrap: break-word;
  }

  /* The tick is an icon now, so it needs to sit on the text baseline. */
  .share-view-visited,
  .bm-visited-badge {
    color: var(--success);
    font-size: 0.9em;
    display: inline-flex;
    vertical-align: -0.1em;
  }

  .share-view-coords {
    margin: 0 0 0.5rem;
    opacity: 0.6;
    font-size: var(--f6);
    font-variant-numeric: tabular-nums;
  }

  .share-view-address {
    margin: 0 0 0.5rem;
    font-size: var(--f5);
  }

  .share-view-description {
    margin: 0 0 0.75rem;
    white-space: pre-wrap;
  }

  /* On the detail page the photo grid carries its own [+] tile, so it needs to
     lay out like the editor's grid rather than a plain image row. */
  .bookmark-page .share-view-images {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2);
    align-items: center;
  }

  .bookmark-page .share-view-images .bm-image-thumb,
  .bookmark-page .share-view-images .share-view-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
  }

  .share-view-images {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
  }

  .share-view-image {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: var(--br-sm);
    display: block;
  }

  .bookmark-page-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s2);
    margin: 0 0 0.75rem;
    padding: 0;
    list-style: none;
  }

  .bookmark-page-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.3rem 0.6rem;
    border: 1px solid color-mix(in srgb, currentColor 25%, transparent);
    border-radius: var(--br-full);
    font-size: var(--f5);
    text-decoration: none;
    color: inherit;
    transition: opacity var(--transition-fast);
  }

  .bookmark-page-link:hover {
    opacity: 0.7;
  }

  .bookmark-page-links-field {
    border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
    border-radius: var(--br-base);
    padding: var(--s2) var(--s3);
    display: flex;
    flex-direction: column;
    gap: var(--s2);
  }

  .bookmark-page-links-field legend {
    font-size: var(--f6);
    opacity: 0.6;
    padding: 0 var(--s2);
  }

  .bookmark-page-link-row {
    display: flex;
    align-items: center;
    gap: var(--s2);
  }

  .bookmark-page-link-row input {
    flex: 1;
    min-width: 0;
  }

  .bookmark-page-link-remove {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--br-sm);
    color: inherit;
    opacity: 0.55;
    cursor: pointer;
  }

  .bookmark-page-link-remove:hover {
    opacity: 1;
  }

  .share-view-open {
    display: inline-block;
    margin-top: 0.5rem;
    color: var(--primary);
    font-weight: 600;
  }

  .bookmark-page-visitor-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--s3);
  }

  .bookmark-page-export-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    margin-top: 0.5rem;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--primary);
    font-weight: 600;
    font-size: inherit;
    font-family: inherit;
    cursor: pointer;
  }

  .bookmark-page-export-btn:hover {
    opacity: 0.7;
  }

  .share-view-error {
    opacity: 0.7;
  }
}
