/* BASE & TYPOGRAPHY (Inspired by boldvoice.com/blog) */
:root {
  --boldvoice-blue: #007aff; /* Primary accent blue */
  --text-color: #1a1a1a; /* Dark text */
  --muted-text: #666; /* Lighter gray for bylines, captions */
  --bg-color: #ffffff; /* White background */
  --border-color: #e5e5e5; /* Subtle borders */
  --content-max-width: 720px; /* Max width for readable text */
  --light-gray: #f7f7f7;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --accent-start: #ea7d35;
  --accent-end: #f5277f;
  --accent-gradient: linear-gradient(
    to top right,
    var(--accent-start) 50%,
    var(--accent-end) 50%
  );
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; /* Match blog font */
  color: var(--text-color);
  line-height: 1.65; /* Slightly more spacious line height */
  background: var(--bg-color);
  font-size: 16px; /* Base font size */
}

/* LAYOUT (Desktop First - Two Columns) */
.wrapper {
  display: flex;
  gap: 2rem;
  max-width: 1440px;
  margin: 0 auto;
}

.left-col {
  min-width: 0; /* allow flex item to shrink below content size */
  flex: 1;
  padding: 40px 20px; /* More vertical padding */
  display: flex;
  flex-direction: column;
  align-items: center;
}

.left-col > .post-header,
.left-col .step {
  width: 100%;
  max-width: var(--content-max-width);
}

.right-col {
  flex: 1.5;
  position: relative; /* Needed for sticky child */
}

/* POST HEADER STYLING */
.post-header {
  margin-bottom: 2.5rem;
}
.post-header h1 {
  font-size: 2.8rem; /* Larger title */
  line-height: 1.2;
  margin-bottom: 0.5rem;
  font-weight: 700; /* Bolder title */
  color: var(--text-color);
  display: inline-block;
  position: relative;
  padding-bottom: 0.4rem;
  background-image: var(--accent-gradient);
  background-repeat: no-repeat;
  background-position: left bottom;
  background-size: 100% 3px;
}
.post-header h2 {
  font-size: 1.6rem;
  margin-top: 0.5rem;
  margin-bottom: 1.5rem;
  font-weight: 400;
  color: var(--muted-text);
  position: relative;
  padding-left: 1rem;
}
.post-header h2::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.25em;
  width: 4px;
  height: calc(100% - 0.5em);
  background: var(--accent-gradient);
}
.byline {
  font-size: 1rem;
  color: var(--muted-text);
}
.byline .date {
  font-style: italic;
  margin-left: 0.5rem;
  color: var(--muted-text);
}

/* STEP SECTIONS STYLING */
.step {
  margin-bottom: 2rem;
  background: var(--light-gray);
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 6px var(--shadow-color);
}
.step h2 {
  font-size: 1.8rem;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  font-weight: 600;
  color: var(--text-color);
  position: relative;
  padding-left: 1rem;
}
.step h2::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.25em;
  width: 4px;
  height: calc(100% - 0.5em);
  background: var(--accent-gradient);
}
.step h3 {
  font-size: 1.4rem;
  margin-top: 2rem;
  margin-bottom: 0.8rem;
  font-weight: 600;
  color: var(--text-color);
  position: relative;
  padding-left: 0.75rem;
}
.step h3::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.25em;
  width: 3px;
  height: calc(100% - 0.5em);
  background: var(--accent-gradient);
}
.step p {
  margin-bottom: 1.25rem;
  font-size: 1.05rem; /* Slightly larger body text */
}
.step ul {
  margin-bottom: 1.25rem;
  padding-left: 1.5em;
  list-style: disc;
}
.step li {
  margin-bottom: 0.5rem;
}
.step a {
  color: var(--boldvoice-blue);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
.step a:hover {
  border-color: var(--boldvoice-blue);
}
.step img {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.step img:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px var(--shadow-color);
}

/* Zoom buttons (Highlights) */
.zoom-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: #fff;
  color: var(--text-color);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 2px 6px var(--shadow-color);
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.zoom-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px var(--shadow-color);
  border-color: var(--boldvoice-blue);
}
.zoom-btn:active {
  transform: translateY(0);
  box-shadow: 0 3px 8px var(--shadow-color);
}
.zoom-trigger {
  display: flex;
  justify-content: flex-start;
}

.step .footnote {
  font-size: 0.75rem;
  color: var(--muted-text);
  margin-top: 0.5rem;
}
.step .footnote:not(:last-of-type) {
  margin-bottom: 0;
}
.step .footnote sup {
  font-size: 0.75rem;
  vertical-align: super;
}

/* FIGURES & IMAGES */
figure {
  margin: 2.5rem 0;
}
figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px; /* Subtle rounded corners */
  border: 1px solid var(--border-color); /* Subtle border */
}
figcaption {
  font-size: 0.9rem;
  color: var(--muted-text);
  text-align: center;
  margin-top: 0.75rem;
}

/* AUDIO PLAYER */
audio {
  display: block;
  width: 100%;
  margin: 1.5rem 0;
}

