/* Serengeti NSDL Bento
   Theme colours and fonts with fallbacks, matching serengeti-hero-carousel.
   Layout responds to the width of the column it sits in (container queries), not the screen. */

.sg-nb {
  --sgnb-rust: var(--color-primary, #B45500);
  --sgnb-espresso: var(--color-secondary, #2A211C);
  --sgnb-cream: var(--color-accent, #F0E6D3);
  --sgnb-muted: #6B5D53;
  --sgnb-ease: cubic-bezier(0.22, 1, 0.36, 1);
  container-type: inline-size;
  width: 100%;
}

.sg-nb__grid {
  display: grid;
  gap: var(--sgnb-gap, 12px);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: var(--sgnb-row, 200px) var(--sgnb-row, 200px) calc(var(--sgnb-row, 200px) * .75);
  grid-template-areas: "a a b" "a a c" "s d d";
}
.sg-nb__photo--1 { grid-area: a; }
.sg-nb__photo--2 { grid-area: b; }
.sg-nb__photo--3 { grid-area: c; }
.sg-nb__stat { grid-area: s; }
.sg-nb__areas { grid-area: d; }

/* fewer tiles: let the remaining ones fill the space */
.sg-nb--tiles-2 .sg-nb__grid { grid-template-areas: "a a b" "a a b" "s d d"; }
.sg-nb--tiles-1 .sg-nb__grid { grid-template-areas: "a a a" "a a a" "s d d"; }
.sg-nb--no-stat .sg-nb__areas { grid-column: 1 / -1; grid-row: 3; }
.sg-nb--no-areas .sg-nb__stat { grid-column: 1 / -1; grid-row: 3; }
.sg-nb--no-stat.sg-nb--no-areas .sg-nb__grid { grid-template-rows: var(--sgnb-row, 200px) var(--sgnb-row, 200px); }

.sg-nb__tile {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  margin: 0;
  min-width: 0;
  border-radius: var(--sgnb-radius, 12px);
  background-color: var(--sgnb-espresso);
  /* Safari/iOS drops overflow + border-radius clipping while a child is animating
     (opacity/transform get their own compositing layer). Clip with clip-path and a mask too. */
  clip-path: inset(0 round var(--sgnb-radius, 12px));
  transform: translateZ(0);
}
/* iOS Safari can still ignore the tile's clip for blended/filtered layers,
   so every layer inside a photo tile carries the radius itself. */
.sg-nb__img { border-radius: var(--sgnb-radius, 12px); }

/* ---------- Photo tiles ---------- */
.sg-nb__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: var(--sgnb-pos, center center);
  transform-origin: var(--sgnb-pos, center center);
  opacity: 0;
  color: transparent;
  transform: scale(1.02);
  transition: opacity 1.6s var(--sgnb-ease), transform 10s linear;
}
.sg-nb__img.is-on { opacity: 1; }
.sg-nb--zoom.sg-nb--playing .sg-nb__img.is-on { transform: scale(1.09); }

.sg-nb--tone .sg-nb__img { filter: grayscale(1) contrast(1.05) brightness(.95); }
.sg-nb--tone .sg-nb__photo::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(160deg, rgba(180, 85, 0, .55), rgba(42, 33, 28, .75));
  mix-blend-mode: multiply;
  border-radius: var(--sgnb-radius, 12px);
}
.sg-nb__photo::before {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 55%;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(to top, rgba(42, 33, 28, .82), rgba(42, 33, 28, 0));
  border-radius: 0 0 var(--sgnb-radius, 12px) var(--sgnb-radius, 12px);
}
.sg-nb__cap {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  z-index: 3;
  margin: 0;
  color: var(--sgnb-cream);
  font-family: var(--font-body, "Inter", "Helvetica Neue", Arial, sans-serif);
  font-size: 12px;
  line-height: 1.35;
  transition: opacity .6s var(--sgnb-ease);
}
.sg-nb__cap.is-swapping { opacity: 0; }
.sg-nb__cap strong {
  display: block;
  color: #fff;
  font-family: var(--font-heading, "Libre Baskerville", Georgia, "Times New Roman", serif);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.25;
}

/* ---------- Number tile ---------- */
.sg-nb__stat {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  padding: 18px;
  background-color: var(--sgnb-rust);
  color: #fff;
}
.sg-nb__num {
  font-family: var(--font-heading, "Libre Baskerville", Georgia, "Times New Roman", serif);
  font-size: 52px;
  line-height: 1;
}
.sg-nb__stat-label {
  font-family: var(--font-body, "Inter", "Helvetica Neue", Arial, sans-serif);
  font-size: 12px;
  line-height: 1.4;
  max-width: 18ch;
}

/* ---------- Critical areas tile ---------- */
.sg-nb__areas {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 22px;
  color: var(--sgnb-cream);
}
.sg-nb__areas-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-body, "Inter", "Helvetica Neue", Arial, sans-serif);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #C9A98A;
}
.sg-nb__count { font-variant-numeric: tabular-nums; letter-spacing: .08em; white-space: nowrap; }
.sg-nb__ticker { position: relative; flex: 1; min-height: 64px; overflow: hidden; }
.sg-nb__area {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font-family: var(--font-heading, "Libre Baskerville", Georgia, "Times New Roman", serif);
  font-size: clamp(19px, 4.4cqi, 27px);
  line-height: 1.2;
  text-wrap: balance;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity .9s var(--sgnb-ease), transform .9s var(--sgnb-ease);
}
.sg-nb__area.is-on { opacity: 1; transform: none; }

