:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e4e8f1;
  --text: #101827;
  --text-muted: #6b7280;
  --blue: #2f5fe0;
  --blue-soft: #eef2ff;
  --blue-dim: rgba(47, 95, 224, 0.08);
  --green: #16a34a;
  --green-soft: #e8f7ee;
  --rose: #dc4c4c;
  --rose-soft: #fdecec;
  --amber: #c2680a;
  --amber-soft: #fdf1e2;
  --violet: #7c3aed;
  --violet-soft: #f2ebfe;
  --cyan: #0891b2;
  --cyan-soft: #e5f6fa;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.10);
  --shadow-sm: 0 4px 14px rgba(16, 24, 40, 0.08);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  overflow: hidden;
  color: var(--text);
}

#map {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
}

/* ===== Floating card (was "liquid glass", now matches RailRadar's clean card) =====
   NOTE ON PERFORMANCE: the old version used a live backdrop-filter blur(16px)
   sitting directly over the WebGL map canvas. A live blur has to resample
   everything behind it every single frame, so while the map camera was
   moving (flyTo) the browser was paying for a full-strength GPU blur AND a
   WebGL redraw AND a compositing pass, every frame, at the same time. That's
   the single biggest source of the stutter. Swapping it for a solid/near-
   solid surface with only a light blur removes that repeated per-frame cost. */
#ui-container {
  position: absolute;
  z-index: 10;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(100vh - 40px);
  /* Promote to its own compositor layer, isolated from the map canvas paints */
  transform: translateZ(0);
  isolation: isolate;
  contain: layout paint;
}

@media (max-width: 768px) {
  #ui-container {
    bottom: 20px;
    left: 16px;
    right: 16px;
    max-height: calc(100vh - 40px);
  }
}

@media (min-width: 769px) {
  #ui-container {
    top: 22px;
    left: 22px;
    width: 320px;
    max-height: calc(100vh - 44px);
  }
}

/* HEADER / TOGGLE BUTTON */
#toggle-menu-btn {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 16px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

#toggle-menu-btn .toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-icon-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#toggle-icon {
  color: var(--text-muted);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

#ui-container.expanded #toggle-icon {
  transform: rotate(180deg);
}

/* MENU CONTENT — animated with grid-template-rows instead of max-height.
   max-height: 0 -> 400px forces the browser to lay out as if the panel were
   always 400px tall and animate through that, which is a layout-thrashing
   technique. The 0fr -> 1fr grid-row trick animates a track size instead,
   which is cheaper and doesn't require guessing a max pixel height. */
#menu-content-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 0;
  flex: 1;
}

#ui-container.expanded #menu-content-wrap {
  grid-template-rows: 1fr;
}

/* Single child of the animated grid track: flex column = scroll list + pinned footer */
.menu-panel {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.22s ease;
}

#ui-container.expanded .menu-panel {
  opacity: 1;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}

/* Scrollable location list */
#menu-content {
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  overflow-y: hidden;
  padding: 0 18px 8px;
  -webkit-overflow-scrolling: touch;
}

#ui-container.expanded #menu-content {
  overflow-y: auto;
}

/* Pinned footer — always visible when menu is open */
.menu-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 18px 14px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
}

.menu-hint {
  margin: 12px 0 12px 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ===== Block groups — same collapsible pattern as the outer menu
   (grid-template-rows instead of max-height, for the same reason: no
   layout-thrashing, and no arbitrary height guess). Nested one level
   inside #menu-content, so opening a block only grows within the already-
   open outer panel. ===== */
.block-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}

.block-group:last-of-type { margin-bottom: 0; }

.block-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  text-align: left;
}

.block-toggle:hover {
  background: var(--blue-dim);
}

.block-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.block-group.expanded .block-chevron {
  transform: rotate(180deg);
}

.block-body-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.block-group.expanded .block-body-wrap {
  grid-template-rows: 1fr;
}

.block-body {
  min-height: 0;
  overflow: hidden;
  padding: 0 10px;
  opacity: 0;
  transition: opacity 0.2s ease, padding-bottom 0.3s ease;
}

.block-group.expanded .block-body {
  opacity: 1;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--border);
}

.block-body .ward-btn:last-of-type { margin-bottom: 0; }

/* ===== Ward rows — same "link card" language as the train-status links:
   icon, title + sub, arrow ===== */
