/* ==========================================================================
   NCAR Brand Style Guide Implementation
   Scrolling Story Version
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties (NCAR Brand Colors)
   -------------------------------------------------------------------------- */
:root {
  /* Primary Colors */
  --ncar-blue: #0057C2;
  --dark-blue: #00357A;

  /* Secondary Colors */
  --space: #011837;
  --light-blue: #42C0FF;
  --light-gray: #F1F0EE;
  --white: #FFFFFF;

  /* Accent Colors */
  --accent-orange: #FAA119;
  --accent-yellow: #FFDD31;

  /* Model Colors (grouped-hue, colorblind-safe) */
  --model-credit: #0072B2;
  --model-multimodel: #56B4E9;
  --model-fourcastnet: #009E73;
  --model-fourcastnet_multimodel: #66CCAA;
  --model-graphcast: #E69F00;
  --model-graphcast_multimodel: #F0C75E;
  --model-pangu: #CC79A7;
  --model-pangu_multimodel: #DEAAC8;
  --model-4dwx: #999999;

  /* Typography */
  --font-family: 'Poppins', Helvetica, Arial, sans-serif;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  --spacing-3xl: 4rem;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;

  /* Content width */
  --content-max-width: 1000px;
  --plot-max-width: 1200px;
}

/* --------------------------------------------------------------------------
   Reset & Base Styles
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background-color: var(--white);
  color: var(--dark-blue);
  line-height: 1.7;
}

/* --------------------------------------------------------------------------
   Hero Section
   -------------------------------------------------------------------------- */
.hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Matches the graphic's edge colors - top is NCAR Blue, bottom is darker */
  background: linear-gradient(to bottom, var(--ncar-blue) 0%, var(--dark-blue) 100%);
}

/* NCAR Brand: Wave graphic - full height, width auto to preserve curvature */
.hero-wave {
  position: absolute;
  inset: 0;
  background: url("../../assets/wave-fills-c-color.png") no-repeat center center;
  background-size: auto 100%;
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 1;
  text-align: center;
  color: var(--white);
  padding: var(--spacing-xl) var(--spacing-3xl);
  max-width: 800px;
  background: rgba(1, 24, 55, 0.75);  /* Semi-transparent Space color backdrop */
  border-radius: 16px;
}

.hero-logo {
  height: 60px;
  margin-bottom: var(--spacing-xl);
}

.logo-fallback {
  font-size: 1.5rem;
  font-weight: 700;
  display: block;
  margin-bottom: var(--spacing-xl);
}

.title-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.title-link:hover {
  opacity: 0.85;
}

.hero h1 {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: var(--spacing-lg);
}

.hero-subtitle {
  font-size: 1.25rem;
  opacity: 0.9;
  margin-bottom: var(--spacing-3xl);
}

.hero-scroll-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
  opacity: 0.7;
  animation: bounce 2s infinite;
}

.hero-scroll-hint svg {
  width: 24px;
  height: 24px;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(10px); }
}

/* --------------------------------------------------------------------------
   Sticky Controls
   -------------------------------------------------------------------------- */
.sticky-controls {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--white);
  border-bottom: 2px solid var(--ncar-blue);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.controls-inner {
  max-width: var(--plot-max-width);
  margin: 0 auto;
  padding: var(--spacing-md) var(--spacing-xl);
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.control-group label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--dark-blue);
}

