:root {
  --bg: #0b0b12;
  --panel: rgba(13, 12, 22, 0.94);
  --panel-solid: #0f0e1a;
  --text: #ece9ff;
  --muted: #9d9aba;
  --line: rgba(255, 255, 255, 0.09);
  --hover: rgba(255, 255, 255, 0.06);
  --pink: #ff2bd6;
  --amber: #ffb347;
  --link: #8fd3ff;
  --radius: 12px;
  --sidebar-w: 310px;
  --detail-w: 390px;
  --gap: 12px;
  --ctrl-w: 40px; /* MapLibre's control column: 29px buttons + 10px margin */
  --info-h: 52px; /* room under the panel for the ⓘ control */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--link); }
code { font-size: 12px; background: var(--hover); padding: 1px 4px; border-radius: 4px; }

#map { position: fixed; inset: 0; }

/* ---------- neon type ---------- */

.neon-title {
  margin: 0;
  font-family: "Monoton", system-ui, sans-serif;
  font-weight: 400;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: 1px;
  color: #fff4fd;
  text-shadow: 0 0 2px #fff, 0 0 8px var(--pink), 0 0 18px var(--pink), 0 0 36px var(--pink);
}
.neon-title span {
  color: #fff6e6;
  text-shadow: 0 0 2px #fff, 0 0 8px var(--amber), 0 0 18px var(--amber), 0 0 36px var(--amber);
}

/* ---------- panels ---------- */

#sidebar, .detail {
  position: fixed;
  z-index: 2;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
/* Not on .detail: backdrop-filter would become the containing block for the
   position:fixed expanded photo and trap it inside the panel. */
#sidebar { backdrop-filter: blur(8px); }

#sidebar {
  top: var(--gap);
  left: var(--gap);
  width: var(--sidebar-w);
  max-height: calc(100% - 2 * var(--gap));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#sidebar header { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.sidebar-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#sidebar.collapsed .sidebar-body { display: none; }
#sidebar.collapsed header { border-bottom: 0; }
/* Caret points up ("fold away") when open, down ("unfold") when collapsed. */
#sidebar-toggle .caret { transition: transform 0.15s ease; }
#sidebar.collapsed #sidebar-toggle .caret { transform: rotate(180deg); }

#filter {
  margin: 10px 12px 4px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
}
#filter:focus { outline: 2px solid var(--pink); outline-offset: 0; }
.list-hint { margin: 4px 14px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

/* On desktop the list scrolls on its own above a fixed footer; phones scroll
   the two together (see the end of the file). */
.list-scroll { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#sign-list { list-style: none; margin: 0; padding: 4px 6px 8px; overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 60px; }
#sign-list button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
#sign-list button:hover, #sign-list button:focus-visible { background: var(--hover); outline: none; }
#sign-list button[aria-current="true"] { background: rgba(255, 43, 214, 0.14); }
#sign-list .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sign-list .empty { padding: 10px; color: var(--muted); }

/* Small marks for what's uncommon about a sign (list rows and chips). */
.ico { flex: none; display: grid; place-items: center; width: 16px; height: 16px; color: var(--muted); }
.ico svg { width: 14px; height: 14px; display: block; }
#sign-list button[aria-current="true"] .ico,
#sign-list button[aria-current="true"] .wbadge { color: var(--text); }

/* Filter chips under the search box. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 12px 4px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip:hover { background: var(--hover); }
.chip:focus-visible { outline: 2px solid var(--pink); outline-offset: 1px; }
.chip[aria-pressed="true"] { border-color: var(--pink); background: rgba(255, 43, 214, 0.15); }
.chip[aria-pressed="true"] .ico, .chip[aria-pressed="true"] .wbadge { color: var(--text); }

/* Collapsible state headings in the list. */
#sign-list .state-head { position: sticky; top: -4px; z-index: 1; background: var(--panel-solid); }
#sign-list .state-head button {
  gap: 6px;
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
#sign-list .state-head button:hover, #sign-list .state-head button:focus-visible { color: var(--text); }
#sign-list .state-head .n { margin-left: auto; font-weight: 400; letter-spacing: 0; font-variant-numeric: tabular-nums; }
#sign-list .state-head .caret { flex: none; transition: transform 0.15s ease; }
#sign-list .state-head button[aria-expanded="true"] .caret { transform: rotate(90deg); }

.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, var(--pink));
  box-shadow: 0 0 4px var(--c, var(--pink)), 0 0 10px var(--c, var(--pink));
}
/* Lifecycle, as on the map: disused = no glow; abandoned = an unlit ring. */
.dot.disused, .legend-dot.disused { box-shadow: none; }
.dot.abandoned, .legend-dot.abandoned {
  box-shadow: none;
  background: transparent;
  border: 2px solid var(--c, var(--pink));
}
.sign-title.disused, .sign-title.abandoned,
.photo-top-title.disused, .photo-top-title.abandoned { text-shadow: none; }

