/* ==========================================================================
   Perspectivist Map Styles
   A cartography of life - Berlin Osloer Str. Garden Democracy
   ========================================================================== */

/* Base Styles
   ========================================================================== */

body {
  font-family: 'Comic Neue', sans-serif;
  margin: 0;
  padding: 0;
  background: #ffffff;
  background-image:
    radial-gradient(circle at 25% 25%, #f8f8f8 1px, transparent 1px),
    radial-gradient(circle at 75% 75%, #f8f8f8 1px, transparent 1px);
  background-size: 50px 50px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Layout Container
   ========================================================================== */

.container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
  overflow: hidden;
}

/* Sidebar Styles
   ========================================================================== */

.sidebar {
  width: 320px;
  background: white;
  border-right: 1px solid #e0e0e0;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-header {
  background: #ffffff;
  color: #000000;
  padding: 15px;
  position: sticky;
  top: 0;
  z-index: 101;
  border-bottom: 1px solid #e0e0e0;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 1.2em;
  font-weight: 300;
  letter-spacing: 0.5px;
}

/* Main Content Area
   ========================================================================== */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Header Styles
   ========================================================================== */

.header {
  background: #ffffff;
  color: #000000;
  padding: 6px 20px;
  padding-top: max(6px, env(safe-area-inset-top));
  text-align: center;
  position: relative;
  flex-shrink: 0;
}


.header-content {
  position: relative;
  z-index: 1;
}

.header h1 {
  margin: 0;
  font-size: 1.4em;
  font-weight: 300;
  letter-spacing: 1px;
}

.subtitle {
  margin: 1px 0 0 0;
  opacity: 0.9;
  font-size: 0.82em;
  font-weight: 300;
}

/* Map Controls
   ========================================================================== */

.map-controls {
  background: #ffffff;
  padding: 5px 15px 5px 15px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

/* When flexbox wraps, center all items */
.map-controls > * {
  flex-shrink: 0;
}

@media screen and (max-width: 1300px) {
  .map-controls {
    justify-content: center !important;
  }

  .reset-btn {
    margin-top: 5px;
  }
}

/* When items wrap to multiple lines, center everything */
@media screen and (max-width: 1200px) {
  .map-controls {
    justify-content: center !important;
    flex-direction: column !important;
    gap: 15px !important;
    align-items: center !important;
    text-align: center !important;
  }

  .filter-group {
    order: 1 !important;
    justify-content: center !important;
    width: 100% !important;
    display: flex !important;
    margin: 0 !important;
  }

  .reset-btn {
    order: 2 !important;
    margin-left: auto !important;
    margin-right: auto !important;
    display: block !important;
    align-self: center !important;
    position: relative !important;
    left: 0 !important;
    right: 0 !important;
  }
}

.filter-group {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 12px;
  border: 1px solid #b0b0b0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  font-family: 'Comic Neue', sans-serif;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  font-weight: 600;
  color: #333333;
  background: #ffffff;
}

.filter-btn.active {
  background: #e0e0e0;
  color: #000000;
  border-color: #888888;
}

.filter-btn:hover:not(.active) {
  background: #f0f0f0;
}

/* Relationship Filter Styles */
.relationship-filter-controls {
  margin-bottom: 8px;
}

.relationship-filter-controls .relationship-filter-btn {
  padding: 5px 12px;
  border: 1px solid #b0b0b0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  font-family: 'Comic Neue', sans-serif;
  font-weight: 600;
  color: #333333;
  background: #ffffff;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.relationship-filter-controls .relationship-filter-btn.active {
  background: #e0e0e0;
  color: #000000;
  border-color: #888888;
}

.relationship-filter-controls .relationship-filter-btn:hover:not(.active) {
  background: #f0f0f0;
}

.relationship-legend .relationship-filter-btn {
  cursor: pointer;
  transition: all 0.3s ease;
}

.relationship-legend .relationship-filter-btn.active,
.relationship-legend .relationship-filter-btn.legend-relation-active {
  background-color: #f0f0f0;
  border-left: 4px solid #000000;
}

.relationship-legend .relationship-filter-btn:hover {
  background-color: #f0f0f0;
  transform: translateX(2px);
}

/* Map Wrapper and SVG
   ========================================================================== */

.map-wrapper {
  flex: 1;
  background: #ffffff;
  padding: 3px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 600px;
}

#svg-container {
  display: block;
  width: 100%;
  height: 100%;
  flex: 1;
  border-radius: 0;
  background: transparent;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

#svg-container::-webkit-scrollbar {
  display: none; /* Chrome, Safari and Opera */
}

#svg-container svg {
  height: 100%;
  width: auto;
  max-width: 1400px;
  min-width: 100%;
  display: block;
  border-radius: 0;
  background: white;
}

/* Species Elements
   ========================================================================== */

.animal,
.plant,
.fungi,
.bacteria,
.virus {
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 22px;
  font-family: 'Comic Neue', sans-serif;
  font-weight: bold;
  opacity: 0.7;
  pointer-events: all;
}

/* Ensure all child elements of species groups allow clicks to bubble up */
.animal *,
.plant *,
.fungi *,
.bacteria *,
.virus * {
  pointer-events: all;
}

/* Add pointer cursor for clickable areas */
.species-click-area {
  cursor: pointer;
}

/* Disable pointer events for clickable areas of hidden species */
.species-click-area.species-hidden,
.species-click-area.species-relationship-filtered {
  pointer-events: none !important;
  cursor: default;
}

/* Disable pointer events for filtered-out relationships */
.relationship-line.relationship-filtered {
  pointer-events: none !important;
  opacity: 0.1 !important;
}

/* Disabled filter buttons (both type and relationship) */
.filter-btn.filter-disabled,
.relationship-filter-btn.filter-disabled {
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

.relationship-filter-btn.filter-disabled.filter-current {
  opacity: 1 !important;
  cursor: default !important;
}

/* New State-Based Visibility System
   ========================================================================== */

/* Initial State - All species visible */
.animal.species-initial,
.plant.species-initial,
.fungi.species-initial,
.bacteria.species-initial,
.virus.species-initial {
  opacity: 1 !important;
  filter: none !important;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

/* Faded State - Species fade when others are hovered/selected.
   grayscale() removed: it creates extra compositor layers on every faded
   element and can't be GPU-cached when many elements change state together.
   Opacity alone achieves the same visual hierarchy at a fraction of the cost. */
.animal.species-faded,
.plant.species-faded,
.fungi.species-faded,
.bacteria.species-faded,
.virus.species-faded {
  opacity: 0.15 !important;
  transition: opacity 0.3s ease;
}

/* Perspective State - Selected perspective species.
   Single drop-shadow replaces the previous two stacked shadows — each extra
   shadow forces an additional rasterisation pass at whatever resolution the
   element is currently rendered (expensive at high zoom). */
.animal.species-perspective,
.plant.species-perspective,
.fungi.species-perspective,
.bacteria.species-perspective,
.virus.species-perspective {
  opacity: 1 !important;
  filter: drop-shadow(0 0 22px #aaaaaa) !important;
  font-size: 28px !important; /* snaps immediately — transitioning font-size triggers layout reflow every frame */
  transition: opacity 0.3s ease, filter 0.3s ease;
}

/* Target State - Target species in relationship.
   Same single-shadow simplification as perspective state. */
.animal.species-target,
.plant.species-target,
.fungi.species-target,
.bacteria.species-target,
.virus.species-target {
  opacity: 1 !important;
  filter: drop-shadow(0 0 18px #bbbbbb) !important;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

/* Hover Highlight State - Temporary highlighting on hover */
.animal.species-hover-highlight,
.plant.species-hover-highlight,
.fungi.species-hover-highlight,
.bacteria.species-hover-highlight,
.virus.species-hover-highlight {
  opacity: 1 !important;
  filter: drop-shadow(0 0 8px #cccccc) !important;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

/* Hidden State - Filtered by type (greyed out) */
.animal.species-hidden,
.plant.species-hidden,
.fungi.species-hidden,
.bacteria.species-hidden,
.virus.species-hidden {
  opacity: 0.12 !important;
  pointer-events: none !important;
  transition: opacity 0.3s ease;
}

/* Relationship-filtered — must come after all state classes so it wins */
.animal.species-relationship-filtered,
.plant.species-relationship-filtered,
.fungi.species-relationship-filtered,
.bacteria.species-relationship-filtered,
.virus.species-relationship-filtered {
  opacity: 0.12 !important;
  pointer-events: none !important;
  transition: opacity 0.3s ease;
}

/* Line and Circle Visibility States */
.relationship-line.relationship-line-visible {
  opacity: 0.85 !important;
  transition: opacity 0.3s ease;
}

.relationship-line.relationship-line-faded {
  opacity: 0.2 !important;
  transition: opacity 0.3s ease;
}

.relationship-line.relationship-line-highlighted {
  opacity: 1 !important;
  transition: opacity 0.3s ease;
}

/* Species Type Colors - Hand-drawn black and white */
.vertebrates { fill: #000000; stroke: #000000; stroke-width: 2; }
.herbaceous { fill: #000000; stroke: #000000; stroke-width: 2; }
.trees { fill: #000000; stroke: #000000; stroke-width: 2; }
.fungi { fill: #000000; stroke: #000000; }
.bacteria { fill: #000000; stroke: #000000; }
.invertebrates { fill: #000000; stroke: #000000; stroke-width: 2; }
.virus { fill: #000000; stroke: #000000; }

/* Relationship Lines
   ========================================================================== */

.relationship-line {
  stroke-width: 4;
  stroke-dasharray: 10,5;
  fill: none;
  pointer-events: all;
  animation: dashFlow 4s linear infinite;
}

/* stroke colour is set per-element in visualization.js (proximity-adjusted).
   Only fallback stroke-dasharray patterns are kept here. */
.relationship-line.cooperation       { stroke-dasharray: 5,3; }
.relationship-line.neutral           { stroke-dasharray: 3,3; }
.relationship-line.parasitism        { stroke-dasharray: 8,2; }
.relationship-line.competition       { stroke-dasharray: 10,5,3,5; }
.relationship-line.predation         { stroke-dasharray: 15,5; }
.relationship-line.indirect-support  { stroke-dasharray: 10,3; }

@keyframes dashFlow {
  0% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: 30; }
}

/* Pause all stroke-dash animations while a species is being animated.
   stroke-dashoffset is not GPU-composited and causes a full repaint every
   frame on every visible line — pausing it removes the largest repaint cost
   during movement. A single class on the container covers all descendants.
   !important is required: visualization.js sets animation via inline style
   (path.style.animation = '…') which has higher CSS specificity than any
   class selector. Without !important the inline style wins and the pause
   never takes effect on the path/line children inside each line group. */
#lines-container.animations-paused .relationship-line path,
#lines-container.animations-paused .relationship-line line {
  animation: none !important;
}
#halos-container.animations-paused .animated-circle {
  animation-play-state: paused !important;
}

/* Simplify the perspective drop-shadow while the species is actively moving.
   drop-shadow re-rasterizes the element area on every frame; at high zoom
   that area is very large. A single lighter shadow is much cheaper. */
.species-animating.species-perspective {
  filter: drop-shadow(0 0 10px #cccccc) !important;
}
.species-animating.species-target {
  filter: drop-shadow(0 0 8px #cccccc) !important;
}

.animated-circle {
  animation: circleFlow 3s linear infinite;
}

.animated-circle.reverse {
  animation-direction: reverse;
}

@keyframes circleFlow {
  0% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: 24; }
}


/* Garden Background Elements
   ========================================================================== */

.garden-shape {
  fill: none;
  stroke: #000000;
  stroke-width: 2;
  stroke-dasharray: 5,5;
  stroke-miterlimit: 10;
  opacity: 0.3;
  transition: opacity 0.3s ease;
}

.pathway {
  stroke: #000000;
  stroke-width: 8px;
  stroke-dasharray: 10,5;
  fill: none;
  stroke-miterlimit: 10;
  opacity: 0.4;
  transition: opacity 0.3s ease;
}

.pathgarden {
  stroke: #000000;
  stroke-dasharray: 3,3;
  fill: none;
  stroke-width: 2px;
  stroke-miterlimit: 10;
  opacity: 0.5;
}

/* Species Panel Context Section (perspective label + relationship/instruction text)
   ========================================================================== */

.species-panel-context-section {
  order: 3;
  padding: 18px 16px 20px;
  margin: 12px 12px 0;
  background: #eef7f1;
  border-top: 3px solid #3a7d52;
  border-radius: 10px;
  border-bottom: none;
  flex-shrink: 0;
}

/* Per-type static colors */
.species-panel-context-section.rel-cooperation       { background-color: #edf9f2; border-top-color: #27ae60; }
.species-panel-context-section.rel-neutral           { background-color: #eaf3fd; border-top-color: #3498db; }
.species-panel-context-section.rel-parasitism        { background-color: #f3ecfa; border-top-color: #9b59b6; }
.species-panel-context-section.rel-competition       { background-color: #fefae6; border-top-color: #f1c40f; }
.species-panel-context-section.rel-predation         { background-color: #fdecea; border-top-color: #e74c3c; }
.species-panel-context-section.rel-indirect-support  { background-color: #e0fafa; border-top-color: #00CED1; }

/* Eyebrow & connector tinted to match type */
.species-panel-context-section.rel-cooperation      .relationship-eyebrow,
.species-panel-context-section.rel-cooperation      .relationship-connector { color: #27ae60; }
.species-panel-context-section.rel-neutral          .relationship-eyebrow,
.species-panel-context-section.rel-neutral          .relationship-connector { color: #3498db; }
.species-panel-context-section.rel-parasitism       .relationship-eyebrow,
.species-panel-context-section.rel-parasitism       .relationship-connector { color: #9b59b6; }
.species-panel-context-section.rel-competition      .relationship-eyebrow,
.species-panel-context-section.rel-competition      .relationship-connector { color: #c9a008; }
.species-panel-context-section.rel-predation        .relationship-eyebrow,
.species-panel-context-section.rel-predation        .relationship-connector { color: #e74c3c; }
.species-panel-context-section.rel-indirect-support .relationship-eyebrow,
.species-panel-context-section.rel-indirect-support .relationship-connector { color: #00a8b5; }

/* Body divider tinted to match type */
.species-panel-context-section.rel-cooperation      .relationship-body { border-top-color: rgba(39, 174, 96, 0.25); }
.species-panel-context-section.rel-neutral          .relationship-body { border-top-color: rgba(52, 152, 219, 0.25); }
.species-panel-context-section.rel-parasitism       .relationship-body { border-top-color: rgba(155, 89, 182, 0.25); }
.species-panel-context-section.rel-competition      .relationship-body { border-top-color: rgba(241, 196, 15, 0.30); }
.species-panel-context-section.rel-predation        .relationship-body { border-top-color: rgba(231, 76, 60, 0.25); }
.species-panel-context-section.rel-indirect-support .relationship-body { border-top-color: rgba(0, 206, 209, 0.25); }

/* Label, type tag, and body text tinted to match type */
.species-panel-context-section.rel-cooperation      .relationship-label,
.species-panel-context-section.rel-cooperation      .rel-type-tag,
.species-panel-context-section.rel-cooperation      .relationship-body { color: #1a8a4a; }
.species-panel-context-section.rel-neutral          .relationship-label,
.species-panel-context-section.rel-neutral          .rel-type-tag,
.species-panel-context-section.rel-neutral          .relationship-body { color: #1f72b8; }
.species-panel-context-section.rel-parasitism       .relationship-label,
.species-panel-context-section.rel-parasitism       .rel-type-tag,
.species-panel-context-section.rel-parasitism       .relationship-body { color: #7d3fa0; }
.species-panel-context-section.rel-competition      .relationship-label,
.species-panel-context-section.rel-competition      .rel-type-tag,
.species-panel-context-section.rel-competition      .relationship-body { color: #a78700; }
.species-panel-context-section.rel-predation        .relationship-label,
.species-panel-context-section.rel-predation        .rel-type-tag,
.species-panel-context-section.rel-predation        .relationship-body { color: #c0322a; }
.species-panel-context-section.rel-indirect-support .relationship-label,
.species-panel-context-section.rel-indirect-support .rel-type-tag,
.species-panel-context-section.rel-indirect-support .relationship-body { color: #007f8a; }

/* Cycling animation for the instruction state */
@keyframes relBgCycle {
  0%   { border-top-color: #27ae60; background-color: #edf9f2; }
  17%  { border-top-color: #3498db; background-color: #eaf3fd; }
  33%  { border-top-color: #9b59b6; background-color: #f3ecfa; }
  50%  { border-top-color: #f39c12; background-color: #fef6e6; }
  67%  { border-top-color: #e74c3c; background-color: #fdecea; }
  83%  { border-top-color: #00CED1; background-color: #e0fafa; }
  100% { border-top-color: #27ae60; background-color: #edf9f2; }
}

@keyframes relTextCycle {
  0%   { color: #1a9050; }
  20%  { color: #1f72b8; }
  40%  { color: #7d3fa0; }
  60%  { color: #b87800; }
  80%  { color: #c0322a; }
  100% { color: #1a9050; }
}

.species-panel-context-section.rel-cycling {
  animation: relBgCycle 20s ease-in-out infinite;
}

.species-panel-context-section.rel-cycling .relationship-info {
  animation: relTextCycle 20s ease-in-out infinite;
}

.perspective-indicator {
  font-size: 0.9em;
  font-weight: 700;
  color: #555;
  display: none;
  margin-bottom: 10px;
  text-align: center;
  letter-spacing: 0.2px;
}

.perspective-name {
  color: #000000;
  font-weight: 700;
  font-style: normal;
}

/* Base container — handles the instruction state (italic prompt text) */
.relationship-info {
  font-size: 0.92em;
  line-height: 1.65;
  color: #2c5a39;
  font-style: italic;
  text-align: center;
  word-wrap: break-word;
  white-space: normal;
  box-sizing: border-box;
}

/* Eyebrow label shown only in relationship state */
.relationship-eyebrow {
  font-size: 0.7em;
  font-weight: 700;
  color: #3a7d52;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 10px;
  font-style: normal;
}

/* Species pair heading */
.relationship-label {
  font-size: 1.05em;
  font-style: normal;
  font-weight: 400;
  color: #1a1a1a;
  text-align: center;
  margin-bottom: 14px;
  line-height: 1.35;
}

.relationship-label strong {
  font-weight: 700;
}

.relationship-connector {
  color: #3a7d52;
  font-style: normal;
  margin: 0 3px;
}

/* Relationship type label — shown between species pair label and body text */
.rel-type-tag {
  display: block;
  font-size: 0.88em;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-align: center;
  margin: 0 auto 14px;
  opacity: 0.85;
}

/* The actual relationship text — the main content */
.relationship-body {
  font-size: 0.97em;
  font-style: italic;
  color: #1a1a1a;
  line-height: 1.7;
  padding-top: 14px;
  border-top: 1px solid rgba(58, 125, 82, 0.25);
  text-align: center;
}



/* Back / reset buttons inside the context section */
.rel-reset-btn {
  display: block;
  margin: 16px auto 0;
  padding: 9px 20px;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 1em;
  font-style: normal;
  font-family: inherit;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s ease;
  color: inherit;
}

.rel-reset-btn:hover {
  opacity: 1;
}

/* Back button inside the relationship box */
.rel-back-btn {
  display: block;
  margin: 20px auto 0;
  padding: 9px 20px;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: 1em;
  font-style: normal;
  font-family: inherit;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s ease;
}

.rel-back-btn:hover {
  opacity: 1;
}

@media (max-width: 768px) {
  .rel-back-btn { display: none; }
}

/* Inherit the relationship type color from the parent section */
.species-panel-context-section.rel-cooperation      .rel-back-btn { color: #1a8a4a; }
.species-panel-context-section.rel-neutral          .rel-back-btn { color: #1f72b8; }
.species-panel-context-section.rel-parasitism       .rel-back-btn { color: #7d3fa0; }
.species-panel-context-section.rel-competition      .rel-back-btn { color: #a78700; }
.species-panel-context-section.rel-predation        .rel-back-btn { color: #c0322a; }
.species-panel-context-section.rel-indirect-support .rel-back-btn { color: #007f8a; }

/* Controls
   ========================================================================== */


@keyframes resetBtnPulse {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.12); }
  65%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

.reset-btn {
  background: #ffffff;
  color: #000000;
  border: 2px solid #000000;
  padding: 8px 22px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  font-family: 'Comic Neue', sans-serif;
  font-weight: 600;
  transition: background 0.15s ease;
  letter-spacing: 0.5px;
}

.reset-btn:hover {
  background: #f0f0f0;
}

.reset-btn.reset-btn--pulsing {
  animation: resetBtnPulse 0.45s ease-out;
}


/* Legend Styles
   ========================================================================== */

.legend-section {
  padding: 10px 12px;
}

.legend-section h3 {
  margin: 0 0 8px 0;
  font-size: 1em;
  color: #505050;
  font-weight: 600;
}

.relationship-legend {
  display: grid;
  gap: 4px;
}

.relationship-item {
  display: flex;
  align-items: center;
  padding: 4px 5px;
  font-size: 0.82em;
  border-radius: 5px;
  transition: background-color 0.2s ease;
}

.relationship-item:hover {
  background-color: #f8f9fa;
}


.relationship-color {
  width: 52px;
  height: 18px;
  margin-right: 8px;
  border-radius: 2px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  flex-shrink: 0;
}


.proximity-legend-note {
  margin-top: 8px;
  padding: 6px 8px;
  background: #f5f5f5;
  border-left: 3px solid #bbb;
  border-radius: 3px;
  font-size: 0.75em;
  color: #555;
  line-height: 1.4;
}

.proximity-legend-note p {
  margin: 0;
}

.proximity-range-demo-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 2px;
}

.proximity-intensity-label {
  font-size: 0.92em;
  color: #555;
  white-space: nowrap;
  flex-shrink: 0;
}

.proximity-range-demo {
  flex: 0 0 70px;
  width: auto;
  height: 2.5px;
  margin: 0;
  color: #27ae60;
  background-image: repeating-linear-gradient(
    to right,
    currentColor 0px,
    currentColor 10px,
    transparent 10px,
    transparent 13px
  );
  pointer-events: none;
  opacity: 0.15;
  transition: opacity 0.8s ease;
  -webkit-mask-image: linear-gradient(to right, black 0%, rgba(0,0,0,0.75) 25%, rgba(0,0,0,0.45) 55%, rgba(0,0,0,0.15) 80%, rgba(0,0,0,0.07) 100%);
  mask-image: linear-gradient(to right, black 0%, rgba(0,0,0,0.75) 25%, rgba(0,0,0,0.45) 55%, rgba(0,0,0,0.15) 80%, rgba(0,0,0,0.07) 100%);
  animation: prx-color-cycle 15s ease-in-out infinite paused;
}

.proximity-range-demo.prx-active {
  opacity: 1;
  animation-play-state: running;
}

@keyframes prx-color-cycle {
  0%   { color: #27ae60; }
  17%  { color: #3498db; }
  33%  { color: #9b59b6; }
  50%  { color: #f1c40f; }
  67%  { color: #e74c3c; }
  83%  { color: #00CED1; }
  100% { color: #27ae60; }
}

.species-legend {
  padding-right: 8px;
}

.species-group {
  margin-bottom: 10px;
}

.species-group h4 {
  margin: 0 0 5px 0;
  font-size: 0.88em;
  color: #495057;
  font-weight: 600;
}

.species-list {
  display: grid;
  gap: 2px;
}

.species-item {
  display: flex;
  align-items: center;
  padding: 2px 0;
  font-size: 0.8em;
  line-height: 1.3;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.species-item:hover {
  background-color: #f8f9fa;
  padding-left: 5px;
}

.legend-clickable {
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.species-item.active {
  background-color: #f0f0f0;
  border-left: 4px solid #000000;
  padding-left: 5px;
}

.species-item.active-target {
  background-color: #f0f0f0;
  border-left: 4px solid #666666;
  padding-left: 5px;
}

.legend-clickable:hover {
  background-color: #f0f0f0 !important;
  transform: translateX(3px);
}

.species-item.legend-faded {
  opacity: 0.25;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.relationship-legend .relationship-filter-btn.legend-faded {
  opacity: 0.35;
  transition: opacity 0.3s ease;
}

.species-group.legend-group-faded h4 {
  opacity: 0.25;
  transition: opacity 0.3s ease;
}

.species-symbol-container {
  margin-right: 8px;
  width: 42px !important;
  height: 42px !important;
  min-width: 42px;
  max-width: 42px;
  min-height: 42px;
  max-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.legend-species-symbol {
  width: 42px !important;
  height: 42px !important;
  max-width: 42px;
  max-height: 42px;
  display: block;
  background: transparent !important;
  overflow: hidden;
}

.legend-species-symbol * {
  background: transparent !important;
}

.species-details {
  flex: 1;
  min-width: 0;
}

.species-common {
  font-weight: 500;
  color: #2c3e50;
}

.species-scientific {
  font-style: italic;
  color: #6c757d;
  font-size: 0.9em;
}

/* Sidebar Toggle Button (hidden on desktop, visible on mobile)
   ========================================================================== */

.sidebar-toggle {
  display: none;
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: #ffffff;
  border: 1.5px solid #aaaaaa;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  font-family: 'Comic Neue', sans-serif;
  z-index: 10;
  padding: 0;
  transition: background 0.2s, border-color 0.2s;
}

.sidebar-toggle:hover {
  background: #f0f0f0;
  border-color: #777777;
}

/* Species Panel Toggle Button (hidden on desktop, visible on mobile)
   Mirror of .sidebar-toggle but on the right side of the header */
.species-panel-toggle {
  display: none;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: #ffffff;
  border: 1.5px solid #aaaaaa;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  font-family: 'Comic Neue', sans-serif;
  z-index: 10;
  padding: 0;
  transition: background 0.2s, border-color 0.2s;
  align-items: center;
  justify-content: center;
}

.species-panel-toggle-icon {
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
}

.species-panel-toggle:hover {
  background: #f0f0f0;
  border-color: #777777;
}

/* Sidebar overlay close button (appears inside sidebar header on mobile) */
.sidebar-close {
  display: none;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid rgba(0, 0, 0, 0.18);
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  color: #333;
  font-family: 'Comic Neue', sans-serif;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: background 0.2s, box-shadow 0.2s;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.sidebar-close:hover,
.sidebar-close:focus {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  outline: none;
}

/* Responsive Design
   ========================================================================== */

/* Laptop screen optimizations (1200px-1600px) */
@media (min-width: 1201px) and (max-width: 1600px) {
  .sidebar {
    width: 260px;
  }

  .header h1 {
    font-size: clamp(1.2em, 2.2vw, 1.4em);
  }

  .subtitle {
    font-size: clamp(0.75em, 1.2vw, 0.85em);
  }

  .sidebar-header h2 {
    font-size: clamp(1.0em, 1.8vw, 1.2em);
  }

  .filter-btn {
    padding: 5px 10px;
    font-size: clamp(0.75em, 1.1vw, 0.85em);
  }

  .reset-btn {
    padding: 5px 14px;
    font-size: clamp(13px, 1.8vw, 15px);
  }

  .legend-section {
    padding: 12px;
  }

  .species-item {
    font-size: clamp(0.75em, 1.2vw, 0.8em);
  }

  .relationship-item {
    font-size: clamp(0.8em, 1.2vw, 0.85em);
  }
}

/* High DPI display optimizations
   Sidebar width is intentionally omitted here — the viewport-width breakpoints above
   already narrow it correctly on compact HiDPI laptops (e.g. 13" Retina at ~1280px CSS).
   Adding a width override here would win by source order and undo that narrowing. */
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx) {
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* Slightly tighter controls — elements appear proportionally larger on dense screens */
  .filter-btn {
    padding: 5px 10px;
    font-size: 0.82em;
  }

  .reset-btn {
    padding: 5px 13px;
    font-size: 14px;
  }

  /* Shorter photo strip on compact HiDPI screens to give more room to text content */
  .species-panel-photo {
    height: 170px;
  }

  /* Slightly smaller nav/zoom controls — HiDPI pixel density makes smaller targets comfortable */
  .nav-arrow,
  .zoom-btn {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  /* Header and subtitle */
  .header h1  { font-size: 1.15em; }
  .subtitle   { font-size: 0.74em; }

  /* Sidebar headings */
  .sidebar-header h2 { font-size: 1.05em; }
  .legend-section h3 { font-size: 1em; }

  /* Species panel name, latin, and description */
  .species-panel-name        { font-size: 1.1em; }
  .species-panel-latin       { font-size: 0.82em; }
  .species-panel-description { font-size: 0.84em; }

  /* Relationship info section */
  .relationship-info  { font-size: 0.85em; }
  .relationship-label { font-size: 0.97em; }
  .relationship-body  { font-size: 0.88em; }
  .rel-type-tag       { font-size: 0.80em; }

  /* Compact context section padding */
  .species-panel-context-section { padding: 16px 16px 18px; }
}

/* Force horizontal overflow when map would get too small.
   Threshold lowered from 1100px to 900px to account for the right species panel
   now taking up space in the layout permanently. */
@media (max-width: 1400px) {
  #svg-container svg { min-width: 900px; }
}

@media (max-width: 1200px) {
  .sidebar { width: 250px; }
  .species-panel { width: 260px; }
}

/* ── Tablet: sidebar becomes a slide-in overlay, species panel stays visible ── */
@media (max-width: 900px) {
  /* Show the hamburger button */
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }

  /* Show sidebar back button and lay it out inside the header */
  .sidebar-close {
    display: flex;
    font-size: 0;
  }
  .sidebar-close::after {
    content: '←';
    font-size: 18px;
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
  }

  .sidebar-header h2 {
    flex: 1;
    margin: 0;
  }

  /* Header needs left room for the toggle button */
  .header { padding-left: 52px; }

  /* Sidebar slides in from the left as a fixed overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: min(300px, 85vw);
    z-index: 300;
    transform: translateX(-110%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,0.18);
  }

  /* When open */
  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  /* Dim backdrop when sidebar is open */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 299;
  }
  .sidebar-backdrop.active { display: block; }

  .species-panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 299;
  }
  .species-panel-backdrop.active { display: block; }

  .map-controls {
    flex-direction: column;
    gap: 6px;
    align-items: center;
    justify-content: center;
  }

  /* Single scrollable row instead of wrapping to multiple rows */
  .filter-group {
    justify-content: flex-start !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  /* Hide "Show:" label to save space */
  .filter-group > span:first-child { display: none; }

  /* Prevent buttons from shrinking in the scroll row */
  .filter-btn { flex-shrink: 0; }

  .reset-btn {
    align-self: center;
    width: auto;
    min-width: 160px;
  }
}

/* ── Mobile: species panel becomes a slide-in overlay ── */
@media (max-width: 768px) {
  /* Main content fills the whole width (species panel is now an overlay) */
  .main-content { width: 100%; }

  /* Zoom buttons are hidden on mobile — pinch-to-zoom is used instead */
  .zoom-btns { display: none !important; }

  /* Map SVG scaling for mobile.
     The map fills the container exactly and the JS viewBox drives ALL pan/zoom.
     The mobile home viewBox is matched to the screen aspect ratio, so the map
     stays edge-to-edge (no letterbox bars) AND every corner is reachable by
     pinch + drag — there is no separate CSS-scroll pan system to fight with. */
  #svg-container {
    overflow: hidden;
    width: 100%;
    touch-action: none; /* JS handles all touch gestures (pan + pinch zoom) */
  }

  #svg-container svg, svg {
    height: 100%;
    width: auto !important;
    max-width: none;
    min-width: 140vw;
    display: block;
  }

  /* The garden SVG itself fills the viewport; viewBox handles framing. */
  #svg-container svg {
    width: 100% !important;
    min-width: 0;
  }

  .header h1  { font-size: 1.2em; }
  .subtitle   { font-size: 0.76em; }

  .filter-btn {
    padding: 5px 9px;
    font-size: 0.76em;
  }

  .reset-btn {
    padding: 5px 12px;
    font-size: 13px;
    min-width: 120px;
  }
}

@media (max-width: 480px) {
  /* Compact zoom buttons on phones so they don't obscure too much of the map */
  .zoom-btn {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .sidebar { width: min(280px, 90vw); }

  /* Filter bar: single horizontal scroll row instead of two stacked blocks */
  .map-controls {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    justify-content: flex-start !important;
    gap: 8px !important;
    padding: 5px 10px !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* hide scrollbar on Firefox */
  }
  .map-controls::-webkit-scrollbar { display: none; }

  .filter-group {
    flex-wrap: nowrap !important;
    flex-shrink: 0 !important;
  }

  .reset-btn {
    flex-shrink: 0 !important;
    order: unset !important;
    margin: 0 !important;
    align-self: center !important;
  }

  .filter-btn {
    padding: 4px 8px;
    font-size: 0.72em;
  }

  .reset-btn {
    padding: 4px 10px;
    font-size: 12px;
    min-width: 90px;
  }

  .header h1  { font-size: 1.05em; }
  .subtitle   { display: none; }

  .sidebar-header { padding: 10px; }
  .legend-section { padding: 10px; }
}

/* Species Hover Name Display */
.species-hover-name {
  position: fixed;
  background: #ffffff;
  color: #4e4e4e;
  padding: 8px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  font-size: 1.1em;
  font-weight: 600;
  font-style: italic;
  font-family: 'Comic Neue', cursive;
  text-align: center;
  pointer-events: none;
  z-index: 1000;
  display: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

/* Footer
   ========================================================================== */

.footer {
  background: #ffffff;
  border-top: 1px solid #e0e0e0;
  padding: 3px 15px;
  flex-shrink: 0;
}

.credit-text {
  text-align: right;
  font-size: 0.85em;
  color: #6c757d;
  font-family: 'Comic Neue', sans-serif;
  font-style: italic;
  opacity: 1;
}

.credit-text a {
  color: #6c757d;
  text-decoration: underline;
}

/* Navigation Arrows
   ========================================================================== */

.nav-arrows {
  position: absolute;
  display: none;
  grid-template-columns: 45px 45px 45px;
  grid-template-rows: 45px 45px 45px;
  gap: 6px;
  z-index: 150;
  pointer-events: none;
  bottom: 10px;
  right: 10px;
}

/* Zoom buttons (left of compass rose) */
.zoom-btns {
  position: fixed;
  display: none;
  flex-direction: column;
  gap: 6px;
  z-index: 150;
  pointer-events: none;
}

.zoom-btn {
  background: #ffffff;
  color: #000000;
  border: 1px solid #b0b0b0;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: bold;
  font-family: 'Comic Neue', sans-serif;
  transition: background 0.15s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  pointer-events: auto;
  line-height: 1;
}

.zoom-btn:hover {
  background: #f0f0f0;
}

/* Compass-rose layout: up spans top-center, left/right share middle row, down spans bottom-center */
.nav-arrow.up    { grid-column: 2; grid-row: 1; }
.nav-arrow.left  { grid-column: 1; grid-row: 2; }
.nav-arrow.right { grid-column: 3; grid-row: 2; }
.nav-arrow.down  { grid-column: 2; grid-row: 3; }

.nav-arrow {
  background: #ffffff;
  color: #000000;
  border: 1px solid #b0b0b0;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  font-family: 'Comic Neue', sans-serif;
  transition: background 0.15s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  pointer-events: auto;
}

.nav-arrow:hover {
  background: #f0f0f0;
}

.nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* Right Species Detail Panel
   ========================================================================== */

/* Desktop: permanent inline sidebar, always present in the flex layout */
.species-panel {
  width: 310px;
  flex-shrink: 0;
  background: white;
  border-left: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
  position: relative;
}

/* Placeholder — visible when no perspective is selected */
.species-panel-placeholder {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.species-panel-placeholder-inner {
  text-align: center;
  color: #444;
  padding: 10px;
  border-radius: 14px;
}

.species-panel-placeholder-icon {
  margin-bottom: 14px;
  opacity: 0.75;
}

.species-panel-placeholder-icon img {
  width: 90px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.species-panel-placeholder-inner p {
  font-size: 0.92em;
  line-height: 1.65;
  margin: 0;
  font-style: italic;
}

/* Content — hidden until a perspective species is active */
.species-panel-content {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
}

/* Species selected state: swap placeholder for content */
.species-panel.species-panel-has-species .species-panel-placeholder {
  display: none;
}

.species-panel.species-panel-has-species .species-panel-content {
  display: flex;
}

/* Close button — hidden on desktop (panel is permanent), visible on mobile.
   Positioned on .species-panel (position: relative/fixed) so it never scrolls away. */
.species-panel-close {
  display: none;
  position: absolute;
  top: 10px;
  right: 12px;
  width: 30px;
  height: 30px;
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid rgba(0, 0, 0, 0.18);
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  color: #333;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  font-family: 'Comic Neue', sans-serif;
  transition: background 0.2s, box-shadow 0.2s;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.species-panel-close:hover,
.species-panel-close:focus {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  outline: none;
}

/* Photo */
.species-panel-photo-wrap {
  order: 1;
  width: 100%;
  flex-shrink: 0;
  background: #f5f5f5;
  display: flex;
  flex-direction: column;
}

.species-panel-photo-credit {
  font-size: 0.68em;
  color: #999;
  text-align: right;
  padding: 3px 6px;
  background: #f5f5f5;
  line-height: 1.3;
}

.species-panel-photo-credit a {
  color: #999;
  text-decoration: none;
}

.species-panel-photo-credit a:hover {
  color: #555;
  text-decoration: underline;
}

.species-panel-svg-icon {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.species-panel-photo {
  width: 100%;
  height: 200px;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: opacity 0.3s ease;
}

/* Name / type block */
.species-panel-info {
  order: 2;
  text-align: center;
  padding: 14px 16px 16px 16px;
}

.species-panel-name {
  margin: 0 0 4px 0;
  font-size: 1.25em;
  font-weight: 700;
  color: #000;
  line-height: 1.2;
}

.species-panel-latin {
  font-style: italic;
  color: #6c757d;
  font-size: 0.88em;
  margin-bottom: 10px;
}

.species-panel-type-badge {
  display: inline-block;
  padding: 3px 12px;
  border: 1.5px solid #000;
  border-radius: 20px;
  font-size: 0.75em;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Overview wrapper (description + traits) */
.species-overview-section {
  order: 4;
  display: flex;
  flex-direction: column;
}

.overview-heading {
  font-size: 0.68em;
  font-weight: 700;
  color: #aaa;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin: 0;
  padding: 18px 18px 8px;
}

/* Description */
.species-panel-description {
  font-size: 0.9em;
  line-height: 1.65;
  color: #333;
  margin: 0;
  padding: 0 18px 14px;
}

/* Traits */
.species-panel-traits-section {
  padding: 4px 16px 16px 16px;
  margin: 0 2px;
}

.species-panel-traits-section h3 {
  margin: 0 0 10px 0;
  font-size: 0.95em;
  font-weight: 600;
  color: #505050;
}

.species-panel-traits {
  list-style: none;
  padding: 0;
  margin: 0;
}

.species-panel-traits li {
  font-size: 0.87em;
  line-height: 1.5;
  padding: 6px 0 6px 18px;
  position: relative;
  color: #333;
}

.species-panel-traits li::before {
  content: '•';
  position: absolute;
  left: 4px;
  color: #000;
}

.species-panel-traits li:last-child {
  border-bottom: none;
}

/* Narrower on laptop range */
@media (min-width: 1441px) and (max-width: 1600px) {
  .species-panel {
    width: 270px;
  }
}

/* Narrower panels for 16:10 and similar compact-width laptops (1280px–1440px) */
@media (min-width: 1201px) and (max-width: 1440px) {
  .sidebar { width: 220px; }
  .species-panel { width: 260px; }
}

/* ≤768px: panel leaves the flex flow and becomes a fixed right-side overlay,
   mirroring the left sidebar overlay pattern. */
@media (max-width: 768px) {
  /* Show the leaf toggle button */
  .species-panel-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Header: add right padding to match left padding for toggle buttons */
  .header {
    padding-right: 52px;
  }

  /* Panel: slide in from the right, full height, covering the map */
  .species-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(420px, 100vw);
    height: 100%;
    border-left: 1px solid #e0e0e0;
    border-top: none;
    z-index: 300;
    transform: translateX(110%);
    transition: transform 0.3s ease;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
  }

  /* Slide in when active */
  .species-panel.species-panel-active {
    transform: translateX(0);
  }

  /* Close button: show as flex so ✕ is centred */
  .species-panel-close {
    display: flex;
  }

  /* Content: fully scrollable column */
  .species-panel-content {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: 0;
    height: 100%;
  }

  /* Full-width photo strip */
  .species-panel-photo-wrap {
    width: 100%;
    min-width: unset;
    height: 220px;
    flex-shrink: 0;
  }

  /* Name / type centred; right padding for the close button overlap */
  .species-panel-info {
    text-align: center;
    padding: 14px 48px 10px 14px;
    border-bottom: 1px solid #e0e0e0;
    border-right: none;
    min-width: unset;
    max-width: none;
    flex-shrink: 0;
  }

  /* Species name: allow wrapping so long names don't overflow */
  .species-panel-name {
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    font-size: 1.05em;
  }

  /* Description visible */
  .species-panel-description {
    display: block !important;
    padding: 10px 16px;
    border-bottom: 1px solid #e0e0e0;
    font-size: 0.83em;
    line-height: 1.5;
    overflow-wrap: break-word;
    overflow: visible;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
  }

  /* Traits visible */
  .species-panel-traits-section {
    display: block;
    padding: 10px 16px 24px 16px;
  }

  .species-panel-traits li {
    overflow-wrap: break-word;
  }

  /* Replace ✕ with directional arrow on species panel close button */
  .species-panel-close {
    font-size: 0;
  }
  .species-panel-close::after {
    content: '→';
    font-size: 18px;
  }

  /* Hide "Back to species selection" — panel is navigated via the close button on mobile */
  .rel-reset-btn {
    display: none;
  }
}

/* Large HiDPI/scaled displays (e.g. 1920×1200 at 150% = 1280px CSS viewport).
   Without this, the two sidebars consume 480px of a 1280px viewport, leaving too little
   room for the map. The combined query targets only wide physical screens with OS scaling
   (not small HiDPI laptops where the viewport really is narrow). */
@media (min-width: 1201px) and (max-width: 1440px) and (-webkit-min-device-pixel-ratio: 1.5),
       (min-width: 1201px) and (max-width: 1440px) and (min-resolution: 1.5dppx) {
  body { font-size: 13.5px; }
  .sidebar { width: 185px; }
  .species-panel { width: 215px; }
  /* Prevent the 900px SVG min-width from overflowing the ~880px map container */
  #svg-container { overflow: hidden; }
  #svg-container svg { min-width: 100%; }
  /* Lock out vertical scroll on the main column — flex layout handles sizing */
  .main-content { overflow-y: hidden; }
  /* Smaller nav/zoom controls — 40px from the general HiDPI rule is still too large here */
  .nav-arrow,
  .zoom-btn      { width: 32px; height: 32px; }
  .nav-arrow     { font-size: 13px; }
  .zoom-btn      { font-size: 16px; }
  .nav-arrows    { grid-template-columns: 32px 32px 32px; grid-template-rows: 32px 32px 32px; gap: 4px; }
  .zoom-btns     { gap: 4px; }
}

/* Phone size adjustments (≤480px) — panel stays as a right-side slide-in (same as 768px) */
@media (max-width: 480px) {
  .species-panel-photo-wrap {
    height: 120px;
    overflow: hidden;
  }

  .species-panel-photo {
    height: 100%;
  }

  /* Hide nav arrows on phones — touch panning is enough */
  .nav-arrows {
    display: none !important;
  }

  .species-panel-name {
    font-size: 0.97em;
  }

  .species-panel-latin {
    font-size: 0.79em;
  }

  .species-panel-type-badge {
    font-size: 0.68em;
  }

  .species-panel-description {
    font-size: 0.79em;
    padding: 8px 14px;
  }

  .species-panel-traits-section {
    padding: 8px 14px 24px 14px;
  }

  .species-panel-traits li {
    font-size: 0.77em;
    padding: 4px 0 4px 14px;
  }
}

/* ==========================================================================
   Info Button (minimized tour state)
   ========================================================================== */

.tour-info-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 45px;
  height: 45px;
  background: #ffffff;
  border: 1px solid #b0b0b0;
  border-radius: 50%;
  cursor: pointer;
  font-family: 'Comic Neue', sans-serif;
  font-size: 1.3em;
  font-style: normal;
  font-weight: 700;
  color: #000000;
  z-index: 201;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: background 0.15s ease;
}

.tour-info-btn:hover {
  background: #f0f0f0;
}

.tour-info-btn-hidden {
  display: none;
}

@media (max-width: 768px) {
  .tour-info-btn {
    display: none !important;
  }
}

/* ==========================================================================
   Guided Tour Overlay
   ========================================================================== */

.tour-overlay {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 210px;
  max-height: calc(100% - 30px);
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-radius: 12px;
  padding: 12px 12px 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transform: translateX(18px);
  transition: opacity 0.38s ease, transform 0.38s ease;
  font-family: 'Comic Neue', sans-serif;
}

.tour-overlay.tour-visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.tour-overlay.tour-exiting {
  opacity: 0;
  transform: translateX(18px);
  transition: opacity 0.32s ease, transform 0.32s ease;
  pointer-events: none;
}

.tour-overlay.tour-visible.tour-dimmed {
  opacity: 0.08;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.tour-overlay.tour-visible.tour-dimmed .tour-header {
  pointer-events: auto;
}

/* Header row */
.tour-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  border-bottom: 1px solid #000;
  padding-bottom: 5px;
}

.tour-title {
  font-size: 0.76em;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #000000;
  transition: opacity 0.18s ease;
}

.tour-dismiss-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  font-size: 0.82em;
  line-height: 1;
  padding: 2px 0 2px 10px;
  transition: color 0.15s;
  font-family: inherit;
}

.tour-dismiss-btn:hover {
  color: #000;
}

/* Text area */
.tour-text {
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tour-line {
  font-size: 0.86em;
  line-height: 1.5;
  color: #000000;
  margin: 0 0 7px;
}

.tour-line:last-child {
  margin-bottom: 0;
}

.tour-action-line {
  font-style: italic;
  font-weight: 700;
  color: #000000;
  border-top: 1px dashed #000;
  padding-top: 6px;
  margin-top: 3px;
}

/* Step indicator dots */
.tour-footer {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin-top: 8px;
  border-top: 1px solid #e8e8e8;
  padding-top: 7px;
}

.tour-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ddd;
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.tour-dot-active {
  background: #000000;
}

/* Compact on mobile */
@media (max-width: 768px) {
  .tour-overlay {
    top: 8px;
    right: 8px;
    width: 270px;
    max-height: calc(100% - 20px);
    padding: 12px 15px 11px;
  }

  .tour-line {
    font-size: 0.84em;
  }
}

/* Short screens — reduce font further so more content fits before scroll kicks in */
@media (max-height: 620px) {
  .tour-overlay {
    top: 8px;
    max-height: calc(100% - 20px);
  }

  .tour-line {
    font-size: 0.82em;
    line-height: 1.48;
    margin-bottom: 7px;
  }

  .tour-header {
    margin-bottom: 6px;
    padding-bottom: 5px;
  }

  .tour-footer {
    margin-top: 8px;
    padding-top: 7px;
  }
}

/* Hide on very small phones where there is no room */
@media (max-width: 380px) {
  .tour-overlay {
    display: none;
  }
}

/* ==========================================================================
   Mobile Experience Notice
   ========================================================================== */

.mobile-notice {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 600;
  align-items: center;
  justify-content: center;
  padding: 24px;
  font-family: 'Comic Neue', sans-serif;
}

.mobile-notice.mobile-notice-visible {
  display: flex;
}

.mobile-notice-card {
  background: #ffffff;
  border: 2px solid #000000;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.10);
  padding: 28px 24px 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
}

.mobile-notice-icon {
  font-size: 2.4em;
  margin-bottom: 14px;
  line-height: 1;
}

.mobile-notice-text {
  font-size: 0.95em;
  line-height: 1.65;
  margin: 0 0 22px;
  color: #333;
}

.mobile-notice-btn {
  background: #000000;
  color: #ffffff;
  border: none;
  padding: 10px 32px;
  font-family: 'Comic Neue', sans-serif;
  font-size: 0.92em;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s;
}

.mobile-notice-btn:hover,
.mobile-notice-btn:focus {
  background: #333;
  outline: none;
}