.control-group select {
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid var(--light-gray);
  border-radius: 6px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  background: var(--white);
  color: var(--dark-blue);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.control-group select:hover,
.control-group select:focus {
  border-color: var(--ncar-blue);
  outline: none;
}

.btn-print {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-md);
  margin-left: auto;
  background: var(--ncar-blue);
  border: none;
  border-radius: 6px;
  color: var(--white);
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.btn-print:hover {
  background: var(--dark-blue);
}

.btn-print svg {
  width: 18px;
  height: 18px;
}

/* --------------------------------------------------------------------------
   Story Content
   -------------------------------------------------------------------------- */
.story-content {
  max-width: var(--plot-max-width);
  margin: 0 auto;
  padding: var(--spacing-3xl) var(--spacing-xl);
}

/* --------------------------------------------------------------------------
   Story Sections
   -------------------------------------------------------------------------- */
.story-section {
  margin-bottom: var(--spacing-xl);
  padding-bottom: var(--spacing-md);
  position: relative;
}

/* NCAR wave separator - using brand SVG with colored wave lines */
.story-section::after {
  content: '';
  display: block;
  width: 120%;
  height: 100px;
  margin-top: 20px;
  margin-left: -10%;
  background: url("../../assets/wave-lines-separator.svg") no-repeat left center;
}

.story-section:last-child::after {
  display: none;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

.section-number {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--ncar-blue);  /* WCAG AA: Light Blue fails on white; NCAR Blue passes */
  line-height: 1;
}

.section-header h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--dark-blue);
}

.section-text {
  max-width: var(--content-max-width);
  margin-bottom: var(--spacing-xl);
}

.section-text p {
  margin-bottom: var(--spacing-md);
  color: var(--dark-blue);
}

.section-text strong {
  color: var(--ncar-blue);
}

/* --------------------------------------------------------------------------
   Metrics Summary (Intro Section)
   -------------------------------------------------------------------------- */
.metrics-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--spacing-md);
  margin-top: var(--spacing-xl);
}

.metric-card {
  background: var(--light-gray);
  padding: var(--spacing-lg);
  border-radius: 8px;
  text-align: center;
}

.metric-card.credit {
  background: rgba(0, 114, 178, 0.1);
  border-left: 4px solid var(--model-credit);
}

.metric-card.multimodel {
  background: rgba(86, 180, 233, 0.1);
  border-left: 4px solid var(--model-multimodel);
}

.metric-card.fourcastnet {
  background: rgba(0, 158, 115, 0.1);
  border-left: 4px solid var(--model-fourcastnet);
}

.metric-card.fourcastnet_multimodel {
  background: rgba(102, 204, 170, 0.1);
  border-left: 4px solid var(--model-fourcastnet_multimodel);
}

.metric-card.graphcast {
  background: rgba(230, 159, 0, 0.1);
  border-left: 4px solid var(--model-graphcast);
}

.metric-card.graphcast_multimodel {
  background: rgba(240, 199, 94, 0.1);
  border-left: 4px solid var(--model-graphcast_multimodel);
}

.metric-card.pangu {
  background: rgba(204, 121, 167, 0.1);
  border-left: 4px solid var(--model-pangu);
}

.metric-card.pangu_multimodel {
  background: rgba(222, 170, 200, 0.1);
  border-left: 4px solid var(--model-pangu_multimodel);
}

.metric-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--dark-blue);
  margin-bottom: var(--spacing-xs);
}

.metric-card.credit .metric-value { color: var(--model-credit); }
.metric-card.multimodel .metric-value { color: var(--model-multimodel); }
.metric-card.fourcastnet .metric-value { color: var(--model-fourcastnet); }
.metric-card.fourcastnet_multimodel .metric-value { color: var(--model-fourcastnet_multimodel); }
.metric-card.graphcast .metric-value { color: var(--model-graphcast); }
.metric-card.graphcast_multimodel .metric-value { color: var(--model-graphcast_multimodel); }
.metric-card.pangu .metric-value { color: var(--model-pangu); }
.metric-card.pangu_multimodel .metric-value { color: var(--model-pangu_multimodel); }

.metric-label {
  font-size: 0.85rem;
  color: var(--dark-blue);
  opacity: 0.7;
}

/* --------------------------------------------------------------------------
   Plot Sub-sections (Section 03 dual plots)
   -------------------------------------------------------------------------- */
.plot-subsection {
  margin-bottom: var(--spacing-xl);
}

.plot-subtitle {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--dark-blue);
  margin-bottom: var(--spacing-md);
}

.plot-controls {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}

.plot-controls label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--dark-blue);
}

