/* Homepage-only layout, intro, and sections. Shared tokens, fonts, buttons, and
 * header/footer chrome live in chrome.css — inner pages (help, legal, releases)
 * load that file without this one. */
html {
  overflow: hidden;
}

body {
  min-height: 100%;
  overflow: hidden;
}

html.intro-done {
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
}

html.intro-done body {
  overflow: visible;
}

#intro-stage {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.grid {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 400ms ease;
}

.grid canvas.blitter-sprite {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.tile {
  width: var(--cell);
  height: var(--cell);
  background-color: var(--tile-fg, #ffffff);
  -webkit-mask-image: var(--sheet);
  mask-image: var(--sheet);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: calc(var(--frames) * var(--cell)) var(--cell);
  mask-size: calc(var(--frames) * var(--cell)) var(--cell);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.tile.is-wrapped {
  animation: none;
  -webkit-mask-size: calc(var(--sheet-cols) * var(--cell)) calc(var(--sheet-rows) * var(--cell));
  mask-size: calc(var(--sheet-cols) * var(--cell)) calc(var(--sheet-rows) * var(--cell));
}

.tile.is-masked {
  visibility: hidden;
  animation: none;
  background: none;
  -webkit-mask-image: none;
  mask-image: none;
}

@keyframes blit {
  from {
    -webkit-mask-position: 0 0;
    mask-position: 0 0;
  }
  to {
    -webkit-mask-position: calc(var(--frames) * var(--cell) * -1) 0;
    mask-position: calc(var(--frames) * var(--cell) * -1) 0;
  }
}

#scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: rgba(19, 4, 46, var(--scrim, 0));
}

#hero {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.25rem 5rem;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 700ms ease, transform 700ms ease;
  pointer-events: none;
}

#hero.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.headline {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 4.4rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.05;
  text-shadow: 0 0 18px rgba(19, 4, 46, 0.95), 0 2px 0 rgba(19, 4, 46, 0.8);
}

.tagline {
  margin: 0.85rem 0 0;
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-shadow: 0 0 14px rgba(19, 4, 46, 0.95);
}

.wordmark {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 0 12px rgba(19, 4, 46, 0.9);
}

.icon {
  width: 72px;
  height: 72px;
  margin: 1.1rem 0 1.6rem;
  border-radius: 18px;
  display: block;
}

.actions {
  display: flex;
  gap: 0.85rem;
  margin-top: 1.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

#debug-hud {
  position: fixed;
  z-index: 20;
  top: 0.75rem;
  left: 0.75rem;
  max-width: 28rem;
  background: rgba(8, 2, 20, 0.88);
  color: #d7cce8;
  border: 1px solid rgba(168, 184, 255, 0.35);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
}

.debug-hud-actions {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}

.debug-hud-actions button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid rgba(168, 184, 255, 0.45);
  border-radius: 3px;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
}

.debug-hud-body {
  margin: 0;
  white-space: pre-wrap;
}

/* Structural layout, background, and .chrome-brand/.chrome-nav live in
 * chrome.css, shared with inner pages. Only the intro-specific fade-in
 * (position: fixed, so it can overlay the intro grid; opacity/pointer-events
 * toggled by director.js; the text-shadow for legibility over the moving
 * background) is homepage-only. */
#site-chrome {
  position: fixed;
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms ease;
  text-shadow: 0 0 14px rgba(19, 4, 46, 0.95);
}

#site-chrome.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.page-section {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 14rem 0 11rem;
  scroll-margin-top: 5.5rem;
}

.page-section-inner {
  width: 100%;
}