/* IFRAME CONTAINER (Desktop - Sticky) */
.frame-container {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  border-left: 1px solid var(--border-color); /* Add subtle separator */
  background: #fff;
  box-shadow: 0 4px 12px var(--shadow-color);
  border-radius: 0px 8px 8px 0px;
}
.frame-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.frame-container iframe.active {
  opacity: 1;
  pointer-events: auto;
}

/* Reposition Plotly modebar (controls) to top-left */
.right-col .js-plotly-plot .modebar,
.right-col .js-plotly-plot .modebar-container {
  left: 0px !important;
  right: auto !important;
  top: 0px !important;
}

/* MOBILE IFRAME STYLING (Initially Hidden on Desktop) */
.mobile-iframe {
  display: none; /* Hidden by default */
  width: 100%;
  height: 45vh; /* Adjust height as needed */
  margin-top: 1rem; /* Space above */
  margin-bottom: 3rem; /* Space below (matches step margin) */
  border: 0;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 4px 12px var(--shadow-color);
  border-radius: 8px;
}

/* CODE BLOCK STYLING */
.code-output pre {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background-color: #282c34;
  border: 1px solid #3a3f4a;
  border-radius: 8px;
  box-shadow: 0 2px 6px var(--shadow-color);
  padding: 1em;
  overflow-x: auto;
  margin-bottom: 0.5em;
}
.code-output code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier,
    monospace;
  font-size: 0.95em;
  color: #34c759;
  white-space: pre;
  display: block;
}

.code-output figcaption {
  font-size: 0.9rem;
  color: var(--muted-text, #666);
  text-align: center;
  margin-top: 0.75rem;
}

/* =================================== */
/* RESPONSIVE (< 1024px) - Single Column */
/* =================================== */
@media (max-width: 1023px) {
  .wrapper {
    flex-direction: column; /* Stack columns */
  }

  .left-col {
    padding: 20px 15px; /* Adjust padding */
    align-items: stretch; /* Let content take full width */
    order: 1; /* Ensure text comes first */
  }

  .left-col > .post-header,
  .left-col .step {
    max-width: none; /* Remove max-width on mobile */
    width: auto;
  }

  /* Hide the right column entirely on mobile */
  .right-col {
    display: none;
  }

  /* Show the mobile iframes */
  .mobile-iframe {
    display: block;
  }

  /* Adjust typography for mobile */
  .post-header h1 {
    font-size: 2.2rem;
  }

  .step {
    padding: 0.5rem;
  }

  .step h2 {
    font-size: 1.6rem;
  }
  .step h3 {
    font-size: 1.3rem;
  }
  .step p {
    font-size: 1rem;
  }
}

/* Floating Action Button (FAB) and Overlay for mobile Plotly */
.fab-plotly {
  position: fixed;
  right: 4px; /* keeps visual circle 16px from edge with 12px hit-slope */
  bottom: 4px;
  width: 80px; /* 56px circle + 12px hit-slope on each side */
  height: 80px;
  background: transparent;
  color: #fff;
  border: none;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  z-index: 1001;
}
.fab-plotly::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 56px;
  height: 56px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--boldvoice-blue);
  box-shadow: 0 6px 16px var(--shadow-color);
  pointer-events: none;
  z-index: 0;
}
.fab-plotly svg {
  width: 26px;
  height: 26px;
  position: relative;
  z-index: 1; /* above ::before */
}

.plot-overlay[hidden] {
  display: none;
}

.plot-overlay {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.plot-overlay .overlay-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 8px;
  border-bottom: 1px solid var(--border-color);
}

.plot-overlay .overlay-close {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
}

.plot-overlay .overlay-body {
  flex: 1;
  min-height: 0;
  position: relative;
}

.overlay-loading[hidden] {
  display: none;
}
.overlay-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  z-index: 1001;
}
.overlay-loading .spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #ccc;
  border-top-color: var(--boldvoice-blue);
  animation: spin 0.8s linear infinite;
}
.overlay-loading .loading-text {
  font-weight: 600;
  color: #111;
}

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

#overlay-graph-host {
  width: 100%;
  height: 100%;
}

.plot-overlay #overlay-graph-host .plotly-graph-div {
  width: 100% !important;
  height: 100% !important;
}

/* Reposition Plotly modebar inside overlay to top-left */
.plot-overlay .js-plotly-plot .modebar,
.plot-overlay .js-plotly-plot .modebar-container {
  left: 0px !important;
  right: auto !important;
  top: 0px !important;
}

@media (max-width: 1023px) {
  .fab-plotly {
    display: flex;
  }
}

/* FAB tooltip (mobile) */
.fab-tooltip[hidden] {
  display: none;
}
.fab-tooltip {
  position: fixed;
  right: 84px; /* place left of FAB */
  bottom: 24px;
  max-width: 220px;
  background: #111;
  color: #fff;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.3;
  box-shadow: 0 6px 16px var(--shadow-color);
  z-index: 1001;
}
.fab-tooltip::after {
  content: '';
  position: absolute;
  right: -7px;
  bottom: 14px;
  width: 0;
  height: 0;
  border-left: 8px solid #111;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}
@media (min-width: 1024px) {
  .fab-tooltip {
    display: none !important;
  }
}