.plot-controls select {
  padding: var(--spacing-sm) var(--spacing-md);
  border: 2px solid var(--light-gray);
  border-radius: 6px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  background: var(--white);
  color: var(--dark-blue);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.plot-controls select:hover,
.plot-controls select:focus {
  border-color: var(--ncar-blue);
  outline: none;
}

/* --------------------------------------------------------------------------
   Plot Wrapper
   -------------------------------------------------------------------------- */
.plot-wrapper {
  background: var(--light-gray);
  border-radius: 12px;
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

.plot-container {
  width: 100%;
  min-height: 450px;
  background: var(--white);
  border-radius: 8px;
}

.map-container {
  min-height: 500px;
}

.heatmap-wrapper .plot-container {
  min-height: 500px;
}

/* --------------------------------------------------------------------------
   Interpretation Boxes
   -------------------------------------------------------------------------- */
.section-interpretation {
  max-width: var(--content-max-width);
  background: linear-gradient(135deg, rgba(0, 87, 194, 0.05) 0%, rgba(66, 192, 255, 0.05) 100%);
  border-left: 4px solid var(--ncar-blue);
  padding: var(--spacing-lg);
  border-radius: 0 8px 8px 0;
}

.section-interpretation h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ncar-blue);
  margin-bottom: var(--spacing-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section-interpretation p {
  margin: 0;
  color: var(--dark-blue);
}

/* --------------------------------------------------------------------------
   Methodology Section
   -------------------------------------------------------------------------- */
.methodology-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--dark-blue);
  margin-top: var(--spacing-xl);
  margin-bottom: var(--spacing-sm);
}

.methodology-content h3:first-child {
  margin-top: 0;
}

.methodology-content ul {
  list-style: none;
  padding-left: 0;
}

.methodology-content li {
  padding: var(--spacing-sm) 0;
  padding-left: var(--spacing-lg);
  position: relative;
}

.methodology-content li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  background: var(--ncar-blue);
  border-radius: 50%;
}

/* --------------------------------------------------------------------------
   Footer - One-Pager Style (per NCAR Brand Guide p.30)
   Wavy top edge transitioning from page content to footer
   -------------------------------------------------------------------------- */
.footer {
  background: var(--space);
  color: var(--white);
  padding: 0;
  margin-top: 100px;  /* Space for wave to overlap into */
  position: relative;
  overflow: visible;
}

/* Wavy top edge - SVG wave shape matching NCAR brand curves */
.footer::before {
  content: '';
  position: absolute;
  top: -100px;
  left: 0;
  right: 0;
  height: 100px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 100' preserveAspectRatio='none'%3E%3Cpath d='M0,100 L0,60 Q360,100 720,40 Q1080,-20 1440,60 L1440,100 Z' fill='%23011837'/%3E%3C/svg%3E");
  background-size: 100% 100%;
}

.footer-content {
  max-width: var(--plot-max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-xl);
  flex-wrap: wrap;
  padding: var(--spacing-xl) var(--spacing-xl) var(--spacing-2xl);
}

.footer-brand {
  order: 2;  /* Logo on right per One-Pager style */
}

.footer-logo {
  height: 60px;  /* NCAR Brand: minimum 5/8" (~60px at 96dpi) */
}

.footer-text {
  order: 1;  /* Text on left */
  flex: 1;
}

.footer-text p {
  margin-bottom: var(--spacing-xs);
  opacity: 0.9;
}

.footer-date {
  opacity: 0.6;
  font-size: 0.85rem;
}

/* --------------------------------------------------------------------------
   Loading State
   -------------------------------------------------------------------------- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 400px;
  font-size: 1rem;
  color: var(--ncar-blue);
  font-weight: 500;
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  margin-left: var(--spacing-sm);
  border: 3px solid var(--light-gray);
  border-top-color: var(--ncar-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
#toast-container {
  position: fixed;
  top: 80px;
  right: var(--spacing-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.toast {
  padding: var(--spacing-md) var(--spacing-lg);
  background: var(--space);
  color: var(--white);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: slideIn 0.3s ease-out;
}

.toast.error { background: #c62828; }
.toast.success { background: #2e7d32; }

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   Map Styles
   -------------------------------------------------------------------------- */