.section-copy h2,
.section-copy p {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.9s cubic-bezier(0.215, 0.61, 0.355, 1),
    transform 0.9s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.page-section-inner > .carousel,
.page-section-inner > .control-split,
.page-section-inner .media-card {
  opacity: 0;
  transform: translateY(44px) scale(0.94);
  transform-origin: 50% 100%;
  transition: opacity 0.9s cubic-bezier(0.215, 0.61, 0.355, 1),
    transform 0.9s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.page-section.is-inview .section-copy h2,
.page-section.is-inview .section-copy p,
.page-section.is-inview > .page-section-inner > .carousel,
.page-section.is-inview > .page-section-inner > .control-split,
.page-section.is-inview .media-card {
  opacity: 1;
  transform: none;
}

.page-section.is-inview .section-copy p {
  transition-delay: 0.12s;
}

.page-section.is-inview > .page-section-inner > .carousel,
.page-section.is-inview > .page-section-inner > .control-split {
  transition-delay: 0.24s;
}

.page-section.is-inview .card-row > :nth-child(1) { transition-delay: 0.24s; }
.page-section.is-inview .card-row > :nth-child(2) { transition-delay: 0.36s; }
.page-section.is-inview .card-row > :nth-child(3) { transition-delay: 0.48s; }

.section-copy {
  text-align: center;
  padding: 0 1.5rem;
  margin-bottom: 3.25rem;
}

.section-copy h2 {
  margin: 0;
  font-size: clamp(2rem, 4.6vw, 3.35rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.1;
  text-shadow: 0 0 18px rgba(19, 4, 46, 0.95);
}

.section-copy p {
  margin: 0.55rem 0 0;
  font-size: clamp(1rem, 1.8vw, 1.35rem);
  font-weight: 400;
  color: var(--muted);
  text-shadow: 0 0 14px rgba(19, 4, 46, 0.95);
}

.card-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.75rem;
  width: min(1080px, calc(100% - 3rem));
  margin: 0 auto;
}

.media-card {
  margin: 0;
  text-align: center;
}

.media-card-frame,
.control-card-frame,
.example-thumb {
  background: var(--card-fill);
  border: 1px solid var(--btn-border);
  border-radius: 20px;
  backdrop-filter: blur(8px);
}

.media-card-frame {
  aspect-ratio: 1;
  width: 100%;
  overflow: hidden;
}

.media-card-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.media-card figcaption,
.control-card > span:last-child {
  margin-top: 0.85rem;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--muted);
}

.carousel {
  overflow: hidden;
}

.carousel-track {
  display: flex;
  align-items: flex-end;
  gap: 1.5rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  /* The first/last card can only ever scroll to true center if there's a
     full half-viewport of room to scroll into on each side (minus half the
     card's own width, which is already offscreen once centered). This has
     to track .example-card's width formula (min(272px, 68vw)) exactly, and
     match scroll-padding-inline below — the previous left/right paddings
     used unrelated formulas that both fell short, so the end cards stopped
     noticeably off-center (left especially) instead of centering flush. */
  --carousel-edge-gutter: max(1.5rem, calc(50vw - min(136px, 34vw)));
  padding-block: 0.5rem 0.75rem;
  padding-inline: var(--carousel-edge-gutter);
  scroll-padding-inline: var(--carousel-edge-gutter);
  scrollbar-width: none;
}

.carousel-track:focus {
  outline: none;
}

.carousel-track::-webkit-scrollbar {
  display: none;
}

.example-card {
  /* Every card is the same square size as the featured one — 272px, capped
     to a share of the viewport so it can't push past small phone widths.
     min-width: 0 is load-bearing: the default min-width: auto resolves to
     the title's nowrap min-content, which grew long names past the basis
     (Ripple stayed 272px; a long title stretched past 480px). */
  flex: 0 0 min(272px, 68vw);
  width: min(272px, 68vw);
  min-width: 0;
  max-width: min(272px, 68vw);
  scroll-snap-align: center;
  opacity: 0.42;
  transition: opacity 280ms ease;
  border: 0;
  padding: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.example-card.is-focus {
  opacity: 1;
  cursor: default;
}

.example-thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  background: rgba(10, 4, 28, 0.55);
}

.example-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* contain, not cover: a non-square recipe (any grid that isn't cols==rows)
     forced into this square box under `cover` gets center-cropped, which
     inflates its apparent tile size (the crop shows fewer of its rows/cols
     than a square recipe does) and, at extreme ratios, crops away the whole
     pattern into a near-solid color. contain keeps every recipe's tiles at
     their true relative size and always shows the full pattern, matching
     the uncropped approach the full community gallery page already uses. */
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.example-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.7rem;
  padding: 0 0.15rem;
}

.example-name {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.example-dl {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
}

.example-dl:hover,
.example-dl:focus-visible {
  color: var(--ink);
  background: rgba(28, 40, 96, 0.45);
  outline: none;
}

.example-dl.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.control-split {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(240px, 400px);
  gap: 2.5rem;
  align-items: center;
  justify-content: center;
  width: min(760px, calc(100% - 3rem));
  margin: 0 auto;
}

.control-list {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.control-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: default;
  opacity: 0.38;
  transition: opacity 320ms ease;
}

.control-card.is-active {
  opacity: 1;
}

.control-card-frame {
  display: block;
  width: 100%;
  aspect-ratio: 1.55;
  overflow: hidden;
  position: relative;
}

/* Card 1, Block: six still frames of the square sweep, not an animation —
   a real crop of the same sprite sheet the live stage plays, laid out as a
   filmstrip so the sequence reads at a glance. */
.control-card-frame.is-filmstrip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 1px;
  background: #000000;
}

.filmstrip-frame {
  background-color: #000000;
  background-image: url("../sequences/demo-square/sprite.png");
  background-repeat: no-repeat;
  /* 16 equal frames wide in the sheet — sizing/positioning by percentage
     keeps this correct regardless of the cell's actual rendered size. */
  background-size: 1600% 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.filmstrip-frame[data-frame="0"] { background-position-x: 0%; }
.filmstrip-frame[data-frame="3"] { background-position-x: 20%; }
.filmstrip-frame[data-frame="6"] { background-position-x: 40%; }
.filmstrip-frame[data-frame="9"] { background-position-x: 60%; }
.filmstrip-frame[data-frame="12"] { background-position-x: 80%; }
.filmstrip-frame[data-frame="15"] { background-position-x: 100%; }

/* Card 2, Color: a plain static swatch — the control being toggled, not a
   preview of the animation (see the Sequence card, which already shows
   the animation content, for the contrast). */
.control-card-frame.is-swatch {
  background: linear-gradient(135deg, #ff3fa0, #7b2ff7);
}

.control-card-frame canvas.blitter-sprite,
.control-stage canvas.blitter-sprite {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.control-stage {
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1;
  justify-self: center;
  border-radius: 22px;
  border: 1px solid var(--btn-border);
  background: #000000;
  overflow: hidden;
  position: relative;
}

.control-stage canvas.blitter-sprite {
  opacity: 0;
  transition: opacity 500ms ease;
}

.control-stage canvas.blitter-sprite.is-visible {
  opacity: 1;
}

.page-section-end {
  justify-content: flex-end;
  min-height: 0;
  padding: 5.25rem 1.5rem 1.4rem;
}

#export {
  padding-bottom: 8.25rem;
}

@media (max-width: 800px) {
  .card-row {
    grid-template-columns: 1fr;
    width: min(360px, calc(100% - 2.5rem));
  }

  .control-split {
    grid-template-columns: 1fr;
    width: min(400px, calc(100% - 2.5rem));
  }

  .control-list {
    flex-direction: row;
    justify-content: center;
  }

  .control-card {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  html.intro-done {
    scroll-behavior: auto;
  }

  #hero,
  #site-chrome,
  .grid,
  #intro-stage,
  .page-section-inner,
  .section-copy h2,
  .section-copy p,
  .page-section-inner > .carousel,
  .page-section-inner > .control-split,
  .page-section-inner .media-card,
  .example-card,
  .control-card,
  .control-stage canvas.blitter-sprite,
  .actions {
    transition: none !important;
  }

  .section-copy h2,
  .section-copy p,
  .page-section-inner > .carousel,
  .page-section-inner > .control-split,
  .page-section-inner .media-card {
    opacity: 1;
    transform: none;
  }

  .tile {
    animation: none;
  }
}