.ward-btn {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 0.85rem;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.ward-btn:last-of-type { margin-bottom: 0; }

.ward-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.ward-7 .ward-icon { background: var(--rose-soft); color: var(--rose); }
.ward-8 .ward-icon { background: var(--blue-soft); color: var(--blue); }
.ward-trauma .ward-icon { background: var(--amber-soft); color: var(--amber); font-size: 1.05rem; }
.ward-casualty .ward-icon { background: var(--green-soft); color: var(--green); }
.ward-op .ward-icon { background: var(--violet-soft); color: var(--violet); font-weight: 800; }
.ward-pharmacy .ward-icon { background: var(--cyan-soft); color: var(--cyan); }

.ward-text { flex: 1; min-width: 0; }
.ward-title { font-size: 0.92rem; font-weight: 600; }
.ward-sub { font-size: 0.76rem; color: var(--text-muted); margin-top: 1px; }

.ward-arrow { color: var(--text-muted); font-size: 1.05rem; }

.ward-btn:hover {
  background: var(--blue-dim);
  border-color: rgba(47, 95, 224, 0.3);
  transform: translateY(-1px);
}

.reset-btn {
  justify-content: center;
  background: var(--rose-soft);
  border: 1px solid rgba(220, 76, 76, 0.25);
  color: var(--rose);
  margin-top: 4px;
  font-weight: 600;
}

.reset-btn:hover {
  background: #fbdada;
  border-color: rgba(220, 76, 76, 0.4);
  transform: none;
}

/* ===== Popup ===== */
.maplibregl-popup.floating-popup .maplibregl-popup-content {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 10px 16px;
}

.maplibregl-popup.floating-popup .maplibregl-popup-tip {
  border-top-color: var(--surface);
}

/* Continuous floating bob, like the original. This is cheap — it only
   animates `transform`, which is compositor-driven and doesn't touch
   layout or paint — so it was never actually part of the stutter. The
   stutter was the backdrop-filter blur on #ui-container (fixed above) and
   the max-height menu animation (fixed above). Because this animation is
   infinite rather than one-shot, it also sidesteps the "doesn't replay on
   content swap" issue: it's always running, so switching from Ward 7 to
   Ward 8 mid-bob just continues smoothly instead of needing a restart. */
@keyframes floatBob {
  0%   { transform: translateY(0px); }
  50%  { transform: translateY(-6px); }
  100% { transform: translateY(0px); }
}

.floating-popup .maplibregl-popup-content {
  animation: floatBob 2.5s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  #toggle-icon,
  #menu-content-wrap,
  #menu-content,
  .ward-btn,
  .block-chevron,
  .block-body-wrap,
  .block-body,
  .floating-popup .maplibregl-popup-content {
    transition: none !important;
    animation: none !important;
  }
}

/* ===== Locate-me map control =====
   Added to the same 'top-right' slot as the NavigationControl (compass +
   zoom), after it — maplibre stacks same-position controls in the order
   they're added, so this sits directly beneath the compass, using its
   existing maplibregl-ctrl-group styling (white rounded box + shadow) so
   it looks like a natural extra row on that control, not a bolted-on
   button. */
.locate-ctrl-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: none;
  cursor: pointer;
  color: var(--text);
}

.locate-ctrl-btn:hover {
  color: var(--blue);
  background: var(--blue-dim);
}

.locate-ctrl-btn.loading svg {
  animation: locateSpin 0.8s linear infinite;
}

@keyframes locateSpin {
  to { transform: rotate(360deg); }
}

/* ===== "You are here" marker =====
   Only transform + opacity are animated on the pulse ring, so — same as
   the toggle-icon-badge and the floating popup bob — this is compositor
   driven and safe to leave running indefinitely. */
.user-location-dot {
  position: relative;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--dot-color, var(--blue));
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(16, 24, 39, 0.15);
}

.user-location-dot::after {
  content: "";
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  background: var(--dot-color, var(--blue));
  opacity: 0.3;
  animation: locatePulse 2.2s ease-out infinite;
}

@keyframes locatePulse {
  0%   { transform: scale(0.5); opacity: 0.35; }
  100% { transform: scale(1.9); opacity: 0; }
}

/* ===== Confirm / floor-select modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(16, 24, 39, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px 20px;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-body {
  margin: 0 0 18px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-actions.row {
  flex-direction: row;
}

.modal-btn {
  flex: 1;
  width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.modal-btn:hover {
  background: var(--blue-dim);
  border-color: rgba(47, 95, 224, 0.3);
  transform: translateY(-1px);
}

.modal-btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.modal-btn.primary:hover {
  background: #2650c2;
  border-color: #2650c2;
}

@media (prefers-reduced-motion: reduce) {
  .locate-ctrl-btn.loading svg,
  .user-location-dot::after,
  .modal-overlay,
  .modal-card,
  .modal-btn {
    transition: none !important;
    animation: none !important;
  }
}

/* ===== Buy Me a Coffee — pinned in menu footer (under Reset View) ===== */
.menu-footer .reset-btn {
  margin-top: 0;
  margin-bottom: 0;
}

.bmc-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #FFDD00;
  color: #000;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.bmc-menu-btn:hover {
  background: #ffd000;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.bmc-menu-btn:active {
  transform: translateY(0);
  background: #f5c800;
}

.bmc-menu-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.bmc-menu-text {
  line-height: 1.2;
}