/* ---------- Footer: disclaimer + pause/play ---------- */
.sg-nb__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
}
.sg-nb__fine {
  margin: 0;
  font-family: var(--font-body, "Inter", "Helvetica Neue", Arial, sans-serif);
  font-size: 11px;
  line-height: 1.45;
  color: var(--sgnb-muted);
}
.sg-nb__toggle {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--sgnb-espresso);
  cursor: pointer;
}
.sg-nb__toggle svg { fill: currentColor; }
.sg-nb__toggle:hover { color: var(--sgnb-rust); }
.sg-nb__toggle:focus-visible { outline: 2px solid var(--sgnb-rust); outline-offset: 2px; }
.sg-nb__i-play { display: none; }
.sg-nb:not(.sg-nb--playing) .sg-nb__i-pause { display: none; }
.sg-nb:not(.sg-nb--playing) .sg-nb__i-play { display: block; }

.sg-nb__sr {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  list-style: none;
}

/* ---------- Narrow columns ---------- */
@container (max-width: 560px) {
  .sg-nb__grid,
  .sg-nb--tiles-2 .sg-nb__grid,
  .sg-nb--tiles-1 .sg-nb__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: calc(var(--sgnb-row, 200px) * 1.15) calc(var(--sgnb-row, 200px) * .85) auto auto;
    grid-template-areas: "a a" "b c" "s s" "d d";
  }
  .sg-nb--tiles-2 .sg-nb__grid { grid-template-areas: "a a" "b b" "s s" "d d"; }
  .sg-nb--tiles-1 .sg-nb__grid { grid-template-areas: "a a" "a a" "s s" "d d"; }
  .sg-nb__stat { flex-direction: row; align-items: center; justify-content: flex-start; gap: 16px; }
  .sg-nb__num { font-size: 44px; }
  .sg-nb__ticker { min-height: 60px; }
  .sg-nb__area { font-size: 21px; }
}
@container (max-width: 360px) {
  .sg-nb__grid,
  .sg-nb--tiles-2 .sg-nb__grid,
  .sg-nb--tiles-1 .sg-nb__grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-rows: auto;
    grid-template-areas: none;
  }
  .sg-nb__grid > * { grid-area: auto !important; grid-column: auto !important; grid-row: auto !important; }
  .sg-nb__photo { height: calc(var(--sgnb-row, 200px) * 1.1); }
}

/* iOS Safari: a scaled image escapes the tile's rounded clip, so skip the slow zoom there (fade only). */
@supports (-webkit-touch-callout: none) {
  .sg-nb__img, .sg-nb--zoom.sg-nb--playing .sg-nb__img.is-on { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sg-nb__img, .sg-nb__area, .sg-nb__cap { transition-duration: .01s; }
  .sg-nb--zoom.sg-nb--playing .sg-nb__img.is-on { transform: scale(1.02); }
}
