/* ============================================================
   ruter base theme — Dansk Cykelturisme
   ------------------------------------------------------------
   Everything here lives in named cascade layers. Any CSS a
   product writes outside these layers wins over them, whatever
   its specificity, so extending the theme never needs
   !important or heavier selectors:

     1. change tokens       :root { --ruter-accent: #043465; }
     2. restyle a part      ruter-legend [data-part="item"] { … }
     3. add your own layer  @layer app { … }

   Load MapLibre's stylesheet through this file only (it is
   imported into ruter.vendor below). A separate unlayered
   <link> to maplibre-gl.css would override the map chrome.
   ============================================================ */

@layer ruter.vendor, ruter.tokens, ruter.base, ruter.components;

@import url("./maplibre-gl.74e94ccfd98f.css") layer(ruter.vendor);

/* ── Tokens ──────────────────────────────────────────────────
   Named by role, not by colour, so a product can re-skin
   without knowing how components use them.                    */

@layer ruter.tokens {
  :root {
    /* Type */
    --ruter-font: "Miki", ui-sans-serif, system-ui, sans-serif;
    --ruter-weight-regular: 400;
    --ruter-weight-bold: 700;
    --ruter-weight-heavy: 800;
    --ruter-text-xs: 0.75rem;
    --ruter-text-sm: 0.875rem;
    --ruter-text-base: 1rem;
    --ruter-text-lg: 1.125rem;
    --ruter-text-xl: 1.25rem;
    --ruter-leading: 1.4;

    /* Colour */
    --ruter-paper: #faf7f1;        /* page canvas */
    --ruter-paper-deep: #f3eee3;
    --ruter-surface: #ffffff;      /* cards, panels, controls */
    --ruter-ink: #12291d;          /* primary text */
    --ruter-ink-soft: #47594e;
    --ruter-ink-faint: #7d8a81;
    --ruter-border: #e9f2ee;
    --ruter-accent: #229966;
    --ruter-accent-strong: #17724b; /* fills under white text; worked out from the accent below */
    --ruter-accent-soft: #e9f2ee;   /* hover tint; worked out from the accent below */
    --ruter-on-accent: #ffffff;
    --ruter-danger: #d64933;        /* destructive actions */
    --ruter-danger-strong: #a03423; /* worked out from the danger colour, like the accent's */
    --ruter-danger-soft: #faece9;
    --ruter-on-danger: #ffffff;
    --ruter-focus: color-mix(in srgb, var(--ruter-accent) 45%, transparent);

    /* Translucent ink, so they sit on any background */
    --ruter-divider: rgb(0 0 0 / 0.12);        /* rules between rows */
    --ruter-outline: rgb(0 0 0 / 0.15);        /* outlined controls */
    --ruter-outline-strong: rgb(0 0 0 / 0.4);
    --ruter-wash: rgb(0 0 0 / 0.04);           /* hover on outlined controls */
    --ruter-sunken: rgb(12 59 38 / 0.06);      /* track behind toggle groups */
    --ruter-highlight: color-mix(in srgb, var(--ruter-accent-strong) 9%, transparent);

    /* Shape & space */
    --ruter-radius: 8px;
    --ruter-radius-lg: 12px;       /* cards */
    --ruter-radius-pill: 999px;
    --ruter-space-1: 0.25rem;
    --ruter-space-2: 0.5rem;
    --ruter-space-3: 0.75rem;
    --ruter-space-4: 1rem;
    --ruter-space-5: 1.25rem;
    --ruter-space-6: 1.5rem;

    /* Control sizes: every control (buttons, pills, toggle group, select, dropdown-menu
       items, map buttons) is one of these fixed heights, picked
       with size="sm|md|lg" on the element. md is the default.     */
    --ruter-control-sm: 28px;
    --ruter-control-md: 36px;
    --ruter-control-lg: 44px;

    /* Elevation & motion */
    --ruter-shadow-1: 0 1px 2px rgb(18 41 29 / 0.06), 0 4px 12px -6px rgb(18 41 29 / 0.2);
    --ruter-shadow-2: 0 2px 4px rgb(18 41 29 / 0.06), 0 18px 40px -16px rgb(18 41 29 / 0.28);
    --ruter-ease-out: cubic-bezier(0.22, 1, 0.36, 1);

    /* Cards: media size beside (orientation="horizontal") or above the body */
    --ruter-card-media-width: 10rem;
    --ruter-card-media-ratio: 16 / 9;

    /* Panels: width beside the map, and the most of the map a bottom sheet
       (phones) may cover before its content scrolls */
    --ruter-panel-width: 22rem;
    --ruter-panel-height: 60%;

    /* Height of a product's sticky header: where linked-to items land */
    --ruter-scroll-offset: var(--ruter-space-6);

    /* Map — read by the map components at runtime.
       Numbers are unitless because MapLibre takes pixels.
       Data colours (--ruter-suitability-<key>, --ruter-surface-<key>,
       --ruter-transport-<key>) default to taxonomy.json; set them
       here only to override.                                       */
    --ruter-map-font: "Miki";
    --ruter-map-inset: var(--ruter-space-3);
    --ruter-map-scrim: rgb(0 0 0 / 0.15);       /* over a locked map */
    --ruter-map-hint-scrim: rgb(0 0 0 / 0.45);  /* behind the cooperative gestures hint */
    --ruter-route-color: var(--ruter-accent);
    --ruter-route-casing: var(--ruter-paper);
    --ruter-route-width: 5;
    --ruter-route-casing-width: 8;
    /* A hovered or selected road (<ruter-taxonomy-layer interactive>):
       a solid line over a wide, soft glow                           */
    --ruter-map-highlight: #3b82f6;
    --ruter-map-highlight-width: 4;
    --ruter-map-highlight-glow: rgb(147 197 253 / 0.5);
    --ruter-map-highlight-glow-width: 12;
  }

  /* The accent's shades follow --ruter-accent, so a product that sets
     only the accent gets matching fills and hover tints. The danger
     colour's shades follow --ruter-danger the same way. With the
     default accent they give the literal values above. The strong
     shade's lightness is capped at OKLCH 0.52, so white text on it
     stays at 5:1 or better whatever the accent. Set either token
     yourself to override it. Browsers without relative colours keep
     the literals.                                                   */
  @supports (color: oklch(from red l c h)) {
    :root {
      --ruter-accent-strong: oklch(from var(--ruter-accent) min(l - 0.116, 0.52) calc(c * 0.81) h);
      --ruter-accent-soft: oklch(from var(--ruter-accent) 0.953 calc(c * 0.085) h);
      --ruter-danger-strong: oklch(from var(--ruter-danger) min(l - 0.116, 0.52) calc(c * 0.81) h);
      --ruter-danger-soft: oklch(from var(--ruter-danger) 0.953 calc(c * 0.085) h);
    }
  }
}

/* ── Base: the structure primitives need to work ─────────── */

