body {image-rendering: -webkit-optimize-contrast};

#loading-spinner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  color: #fff;
  background: rgba(187, 51, 51,0.8);
  padding: 10px 20px;
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
  z-index: 2000; /* Ensure spinner is above other elements */
}

/* Gallery grid lives inside the flex-centered modal-content */
/* make the grid use 2 rows that can shrink */
#modal .modal-gallery{
  width: 100%;
  height: 100%;
  min-height: 0;

  display: grid;
  gap: 10px;

  grid-template-columns: repeat(3, minmax(0, 1fr));
   /* key lines */
  grid-auto-rows: clamp(180px, 39vh, 400px); /*minmax(0, 1fr);*/
  /* align-content: stretch; */
  align-content: start;
  overflow-y: auto;       /* ready for future large galleries */
  padding-right: 6px;     /* keeps scrollbar off images slightly */
  box-sizing: border-box;
}

/* 1 image gallery can be forced to 1 column if you ever use the wrapper with 1 img */
#modal .modal-gallery.one{
  grid-template-columns: 1fr;
}




#modal {
  
  display: none;
  position: fixed; /* Position relative to the viewport */
  top: 50%;
  left: 50%;
  /*transform: translate(-50%, -50%); /* Center the modal */
  width: 70vw; /* Set a percentage width for responsiveness */
  max-width: 90vw; /* Optional: limit modal width */
  height: auto; /* Adjust height to fit content */
  max-height: 90vh; /* Optional: limit modal height */
  border: 1px solid #CCC;
  background: #EEE;
  padding: 5px;
    z-index: 1000;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
  overflow: hidden; /* Hide scrollbars */
    overflow-y:auto;
  text-align: center; /* Center text or image within modal */
}



/* applies only to images directly in .modal-content, not inside gallery */
#modal .modal-content > img{
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: auto;
}
/* Ensure each image fills its grid cell, but is not cropped
#modal .modal-gallery img{
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
} */
/* Each grid cell wrapper */
#modal .modal-gallery .windrose-slot{
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;         /* prevents bleed */
  display: flex;            /* helps center SVG */
  align-items: center;
  justify-content: center;
}

/* Make inlined SVG behave like your <img> did */
#modal .modal-gallery .windrose-slot svg{
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}
/* When a windrose tile is fullscreen, center its contents */
.windrose-slot:fullscreen{
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
}

.windrose-slot:fullscreen svg{
  width: min(95vw, 95vh);
  height: auto;
  max-height: 95vh;
}
/* Fullscreen: default cursor everywhere */
.windrose-slot:fullscreen,
.windrose-slot:fullscreen svg {
  cursor: zoom-out;
}
/* Only in fullscreen, when hovering a wedge, show pointer */
.windrose-slot:fullscreen .wedge-hit:hover {
  cursor: pointer;
}
.windrose-slot:fullscreen .legend-hit:hover {
  cursor: pointer;
}

.windrose-slot,
.windrose-slot svg {
  cursor: zoom-in;
}
/* Ensure fullscreen element paints black immediately */
.windrose-slot{
  position: relative;
  background: #0000; /* normal mode can be transparent */
  transform: translateZ(0); /* Forces hardware acceleration */
    /* or */
    transform: translate3d(0, 0, 0);

}
/* Ensure SVG sits below overlay */
.windrose-slot svg{ position: relative; z-index: 1; }

.windrose-slot .fs-overlay{
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 10;
}

/* Turn it on briefly during transitions */
.windrose-slot.fs-fade-local .fs-overlay{
  opacity: 1;
}
.windrose-slot:fullscreen{
  background: #000;
}
.windrose-slot:fullscreen svg{
  background: #000;
}
.windrose-svg image { pointer-events: none; }
.windrose-svg .wedge-hit { pointer-events: all; }
.windrose-svg .legend-hit {
  pointer-events: all;
  cursor: pointer;
  fill: transparent;
  stroke: transparent;
  vector-effect: non-scaling-stroke; /* keeps stroke ~same thickness when SVG scales */
}

.modal-content iframe {
  width: 100%;
  height: 100%;
  border: 0;
  max-width: 100%; /* Ensure the image fits the modal width */
    max-height: 100%;
  display: block; /* Remove inline spacing */
  /* margin: auto; /*Center the image horizontally */
}


#modal:target {
  display: block;
}

