:root {
  --ink: #161616;
  --muted: #5c6470;
  --panel: #ffffff;
  --line-shadow: rgba(0, 0, 0, 0.16);
  --grid-major: #d2d6dc;
  --grid-minor: #eceff3;
  --accent: #0b6bcb;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background: #fff;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.map-shell {
  height: 100dvh;
  position: relative;
  background: #ffffff;
}

.top-bar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.top-bar > div {
  pointer-events: auto;
}

.top-bar > div:first-child {
  max-width: min(460px, calc(100vw - 28px));
  padding: 12px 14px;
  border: 2px solid #111;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 4px 4px 0 #111;
}

.top-bar h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.75rem);
  line-height: 1.1;
}

.top-bar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.controls button,
.grid-toggle {
  min-height: 38px;
  border: 2px solid #111;
  border-radius: 6px;
  background: #fff;
  color: #111;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 2px 2px 0 #111;
}

.controls button {
  min-width: 38px;
}

.controls button:hover,
.grid-toggle:hover {
  background: #f3f3f3;
}

.controls button:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 #111;
}

.grid-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.map-wrap {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: #fff;
  touch-action: none;
}

#map {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background: #fff;
}

#map.dragging {
  cursor: grabbing;
}

.route-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 18;
  paint-order: stroke;
  filter: drop-shadow(0 3px 0 var(--line-shadow));
}

.route-outline {
  fill: none;
  stroke: #111;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 24;
}

.station-hit {
  cursor: pointer;
  fill: transparent;
}

.station-node {
  fill: #fff;
  stroke: #111;
  stroke-width: 4;
  filter: url(#station-shadow);
}

.station-node.major {
  stroke-width: 5;
}

.station-ring {
  fill: none;
  stroke-width: 6;
}

.station-label {
  font-size: 24px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 5;
  stroke-linejoin: round;
  fill: #111;
  user-select: none;
  vector-effect: non-scaling-stroke;
}

.grid-line {
  stroke: var(--grid-minor);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.grid-line.major {
  stroke: var(--grid-major);
  stroke-width: 1.5;
}

.grid-axis {
  stroke: #9aa2af;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.grid-label {
  fill: #68707c;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4;
  stroke-linejoin: round;
  pointer-events: none;
}


.scale-legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: min(300px, calc(100% - 32px));
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.94);
  border: 2px solid #111;
  border-radius: 8px;
  box-shadow: 4px 4px 0 #111;
  pointer-events: none;
}

.scale-line {
  width: 120px;
  height: 12px;
  margin-bottom: 8px;
  border-left: 3px solid #111;
  border-right: 3px solid #111;
  border-bottom: 3px solid #111;
}

.scale-legend strong,
.scale-legend span {
  display: block;
}

.scale-legend strong {
  font-size: 0.95rem;
}

.scale-legend span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.tooltip {
  position: fixed;
  z-index: 5;
  max-width: 280px;
  padding: 10px 12px;
  background: #111;
  color: #fff;
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.tooltip strong {
  display: block;
  margin-bottom: 5px;
  font-size: 0.98rem;
}

.tooltip span {
  display: block;
  color: #d7dce2;
}

.tooltip span.tooltip-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2; /* Adjust this number to show 1, 2, or 3 lines before clipping */
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  /*color: #a5b4fc; /* Optional: gives the description a slight tint to separate it from coordinates */
  margin-top: 6px;
  border-top: 1px solid #333;
  padding-top: 4px;
}

.line-legend {
  position: absolute;
  right: 16px;
  bottom: 16px; /* Moved down to the bottom corner */
  width: min(240px, calc(100% - 32px));
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.94);
  border: 2px solid #111;
  border-radius: 8px;
  box-shadow: 4px 4px 0 #111;
  pointer-events: auto;
  z-index: 2;

  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.line-legend h3 {
  margin: 0 0 8px 0;
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.line-legend ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 700;
}

.legend-color-swatch {
  width: 24px;
  height: 8px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.legend-boundary-swatch {
  width: 24px;
  height: 0;
  border-top: 3px dashed #32CD32;
  flex-shrink: 0;
  margin: 0 4px; 
}

.legend-node {
  background: #fff;
  border: 2.5px solid #111;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-node.major {
  width: 16px;
  height: 16px;
  border-width: 3.5px;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #111; /* Simulates the outer ring */
  margin: 4px; /* Give the double ring room to breathe */
}

.legend-node.minor {
  width: 12px;
  height: 12px;
  margin-left: 6px; /* Balance visually with the major icon */
  margin-right: 6px;
}

.legend-divider {
  height: 2px;
  background: var(--grid-minor);
  margin: 6px 0;
}

/* The state where the panel is tucked away */
.line-legend.is-collapsed {
  /* Shifts the panel exactly its full width plus its right-margin off-screen */
  transform: translateX(calc(100% + 16px));
}

/* The Tab Button sticking out on the left side of the panel */
.legend-tab {
  position: absolute;
  left: -40px; /* Pulls it outside the container boundary */
  top: 12px;
  width: 40px;
  height: 90px;
  background: rgba(255, 255, 255, 0.94);
  border-left: 2px solid #111;
  border-top: 2px solid #111;
  border-bottom: 2px solid #111;
  border-right: none;
  border-radius: 6px 0 0 6px;
  box-shadow: -4px 4px 0 rgba(0, 0, 0, 0.15); /* Match neubrutalism aesthetic */
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

/* Rotate the text vertically inside the tab */
.legend-tab span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #111;
}

.legend-tab:hover {
  background: #f3f3f3;
}

/* Modal Overlay Styling */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay:not([hidden]) {
  display: flex;
}

/* Container Box */
.modal-window {
  position: relative;
  width: min(540px, calc(100% - 32px));
  background: #ffffff;
  border: 3px solid #111;
  border-radius: 12px;
  box-shadow: 8px 8px 0 #111;
  padding: 24px;
  animation: modalSlideUp 0.25s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Close Button styling matching the neubrutalist UI */
.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: 2px solid #111;
  border-radius: 6px;
  background: #fff;
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 0 #111;
}

.modal-close-btn:hover {
  background: #f3f3f3;
}

.modal-close-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 #111;
}