#sidebar footer { padding: 10px 14px 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
#sidebar footer p { margin: 0 0 6px; }
#sidebar footer p:last-child { margin-bottom: 0; }
.legend { display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--pink); box-shadow: 0 0 8px var(--pink); }
.legend-line { width: 22px; height: 3px; border-radius: 2px; background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.legend-line.alt { height: 2px; box-shadow: none; opacity: 0.75; background: repeating-linear-gradient(90deg, var(--amber) 0 5px, transparent 5px 9px); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); }

/* ---------- detail panel ---------- */

/* The map controls (zoom, locate, ⓘ) keep the screen's right edge; the panel
   sits just left of them, and stops short of the bottom so the expanded ⓘ
   credits have a clear strip to open into. */
.detail {
  top: var(--gap);
  right: calc(var(--ctrl-w) + var(--gap));
  width: var(--detail-w);
  max-height: calc(100% - var(--gap) - var(--info-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
}
.detail[hidden] { display: none; }
.peek-btn { display: none; } /* phones only */

.detail-top { display: flex; align-items: flex-start; gap: 10px; }
.sign-title {
  flex: 1;
  margin: 2px 0 12px;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 6px var(--c), 0 0 16px var(--c);
  overflow-wrap: anywhere;
}

.photo {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
}
/* Pinned to the frame: a percentage height on a grid item resolves against its
   auto-sized row, which let tall photos overflow and get cropped. */
.photo > img, .photo > iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; object-fit: contain; display: block; }
.photo .msg { padding: 16px; text-align: center; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15); border-top-color: var(--pink);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Commons category gallery ---------- */

.gallery {
  align-self: stretch;
  justify-self: stretch;
  margin: 0;
  padding: 4px;
  list-style: none;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  align-content: start;
  gap: 4px;
}
.photo-frame.expanded .gallery { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; padding: 6px; }
.gallery-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  overflow: hidden;
  background: #111;
  cursor: zoom-in;
}
.photo .gallery-thumb img { width: 100%; height: 100%; object-fit: cover; }
.gallery-thumb:hover, .gallery-thumb:focus-visible { border-color: var(--pink); outline: none; }
.gallery-back {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px 6px 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.gallery-back:hover, .gallery-back:focus-visible { background: rgba(255, 43, 214, 0.55); outline: none; }

/* ---------- expandable photo ---------- */

.photo-stage { position: relative; }
.photo-top { display: none; }

.photo-expand {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  cursor: pointer;
}
.photo-expand:hover, .photo-expand:focus-visible { background: rgba(255, 43, 214, 0.55); outline: none; }

.photo-frame.expanded {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
  background: #06050c; /* opaque: the panel's neon glow would show through */
}
.photo-frame.expanded .photo-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}
.photo-top-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 6px var(--c), 0 0 16px var(--c);
}
.photo-top-nav { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.photo-top-nav button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: none;
  color: var(--text);
  cursor: pointer;
}
.photo-top-nav button:hover:not(:disabled) { background: var(--hover); }
.photo-top-nav button:disabled { opacity: 0.35; cursor: default; }
.photo-frame.expanded .photo-stage { flex: 1; min-height: 0; }
.photo-frame.expanded .photo { aspect-ratio: auto; height: 100%; }
.photo-frame.expanded .photo-expand { display: none; }
.photo-frame.expanded .photo-foot { flex: none; }