#modal .modal-header {
  cursor: grab; /* Indicate draggable area */
  padding: 5px;
  background: #b33;
  color: #fff;
  display: flex;
  justify-content: space-between; /* push first item far-left and last item far-right */
  align-items: center;
    font-size: 20px;
}
#modal .modal-header .close {
  color: #ffff00; /* Bright yellow color for close button */
  font-size: 20px; /* Make it slightly larger */
  font-weight: bold; /* Ensure it looks bold */
  text-decoration: none; /* Remove underline */
  padding: 0 5px; /* Add padding for better clickability */
  cursor: pointer; /* Change cursor to pointer */
  transition: color 0.095s ease-in-out; /* Smooth hover effect */
}

#modal .modal-header .close:hover {
  color: #ff4c4c; /* Change color on hover */
    background-color: #fff;
}

#modal .modal-content {
  padding: 5px;
   height: calc(90vh - 52px); /* subtract your header height (adjust) */
  overflow-y: auto;          /* or auto if you want scroll */
  overflow-x: hidden;
  display: block;
  /* align-items: center; */
  /* justify-content: center; */
  min-height: 0;
  min-width: 0;
}
/* Backdrop styling (optional) */
body::before {
  content: ""; /* Required for pseudo-element to appear */
  position: fixed; /* Covers the viewport */
  top: 0;
  left: 0;
  width: 100vw; /* Full width */
  height: 100vh; /* Full height */
  background: rgba(0, 0, 0, 0.3); /* Semi-transparent black */
  z-index: 900; /* Below the modal but above other content */
  /*display: none; /* Initially hidden */
    opacity: 0;
    pointer-events: none;
     transition: opacity 0.25s ease; /* Smooth transition */
}

body.modal-active::before {
  display: block; /* Show backdrop when modal is active */
    opacity:1;
    pointer-events: auto;
}
/* Fullscreen transition overlay */
body::after{
  content:"";
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 2147483647; /* top */
}
body.fs-fade::after{
  opacity: 1;
}

/* Container for the tooltip */
.tooltip-container {
  /*position: relative;*/ /* Ensures tooltip is positioned relative to this element */
  display: inline-block;
  cursor: pointer;
    white-space: pre-line;
    /* line-height: 0; */
}
.tooltip-blue  .tooltiptext { background-color:#2c6fb7; }
.tooltip-purple .tooltiptext {background-color: #6c1990;}
.tooltip-green .tooltiptext { background-color:#2e7d32; }
.tooltip-red   .tooltiptext { background-color:#c62828; }
.tooltip-CardinalRed   .tooltiptext { background-color:#b33;}


.tooltip {
      /* pointer-events: none; */
    will-change: transform;

 position: fixed; /* Makes it follow the viewport */
 left: 0;
 top: 0;
   text-align: center;
  background-color: var(--tooltip-bg, #b33);
  color: #fff;
  padding: 5px 10px;
  border-radius: 4px;
  white-space: pre-line; /*nowrap;*/
  pointer-events: none; /* Ensures it doesn't interfere with pointer events */
  opacity: 0; /* Hidden by default */
  visibility: hidden; /* Prevents rendering when not needed */
  /* transition: opacity 0.25s ease-in-out; */
  transition: opacity 0.3s ease-in-out, visibility 0s linear 0.3s;
  z-index: 9999999;
}
.tooltip.show{
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s ease-in-out, visibility 0s; /* needed for windrose tooltip behavior */
}

/*

/* Show the tooltip on hover */
.tooltip-container:hover .tooltip {
  visibility: visible; /* Make the tooltip visible */
  opacity: 1; /* Fully opaque */
}

/* Make tooltip content compact */
#wr-tooltip.tooltip{
  text-align: center;
  padding: 6px 8px;          /* smaller */
  white-space: normal;
  line-height: 1.15;         /* tighter lines */
  /* align-items: center; */
}
.wr-tooltip-title {
  font-weight: bold;
  margin: 0 0 4px 0;         /* remove top space */
  line-height: 1.1;
}

.wr-tooltip-row{
  margin: 0;
  line-height: 1.1;
}
.wr-tooltip-pct{
  margin: 2px 0 0 0;         /* small gap before pct */
  line-height: 1.1;
}
.wr-tooltip-swatch {
  width: 15px;
  height: 15px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
  margin-right: 8px;
  border: 2px solid #909090;  
}

.wldatacell{
text-align: center;
  max-width:fit-content;
}
.wldatatitle{
  max-width:fit-content;
}

@media (max-width:600px){
    #modal {
        width: 90vw;
        max-height: 80vh;
        padding: 10px;
    }
    
    .modal-content iframe {
        max-width: 100%; /* ensure iframe fits smaller modal. */
        height: 300px; /* adjust height for mobile*/
    }
}

@media (prefers-reduced-motion: reduce){
  .windrose-slot .fs-overlay{
    transition: none !important;
  }
}
/* when inside an iframe, reduce vertical footprint a bit */
@media (max-height: 750px){
  #button-container button { margin: 4px 6px; }
  #button-container { min-height: 32px; }
  #sldr { margin-top: 4px; }
}

/* Cap modal aspect ratio so W/H never exceeds ~1.61 */
#modal{
  --arMax: 1.64; /* aspect ratio variable */
  --headerH: 52px; /* matches your .modal-content height calc */

  /* height constraint (you already have max-height: 90vh) */
  max-height: 90vh;

  /* key: width cannot exceed (available height * arMax) */
  width: min(90vw, calc((90vh - var(--headerH)) * var(--arMax)));

  /* keep your existing min width behavior if desired */
  min-width: 360px;
}

/* --- NWS Forecast modal layout --- */
#modal .forecast-wrap{
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 10px;
  height: 100%;
  min-height: 0;
}

#modal .forecast-list{
  overflow: auto;
  background: #fff;
  border: 1px solid #bbb;
  text-align: left;
}

#modal .forecast-item{
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid #e2e2e2;
  cursor: pointer;
}

