/* The figures are embedded in the Duzz blog post inside an iframe: force the
   light palette (the site is light-only), the site font, and drop the page
   chrome/margins so each figure sits flush inside the article column. */
:root {
  color-scheme: light;
  --panel: #FFFFFF;
  --ink: #0A0A0A;
  --muted: #5A5A5A;
  --line: #E5E7EB;
  --accent: #F5D97A;
  --accent-soft: rgba(245, 217, 122, 0.18);
}

html,
body.embed {
  margin: 0;
  padding: 0;
  background: transparent;
  font-family: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}

body.embed figure.breakout {
  width: 100%;
  margin: 0;
  border-radius: 20px;
}

body.embed figure.breakout .plot {
  height: 560px;
}

body.embed .card .tag {
  color: var(--ink);
  font-weight: 800;
}

.carousel-controls {
  display: none;
}

@media (max-width: 700px) {
  body.embed figure.breakout .plot {
    height: 520px;
  }
}

/* The article column is narrower than the original standalone page, so keep the
   three examples side by side down to phone width instead of stacking at 700px. */
@media (min-width: 561px) {
  body.embed .example .trio {
    grid-template-columns: repeat(3, 1fr);
  }
  body.embed .trio .frame {
    width: auto;
    margin: 0;
  }
  body.embed .trio .frame img {
    max-height: none;
    width: 100%;
  }
}

/* The blog is light-only, but the standalone stylesheet still flips to a dark
   palette when the visitor's OS is in dark mode, which turned the example
   cards black with washed-out text inside the article. Pin the light values
   for dark mode too. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: light;
    --bg: #FFFFFF;
    --panel: #FFFFFF;
    --ink: #0A0A0A;
    --muted: #5A5A5A;
    --line: #E5E7EB;
    --accent: #F5D97A;
    --accent-soft: rgba(245, 217, 122, 0.18);
    --good: #2E7D6B;
    --bad: #B0552F;
  }
}

/* ---- phones ------------------------------------------------------------
   The article column is far too narrow for these dense charts, so on small
   screens only the plot / examples scroll sideways while the caption text
   stays pinned to the visible column width. */
@media (max-width: 700px) {
  html,
  body.embed {
    overflow-x: hidden;
  }

  body.embed figure.breakout {
    overflow-x: hidden;
  }

  /* inline preview: the whole chart fits the phone screen; tapping it opens
     the full-screen viewer (?view=full), which gets the roomy version */
  body.embed figure.breakout .plot {
    min-width: 0;
    height: 430px;
  }

  body.embed.fullscreen figure.breakout {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  body.embed.fullscreen figure.breakout .plot {
    min-width: 720px;
    height: 560px;
  }


  body.embed figure.breakout.example {
    overflow: hidden;
  }

  body.embed .example .trio {
    display: flex;
    grid-template-columns: none;
    gap: 0;
    min-width: 0;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.embed .example .trio::-webkit-scrollbar {
    display: none;
  }

  body.embed .example .trio > div {
    flex: 0 0 100%;
    min-width: 0;
    padding: 0 2px;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }

  body.embed .trio .frame {
    width: fit-content;
    max-width: 100%;
    height: min(54vh, 430px);
    margin: 0 auto;
  }

  body.embed .trio .frame img {
    width: auto;
    height: 100%;
    max-height: none;
    object-fit: contain;
  }

  body.embed .trio .card {
    width: 100%;
    min-height: 164px;
    margin-top: 10px;
    padding: 11px 12px;
  }

  body.embed .trio .card p {
    font-size: 0.82rem;
    line-height: 1.4;
  }

  body.embed .carousel-controls {
    display: grid;
    grid-template-columns: 36px 1fr 36px;
    align-items: center;
    gap: 12px;
    margin: 12px 2px 2px;
  }

  body.embed .carousel-button {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--panel);
    color: var(--ink);
    font: 600 18px/1 "Montserrat", sans-serif;
  }

  body.embed .carousel-button:disabled {
    opacity: 0.3;
  }

  body.embed .carousel-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
  }

  body.embed .carousel-dot {
    width: 8px;
    height: 8px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--line);
  }

  body.embed .carousel-dot.active {
    background: var(--ink);
  }

  body.embed.fullscreen figcaption {
    position: sticky;
    left: 0;
    width: 100vw;
    max-width: 100%;
    box-sizing: border-box;
    padding-right: 4px;
  }
}

/* Plotly draws the x-axis title slightly outside the plot box at narrow inner
   widths, which collided with the caption underneath. Give it room. */
@media (max-width: 700px) {
  body.embed figure.breakout .plot {
    margin-bottom: 10px;
  }

  body.embed.fullscreen figcaption {
    background: var(--panel);
    z-index: 2;
  }
}
