/* @link https://utopia.fyi/type/calculator?c=360,12,1.2,1240,16,1.25,5,2,&s=0.75|0.5|0.25,1.5|2|3|4|6,s-l&g=s,l,xl,12 */

:root {
  --size--2: clamp(0.5208rem, 0.4721rem + 0.2167vw, 0.64rem);
  --size--1: clamp(0.625rem, 0.5534rem + 0.3182vw, 0.8rem);
  --size-0: clamp(0.75rem, 0.6477rem + 0.4545vw, 1rem);
  --size-1: clamp(0.9rem, 0.7568rem + 0.6364vw, 1.25rem);
  --size-2: clamp(1.08rem, 0.8826rem + 0.8773vw, 1.5625rem);
  --size-3: clamp(1.296rem, 1.0272rem + 1.1948vw, 1.9531rem);
  --size-4: clamp(1.5552rem, 1.1927rem + 1.6113vw, 2.4414rem);
  --size-5: clamp(1.8662rem, 1.3813rem + 3.5vw, 5.0518rem);
}

/* @link https://utopia.fyi/space/calculator?c=360,12,1.2,1240,16,1.25,5,2,&s=0.75|0.5|0.25,1.5|2|3|4|6,s-l&g=s,l,xl,12 */

:root {
  --space-3xs: clamp(0.1875rem, 0.1619rem + 0.1136vw, 0.25rem);
  --space-2xs: clamp(0.375rem, 0.3239rem + 0.2273vw, 0.5rem);
  --space-xs: clamp(0.5625rem, 0.4858rem + 0.3409vw, 0.75rem);
  --space-s: clamp(0.75rem, 0.6477rem + 0.4545vw, 1rem);
  --space-m: clamp(1.125rem, 0.9716rem + 0.6818vw, 1.5rem);
  --space-l: clamp(1.5rem, 1.2955rem + 0.9091vw, 2rem);
  --space-xl: clamp(2.25rem, 1.9432rem + 1.3636vw, 3rem);
  --space-2xl: clamp(3rem, 2.5909rem + 1.8182vw, 4rem);
  --space-3xl: clamp(4.5rem, 3.8864rem + 2.7273vw, 6rem);

  /* One-up pairs */
  --space-3xs-2xs: clamp(0.1875rem, 0.0597rem + 0.5682vw, 0.5rem);
  --space-2xs-xs: clamp(0.375rem, 0.2216rem + 0.6818vw, 0.75rem);
  --space-xs-s: clamp(0.5625rem, 0.3835rem + 0.7955vw, 1rem);
  --space-s-m: clamp(0.75rem, 0.4432rem + 1.3636vw, 1.5rem);
  --space-m-l: clamp(1.125rem, 0.767rem + 1.5909vw, 2rem);
  --space-l-xl: clamp(1.5rem, 0.8864rem + 2.7273vw, 3rem);
  --space-xl-2xl: clamp(2.25rem, 1.5341rem + 3.1818vw, 4rem);
  --space-2xl-3xl: clamp(3rem, 1.7727rem + 5.4545vw, 6rem);

  /* Custom pairs */
  --space-s-l: clamp(0.75rem, 0.2386rem + 2.2727vw, 2rem);
}

/* Color tokens */
:root {
  --color-card-bg: rgba(2, 38, 64, 0.95);
  --color-card-border: rgba(255, 255, 255, 0.15);
  --color-text-muted: rgba(255, 255, 255, 0.6);
  --color-accent: hsl(218, 60%, 58%);
  --color-shadow: rgba(0, 0, 0, 0.3);
  --color-text-primary: #fff;
  --color-text-secondary: rgba(255, 255, 255, 0.85);
  --color-text-dim: rgba(255, 255, 255, 0.4);
  --color-surface-subtle: rgba(255, 255, 255, 0.04);
  --color-border-subtle: rgba(255, 255, 255, 0.06);
  --color-threat: hsl(348, 80%, 72%);
  --color-threat-bg: hsla(348, 60%, 55%, 0.1);
  --color-threat-border: hsla(348, 60%, 55%, 0.2);

  /* Cargo type colors (from Renewables palette) */
  --color-cargo-container: hsl(218, 60%, 58%);
  --color-cargo-dry-bulk: hsl(34, 60%, 50%);
  --color-cargo-tanker: hsl(348, 60%, 55%);
}

/* --- Shared stacked-bar styles (used by StraitDetailPanel + StraitMobileDetail) --- */
.stacked-bar {
  width: 100%;
}

.stacked-bar__track {
  display: flex;
  width: 100%;
  height: 24px;
  border-radius: 4px;
  overflow: hidden;
}

.stacked-bar__segment {
  flex: none;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-sizing: border-box;
}

.stacked-bar__segment + .stacked-bar__segment {
  border-left: 1px solid rgba(0, 0, 0, 0.3);
}

.stacked-bar__value {
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.stacked-bar__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
}

.stacked-bar__legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
}