#modal .forecast-item:hover{ background: #f3f3f3; }
#modal .forecast-item.active{ background: #e7eef8; }

#modal .forecast-item img{
  width: 56px;
  height: 56px;
  object-fit: contain;
}

#modal .forecast-item .name{ font-weight: 700; }
#modal .forecast-item .meta{ font-size: 12px; color: #444; }

#modal .forecast-detail{
  overflow: auto;
  background: #fff;
  border: 1px solid #bbb;
  padding: 10px;
  text-align: left;
}

#modal .forecast-detail h3{
  margin: 0 0 6px 0;
}

#modal .forecast-detail .detail-meta{
  font-size: 13px;
  color: #333;
  margin-bottom: 10px;
}
/* Left list no longer has icon column */
#modal .forecast-item{
  display: block;
  padding: 8px;
}

/* Pair detail blocks */
#modal .forecast-block{ margin-bottom: 10px; }
#modal .forecast-block-head{
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 16px;
  align-items: center;
}
#modal .forecast-icon{
  width: 128px;
  height: 128px;
  object-fit: contain;
}
#modal .forecast-block-title{ font-weight: 800; }
#modal .forecast-block-meta{ font-size: 13px; margin-top: 2px; color: #333; }
#modal .forecast-block-short{ margin-top: 6px; }
#modal .forecast-block-detail{ margin-top: 8px; }

#modal .forecast-divider{
  border: 0;
  border-top: 1px solid #ddd;
  margin: 10px 0;
}
/* Stack on narrow screens */
@media (max-width: 720px){
  #modal .forecast-wrap{ grid-template-columns: 1fr; }
}


/* p.gauge-rows {
  margin: 0 !important;
  padding: 0 !important;
  display: flex !important;
  justify-content: center !important;
  align-items: flex-end !important;
  row-gap: 50px !important;
  background: rgba(255,0,0,0.2) !important;
}

p.gauge-rows {
  align-items: bottom;
  display: block !important;
  margin: 20px 0 0px 0 !important;
  padding: 0 10px 0 0 !important;
  outline: 2px solid red !important;
  background: rgba(255,0,0,0.08) !important;
} */

p.gauge-rows {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 12px;
  margin-top: 18px;
  margin-left: 20px;
  margin-right: 20px;
  /* outline: 1px solid red;
  background: rgba(255,0,0,0.09); */
}

td p.gauge-rows + p.gauge-rows {
  margin-top: 18px;
}

#windGaugeSvg:fullscreen {
   cursor: zoom-out;
}

/* #windGaugeTitle {
  color: #f00;
} */

#ticksGroup .minor-tick {
  stroke-width: 2.5;
  opacity: 0.9;
}

/* additional windrose gallery css*/
.windrose-slot {
  min-height: 220px;
  position: relative;
  box-sizing: border-box;
}

.windrose-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  border: 1px solid #bbb;
  background: #f7f7f7;
  color: #444;
  text-align: center;
  padding: 10px;
  box-sizing: border-box;
}

.windrose-loading-title {
  font-weight: bold;
  margin-bottom: 8px;
}

.windrose-loading-body {
  font-size: 14px;
}

.windrose-load-failed {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid #c88;
  background: #fff3f3;
  color: #933;
  text-align: center;
  padding: 10px;
  box-sizing: border-box;
}

.windrose-customize-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  cursor: pointer;
  border: 2px dashed #777;
  background: #f3f3f3;
}

.windrose-customize-inner {
  text-align: center;
  color: #444;
  user-select: none;
}

.windrose-customize-plus {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 8px;
}

.windrose-customize-label {
  font-size: 20px;
  font-weight: bold;
}