/* Content Elements */
.modal-content h2 {
  margin: 0 0 16px;
  font-size: 1.6rem;
  border-bottom: 2px solid #111;
  padding-bottom: 8px;
}

.modal-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.meta-block strong {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.meta-block span {
  font-size: 1.1rem;
  font-weight: 800;
}

.modal-divider {
  border: 0;
  height: 2px;
  background: #111;
  margin: 16px 0;
}

.modal-content p {
  font-size: 1rem;
  line-height: 1.5;
  color: #222;
  margin-bottom: 20px;
}

#modal-description,
.tooltip-desc {
  white-space: pre-line; /* Tells the browser to break lines on raw \n characters */
}

/* Photo Placeholder Box */
.modal-photos-placeholder {
  background: #f3f4f6;
  border: 2px dashed #9aa2af;
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

/* Intro Animation */
@keyframes modalSlideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.map-boundary {
  fill: none;
  stroke: #32CD32;       /* Match your dominant dark ink color */
  stroke-width: 20;       /* Make it prominent but thinner than routes */
  stroke-dasharray: 12 8; /* Gives it a clean, dashed "world border" mapping look */
  pointer-events: none;
}

@media (max-width: 720px) {
  /* --- Global UI & Layout Elements --- */

  /* Hide the top-left title banner entirely */
  .top-bar > div:first-child {
    display: none;
  }

  /* Reposition the zoom controls slightly */
  .top-bar {
    top: 10px;
    right: 10px;
    left: auto;
    width: auto;
  }

  /* Make the buttons more compact */
  .controls button,
  .grid-toggle {
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.9rem;
    box-shadow: 1.5px 1.5px 0 #111;
  }
  .controls button {
    min-width: 34px;
  }

  /* Shift and downsize the Legend */
  .line-legend {
    right: 10px;
    bottom: auto;
    top: 50px;
    width: 200px;
    padding: 8px 10px;
    box-shadow: 2px 2px 0 #111;
  }

  .line-legend h3 {
    font-size: 0.8rem;
    margin-bottom: 4px;
  }

  .legend-item {
    font-size: 0.78rem;
    gap: 6px;
  }

  .legend-color-swatch {
    width: 18px;
    height: 6px;
  }

  .legend-node.major {
    width: 12px;
    height: 12px;
    border-width: 2.5px;
    box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.5px #111;
    margin: 3px;
  }

  .legend-node.minor {
    width: 10px;
    height: 10px;
    border-width: 2px;
    margin-left: 4px;
    margin-right: 4px;
  }

  .legend-divider {
    margin: 4px 0;
  }

  .line-legend.is-collapsed {
    transform: translateX(calc(100% + 10px));
  }

  .legend-tab {
    height: 70px;
    left: -34px;
    width: 34px;
    top: 8px;
  }

  .scale-legend {
    left: 10px;
    bottom: 16px;
    width: calc(100% - 20px);
    padding: 8px 12px;
    box-shadow: 2px 2px 0 #111;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 8px;
  }

  .scale-line {
    margin-bottom: 0;
    width: 80px !important;
    height: 8px;
  }

  .scale-legend strong,
  .scale-legend span {
    display: inline-block;
    font-size: 0.75rem;
    margin-top: 0;
  }

  #grid-size {
    display: none;
  }


  /* --- Mobile Bottom Sheet Modal Layout --- */

  /* Turn the dim overlay into a transparent background anchored to the base */
  .modal-overlay {
    background: rgba(0, 0, 0, 0.15);
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: none;
    overflow: hidden;
  }

  /* Target .modal-window to match your HTML framework */
  .modal-window {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 20px;
    border-radius: 24px 24px 0 0; /* Rounded top corners only */
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-top: 3px solid #111111;

    /* Clean, upward neubrutalist border shadow replaces the looping side offsets */
    box-shadow: 0 -6px 0 #111111;

    /* Expand up to 70% of viewport height */
    height: 90dvh;
    max-height: 90dvh;
    display: flex;
    flex-direction: column;
    animation: none; /* Disable standard desktop pop animation */

    /* Animation transition properties handled by JavaScript slider mechanics */
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
  }

  /* When the overlay parent is active, pop the bottom card into clear frame view */
  .modal-overlay:not([hidden]) .modal-window {
    transform: translateY(0);
  }

  /* Restructure content inside the window to allow scrolling */
  .modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Kinetic scrolling on mobile devices */
    padding-bottom: 24px; /* Room for virtual phone system home indicators */
  }

  /* Reposition the close button to behave cleanly with relative text flows */
  .modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 2;
  }

  .modal-content h2 {
    padding-right: 40px; /* Keep title from overlapping the close button */
    font-size: 1.5rem;
  }

  /* The visual grab handle bar */
  .modal-drag-handle {
    width: 40px;
    height: 5px;
    background-color: #111111;
    border-radius: 3px;
    margin: -8px auto 12px auto; /* Centers it and snuggles it near the top border */
    cursor: grab;
    flex-shrink: 0;
  }

  /* Active class used when javascript dynamically tracks a finger drag */
  .modal-window.is-dragging {
    transition: none !important; /* Disables transitions so the card tracks your finger perfectly in real-time */
  }
}

/* --- Touch Device Specific Overrides --- */
@media (hover: none) {
  #tooltip,
  .tooltip {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
}

