/* The in-map control: one pill and its panel.
 *
 * Layout rules, deliberately explicit:
 *   - desktop: the pill sits at the top centre;
 *   - phones: the top-right belongs to the MOTIS colour-mode selector (160 px
 *     wide, from `top-right`), which the centred pill overlapped on a narrow
 *     screen. Under 480 px the pill moves to the top-left, under the map
 *     attribution, and the panel opens rightwards so it is never clipped;
 *   - nothing moves when the panel opens: the chip has no transform of any
 *     state, and the panel is absolutely positioned inside the same wrapper;
 *   - the home link lives inside the panel, as its last row.
 */

.afk-float {
  --afk-chip-bg: rgba(10, 15, 25, 0.55);
  --afk-chip-border: rgba(255, 255, 255, 0.18);
  --afk-chip-text: #f8fafc;
  --afk-chip-hover: rgba(10, 15, 25, 0.76);
  --afk-panel-bg: rgba(10, 15, 25, 0.8);
  --afk-panel-border: rgba(255, 255, 255, 0.14);
  --afk-panel-shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
  --afk-panel-shift: -50%;
  --afk-item-text: #f8fafc;
  --afk-item-hover: rgba(255, 255, 255, 0.1);
  --afk-muted: #94a3b8;
  --afk-rule-color: rgba(255, 255, 255, 0.12);
  --afk-control-bg: rgba(255, 255, 255, 0.08);
  --afk-control-border: rgba(255, 255, 255, 0.16);
  --afk-control-text: #f8fafc;
  --afk-control-hover: rgba(255, 255, 255, 0.12);
  --afk-control-active-bg: #008000;
  --afk-control-active-text: #ffffff;
  --afk-focus: #1fa66a;

  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2147482000;
  display: block;
}

.afk-float[data-theme="light"] {
  --afk-chip-bg: rgba(255, 255, 255, 0.88);
  --afk-chip-border: rgba(15, 23, 42, 0.14);
  --afk-chip-text: #1f2937;
  --afk-chip-hover: #ffffff;
  --afk-panel-bg: rgba(255, 255, 255, 0.95);
  --afk-panel-border: rgba(15, 23, 42, 0.12);
  --afk-panel-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
  --afk-item-text: #1f2937;
  --afk-item-hover: rgba(15, 23, 42, 0.07);
  --afk-muted: #64748b;
  --afk-rule-color: rgba(15, 23, 42, 0.1);
  --afk-control-bg: rgba(15, 23, 42, 0.05);
  --afk-control-border: rgba(15, 23, 42, 0.12);
  --afk-control-text: #1f2937;
  --afk-control-hover: rgba(15, 23, 42, 0.08);
  --afk-control-active-bg: #008000;
  --afk-control-active-text: #ffffff;
  --afk-focus: #008000;
}

/* ---- The pill ----------------------------------------------------------- */

.afk-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px 0 9px;
  border: 1px solid var(--afk-chip-border);
  border-radius: 999px;
  background: var(--afk-chip-bg);
  color: var(--afk-chip-text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

/* 44 px touch target without growing the pill: the pseudo-element is part of
   the button, so taps above and below still land. */
.afk-chip::after {
  content: "";
  position: absolute;
  inset: -5px -3px;
  border-radius: 999px;
}

.afk-chip:hover,
.afk-chip:focus-visible {
  background: var(--afk-chip-hover);
  border-color: var(--afk-focus);
}

.afk-chip-name {
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Short city code (ABJ, BKO, DKR): only shown when the name does not fit. */
.afk-chip-code {
  display: none;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.afk-caret {
  font-size: 9px;
  opacity: 0.65;
  transform: translateY(1px);
}

/* ---- The panel ---------------------------------------------------------- */

.afk-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 244px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 72px);
  padding: 8px;
  overflow-y: auto;
  border: 1px solid var(--afk-panel-border);
  border-radius: 16px;
  background: var(--afk-panel-bg);
  color: var(--afk-item-text);
  box-shadow: var(--afk-panel-shadow);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  transform: translateX(var(--afk-panel-shift));
  transform-origin: top center;
  animation: afk-panel-in 0.12s ease-out;
}

.afk-panel[hidden] {
  display: none;
}

.afk-panel:focus,
.afk-panel:focus-visible {
  outline: none;
}

@keyframes afk-panel-in {
  from {
    opacity: 0;
    transform: translateX(var(--afk-panel-shift)) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateX(var(--afk-panel-shift)) scale(1);
  }
}

.afk-cities {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.afk-panel > .afk-label {
  padding: 4px 10px 2px;
}

.afk-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 4px 4px 10px;
}

/* Theme/language is duplicated in the panel only on mobile. */
.afk-mobile-only {
  display: none;
}

@media (max-width: 767px), (pointer: coarse) {
  .afk-mobile-only {
    display: block;
  }
}

.afk-item-country {
  color: var(--afk-muted);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.afk-item-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  color: var(--afk-focus);
}

.afk-item-check svg {
  width: 14px;
  height: 14px;
}

.afk-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--afk-muted);
}

.afk-item-icon svg {
  width: 16px;
  height: 16px;
}

.afk-item-home {
  font-weight: 650;
}

/* ---- Geolocation status (features/geolocation.js) ----------------------- */

.afk-toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 2147482400;
  display: flex;
  align-items: center;
  gap: 10px;
  /* A shrink-to-fit width collapsed the message to one word per line on a
   * phone; give the toast a real width and keep the message readable. */
  width: min(560px, calc(100vw - 24px));
  max-width: none;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(10, 15, 25, 0.86);
  color: #f8fafc;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  font-size: 13px;
  line-height: 1.4;
}

.afk-toast-msg {
  flex: 1;
  min-width: 0;
}

.afk-toast-action {
  flex: none;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.afk-toast-action:hover,
.afk-toast-action:focus-visible {
  background: rgba(255, 255, 255, 0.18);
}

.afk-toast-close {
  flex: none;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.afk-toast-close:hover,
.afk-toast-close:focus-visible {
  background: rgba(255, 255, 255, 0.12);
}


/* ---- Phones ------------------------------------------------------------- */

/* The top band is shared: attribution and scale on the left (down to 47 px),
   the colour-mode selector on the right (y 8–44, from x = W - 176) and the
   compass/locate column under it (44–104 px, from x = W - 91).

   The pill stays centred at the top but is compacted: the city name gives way
   to the short code, the glass is lighter, and the pill slides left by exactly
   what is needed to clear the selector (0 from 422 px, ~31 px at 360 px). Under
   360 px it drops one row, below the attribution. */
@media (max-width: 480px) {
  .afk-float {
    --afk-chip-bg: rgba(10, 15, 25, 0.42);
    /* The colour-mode selector starts at x = W - 168. Slide the pill left by
       exactly what is needed and no more: 0 at 422 px, ~31 px at 360 px. */
    left: calc(50% - max(0px, 211px - 50vw));
  }

  .afk-float[data-theme="light"] {
    --afk-chip-bg: rgba(255, 255, 255, 0.78);
  }

  .afk-chip {
    height: 32px;
    gap: 4px;
    padding: 0 8px;
    font-size: 12.5px;
  }

  /* Grows the hit area back to 44 px without growing the pill. */
  .afk-chip::after {
    inset: -6px -4px;
  }

  .afk-chip-name {
    display: none;
  }

  .afk-chip-code {
    display: inline;
  }
}

/* Under 360 px the attribution reaches x = 108 at y = 10: drop one row, below
   it and beside the scale. */
@media (max-width: 359px) {
  .afk-float {
    top: calc(env(safe-area-inset-top, 0px) + 26px);
  }
}