.stacked-bar__dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.stacked-bar__legend-count {
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Global Styles */
html {
  font-family: 'Encode Sans', sans-serif;
  font-size: var(--size-0);
  line-height: 1.5;
  color: #fff;
  background: #000;
}

.master-grid {
  width: 100svw;
  aspect-ratio: 16 / 9;

  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: repeat(7, 1fr);
  overflow: hidden;
}

/* layout-2: straits infographic grid — map-centric layout */
.layout-2 {
  padding-bottom: 0;

  .strait-map {
    grid-row: 1 / 8;
    grid-column: 1 / -1;
  }

  .strait-header {
    grid-row: 6 / 8;
    grid-column: 2 / 7;
  }

  .strait-logo-link {
    display: contents;
  }

  .strait-logo {
    grid-row: 1 / 2;
    grid-column: 11 / 13;
    justify-self: end;
    align-self: start;
    width: 120px;
    padding: 1.5rem 1.5rem 0 0;
    z-index: 10;
  }

  @media (max-width: 879px) {
    height: auto;
    min-height: 100svh;
    overflow: visible;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
  }
}

/* Hide footer and back-link on layout-2 — source & logo are in StraitHeader instead */
.layout-2 footer,
.layout-2 .back-link-nav {
  display: none !important;
}

/* Fade out header when a strait is active */
[data-strait] .strait-header {
  opacity: 0;
  pointer-events: none;
}

.layout-1 {
  .title {
    font-size: var(--size-5);

    @media (max-width: 879px) {
      grid-row: 1 / 2;
      grid-column: 1 / 12;
      text-align: left;
      align-self: end;

      br {
        display: none;
      }
    }
  }

  .description {
    grid-row: 1 / 3;
    grid-column: 4 / 12;
    align-self: center;
    justify-self: start;

    @media (max-width: 879px) {
      grid-row: 1 / 3;
      grid-column: 1 / 12;
      align-self: start;
      justify-self: start;
      padding: 1rem 0 0 2rem;
    }
  }

  .chart {
    grid-row: 3 / 8;
    grid-column: 4 / 11;

    @media (max-width: 879px) {
      grid-row: 3 / 7;
      grid-column: 2 / 10;
    }
  }

  .bg-image {
    grid-row: 1 / 8;
    grid-column: 1 / 7;

    @media (max-width: 879px) {
      display: none;
    }
  }
}

/* layout-home: scrollable hub page — overrides master-grid viewport lock */
.layout-home {
  height: auto;
  min-height: 100svh;
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: var(--space-xl) var(--space-l);
  padding-bottom: 6rem;
}

/* Footer flows in document order on homepage instead of position: absolute,
   preventing overlap with card content on short viewports or long card lists. */
.layout-home footer {
  position: relative;
  margin-top: auto;
}

/* layout-test: scrollable test pages — overrides master-grid viewport lock */
.layout-test {
  height: auto;
  min-height: 100svh;
  max-height: none;
  overflow-y: auto;
  display: block;
}

.layout-test footer {
  position: relative;
}


.title {
  z-index: 1;
  margin: 0;
  line-height: 1.1;
  text-shadow: 0px 5px 5px rgba(0, 0, 0, 0.25);
}

.description {
  z-index: 1;
  padding: 1rem 0;
  max-width: 100ch;
  font-size: var(--size-0);
  letter-spacing: 0.01em;
}

.chart {
  z-index: 1;
}

.bg-image {
  z-index: 0;

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: right;
  }
}

/* Shared secondary button style — used by EmbedCodeButton and InfographicCard.
   Update here to change the button appearance in both places. */
.btn-secondary {
  font-family: 'Encode Sans', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.375rem;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.35);
}

.btn-secondary:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .btn-secondary {
    transition: none;
  }
}

/* Accessibility: visually-hidden utility for screen-reader-only content.
   Shared across all components — do not duplicate in scoped styles.
   See: https://webaim.org/techniques/css/invisiblecontent/ */
/* --- Strait transition: floating clone (FLIP animation) --- */
.strait-transition-clone {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  border-radius: 50%;
  overflow: hidden;
  will-change: transform, opacity;
  -webkit-transform: translateZ(0); /* iOS Safari compositing fix */
}

.strait-transition-clone img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* --- Strait transition: content fade-in/out --- */
.strait-transition-content {
  transition: opacity 200ms ease, transform 200ms ease, filter 200ms ease;
}

.strait-transition-content--hidden {
  opacity: 0;
  transform: translateY(8px);
  filter: blur(4px);
}

.strait-transition-content--exit {
  opacity: 0;
  transition: opacity 100ms ease;
}

/* Staggered delays for detail sections */
.strait-transition-content--delay-0 { transition-delay: 0ms; }
.strait-transition-content--delay-1 { transition-delay: 50ms; }
.strait-transition-content--delay-2 { transition-delay: 100ms; }
.strait-transition-content--delay-3 { transition-delay: 150ms; }
.strait-transition-content--delay-4 { transition-delay: 200ms; }

@media (prefers-reduced-motion: reduce) {
  .strait-transition-clone {
    will-change: auto;
  }
  .strait-transition-content {
    transition: none;
  }
}

/* --- Swipe navigation slide transitions --- */

/* Slide-left: content exits left, enters from right (swipe left = next) */
.slide-left-enter-active {
  animation: slideInRight 250ms ease-out;
}
.slide-left-leave-active {
  animation: slideOutLeft 250ms ease-in;
}

/* Slide-right: content exits right, enters from left (swipe right = prev) */
.slide-right-enter-active {
  animation: slideInLeft 250ms ease-out;
}
.slide-right-leave-active {
  animation: slideOutRight 250ms ease-in;
}

@keyframes slideOutLeft {
  to { transform: translateX(-30%); opacity: 0; }
}
@keyframes slideInRight {
  from { transform: translateX(30%); opacity: 0; }
}
@keyframes slideOutRight {
  to { transform: translateX(30%); opacity: 0; }
}
@keyframes slideInLeft {
  from { transform: translateX(-30%); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .slide-left-enter-active,
  .slide-left-leave-active,
  .slide-right-enter-active,
  .slide-right-leave-active {
    animation: none;
  }
}


.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