#map,
.leaflet-container {
  height: 100%;
  width: 100%;
  min-height: 450px;
  border-radius: 8px;
}

.leaflet-popup-content {
  font-family: var(--font-family);
  font-size: 0.9rem;
}

.legend {
  background: var(--white);
  padding: var(--spacing-md);
  border-radius: 6px;
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Map Mode Toggle */
.map-mode-toggle {
  display: inline-flex;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--ncar-blue);
  flex-shrink: 0;
}

.map-mode-btn {
  padding: 3px 12px;
  border: none;
  background: transparent;
  color: var(--ncar-blue);
  font-family: var(--font-family);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.map-mode-btn.active {
  background: var(--ncar-blue);
  color: #fff;
}

.map-mode-btn:hover:not(.active) {
  background: rgba(0, 87, 194, 0.08);
}

/* Split Marker */
.split-marker {
  background: transparent !important;
  border: none !important;
}

.split-marker-inner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid #333;
  transition: transform 120ms ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.split-marker-inner:hover {
  transform: scale(1.25);
}

/* Enhanced Map Popup */
.map-popup { min-width: 160px; }

.popup-station-name {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e0e0e0;
}

.popup-model-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.popup-model-table td { padding: 2px 4px; white-space: nowrap; }
.popup-model-table tr.best-row td { font-weight: 700; }

.popup-color-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* Map Legend */
.map-legend {
  background: var(--white);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: 6px;
  font-size: 0.75rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.6;
}

.map-legend strong {
  display: block;
  margin-bottom: 2px;
  font-size: 0.8rem;
}

.map-legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.map-legend-note {
  font-style: italic;
  color: #666;
  margin-top: 4px;
  font-size: 0.7rem;
}

/* --------------------------------------------------------------------------
   Responsive Design
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: 1rem;
  }

  .controls-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .control-group {
    width: 100%;
  }

  .control-group select {
    flex: 1;
  }

  .btn-print {
    margin-left: 0;
    justify-content: center;
  }

  .section-header {
    flex-direction: column;
    gap: var(--spacing-xs);
  }

  .section-number {
    font-size: 1.5rem;
  }

  .section-header h2 {
    font-size: 1.3rem;
  }

  .story-content {
    padding: var(--spacing-xl) var(--spacing-md);
  }

  .metrics-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .footer-content {
    flex-direction: column;
    text-align: center;
  }

  .footer-brand {
    order: 1;  /* Logo on top for mobile */
  }

  .footer-text {
    order: 2;  /* Text below logo on mobile */
  }
}

/* --------------------------------------------------------------------------
   Print Styles
   -------------------------------------------------------------------------- */
@media print {
  body {
    background: white;
    font-size: 11pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .hero {
    min-height: auto;
    padding: 2cm 1cm;
    page-break-after: always;
  }

  .hero-wave,
  .hero-scroll-hint {
    display: none;
  }

  .hero-content {
    max-width: none;
  }

  .sticky-controls {
    position: static;
    display: none;
  }

  .story-content {
    max-width: none;
    padding: 0;
  }

  .story-section {
    page-break-inside: avoid;
    margin-bottom: 1cm;
    padding-bottom: 1cm;
  }

  .plot-wrapper {
    page-break-inside: avoid;
    background: none;
    padding: 0;
  }

  .plot-container {
    min-height: 300px;
    border: 1px solid #ddd;
  }

  .section-interpretation {
    page-break-inside: avoid;
  }

  .plot-subsection {
    page-break-inside: avoid;
  }

  .plot-controls {
    display: none;
  }

  .footer {
    page-break-before: always;
    background: var(--light-gray);
    color: var(--dark-blue);
  }

  #toast-container {
    display: none;
  }
}