.photo-meta { margin: 6px 2px 0; font-size: 12px; color: var(--muted); min-height: 1em; }
/* Source tabs sit on top of the photo; the active one joins the photo frame. */
.photo-tabs {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: -1px; /* overlap the photo's top border */
}
.photo-tabs:empty { display: none; }
.photo-tabs:not(:empty) + .photo-stage .photo { border-top-left-radius: 0; }
.photo-tabs button {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-bottom-color: transparent;
  border-radius: 8px 8px 0 0;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.photo-tabs button:hover { color: var(--text); background: var(--hover); }
.photo-tabs button:focus-visible { outline: 2px solid var(--pink); outline-offset: -2px; }
.photo-tabs button[aria-pressed="true"] {
  background: #000; /* the photo's own background */
  border-bottom-color: #000;
  color: #fff;
  box-shadow: inset 0 2px 0 var(--pink);
}
.photo-frame.expanded .photo-tabs { flex: none; margin-bottom: -9px; /* the frame's 8px gap + the border */ }

/* ---------- Wikipedia / Wikidata ---------- */

.section-label {
  margin: 16px 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.wiki-card {
  display: flex;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}
.wiki-card + .wiki-card { margin-top: 8px; }
.wiki-thumb { flex: none; width: 84px; height: 84px; border-radius: 6px; overflow: hidden; background: #000; }
.wiki-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.wiki-body { min-width: 0; }
.wiki-body p { margin: 0; }
.wiki-title { font-weight: 700; font-size: 15px; }
.wiki-title a { color: var(--text); text-decoration: none; }
.wiki-title a:hover { text-decoration: underline; }
.wiki-desc { color: var(--muted); font-size: 13px; margin-top: 2px !important; }
.wiki-links { display: flex; gap: 12px; font-size: 13px; margin-top: 6px !important; }
.wiki-via { font-size: 12px; color: var(--muted); margin-top: 6px !important; }

.wbadge {
  flex: none;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid currentColor;
  color: var(--muted);
  font: 700 10px/1 Georgia, "Times New Roman", serif;
}

.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 14px 0 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.open-in { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
}
.tool-btn:hover, .tool-btn:focus-visible {
  border-color: var(--pink);
  background: rgba(255, 43, 214, 0.12);
  outline: none;
}
.tool-btn svg { width: 22px; height: 22px; }
.tool-btn img { width: 24px; height: 24px; display: block; }
.tool-btn img.invert { filter: invert(1); } /* iD's logo is dark grey */
.josm-status { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.josm-status:empty { display: none; }

/* ---------- "open this view in…" map control ---------- */

.maplibregl-ctrl-group button.view-menu-btn { display: grid; place-items: center; color: #333; }
.view-menu {
  position: fixed;
  z-index: 5; /* above the panels (2), below the expanded photo (50) */
  width: 200px;
  max-height: calc(100% - 16px);
  overflow-y: auto;
  padding: 6px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.view-menu[hidden] { display: none; }
.view-menu-head { margin: 4px 8px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.view-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.view-item svg, .view-item img { flex: none; width: 20px; height: 20px; display: block; }
.view-item img.invert { filter: invert(1); }
.view-item:hover:not(:disabled), .view-item:focus-visible {
  border-color: var(--pink);
  background: rgba(255, 43, 214, 0.12);
  outline: none;
}
.view-item:disabled { opacity: 0.4; cursor: default; }
.view-menu .josm-status { margin: 4px 8px 2px; user-select: all; }
.view-sep { margin: 4px 2px; border: 0; border-top: 1px solid var(--line); }

.all-tags { margin-top: 12px; font-size: 12px; }
.all-tags summary { cursor: pointer; color: var(--muted); }
.all-tags table { width: 100%; border-collapse: collapse; margin-top: 6px; font-family: ui-monospace, Consolas, monospace; }
.all-tags td { padding: 2px 6px 2px 0; vertical-align: top; overflow-wrap: anywhere; }
.all-tags td:first-child { color: var(--muted); white-space: nowrap; }

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.stepper button {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.stepper button:hover:not(:disabled) { background: var(--hover); }
.stepper button:disabled { opacity: 0.35; cursor: default; }


.maplibregl-popup.hover-tip .maplibregl-popup-content {
  background: var(--panel-solid);
  color: var(--text);
  padding: 5px 9px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
.maplibregl-popup.hover-tip .maplibregl-popup-tip { display: none; }
.route-tip { display: grid; gap: 2px; }
.route-tip .sub { color: var(--amber); font-size: 12px; }
.route-tip .note { font-size: 12px; }

/* ---------- phones ---------- */

/* Narrow or short screens, including phones held sideways. Keep this query in
   step with PHONE_QUERY in app.js. There's no room to show a panel and the map
   side by side, so the list and the sign panel each take the whole screen
   while open; the map is one tap away (fold the list / minimise the panel). */
@media (max-width: 720px), (max-height: 500px) {
  :root { --gap: 8px; --peek-h: 60px; }
  .neon-title { font-size: 21px; }

  /* Folded: a title bar across the top. Open: the whole screen. */
  #sidebar { right: var(--gap); width: auto; }
  #sidebar:not(.collapsed) {
    inset: 0;
    max-height: none;
    border: 0;
    border-radius: 0;
    background: var(--panel-solid);
  }
  /* The list and the legend scroll together, so the legend doesn't squeeze
     the list to a row or two on short screens. */
  .list-scroll { display: block; overflow-y: auto; overscroll-behavior: contain; }
  #sign-list { overflow: visible; min-height: 0; }
  body.detail-open #sidebar { display: none; }

  /* 16px stops iOS Safari zooming the page in when the box gets focus. */
  #filter { font-size: 16px; }

  /* Bigger touch targets. */
  #sign-list button { padding-block: 11px; }
  #sign-list .state-head button { padding-block: 12px 8px; }
  .chip { padding: 7px 12px 7px 9px; font-size: 13px; }
  .photo-tabs button { padding: 9px 14px; }
  .stepper button { padding: 10px 12px; }
  .icon-btn { width: 40px; height: 40px; }
  .chips { gap: 8px; margin-block: 4px 6px; }

  /* The sign panel: the whole screen, its content in a centred column so a
     sideways phone doesn't get a photo taller than the screen. */
  .detail {
    inset: 0;
    width: auto;
    max-height: none;
    border: 0;
    border-radius: 0;
    background: var(--panel-solid);
    padding: 14px max(14px, calc((100% - 640px) / 2));
  }
  /* 4:3 across the column, but never taller than most of the screen. (A
     max-height alongside aspect-ratio would narrow the photo instead.) */
  .photo-frame:not(.expanded) .photo {
    aspect-ratio: auto;
    height: min(calc(min(100vw - 28px, 640px) * 0.75), 62vh);
  }
  .peek-btn { display: grid; }
  .peek-btn .caret { transform: rotate(180deg); transition: transform 0.15s ease; }

  /* Minimised: just the title as a bar along the bottom, over the map. */
  .detail.peek {
    top: auto;
    height: var(--peek-h);
    overflow: hidden;
    padding-block: 0;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    cursor: pointer;
  }
  .detail.peek > :not(.detail-top) { display: none; }
  .detail.peek .detail-top { height: 100%; align-items: center; }
  .detail.peek .sign-title { min-width: 0; margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .detail.peek .peek-btn .caret { transform: none; }
  body.detail-peek .maplibregl-ctrl-bottom-right { bottom: var(--peek-h); }
}
