.desktop-map-rail[hidden], #search-extra-tools { display: none; }

@media (min-width: 481px) {
  body[data-map-layout="rail"] {
    --rail-width: 42px;
    --search-home-gap: 8px;
    --search-home-offset: calc(var(--rail-width) + var(--search-home-gap));
    --rail-card-top: 8px;
    --map-card-left: 10px;
    --map-card-width: min(374px, calc(100vw - 2 * var(--map-card-left)));
  }

  body[data-map-layout="rail"] #top-bar {
    top: 18px; left: 50%; right: auto; transform: translateX(-50%);
    width: min(614px, calc(100vw - 2 * (var(--search-home-offset) + 10px)));
  }
  body[data-map-layout="rail"] #search-container { --search-input-width: calc(100% - 54px); width: 100%; }
  body[data-map-layout="rail"] #search-input-wrap { position: relative; grid-template-columns: minmax(0, 1fr) 44px; }
  body[data-map-layout="rail"] #search-extra-tools {
    position: absolute; top: 0; left: calc(100% + 10px);
    height: 44px; display: flex; align-items: center; gap: 16px;
  }
  #desktop-map-tools { display: flex; align-items: center; gap: 5px; }
  body[data-map-layout="rail"] #search-input-wrap > :is(#action-group, #mode-filter-tabs) { display: none; }

  .desktop-map-rail:not([hidden]) {
    position: absolute; top: calc((44px - var(--rail-width)) / 2); right: calc(100% + var(--search-home-gap));
    display: block;
  }
  .desktop-map-rail button {
    display: grid; place-items: center; box-sizing: border-box; width: var(--rail-width); height: var(--rail-width); padding: 0;
    border: 1px solid #e8e3de; border-radius: 50%; background: #fffdfb; color: #282523; box-shadow: 0 5px 18px #0005;
    cursor: pointer;
    transition: background-color .16s ease, color .16s ease, border-color .16s ease;
  }
  .desktop-map-rail button:hover { background: #eeeae5; }
  .desktop-map-rail button[aria-expanded="true"] { background: #282523; color: #fff; }
  .desktop-map-rail button svg {
    width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.65;
    stroke-linecap: round; stroke-linejoin: round; pointer-events: none;
  }
  .desktop-map-rail button:focus-visible { outline: 2px solid var(--night-accent, #e60012); outline-offset: -3px; }

  body[data-map-layout="rail"] :is(#map-home-panel, #rank-panel, #artist-profile-panel) {
    position: fixed; top: var(--rail-card-top); bottom: 24px; left: var(--map-card-left); right: auto;
    width: var(--map-card-width); height: auto; max-height: none; box-sizing: border-box;
    border: 1px solid #fff; border-radius: 24px;
    box-shadow: 0 14px 46px #30251c25, 0 2px 8px #30251c0a;
  }
  body[data-map-layout="rail"] #map .leaflet-top.leaflet-left { top: var(--rail-zoom-top, 52px); right: 14px; left: auto; }
  body[data-map-layout="rail"] #exit-network-btn.network-dock { z-index: 1520; }
}

@media (481px <= width < 1240px) {
  body[data-map-layout="rail"] #search-container { --search-popover-top: 104px; --filter-viewport-offset: 130px; }
  body[data-map-layout="rail"] #search-extra-tools { position: static; grid-column: 1 / -1; justify-self: end; }
  body[data-map-layout="rail"] { --rail-zoom-top: 108px; }
}
@media (1240px <= width < 1360px) {
  body[data-map-layout="rail"]:has(#map-home-panel:not([hidden]), #rank-panel.show, #artist-profile-panel:not([hidden])) #search-container { --search-popover-top: 104px; --filter-viewport-offset: 130px; }
  body[data-map-layout="rail"]:has(#map-home-panel:not([hidden]), #rank-panel.show, #artist-profile-panel:not([hidden])) #search-extra-tools { position: static; grid-column: 1 / -1; justify-self: end; }
  body[data-map-layout="rail"]:has(#map-home-panel:not([hidden]), #rank-panel.show, #artist-profile-panel:not([hidden])) { --rail-zoom-top: 108px; }
}

@media (min-width: 821px) {
  /* Leave room for the home button between an open card and the search field. */
  body[data-map-layout="rail"]:has(#map-home-panel:not([hidden]), #rank-panel.show, #artist-profile-panel:not([hidden])) #top-bar {
    --rail-search-width: min(614px, calc(100vw - var(--map-card-left) - var(--map-card-width) - var(--search-home-offset) - 80px));
    left: max(50%, calc(var(--map-card-left) + var(--map-card-width) + var(--search-home-offset) + 14px + var(--rail-search-width) / 2));
    width: var(--rail-search-width);
  }
}
@media (min-width: 481px) and (max-width: 820px) {
  body[data-map-layout="rail"] { --rail-card-top: 126px; }
}
@media (min-width: 481px) and (prefers-reduced-motion: no-preference) {
  body[data-map-layout="rail"] :is(#map-home-panel, #artist-profile-panel) { animation-name: rail-card-fade-in; }
  @keyframes rail-card-fade-in { from { opacity: 0; } to { opacity: 1; } }
}

@media (prefers-reduced-motion: reduce) {
  .desktop-map-rail button { transition: none; }
}