@layer ruter.base {
  ruter-map {
    display: block;
    position: relative;
    min-height: 240px;
  }

  ruter-map > [data-part="canvas"] {
    position: absolute;
    inset: 0;
  }

  /* Control areas sit in the map's corners, under the lock's scrim (z-index 3).
     Only their contents take clicks, so the map still pans between them. */
  ruter-map-controls {
    position: absolute;
    z-index: 2;
    top: var(--ruter-map-inset);
    right: var(--ruter-map-inset);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: calc(100% - 2 * var(--ruter-map-inset));
    pointer-events: none;
  }

  ruter-map-controls > * {
    pointer-events: auto;
  }

  ruter-map-controls[position^="bottom"] {
    top: auto;
    bottom: var(--ruter-map-inset);
  }

  ruter-map-controls[position$="left"] {
    right: auto;
    left: var(--ruter-map-inset);
    align-items: flex-start;
  }

  /* The lock button has the top-left corner; an area there goes below it */
  ruter-map[gestures="locked"] > ruter-map-controls[position="top-left"] {
    top: calc(2 * var(--ruter-map-inset) + var(--_ruter-control-height, 36px));
  }

  :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-scale, ruter-map-attribution, ruter-map-terrain, ruter-map-globe, ruter-map-button) {
    display: block;
  }

  ruter-map-attribution > [data-part="text"][hidden] {
    display: none;
  }

  /* <ruter-map-fullscreen> where the browser has no element full screen.
     Important, so the page's own size for the map (often inline) gives way. */
  ruter-map[data-fullscreen="pseudo"] {
    position: fixed !important;
    inset: 0 !important;
    z-index: 2147483000;
    width: auto !important;
    height: auto !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
  }

  /* gestures="…" stacks its scrim and hints inside the map, so their
     z-indexes never reach the page. */
  ruter-map[gestures] {
    isolation: isolate;
  }

  /* gestures="locked": a scrim over the map, its controls and legend (z-index
     2) catches the click that activates it; the lock button is on top. */

  ruter-map > [data-part="lock-scrim"] {
    position: absolute;
    inset: 0;
    z-index: 3;
  }

  ruter-map[data-state="unlocked"] > [data-part="lock-scrim"] {
    visibility: hidden;
    pointer-events: none;
  }

  ruter-map > [data-part="lock"] {
    position: absolute;
    z-index: 4;
    display: inline-flex;
    align-items: center;
  }

  ruter-taxonomy-layer,
  ruter-route-line {
    display: none;
  }

  ruter-legend {
    display: block;
  }

  ruter-legend [data-part="list"] {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  ruter-accordion {
    display: block;
  }

  ruter-badge {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
  }

  ruter-badge [data-part="icon"] {
    display: block;
    flex: none;
  }

  ruter-button {
    display: inline-flex;
    vertical-align: middle;
  }

  /* Fills the host, so widening <ruter-button> widens the button */
  ruter-button > :is(button, a) {
    flex: auto;
  }

  ruter-button [data-part="icon"] {
    display: block;
    flex: none;
  }

  ruter-icon {
    --_ruter-icon-size: var(--ruter-icon-size, 1em);
    display: inline-block;
    flex: none;
    inline-size: var(--_ruter-icon-size);
    block-size: var(--_ruter-icon-size);
    vertical-align: -0.125em;
  }

  ruter-icon > svg {
    display: block;
    inline-size: 100%;
    block-size: 100%;
    stroke-width: var(--ruter-icon-stroke, 2);
  }

  ruter-pills {
    display: flex;
    flex-wrap: wrap;
  }

  ruter-toggle-group {
    display: inline-flex;
  }

  /* One <form> per option (e.g. a server-side language switch) */
  ruter-toggle-group form {
    display: contents;
  }

  /* Items can be <label>s wrapping a radio or checkbox: hide the input, keep it focusable */
  :is(ruter-pills, ruter-toggle-group) [data-part="item"]:has(> input) {
    position: relative;
  }

  :is(ruter-pills, ruter-toggle-group) [data-part="item"] > input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
  }

  ruter-dropdown-menu {
    display: inline-block;
  }

  /* The theme draws the chevron on the host, over the select */
  ruter-select {
    position: relative;
    display: inline-flex;
    vertical-align: middle;
  }

  ruter-select > select {
    appearance: none;
  }

  ruter-select::after {
    pointer-events: none;
  }

  /* Until the element upgrades and makes the content a popover */
  ruter-dropdown-menu:not(:defined) [data-part="content"] {
    display: none;
  }

  ruter-card {
    position: relative;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
  }

  /* Popups (RuterPopup subclasses; add new popovers to these lists): a
     column of header, content and footer where only the content scrolls.
     Closed, they're hidden. */
  :is(ruter-panel) {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  :is(ruter-panel):not([open]) {
    visibility: hidden;
  }

  :is(ruter-panel) > :is([data-part="header"], [data-part="footer"]) {
    flex: none;
  }

  :is(ruter-panel) > [data-part="content"] {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* A panel floats over its map, above the map's controls, legend and lock
     (an app's own UI, so a locked map doesn't block it). Beside the map on wider screens, full height; a bottom sheet on
     phones, as tall as its content up to --ruter-panel-height. */
  ruter-panel {
    position: absolute;
    z-index: 5;
    inset-block: var(--ruter-map-inset);
    inset-inline-start: var(--ruter-map-inset);
    width: min(var(--ruter-panel-width), 100% - 2 * var(--ruter-map-inset));
  }

  ruter-panel[side="end"] {
    inset-inline: auto var(--ruter-map-inset);
  }

  @media (max-width: 639px) {
    ruter-panel,
    ruter-panel[side="end"] {
      inset: auto 0 0;
      width: auto;
      max-height: var(--ruter-panel-height);
    }
  }

  /* A link part stretches over the whole card. Other links, buttons and
     fields in a linked card sit above it, so they stay usable. */
  ruter-card [data-part="link"]::after {
    content: "";
    position: absolute;
    inset: 0;
  }

  ruter-card:has([data-part="link"]) :is(a[href], button, input, select, textarea, label, summary, [tabindex]):not([data-part="link"]) {
    position: relative;
    z-index: 1;
  }
}

/* ── Components ──────────────────────────────────────────── */

@layer ruter.components {
  /* Control sizes. size="sm|md|lg" on a control element picks its
     fixed height, text size and inline padding; md is the default.
     The --_ruter-control-* properties are internal: set the
     --ruter-control-<size> tokens instead.                      */

  :is(ruter-button, ruter-pills, ruter-toggle-group, ruter-dropdown-menu, ruter-select, ruter-map) {
    --_ruter-control-height: var(--ruter-control-md);
    --_ruter-control-text: var(--ruter-text-sm);
    --_ruter-control-padding: 14px;
  }

  :is(ruter-button, ruter-pills, ruter-toggle-group, ruter-dropdown-menu, ruter-select, ruter-map)[size="sm"] {
    --_ruter-control-height: var(--ruter-control-sm);
    --_ruter-control-text: var(--ruter-text-xs);
    --_ruter-control-padding: 10px;
  }

  :is(ruter-button, ruter-pills, ruter-toggle-group, ruter-dropdown-menu, ruter-select, ruter-map)[size="lg"] {
    --_ruter-control-height: var(--ruter-control-lg);
    --_ruter-control-text: var(--ruter-text-base);
    --_ruter-control-padding: 18px;
  }

  /* Button variants. variant="primary|outline|ghost|muted|surface" on
     <ruter-button> (also a dropdown menu's trigger); outline|ghost|muted
     on <ruter-pills> (primary would leave nothing to show selection
     with) and <ruter-select>. Defaults: primary for buttons, outline
     for pills and selects.
     The --_ruter-button-* properties are internal.               */

  :is(ruter-button, ruter-pills, ruter-select)[variant="ghost"] {
    --_ruter-button-bg: transparent;
    --_ruter-button-fg: var(--ruter-ink-soft);
    --_ruter-button-border: transparent;
    --_ruter-button-hover-bg: var(--ruter-accent-soft);
    --_ruter-button-hover-fg: var(--ruter-accent-strong);
    --_ruter-button-hover-border: transparent;
  }

  ruter-pills,
  ruter-select,
  :is(ruter-button, ruter-pills, ruter-select)[variant="outline"] {
    --_ruter-button-bg: transparent;
    --_ruter-button-fg: var(--ruter-ink);
    --_ruter-button-border: var(--ruter-outline);
    --_ruter-button-hover-bg: var(--ruter-wash);
    --_ruter-button-hover-fg: var(--ruter-ink);
    --_ruter-button-hover-border: var(--ruter-outline-strong);
  }

  :is(ruter-button, ruter-pills, ruter-select)[variant="muted"] {
    --_ruter-button-bg: var(--ruter-sunken);
    --_ruter-button-fg: var(--ruter-ink);
    --_ruter-button-border: transparent;
    --_ruter-button-hover-bg: color-mix(in srgb, var(--ruter-accent-strong) 12%, transparent);
    --_ruter-button-hover-fg: var(--ruter-ink);
    --_ruter-button-hover-border: transparent;
  }

  /* The map's lock-button look: white, a 2px border, a shadow, the
     accent border on hover. <ruter-map> draws its lock button with it,
     and variant="surface" gives an app's buttons over a map the same
     look. (Map controls are outline buttons on a white fill.) */
  ruter-map,
  ruter-button[variant="surface"] {
    --_ruter-button-bg: var(--ruter-surface);
    --_ruter-button-fg: var(--ruter-ink);
    --_ruter-button-border: var(--ruter-border);
    --_ruter-button-hover-bg: var(--ruter-paper);
    --_ruter-button-hover-fg: var(--ruter-ink);
    --_ruter-button-hover-border: var(--ruter-accent);
  }

  /* Colour. color="accent|neutral|danger" on <ruter-button> and
     <ruter-badge> picks the hue; variant picks how it's applied.
     Without it nothing changes: a primary button and every badge use
     the accent, and the other button variants are neutral.
     color="neutral" only changes a primary button (an ink fill): the
     other variants are neutral already.
     The --_ruter-color-* properties are internal.                */

  :is(ruter-button, ruter-badge) {
    --_ruter-color: var(--ruter-accent);
    --_ruter-color-strong: var(--ruter-accent-strong);
    --_ruter-color-soft: var(--ruter-accent-soft);
    --_ruter-on-color: var(--ruter-on-accent);
    --_ruter-color-hover: color-mix(in srgb, var(--_ruter-color-strong) 80%, var(--ruter-ink));
  }

  :is(ruter-button, ruter-badge)[color="danger"] {
    --_ruter-color: var(--ruter-danger);
    --_ruter-color-strong: var(--ruter-danger-strong);
    --_ruter-color-soft: var(--ruter-danger-soft);
    --_ruter-on-color: var(--ruter-on-danger);
  }

  :is(ruter-button, ruter-badge)[color="neutral"] {
    --_ruter-color: var(--ruter-ink-soft);
    --_ruter-color-strong: var(--ruter-ink);
    --_ruter-color-soft: var(--ruter-wash);
    --_ruter-on-color: var(--ruter-surface);
    --_ruter-color-hover: var(--ruter-ink-soft);
  }

  /* A standalone button fills with the strong shade: white bold text on
     --ruter-accent is under 4.5:1 at control sizes. */
  ruter-button,
  ruter-button[variant="primary"] {
    --_ruter-button-bg: var(--_ruter-color-strong);
    --_ruter-button-fg: var(--_ruter-on-color);
    --_ruter-button-border: var(--_ruter-color-strong);
    --_ruter-button-hover-bg: var(--_ruter-color-hover);
    --_ruter-button-hover-fg: var(--_ruter-on-color);
    --_ruter-button-hover-border: var(--_ruter-color-hover);
  }

  ruter-button[color]:not([color="neutral"])[variant="outline"] {
    --_ruter-button-fg: var(--_ruter-color-strong);
    --_ruter-button-border: var(--_ruter-color);
    --_ruter-button-hover-bg: var(--_ruter-color-soft);
    --_ruter-button-hover-fg: var(--_ruter-color-strong);
    --_ruter-button-hover-border: var(--_ruter-color-strong);
  }

  ruter-button[color]:not([color="neutral"])[variant="ghost"] {
    --_ruter-button-fg: var(--_ruter-color-strong);
    --_ruter-button-hover-bg: var(--_ruter-color-soft);
    --_ruter-button-hover-fg: var(--_ruter-color-strong);
  }

  ruter-button[color]:not([color="neutral"])[variant="muted"] {
    --_ruter-button-bg: color-mix(in srgb, var(--_ruter-color-strong) 8%, transparent);
    --_ruter-button-fg: var(--_ruter-color-strong);
    --_ruter-button-hover-bg: color-mix(in srgb, var(--_ruter-color-strong) 14%, transparent);
    --_ruter-button-hover-fg: var(--_ruter-color-strong);
  }

  ruter-button[color]:not([color="neutral"])[variant="surface"] {
    --_ruter-button-fg: var(--_ruter-color-strong);
    --_ruter-button-hover-fg: var(--_ruter-color-strong);
    --_ruter-button-hover-border: var(--_ruter-color);
  }

  /* Map */

  ruter-map {
    font-family: var(--ruter-font);
    color: var(--ruter-ink);
    background: var(--ruter-paper-deep);
    border-radius: var(--ruter-radius);
    overflow: hidden;
  }

  ruter-map .maplibregl-map {
    font-family: inherit;
  }

  /* Map controls are <ruter-button variant="outline" square>s at the map's
     size (36px at md), on a white fill with a soft shadow so the map doesn't
     show through. Tints go over the white. <ruter-button-group> joins
     several, as the zoom buttons are. */

  ruter-map-controls {
    gap: var(--ruter-space-2);
  }

  /* Take the size from <ruter-map> rather than the button's own default */
  :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-terrain, ruter-map-globe, ruter-map-button) > ruter-button:not([size]) {
    --_ruter-control-height: inherit;
    --_ruter-control-text: inherit;
    --_ruter-control-padding: inherit;
  }

  :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-terrain, ruter-map-globe, ruter-map-button, ruter-map-attribution) > ruter-button[variant] > [data-part="button"] {
    --_tint: transparent;
    background: linear-gradient(var(--_tint), var(--_tint)) var(--ruter-surface);
    box-shadow: var(--ruter-shadow-1);
    -webkit-tap-highlight-color: transparent;
  }

  :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-terrain, ruter-map-globe, ruter-map-button, ruter-map-attribution) > ruter-button[variant] > [data-part="button"]:hover {
    --_tint: var(--ruter-wash);
    background: linear-gradient(var(--_tint), var(--_tint)) var(--ruter-surface);
  }

  :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-terrain, ruter-map-globe, ruter-map-button, ruter-map-attribution) > ruter-button[variant] > [data-part="button"]:focus-visible {
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  /* Faded, the map would show through: grey the icon instead */
  :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-terrain, ruter-map-globe, ruter-map-button, ruter-map-attribution) > ruter-button[variant] > [data-part="button"]:disabled {
    --_tint: transparent;
    opacity: 1;
    color: var(--ruter-ink-faint);
    background: linear-gradient(var(--_tint), var(--_tint)) var(--ruter-surface);
    cursor: default;
  }

  /* On: a pressed toggle, an open panel's button, a followed position */
  :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-terrain, ruter-map-globe, ruter-map-button, ruter-map-attribution) > ruter-button[variant] > [data-part="button"]:is([aria-pressed="true"], [aria-expanded="true"]) {
    --_tint: var(--ruter-accent-soft);
    color: var(--ruter-accent-strong);
    background: linear-gradient(var(--_tint), var(--_tint)) var(--ruter-surface);
    border-color: var(--ruter-accent);
  }

  /* A group casts one shadow, not one per button */
  ruter-button-group:has(> :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-terrain, ruter-map-globe, ruter-map-button)) {
    box-shadow: var(--ruter-shadow-1);
  }

  ruter-button-group :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
    ruter-map-terrain, ruter-map-globe, ruter-map-button, ruter-map-attribution) > ruter-button[variant] > [data-part="button"]:not(:focus-visible) {
    box-shadow: none;
  }

  /* The geolocate button stays pressed while the map has moved off the
     position, but without the tint */
  ruter-map-geolocate[data-state="background"] [data-part="button"] {
    --_tint: transparent;
    color: var(--ruter-ink);
    border-color: var(--ruter-outline);
  }

  ruter-map-geolocate[data-state="locating"] [data-part="icon"] {
    animation: ruter-map-locating 1s ease-in-out infinite alternate;
  }

  @keyframes ruter-map-locating {
    to { opacity: 0.35; }
  }

  ruter-map-geolocate[data-state="error"] [data-part="icon"] {
    color: var(--ruter-ink-faint);
  }

  ruter-map-compass [data-part="icon"] {
    transition: rotate 0.1s linear;
  }

  /* The position: a dot, and a circle for its accuracy (sized inline) */

  ruter-map [data-part="user-location"] {
    box-sizing: border-box;
    width: 18px;
    height: 18px;
    border: 3px solid var(--ruter-surface);
    border-radius: 50%;
    background: var(--ruter-accent);
    box-shadow: 0 0 0 1px var(--ruter-outline), var(--ruter-shadow-1);
  }

  ruter-map [data-part="accuracy"] {
    box-sizing: border-box;
    border: 1px solid color-mix(in srgb, var(--ruter-accent) 40%, transparent);
    border-radius: 50%;
    background: color-mix(in srgb, var(--ruter-accent) 12%, transparent);
    pointer-events: none;
  }

  /* Attribution: a small round info button (sm, whatever the map's size)
     that opens into a pill of credits */

  ruter-map-attribution {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    max-width: 100%;
    border-radius: var(--ruter-radius-pill);
    font-size: var(--ruter-text-xs);
    line-height: 1.3;
    color: var(--ruter-ink-soft);
  }

  ruter-map-attribution[open] {
    background: color-mix(in srgb, var(--ruter-surface) 85%, transparent);
  }

  ruter-map-attribution > ruter-button {
    flex: none;
  }

  ruter-map-attribution > [data-part="text"] {
    padding: 4px var(--ruter-space-2) 4px var(--ruter-space-3);
  }

  ruter-map-attribution a {
    color: inherit;
  }

  /* Scale: a bar to scale with the distance inside it */

  ruter-map-scale [data-part="bar"] {
    box-sizing: border-box;
    padding: 0 4px;
    border: 2px solid var(--ruter-ink-soft);
    border-top: 0;
    background: color-mix(in srgb, var(--ruter-surface) 75%, transparent);
    font-size: var(--ruter-text-xs);
    line-height: 1.4;
    color: var(--ruter-ink);
    white-space: nowrap;
  }

  ruter-map:fullscreen,
  ruter-map[data-fullscreen] {
    border-radius: 0;
  }

  ruter-map .maplibregl-popup-content {
    font-family: var(--ruter-font);
    color: var(--ruter-ink);
    background: var(--ruter-surface);
    border: 2px solid var(--ruter-border);
    border-radius: var(--ruter-radius);
    box-shadow: var(--ruter-shadow-2);
    padding: var(--ruter-space-3) var(--ruter-space-4);
  }

  /* gestures="cooperative": MapLibre's hint ("Use Ctrl + scroll…"), in the
     theme's type, under the controls rather than over the whole page. */

  ruter-map .maplibregl-cooperative-gesture-screen {
    z-index: 1;
    padding: var(--ruter-space-6);
    background: var(--ruter-map-hint-scrim);
    color: var(--ruter-on-accent);
    font-family: var(--ruter-font);
    font-size: var(--ruter-text-lg);
    font-weight: var(--ruter-weight-bold);
    line-height: var(--ruter-leading);
    text-align: center;
  }

  /* gestures="locked": a round lock icon and, while locked, the label as an accent
     pill beside it. Once active only the icon shows; the label stays as the
     button's accessible name. data-pulse hints at it when the user wheels or
     pinches over the locked map. */

  ruter-map > [data-part="lock-scrim"] {
    background: var(--ruter-map-scrim);
    cursor: pointer;
    transition: opacity 0.3s, visibility 0.3s;
  }

  ruter-map[data-state="unlocked"] > [data-part="lock-scrim"] {
    opacity: 0;
  }

  ruter-map > [data-part="lock"] {
    top: var(--ruter-map-inset);
    left: var(--ruter-map-inset);
    gap: calc(var(--ruter-space-2) + 4px); /* + the label's 4px ring */
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-size: var(--_ruter-control-text);
    color: var(--_ruter-button-fg);
    cursor: pointer;
    transform-origin: left center;
    -webkit-tap-highlight-color: transparent;
  }

  ruter-map > [data-part="lock"]:focus-visible {
    outline: none;
  }

  ruter-map > [data-part="lock"] [data-part="lock-icon"] {
    box-sizing: border-box;
    flex: none;
    width: var(--_ruter-control-height);
    height: var(--_ruter-control-height);
    padding: calc(var(--_ruter-control-height) * 0.22);
    background-color: var(--_ruter-button-bg);
    border: 2px solid var(--_ruter-button-border);
    border-radius: var(--ruter-radius-pill);
    box-shadow: var(--ruter-shadow-1);
    transition: border-color 0.15s, background-color 0.15s;
  }

  /* Hovering the locked map hovers the button too: a click anywhere activates it */
  ruter-map > [data-part="lock"]:hover [data-part="lock-icon"],
  ruter-map[data-state="locked"] > [data-part="lock-scrim"]:hover ~ [data-part="lock"] [data-part="lock-icon"] {
    background-color: var(--_ruter-button-hover-bg);
    border-color: var(--_ruter-button-hover-border);
  }

  ruter-map > [data-part="lock"]:focus-visible [data-part="lock-icon"] {
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  ruter-map > [data-part="lock"] [data-part="lock-label"] {
    display: inline-flex;
    align-items: center;
    height: calc(var(--_ruter-control-height) - 12px);
    padding-inline: var(--ruter-space-2);
    background: var(--ruter-accent);
    color: var(--ruter-on-accent);
    border-radius: var(--ruter-radius-pill);
    box-shadow: 0 0 0 4px var(--ruter-surface), var(--ruter-shadow-1);
    white-space: nowrap;
  }

  ruter-map > [data-part="lock"]:hover [data-part="lock-label"],
  ruter-map[data-state="locked"] > [data-part="lock-scrim"]:hover ~ [data-part="lock"] [data-part="lock-label"] {
    background: var(--ruter-accent-strong);
  }

  ruter-map[data-state="unlocked"] > [data-part="lock"] [data-part="lock-label"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
  }

  ruter-map > [data-part="lock"][data-pulse] {
    animation: ruter-map-lock-pulse 0.55s ease 3;
  }

  ruter-map > [data-part="lock"][data-pulse] [data-part="lock-icon"] {
    animation: ruter-map-lock-glow 0.55s ease 3;
  }

  @keyframes ruter-map-lock-pulse {
    50% { scale: 1.08; }
  }

  @keyframes ruter-map-lock-glow {
    50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ruter-accent) 40%, transparent); }
  }

  /* A legend placed inside a map floats over it */
  ruter-map > ruter-legend {
    position: absolute;
    left: var(--ruter-map-inset);
    bottom: var(--ruter-map-inset);
    z-index: 2;
    max-width: calc(100% - 2 * var(--ruter-map-inset));
    background: var(--ruter-surface);
    border-radius: var(--ruter-radius);
    box-shadow: var(--ruter-shadow-2);
    padding: var(--ruter-space-3);
  }

  /* Legend */

  ruter-legend {
    font-family: var(--ruter-font);
    font-size: var(--ruter-text-sm);
    line-height: var(--ruter-leading);
    color: var(--ruter-ink);
  }

  ruter-legend [data-part="heading"] {
    margin: 0 0 var(--ruter-space-2);
    font-size: var(--ruter-text-xs);
    font-weight: var(--ruter-weight-bold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ruter-ink-soft);
  }

  ruter-legend [data-part="list"] {
    display: grid;
    gap: var(--ruter-space-1);
  }

  ruter-legend[orientation="horizontal"] [data-part="list"] {
    grid-auto-flow: column;
    gap: var(--ruter-space-3);
  }

  ruter-legend [data-part="item"] {
    display: flex;
    align-items: center;
    gap: var(--ruter-space-2);
  }

  ruter-legend [data-part="swatch"] {
    flex: none;
    width: 1.5rem;
    height: 0.375rem;
    border-radius: var(--ruter-radius-pill);
    background: var(--ruter-swatch);
  }

  /* Toggle legends (filters) */
  ruter-legend [data-part="toggle"] {
    all: unset;
    display: flex;
    align-items: center;
    gap: var(--ruter-space-2);
    margin: calc(-1 * var(--ruter-space-1));
    padding: var(--ruter-space-1);
    border-radius: calc(var(--ruter-radius) / 2);
    cursor: pointer;
  }

  ruter-legend [data-part="toggle"]:hover {
    background: var(--ruter-accent-soft);
  }

  ruter-legend [data-part="toggle"]:focus-visible {
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  ruter-legend [data-part="item"][data-state="off"] [data-part="swatch"] {
    opacity: 0.25;
  }

  ruter-legend [data-part="item"][data-state="off"] [data-part="label"] {
    color: var(--ruter-ink-faint);
    text-decoration: line-through;
  }

  /* Width scales: the swatch shows the line weight, not a colour */
  ruter-legend[data-kind="width"] [data-part="swatch"] {
    height: calc(var(--ruter-swatch-width) * 1px);
    background: var(--ruter-ink-soft);
  }

  /* Dashed categories (ferry, railway) */
  ruter-legend [data-part="item"][data-dashed] [data-part="swatch"] {
    height: 0;
    background: none;
    border-top: 3px dashed var(--ruter-swatch);
    border-radius: 0;
  }

  /* Accordion */

  ruter-accordion {
    font-family: var(--ruter-font);
    line-height: var(--ruter-leading);
    color: var(--ruter-ink);
    border-top: 1px solid var(--ruter-divider);
  }

  ruter-accordion [data-part="item"] {
    border-bottom: 1px solid var(--ruter-divider);
    scroll-margin-top: var(--ruter-scroll-offset);
    transition: background-color 0.6s var(--ruter-ease-out);
  }

  /* Just arrived at via a link: tint it, bleeding into the gutter so text doesn't move */
  ruter-accordion [data-part="item"][data-state="targeted"] {
    margin-inline: calc(-1 * var(--ruter-space-3));
    padding-inline: var(--ruter-space-3);
    border-radius: var(--ruter-radius);
    background: var(--ruter-highlight);
  }

  ruter-accordion [data-part="trigger"] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ruter-space-4);
    padding: var(--ruter-space-4) 0;
    font-size: var(--ruter-text-base);
    font-weight: var(--ruter-weight-bold);
    list-style: none;
    cursor: pointer;
    /* Clicking it toggles; it shouldn't also select its text */
    -webkit-user-select: none;
    user-select: none;
  }

  ruter-accordion [data-part="trigger"]::-webkit-details-marker {
    display: none;
  }

  ruter-accordion [data-part="trigger"]:hover {
    color: var(--ruter-accent-strong);
  }

  ruter-accordion [data-part="trigger"]:focus-visible {
    outline: none;
    border-radius: calc(var(--ruter-radius) / 2);
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  /* A plus that becomes a minus: icons/plus.svg, its two strokes masked
     separately so the upright can fold away. Drawn in CSS, so it shows
     without JavaScript too. */
  ruter-accordion [data-part="marker"] {
    position: relative;
    flex: none;
    width: 1.25em;
    height: 1.25em;
  }

  ruter-accordion [data-part="marker"]::before,
  ruter-accordion [data-part="marker"]::after {
    content: "";
    position: absolute;
    inset: 0;
    background: currentColor;
    mask: no-repeat center / 100%;
  }

  ruter-accordion [data-part="marker"]::before {
    mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><path d='M5 12h14'/></svg>");
  }

  ruter-accordion [data-part="marker"]::after {
    mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><path d='M12 5v14'/></svg>");
    transition: transform 0.2s var(--ruter-ease-out);
  }

  ruter-accordion [open] > [data-part="trigger"] [data-part="marker"]::after {
    transform: scaleY(0);
  }

  /* Slide the content open and shut. ::details-content wraps everything
     after the summary; a 0fr → 1fr grid row animates to the content's
     own height, and content-visibility is held over (allow-discrete) so
     the closing slide is visible before the browser hides the content.
     Browsers without ::details-content snap open and shut as before. */
  ruter-accordion [data-part="item"]::details-content {
    display: grid;
    grid-template-rows: 0fr;
    /* Clip only vertically, so focus rings at the sides still show */
    overflow: visible clip;
    transition:
      grid-template-rows 0.2s var(--ruter-ease-out),
      content-visibility 0.2s allow-discrete;
  }

  ruter-accordion [data-part="item"][open]::details-content {
    grid-template-rows: 1fr;
  }

  ruter-accordion [data-part="content"] {
    min-height: 0;
    max-width: 68ch;
    color: var(--ruter-ink-soft);
  }

  /* The space below the content. Padding would set a floor under the
     collapsing row, so the last 1.25rem would snap rather than slide. */
  ruter-accordion [data-part="content"]::after {
    content: "";
    display: block;
    height: 1.25rem;
  }

  ruter-accordion [data-part="content"] > :first-child {
    margin-top: 0;
  }

  ruter-accordion [data-part="content"] > :last-child {
    margin-bottom: 0;
  }

  /* Badge. A static label (a facility, a certification), not a control,
     so its sizes sit below the control heights: sm 22px, md 28px,
     lg 36px (lines up with md controls). An optional icon part
     comes first; inline SVGs drawn with currentColor follow the
     variant. The --_ruter-badge-* properties are internal.       */

  ruter-badge {
    --_ruter-badge-height: 28px;
    --_ruter-badge-text: var(--ruter-text-sm);
    --_ruter-badge-padding: 12px;
    --_ruter-badge-gap: 6px;
    --_ruter-badge-fg: var(--_ruter-color-strong);
    --_ruter-badge-bg: transparent;
    --_ruter-badge-border: var(--_ruter-color-strong);
    box-sizing: border-box;
    gap: var(--_ruter-badge-gap);
    block-size: var(--_ruter-badge-height);
    padding: 0 var(--_ruter-badge-padding);
    font-family: var(--ruter-font);
    font-size: var(--_ruter-badge-text);
    font-weight: var(--ruter-weight-bold);
    line-height: 1;
    white-space: nowrap;
    color: var(--_ruter-badge-fg);
    background: var(--_ruter-badge-bg);
    border: 1px solid var(--_ruter-badge-border);
    border-radius: var(--ruter-radius-pill);
  }

  ruter-badge[size="sm"] {
    --_ruter-badge-height: 22px;
    --_ruter-badge-text: var(--ruter-text-xs);
    --_ruter-badge-padding: 8px;
    --_ruter-badge-gap: 4px;
  }

  ruter-badge[size="lg"] {
    --_ruter-badge-height: var(--ruter-control-md);
    --_ruter-badge-text: var(--ruter-text-base);
    --_ruter-badge-padding: 14px;
    --_ruter-badge-gap: 8px;
  }

  ruter-badge[variant="primary"] {
    --_ruter-badge-fg: var(--_ruter-on-color);
    --_ruter-badge-bg: var(--_ruter-color-strong);
  }

  ruter-badge[variant="muted"] {
    --_ruter-badge-bg: var(--ruter-sunken);
    --_ruter-badge-border: transparent;
  }

  ruter-badge[color][variant="muted"] {
    --_ruter-badge-bg: color-mix(in srgb, var(--_ruter-color-strong) 8%, transparent);
  }

  /* The icon is a circle's worth of the badge: a 2px ring inside the
     border all round, so a round logo sits evenly in the pill end. */
  ruter-badge [data-part="icon"] {
    inline-size: calc(var(--_ruter-badge-height) - 6px);
    block-size: calc(var(--_ruter-badge-height) - 6px);
    object-fit: contain;
  }

  ruter-badge:has(> [data-part="icon"]:first-child) {
    padding-inline-start: 2px;
  }

  /* Button. Wraps one native <button> or <a>, which keeps its own
     semantics, focus and form behaviour. Optional icon parts sit
     before or after the text, sized to it. Rounded corners by
     default; shape="pill" for a fully rounded marketing button.
     square makes it as wide as it is tall, for an icon on its own
     (a circle with shape="pill"). inset="top|bottom|start|end", or
     bare for all four, pulls a ghost button out by its padding so
     its content lines up with the text around it.                */

  ruter-button {
    --_ruter-button-inset-block: calc((var(--_ruter-control-height) - var(--_ruter-control-text) * var(--ruter-leading)) / 2);
    --_ruter-button-inset-inline: var(--_ruter-control-padding);
    font-family: var(--ruter-font);
  }

  /* The icon is 1.25 × the text: the inset is the space round it */
  ruter-button[square] {
    --_ruter-button-inset-block: calc((var(--_ruter-control-height) - var(--_ruter-control-text) * 1.25) / 2);
    --_ruter-button-inset-inline: var(--_ruter-button-inset-block);
  }

  ruter-button:is([inset=""], [inset~="top"]) {
    margin-block-start: calc(-1 * var(--_ruter-button-inset-block));
  }

  ruter-button:is([inset=""], [inset~="bottom"]) {
    margin-block-end: calc(-1 * var(--_ruter-button-inset-block));
  }

  ruter-button:is([inset=""], [inset~="start"]) {
    margin-inline-start: calc(-1 * var(--_ruter-button-inset-inline));
  }

  ruter-button:is([inset=""], [inset~="end"]) {
    margin-inline-end: calc(-1 * var(--_ruter-button-inset-inline));
  }

  ruter-button > :is(button, a) {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ruter-space-2);
    block-size: var(--_ruter-control-height);
    margin: 0;
    padding: 0 var(--_ruter-control-padding);
    font: inherit;
    font-size: var(--_ruter-control-text);
    font-weight: var(--ruter-weight-bold);
    line-height: var(--ruter-leading);
    white-space: nowrap;
    color: var(--_ruter-button-fg);
    text-decoration: none;
    background: var(--_ruter-button-bg);
    border: 1px solid var(--_ruter-button-border);
    border-radius: var(--ruter-radius);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s, color 0.15s;
  }

  /* shape="pill" fully rounds the ends, for marketing calls to action */
  ruter-button[shape="pill"] > :is(button, a) {
    border-radius: var(--ruter-radius-pill);
  }

  ruter-button[square] > :is(button, a) {
    inline-size: var(--_ruter-control-height);
    padding: 0;
  }

  /* Before the focus rule, whose ring replaces the shadow */
  ruter-button[variant="surface"] > :is(button, a) {
    border-width: 2px;
    box-shadow: var(--ruter-shadow-1);
  }

  /* Expanded (e.g. the trigger of an open dropdown menu) stays in its hover look */
  ruter-button > :is(button, a):is(:hover, [aria-expanded="true"]) {
    color: var(--_ruter-button-hover-fg);
    border-color: var(--_ruter-button-hover-border);
    background: var(--_ruter-button-hover-bg);
  }

  ruter-button > :is(button, a):focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  /* A link can't be disabled natively: aria-disabled="true" (and no href)
     greys it out and stops clicks. */
  ruter-button > :is(button:disabled, [aria-disabled="true"]) {
    opacity: 0.5;
    cursor: not-allowed;
  }

  ruter-button > a[aria-disabled="true"] {
    pointer-events: none;
  }

  ruter-button [data-part="icon"] {
    inline-size: 1.25em;
    block-size: 1.25em;
    object-fit: contain;
  }

  /* Icon. 1em by default, so it follows the text it sits in;
     size="sm|md|lg" pins it to 16, 20 or 24px.                 */

  ruter-icon[size="sm"] { --_ruter-icon-size: 16px; }
  ruter-icon[size="md"] { --_ruter-icon-size: 20px; }
  ruter-icon[size="lg"] { --_ruter-icon-size: 24px; }

  /* Pills and toggle groups share the "on" selector:
     links           aria-current="page"
     toggle buttons  aria-pressed="true"
     tabs            aria-selected="true"
     inputs          <label><input type=radio|checkbox> …</label>
     anything else   data-state="on"                                */

  /* Pills */

  ruter-pills {
    gap: var(--ruter-space-2);
    font-family: var(--ruter-font);
    font-size: var(--_ruter-control-text);
    line-height: var(--ruter-leading);
  }

  ruter-pills [data-part="item"] {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: var(--ruter-space-2);
    block-size: var(--_ruter-control-height);
    margin: 0;
    padding: 0 var(--_ruter-control-padding);
    font: inherit;
    white-space: nowrap;
    color: var(--_ruter-button-fg);
    text-decoration: none;
    background: var(--_ruter-button-bg);
    border: 1px solid var(--_ruter-button-border);
    border-radius: var(--ruter-radius-pill);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s, color 0.15s;
  }

  ruter-pills [data-part="item"]:hover {
    color: var(--_ruter-button-hover-fg);
    border-color: var(--_ruter-button-hover-border);
    background: var(--_ruter-button-hover-bg);
  }

  ruter-pills [data-part="item"]:is(:focus-visible, :has(> input:focus-visible)) {
    outline: none;
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  ruter-pills [data-part="item"]:is(
      [aria-current]:not([aria-current="false"]),
      [aria-pressed="true"],
      [aria-selected="true"],
      [data-state="on"],
      :has(> input:checked)
    ) {
    color: var(--ruter-on-accent);
    background: var(--ruter-accent-strong);
    border-color: var(--ruter-accent-strong);
  }

  ruter-pills [data-part="item"]:is(:disabled, [aria-disabled="true"], :has(> input:disabled)) {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* Button group: joins its buttons into one bar (or a column with
     orientation="vertical"), rounding only the ends. The buttons overlap by a
     border; at rest each hides the edge it shares with the next, so there's
     one line between them (borders can be translucent: two would show
     darker). A hovered, focused or pressed button shows all its edges, in
     front of its neighbours.
     Holds <ruter-button>s, or map controls (which are <ruter-button>s).
     A surface group casts one shadow, not one per button. */

  ruter-button-group {
    --_ruter-button-group-border: 1px;
    display: inline-flex;
    vertical-align: middle;
    border-radius: var(--ruter-radius);
  }

  ruter-button-group[orientation="vertical"] {
    flex-direction: column;
    align-items: stretch;
  }

  ruter-button-group:has(ruter-button[variant="surface"]) {
    --_ruter-button-group-border: 2px;
    box-shadow: var(--ruter-shadow-1);
  }

  ruter-button-group ruter-button > :is(button, a):not(:focus-visible) {
    box-shadow: none;
  }

  ruter-button-group ruter-button > :is(button, a):is(:hover, :focus-visible, [aria-pressed="true"], [aria-expanded="true"]) {
    position: relative;
    z-index: 1;
  }

  ruter-button-group:not([orientation="vertical"]) > * + * {
    margin-inline-start: calc(-1 * var(--_ruter-button-group-border));
  }

  ruter-button-group[orientation="vertical"] > * + * {
    margin-block-start: calc(-1 * var(--_ruter-button-group-border));
  }

  ruter-button-group:not([orientation="vertical"]) > :not(:last-child) ruter-button > :is(button, a):not(:hover, :focus-visible, [aria-pressed="true"], [aria-expanded="true"]),
  ruter-button-group:not([orientation="vertical"]) > ruter-button:not(:last-child) > :is(button, a):not(:hover, :focus-visible, [aria-pressed="true"], [aria-expanded="true"]) {
    border-inline-end-color: transparent;
  }

  ruter-button-group[orientation="vertical"] > :not(:last-child) ruter-button > :is(button, a):not(:hover, :focus-visible, [aria-pressed="true"], [aria-expanded="true"]),
  ruter-button-group[orientation="vertical"] > ruter-button:not(:last-child) > :is(button, a):not(:hover, :focus-visible, [aria-pressed="true"], [aria-expanded="true"]) {
    border-block-end-color: transparent;
  }

  ruter-button-group:not([orientation="vertical"]) > :not(:first-child) ruter-button > :is(button, a),
  ruter-button-group:not([orientation="vertical"]) > ruter-button:not(:first-child) > :is(button, a) {
    border-start-start-radius: 0;
    border-end-start-radius: 0;
  }

  ruter-button-group:not([orientation="vertical"]) > :not(:last-child) ruter-button > :is(button, a),
  ruter-button-group:not([orientation="vertical"]) > ruter-button:not(:last-child) > :is(button, a) {
    border-start-end-radius: 0;
    border-end-end-radius: 0;
  }

  ruter-button-group[orientation="vertical"] > :not(:first-child) ruter-button > :is(button, a),
  ruter-button-group[orientation="vertical"] > ruter-button:not(:first-child) > :is(button, a) {
    border-start-start-radius: 0;
    border-start-end-radius: 0;
  }

  ruter-button-group[orientation="vertical"] > :not(:last-child) ruter-button > :is(button, a),
  ruter-button-group[orientation="vertical"] > ruter-button:not(:last-child) > :is(button, a) {
    border-end-start-radius: 0;
    border-end-end-radius: 0;
  }

  /* Toggle group */

  /* The track is the control height; items sit inside its inset */
  ruter-toggle-group {
    --_ruter-toggle-group-inset: 3px;
    box-sizing: border-box;
    block-size: var(--_ruter-control-height);
    gap: 2px;
    padding: var(--_ruter-toggle-group-inset);
    font-family: var(--ruter-font);
    background: var(--ruter-sunken);
    border-radius: var(--ruter-radius-pill);
  }

  ruter-toggle-group [data-part="item"] {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ruter-space-1);
    block-size: calc(var(--_ruter-control-height) - 2 * var(--_ruter-toggle-group-inset));
    margin: 0;
    padding: 0 calc(var(--_ruter-control-padding) - var(--_ruter-toggle-group-inset));
    font: inherit;
    font-size: var(--_ruter-control-text);
    font-weight: var(--ruter-weight-bold);
    line-height: var(--ruter-leading);
    letter-spacing: 0.04em;
    white-space: nowrap;
    color: var(--ruter-accent-strong);
    text-decoration: none;
    background: transparent;
    border: 0;
    border-radius: var(--ruter-radius-pill);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
  }

  ruter-toggle-group [data-part="item"]:hover {
    background: color-mix(in srgb, var(--ruter-surface) 90%, transparent);
  }

  ruter-toggle-group [data-part="item"]:is(:focus-visible, :has(> input:focus-visible)) {
    outline: none;
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  ruter-toggle-group [data-part="item"]:is(
      [aria-current]:not([aria-current="false"]),
      [aria-pressed="true"],
      [aria-selected="true"],
      [data-state="on"],
      :has(> input:checked)
    ) {
    color: var(--ruter-on-accent);
    background: var(--ruter-accent);
  }

  ruter-toggle-group [data-part="item"]:is(:disabled, [aria-disabled="true"], :has(> input:disabled)) {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* Dropdown menu */

  ruter-dropdown-menu {
    font-family: var(--ruter-font);
  }

  /* The trigger is the app's own element (usually a <ruter-button>'s
     button), so the menu doesn't style it. One that isn't a button
     (a badge, an avatar) gets a pointer and the focus ring.       */
  ruter-dropdown-menu [data-part="trigger"][role="button"]:not(button) {
    cursor: pointer;
  }

  ruter-dropdown-menu [data-part="trigger"][role="button"]:not(button):focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  /* A caret for any trigger, in its text colour: icons/chevron-down.svg,
     1.25 × the text like a button's icon (the same chevron as
     <ruter-select>'s). The drawn chevron is the middle half of its box,
     so the box overhangs the end by a quarter to line the chevron up with
     the trigger's padding. It turns over while the menu is open. */
  ruter-dropdown-menu [data-part="chevron"] {
    display: inline-block;
    flex: none;
    inline-size: 1.25em;
    block-size: 1.25em;
    margin-inline-end: -0.3125em;
    vertical-align: middle;
    background: currentColor;
    mask: no-repeat center / 100%;
    mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
    transition: transform 0.2s var(--ruter-ease-out);
  }

  ruter-dropdown-menu[data-state="open"] [data-part="chevron"] {
    transform: rotate(180deg);
  }

  /* The content is a popover in the top layer, placed under the
     trigger by anchor positioning; it flips when it would overflow. */
  ruter-dropdown-menu [data-part="content"] {
    box-sizing: border-box;
    inset: auto;
    margin: 6px 0 0;
    position-area: block-end span-inline-end;
    position-try-fallbacks: flip-inline, flip-block;
    min-width: 190px;
    max-height: 70vh;
    overflow: auto;
    padding: 0.4rem;
    font-family: var(--ruter-font);
    color: var(--ruter-ink);
    background: var(--ruter-surface);
    border: 1px solid var(--ruter-divider);
    border-radius: var(--ruter-radius);
    box-shadow: var(--ruter-shadow-2);
  }

  ruter-dropdown-menu[placement="end"] [data-part="content"] {
    position-area: block-end span-inline-start;
  }

  ruter-dropdown-menu [data-part="content"]:popover-open {
    display: grid;
    gap: 2px;
  }

  ruter-dropdown-menu [data-part="item"] {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: var(--ruter-space-2);
    width: 100%;
    block-size: var(--_ruter-control-height);
    margin: 0;
    padding: 0 var(--_ruter-control-padding);
    font: inherit;
    font-size: var(--_ruter-control-text);
    font-weight: var(--ruter-weight-bold);
    line-height: var(--ruter-leading);
    color: var(--ruter-ink-soft);
    text-align: start;
    text-decoration: none;
    white-space: nowrap;
    background: transparent;
    border: 0;
    border-radius: var(--ruter-radius);
    cursor: pointer;
  }

  ruter-dropdown-menu [data-part="item"]:is(:hover, :focus-visible, [aria-current]:not([aria-current="false"])) {
    outline: none;
    color: var(--ruter-accent-strong);
    background: var(--ruter-accent-soft);
  }

  ruter-dropdown-menu [data-part="item"]:focus-visible {
    box-shadow: inset 0 0 0 2px var(--ruter-focus);
  }

  ruter-dropdown-menu [data-part="item"]:is(:disabled, [aria-disabled="true"]) {
    color: var(--ruter-ink-faint);
    background: transparent;
    cursor: not-allowed;
  }

  ruter-dropdown-menu [data-part="swatch"] {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ruter-swatch, currentColor);
  }

  ruter-dropdown-menu [data-part="separator"] {
    height: 1px;
    margin: var(--ruter-space-1) 0;
    background: var(--ruter-divider);
  }

  /* Select */

  ruter-select {
    font-family: var(--ruter-font);
  }

  ruter-select > select {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    block-size: var(--_ruter-control-height);
    margin: 0;
    /* room for the chevron: its drawn width plus the gap to the text */
    padding-block: 0;
    padding-inline: var(--_ruter-control-padding) calc(var(--_ruter-control-padding) + var(--_ruter-select-chevron) * 0.75 + var(--ruter-space-2));
    font: inherit;
    font-size: var(--_ruter-control-text);
    line-height: var(--ruter-leading);
    color: var(--_ruter-button-fg);
    background: var(--_ruter-button-bg);
    border: 1px solid var(--_ruter-button-border);
    border-radius: var(--ruter-radius);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s, color 0.15s;
  }

  ruter-select[shape="pill"] > select {
    border-radius: var(--ruter-radius-pill);
  }

  ruter-select > select:hover {
    color: var(--_ruter-button-hover-fg);
    border-color: var(--_ruter-button-hover-border);
    background: var(--_ruter-button-hover-bg);
  }

  ruter-select > select:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  ruter-select > select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* icons/chevron-down.svg, 1.25 × the text like a button's icon. The
     drawn chevron is the middle half of its box, so the box overhangs
     the padding by a quarter to line the chevron up with it. */
  ruter-select {
    --_ruter-select-chevron: calc(var(--_ruter-control-text) * 1.25);
  }

  ruter-select::after {
    content: "";
    position: absolute;
    inset-inline-end: calc(var(--_ruter-control-padding) - var(--_ruter-select-chevron) * 0.25);
    top: 50%;
    translate: 0 -50%;
    width: var(--_ruter-select-chevron);
    height: var(--_ruter-select-chevron);
    background: var(--_ruter-button-fg);
    mask: no-repeat center / 100%;
    mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  }

  ruter-select:has(> select:disabled)::after {
    opacity: 0.5;
  }

  /* Card

     <ruter-card>
       [data-part="media"]          image above the body (beside it when horizontal)
       [data-part="header"]
         [data-part="icon"]         leading dot, icon or thumbnail
         [data-part="title"]
           [data-part="link"]       stretches over the card
         [data-part="description"]
         [data-part="action"]       trailing arrow, button or menu
       [data-part="content"]
       [data-part="footer"]         actions, pushed to the bottom

     variant="surface|outline|muted" (default surface), size="sm|md|lg"
     (padding and title size, default md), orientation="horizontal".
     The --_ruter-card-* properties are internal.                 */

  ruter-card {
    --_ruter-card-padding: var(--ruter-space-5);
    --_ruter-card-gap: var(--ruter-space-3);
    --_ruter-card-title: var(--ruter-text-lg);
    --_ruter-card-radius: var(--ruter-radius-lg);
    --_ruter-card-bg: var(--ruter-surface);
    --_ruter-card-border: var(--ruter-divider);
    --_ruter-card-shadow: var(--ruter-shadow-1);
    --_ruter-card-hover-bg: var(--_ruter-card-bg);
    --_ruter-card-hover-border: color-mix(in srgb, var(--ruter-accent) 40%, transparent);
    --_ruter-card-hover-shadow: var(--ruter-shadow-2);
    gap: var(--_ruter-card-gap);
    padding: var(--_ruter-card-padding);
    font-family: var(--ruter-font);
    line-height: var(--ruter-leading);
    color: var(--ruter-ink);
    background: var(--_ruter-card-bg);
    border: 1px solid var(--_ruter-card-border);
    border-radius: var(--_ruter-card-radius);
    box-shadow: var(--_ruter-card-shadow);
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s var(--ruter-ease-out), translate 0.2s var(--ruter-ease-out);
  }

  ruter-card[variant="outline"] {
    --_ruter-card-bg: transparent;
    --_ruter-card-shadow: none;
    --_ruter-card-hover-border: var(--ruter-outline-strong);
    --_ruter-card-hover-shadow: none;
  }

  ruter-card[variant="muted"] {
    --_ruter-card-bg: var(--ruter-sunken);
    --_ruter-card-border: transparent;
    --_ruter-card-shadow: none;
    --_ruter-card-hover-bg: color-mix(in srgb, var(--ruter-accent-strong) 12%, transparent);
    --_ruter-card-hover-border: transparent;
    --_ruter-card-hover-shadow: none;
  }

  ruter-card[size="sm"] {
    --_ruter-card-padding: var(--ruter-space-3);
    --_ruter-card-gap: var(--ruter-space-2);
    --_ruter-card-title: var(--ruter-text-base);
  }

  ruter-card[size="lg"] {
    --_ruter-card-padding: var(--ruter-space-6);
    --_ruter-card-gap: var(--ruter-space-4);
    --_ruter-card-title: var(--ruter-text-xl);
  }

  /* Linked cards respond as a whole */
  ruter-card:has([data-part="link"]):hover {
    background: var(--_ruter-card-hover-bg);
    border-color: var(--_ruter-card-hover-border);
    box-shadow: var(--_ruter-card-hover-shadow);
    translate: 0 -2px;
  }

  ruter-card:has([data-part="link"]:focus-visible) {
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  ruter-card [data-part="link"] {
    color: var(--ruter-accent-strong);
    text-decoration: none;
    outline: none;
  }

  /* Header: [icon] title / description [action]. Title and description
     stay together, centred beside an icon taller than they are. Empty
     tracks take no space, so the gaps are margins, not grid gaps.  */
  ruter-card [data-part="header"] {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: 1fr auto auto 1fr;
    align-items: center;
  }

  ruter-card [data-part="header"] > * {
    grid-column: 2;
  }

  ruter-card [data-part="header"] > [data-part="title"] {
    grid-row: 2;
  }

  ruter-card [data-part="header"] > [data-part="description"] {
    grid-row: 3;
  }

  ruter-card [data-part="header"] > [data-part="icon"] {
    grid-column: 1;
    grid-row: 1 / -1;
    margin-inline-end: var(--ruter-space-4);
  }

  ruter-card [data-part="header"] > [data-part="action"] {
    grid-column: 3;
    grid-row: 1 / -1;
    margin-inline-start: var(--ruter-space-4);
  }

  ruter-card [data-part="header"] > [data-part="description"] {
    margin-top: var(--ruter-space-1);
  }

  ruter-card [data-part="title"] {
    margin: 0;
    font-size: var(--_ruter-card-title);
    font-weight: var(--ruter-weight-bold);
    line-height: 1.25;
    letter-spacing: -0.01em;
    text-wrap: balance;
  }

  ruter-card [data-part="description"] {
    margin: 0;
    font-size: var(--ruter-text-sm);
    line-height: 1.5;
    color: var(--ruter-ink-soft);
  }

  /* Not a nested badge's icon, which shares the part name */
  ruter-card [data-part="icon"]:not(ruter-badge > *) {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ruter-accent);
  }

  ruter-card [data-part="icon"] > :is(img, svg) {
    display: block;
  }

  ruter-card [data-part="icon"] > img {
    border-radius: var(--ruter-radius);
    object-fit: cover;
  }

  ruter-card [data-part="action"] {
    display: flex;
    align-items: center;
    justify-self: end;
    color: var(--ruter-accent);
  }

  ruter-card [data-part="content"] > :first-child { margin-top: 0; }
  ruter-card [data-part="content"] > :last-child { margin-bottom: 0; }

  ruter-card [data-part="footer"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ruter-space-2) var(--ruter-space-4);
    margin-top: auto;
  }

  ruter-card [data-part="footer"] > a {
    font-size: var(--ruter-text-sm);
    font-weight: var(--ruter-weight-bold);
    color: var(--ruter-accent-strong);
    text-decoration: none;
  }

  ruter-card [data-part="footer"] > a:hover {
    text-decoration: underline;
  }

  /* Media bleeds to the card's edges */
  ruter-card > [data-part="media"] {
    margin-inline: calc(-1 * var(--_ruter-card-padding));
    aspect-ratio: var(--ruter-card-media-ratio);
    overflow: hidden;
    background: var(--ruter-paper-deep);
  }

  ruter-card > [data-part="media"]:first-child {
    margin-top: calc(-1 * var(--_ruter-card-padding));
    border-start-start-radius: calc(var(--_ruter-card-radius) - 1px);
    border-start-end-radius: calc(var(--_ruter-card-radius) - 1px);
  }

  ruter-card > [data-part="media"]:last-child {
    margin-bottom: calc(-1 * var(--_ruter-card-padding));
    border-end-start-radius: calc(var(--_ruter-card-radius) - 1px);
    border-end-end-radius: calc(var(--_ruter-card-radius) - 1px);
  }

  ruter-card [data-part="media"] :is(img, video) {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: scale 0.35s var(--ruter-ease-out);
  }

  ruter-card:has([data-part="link"]):hover [data-part="media"] :is(img, video) {
    scale: 1.04;
  }

  /* Horizontal: the media fills the start side, at full height. It
     narrows on small screens (vw, since padding percentages would
     resolve against the card's parent, not the card).          */
  ruter-card[orientation="horizontal"] {
    --_ruter-card-media-width: min(var(--ruter-card-media-width), 30vw);
  }

  ruter-card[orientation="horizontal"]:has(> [data-part="media"]) {
    padding-inline-start: calc(var(--_ruter-card-media-width) + var(--_ruter-card-padding));
  }

  ruter-card[orientation="horizontal"] > [data-part="media"] {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    inline-size: var(--_ruter-card-media-width);
    margin: 0;
    aspect-ratio: auto;
    border-radius: 0;
    border-start-start-radius: calc(var(--_ruter-card-radius) - 1px);
    border-end-start-radius: calc(var(--_ruter-card-radius) - 1px);
  }

  /* Popups: the surface and parts every popup shares

     [data-part="header"]
       [data-part="title"]
       [data-part="close"]          a round icon button at the end
     [data-part="content"]          scrolls
     [data-part="footer"]           actions                       */

  :is(ruter-panel) {
    font-family: var(--ruter-font);
    line-height: var(--ruter-leading);
    color: var(--ruter-ink);
    background: var(--ruter-surface);
    border: 1px solid var(--ruter-divider);
    border-radius: var(--ruter-radius-lg);
    box-shadow: var(--ruter-shadow-2);
  }

  :is(ruter-panel) > [data-part="header"] {
    display: flex;
    align-items: center;
    gap: var(--ruter-space-3);
    padding: var(--ruter-space-2) var(--ruter-space-2) var(--ruter-space-2) var(--ruter-space-5);
    min-height: var(--ruter-control-lg);
    border-bottom: 1px solid var(--ruter-divider);
  }

  :is(ruter-panel) [data-part="title"] {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: var(--ruter-text-lg);
    font-weight: var(--ruter-weight-bold);
    line-height: 1.25;
    letter-spacing: -0.01em;
    text-wrap: balance;
  }

  :is(ruter-panel) [data-part="close"] {
    flex: none;
    display: inline-grid;
    place-items: center;
    width: var(--ruter-control-md);
    height: var(--ruter-control-md);
    margin: 0 0 0 auto;
    padding: 0;
    font: inherit;
    font-size: 20px; /* the icon's size */
    color: var(--ruter-ink-soft);
    background: transparent;
    border: 0;
    border-radius: var(--ruter-radius-pill);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
  }

  :is(ruter-panel) [data-part="close"]:hover {
    color: var(--ruter-ink);
    background: var(--ruter-wash);
  }

  :is(ruter-panel) [data-part="close"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ruter-focus);
  }

  :is(ruter-panel) > [data-part="content"] {
    padding: var(--ruter-space-5);
  }

  :is(ruter-panel) > [data-part="footer"] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ruter-space-2);
    padding: var(--ruter-space-3) var(--ruter-space-5);
    border-top: 1px solid var(--ruter-divider);
  }

  /* Panel: slides in from its side (from below on phones) and fades */

  ruter-panel {
    translate: calc(-100% - var(--ruter-map-inset)) 0;
    opacity: 0;
    transition: translate 0.3s var(--ruter-ease-out), opacity 0.2s, visibility 0s 0.3s;
  }

  ruter-panel[side="end"] {
    translate: calc(100% + var(--ruter-map-inset)) 0;
  }

  ruter-panel[open] {
    translate: none;
    opacity: 1;
    transition: translate 0.3s var(--ruter-ease-out), opacity 0.2s;
  }

  @media (max-width: 639px) {
    ruter-panel,
    ruter-panel[side="end"] {
      translate: 0 100%;
      border-width: 1px 0 0;
      border-end-start-radius: 0;
      border-end-end-radius: 0;
    }

    ruter-panel[open] {
      translate: none;
    }
  }

  /* The masked icons (the dropdown and select chevrons, the accordion
     marker) are painted with a currentColor background, which forced
     colours would replace with the page's. Opting them out keeps that
     background, and currentColor is still the forced text colour. The
     select's chevron is in the button colour, so it gets ButtonText. */
  @media (forced-colors: active) {
    ruter-dropdown-menu [data-part="chevron"],
    ruter-accordion [data-part="marker"]::before,
    ruter-accordion [data-part="marker"]::after,
    ruter-select::after {
      forced-color-adjust: none;
    }

    ruter-select::after {
      background: ButtonText;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    :is(ruter-accordion, ruter-button, ruter-pills, ruter-toggle-group, ruter-dropdown-menu, ruter-select, ruter-card, ruter-panel),
    :is(ruter-accordion, ruter-button, ruter-pills, ruter-toggle-group, ruter-dropdown-menu, ruter-select, ruter-card, ruter-panel) * {
      transition: none !important;
    }

    ruter-accordion [data-part="item"]::details-content {
      transition: none;
    }

    ruter-map > [data-part="lock-scrim"],
    ruter-map > [data-part="lock"] [data-part="lock-icon"] {
      transition: none;
    }

    :is(ruter-map-zoom-in, ruter-map-zoom-out, ruter-map-compass, ruter-map-geolocate, ruter-map-fullscreen,
      ruter-map-terrain, ruter-map-globe, ruter-map-button) > [data-part="button"],
    ruter-map-compass [data-part="icon"] {
      transition: none;
    }

    ruter-map-geolocate[data-state="locating"] [data-part="icon"] {
      animation: none;
    }

    /* Keep the glow, drop the movement */
    ruter-map > [data-part="lock"][data-pulse] {
      animation: none;
    }

    ruter-card:has([data-part="link"]):hover,
    ruter-card:has([data-part="link"]):hover [data-part="media"] :is(img, video) {
      translate: none;
      scale: none;
    }
  }
}
