/* Scoped to .sticky-demo — this demo used to own the whole page (a
   standalone single-file CodePen-style demo), so its reset and "main"
   background were originally unscoped. Now that it's embedded inside the
   site's own main/header/footer chrome, an unscoped `*` reset or a bare
   `main` selector would strip margin/padding and background from the real
   site layout too. Every rule below is scoped under .sticky-demo so it
   only ever touches its own subtree. */
.sticky-demo,
.sticky-demo *,
.sticky-demo *::before,
.sticky-demo *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.sticky-demo {
  font-family: system-ui, sans-serif;
  color: #f0e8e0;
  line-height: 1.6;
}

/* ── STICKY HEADER (shared base) ── */
/* top offset matches the site's own fixed nav height (--safe-top-padding —
   see the "Header Offset Contract" note in styles/layout.css), so this
   demo's own sticky header docks directly beneath it instead of colliding. */
.sticky-demo .demo-header {
  position: sticky;
  top: calc(var(--safe-top-padding) + var(--safe-top));
  background: #1e0c00;
  border-bottom: 1px solid #3a1800;
  z-index: 10;
}

.sticky-demo .header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  transition: padding 0.3s ease;
}

.sticky-demo .logo {
  font-size: 2rem;
  font-weight: 700;
  color: #f97316;
  transition: font-size 0.3s ease, color 0.3s ease;
  white-space: nowrap;
}

.sticky-demo .demo-header nav {
  display: flex;
  gap: 1.5rem;
  opacity: 1;
  transition: opacity 0.3s ease, font-size 0.3s ease;
  font-size: 0.95rem;
}

.sticky-demo .demo-header nav a {
  color: #9ca3af;
  text-decoration: none;
}

.sticky-demo .demo-header nav a:hover {
  color: #f97316;
}

.sticky-demo .badge {
  margin-left: auto;
  background: #f9731622;
  color: #f97316;
  border: 1px solid #f9731655;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  white-space: nowrap;
  transition: font-size 0.3s, padding 0.3s;
}

/* ── shared "stuck" styles used by both paths ── */
.sticky-demo .demo-header.stuck .header-inner {
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}

.sticky-demo .demo-header.stuck .logo {
  font-size: 1rem;
  color: #fb923c;
}

.sticky-demo .demo-header.stuck nav {
  font-size: 0.8rem;
  opacity: 0.75;
}

.sticky-demo .demo-header.stuck .badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
}

/* ── PATH A: native scroll-state ── */
@supports (container-type: scroll-state) {
  .sticky-demo .demo-header {
    container-type: scroll-state;
  }

  /* CSS drives the stuck state — JS class not needed */
  @container scroll-state(stuck: top) {
    .sticky-demo .demo-header .header-inner {
      padding-top: 0.4rem;
      padding-bottom: 0.4rem;
    }

    .sticky-demo .demo-header .logo {
      font-size: 1rem;
      color: #fb923c;
    }

    .sticky-demo .demo-header nav {
      font-size: 0.8rem;
      opacity: 0.75;
    }

    .sticky-demo .demo-header .badge {
      font-size: 0.65rem;
      padding: 0.15rem 0.5rem;
    }
  }
}

/* ── sentinel for the JS fallback (always in DOM, only used when needed) ── */
/* Kept in normal flow rather than absolutely positioned: with no positioned
   ancestor, `position: absolute` would place it against the document root
   regardless of where it sits in the DOM, not against this demo. The JS
   fallback moves this element to be .demo-header's immediate previous
   sibling at runtime, so its resting point in the flow is exactly the
   header's own pre-stuck position. */
.sticky-demo #sticky-sentinel {
  height: 1px;
  pointer-events: none;
}

/* ── back-to-site link ── */
.sticky-demo .site-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 1.5rem 1.5rem 0;
  color: #9ca3af;
  text-decoration: none;
  font-size: 0.85rem;
}

.sticky-demo .site-back:hover {
  color: #f97316;
}

/* ── HERO ── */
.sticky-demo .hero {
  max-width: 900px;
  margin: 0 auto;
  padding: 5rem 1.5rem 4rem;
  text-align: center;
}

.sticky-demo .hero h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 800;
  background: linear-gradient(135deg, #f97316, #ef4444);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 1rem;
}

.sticky-demo .hero p {
  max-width: 600px;
  margin: 0 auto 2rem;
  color: #9ca3af;
  font-size: 1.1rem;
}

.sticky-demo .hint {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #2a1000;
  border: 1px solid #3a1800;
  border-radius: 999px;
  padding: 0.5rem 1.25rem;
  font-size: 0.85rem;
  color: #6b7280;
  animation: bounce 2s infinite;
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(6px);
  }
}

/* ── CONTENT CARDS ── */
.sticky-demo .content {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 6rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}

.sticky-demo .content .card {
  background: #1e0c00;
  border: 1px solid #3a1800;
  border-radius: 12px;
  padding: 1.5rem;
}

.sticky-demo .card-icon {
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
}

.sticky-demo .content .card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #f0e8e0;
}

.sticky-demo .content .card p {
  font-size: 0.875rem;
  color: #6b7280;
  line-height: 1.5;
}

/* ── CODE BLOCK ── */
.sticky-demo .code-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

.sticky-demo .code-section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: #f97316;
}

.sticky-demo .code-section pre {
  background: #0d0500;
  border: 1px solid #3a1800;
  border-radius: 12px;
  padding: 1.5rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.7;
  color: #f5d0c8;
}

.sticky-demo .tok-prop {
  color: #fb923c;
}

.sticky-demo .tok-val {
  color: #fcd34d;
}

.sticky-demo .tok-sel {
  color: #fca5a5;
}

.sticky-demo .tok-at {
  color: #f97316;
}

.sticky-demo .tok-cmt {
  color: #a36050;
  font-style: italic;
}
