/* KIRUPA home page proposal: treatments of the opening.
   Loaded after home.css. Each page sets data-hp-variant on #mainContent #hp-main:
   - blend: the opening keeps the page's own background; a faint field only shifts it subtly.
   - icons: the same background, with theme icons (one per explainer) drifting and dancing.
   - mix: the faint field plus a sparse icon layer.
   index_preview.htm is Mix without the field (data-hp-field="icons"): the sparse icon layer is all
   that moves, and icons.js hangs the tour's label on the lit icons (see the end of this file).
   The background options (index_preview_molecules.htm and the rest) are Mix with
   data-hp-field="wide": a drawing spans the whole window instead of the space beside the column.
   index_preview_blend.htm, index_preview_icons.htm, and index_preview_mix.htm stay as they were
   for comparison. */

/* ---------- Every variation: the page keeps the site's own background ---------- */

/* Pixel and Smooooth use a custom night in dark mode; here they use the site's dark page color. */
html.theme_dark:not(.style_scifi):not(.style_minimal):not(.style_ukiyoe):not(.style_platformer) body #mainContent #hp-main[data-hp-variant] {
  --hp-night: var(--pageBackground);
  --hp-bg: var(--pageBackground);
  --hp-bg-alt: color-mix(in oklab, var(--pageBackground) 86%, #000);
  --hp-panel: color-mix(in oklab, var(--pageBackground) 76%, #000);
  --hp-panel-2: color-mix(in oklab, var(--pageBackground) 66%, #000);
}

/* The opening's sky is the page background. Tokens are set on the section itself, so they win
   over whatever each style and mode declares on #mainContent #hp-main. */
#mainContent #hp-main[data-hp-variant] .hp-hero {
  --hp-sky-top: var(--hp-bg);
  --hp-sky: var(--hp-bg);
  --hp-hero-top: var(--hp-bg);
  --hp-f-top: var(--hp-bg);
  --hp-f-night: var(--hp-bg);
  --hp-f-grid: 0;
  --hp-f-neb: .3;
  --hp-f-dust: .55;
  --hp-f-ink-amt: .18;
}
/* Pixel and Smooooth headers fade into the page by themselves, so the top stays see-through. */
html:not(.style_scifi):not(.style_minimal):not(.style_ukiyoe):not(.style_platformer) #mainContent #hp-main[data-hp-variant] .hp-hero {
  --hp-hero-top: transparent;
}
html:not(.theme_dark):not(.style_minimal) #mainContent #hp-main[data-hp-variant] .hp-hero {
  --hp-f-bloom: .2;
}
html.theme_dark:not(.style_minimal) #mainContent #hp-main[data-hp-variant] .hp-hero {
  --hp-f-bloom: .45;
  --hp-f-gain: .62;
}
#mainContent #hp-main[data-hp-variant] .hp-hero__foot .hp-figcap {
  max-width: 70ch;
}
/* No band or seam between the header art and the opening. */
html:is(.style_nature, .style_scifi, .style_minimal, .style_ukiyoe) #mainContent #hp-main[data-hp-variant] .hp-seam {
  display: none;
}

/* ---------- Switcher (variation pages only) ---------- */

#mainContent #hp-main .hp-variants {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 22px;
  color: var(--hp-muted);
  font: 500 12.5px/1.2 var(--hp-mono);
  letter-spacing: .06em;
  text-transform: uppercase;
}
#mainContent #hp-main .hp-variants__label {
  margin-right: 4px;
}
#mainContent #hp-main .hp-variants a {
  padding: 6px 10px;
  border: 1px solid var(--hp-line);
  border-radius: var(--hp-r-sm);
  background: var(--hp-veil);
  color: var(--hp-ink);
  text-decoration: none;
}
#mainContent #hp-main .hp-variants a:hover {
  border-color: var(--hp-accent);
}
#mainContent #hp-main .hp-variants a[aria-current="page"] {
  border-color: var(--hp-accent-fill);
  background: var(--hp-accent-fill);
  color: var(--hp-on-accent);
}

/* ---------- Icons: one per explainer, from the reader's style set ---------- */

#mainContent #hp-main .hp-icons {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  --hp-icon-op: .42;
  --hp-icon-sat: .55;
}
html.theme_dark #mainContent #hp-main .hp-icons {
  --hp-icon-op: .5;
  --hp-icon-sat: .6;
}
html.style_minimal #mainContent #hp-main .hp-icons {
  --hp-icon-op: .34;
}
#mainContent #hp-main[data-hp-variant="mix"] .hp-icons {
  --hp-icon-op: .36;
}
html.theme_dark #mainContent #hp-main[data-hp-variant="mix"] .hp-icons {
  --hp-icon-op: .44;
}
#mainContent #hp-main .hp-icon {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: var(--s, 44px);
  height: var(--s, 44px);
  border: 0;
  background: none;
  filter: saturate(var(--hp-icon-sat)) blur(.3px);
  opacity: var(--hp-icon-op);
  cursor: pointer;
  pointer-events: auto;
  transform: translate(var(--x), var(--y));
  transition: opacity .35s ease, filter .35s ease;
  animation: hp-wander var(--wander, 9s) ease-in-out var(--delay, 0s) infinite alternate;
}
#mainContent #hp-main .hp-icon img {
  display: block;
  width: 100%;
  height: 100%;
  animation: var(--dance, hp-bob) var(--beat, 1.6s) ease-in-out var(--delay, 0s) infinite alternate;
}
html:is([data-twemoji="pixel"], [data-twemoji="platformer"]) #mainContent #hp-main .hp-icon img {
  image-rendering: pixelated;
}
#mainContent #hp-main .hp-icons.is-focused .hp-icon {
  opacity: calc(var(--hp-icon-op) * .55);
}
#mainContent #hp-main .hp-icon:is(:hover, .is-lit),
#mainContent #hp-main .hp-icons.is-focused .hp-icon.is-lit {
  filter: none;
  opacity: 1;
}
#mainContent #hp-main .hp-icon:hover img {
  animation: hp-boogie .5s ease-in-out infinite alternate;
}
#mainContent #hp-main .hp-icon.is-lit img {
  animation: var(--dance, hp-bob) calc(var(--beat, 1.6s) * .6) ease-in-out infinite alternate;
}
/* The icons replace the star field on the Icons page. */
#mainContent #hp-main[data-hp-variant="icons"] :is(.hp-field, .hp-static, .hp-probe) {
  display: none;
}
#mainContent #hp-main .hp-hero--icons .hp-motion {
  display: inline-flex;
}
#mainContent #hp-main .hp-hero--icons .hp-figcap__hint {
  display: inline;
}

@keyframes hp-wander {
  from { transform: translate(var(--x), var(--y)) translate(-12px, 6px) rotate(-5deg); }
  to { transform: translate(var(--x), var(--y)) translate(12px, -8px) rotate(5deg); }
}
@keyframes hp-bob {
  from { transform: translateY(0); }
  to { transform: translateY(-9px); }
}
@keyframes hp-sway {
  from { transform: rotate(-10deg); }
  to { transform: rotate(10deg); }
}
@keyframes hp-hop {
  from { transform: translateY(0) scale(1.06, .94); }
  to { transform: translateY(-14px) scale(.96, 1.04); }
}
@keyframes hp-jelly {
  0% { transform: scale(1, 1); }
  40% { transform: scale(1.14, .88); }
  70% { transform: scale(.9, 1.1); }
  100% { transform: scale(1.04, .96); }
}
@keyframes hp-spin {
  from { transform: rotate(-20deg); }
  to { transform: rotate(200deg); }
}
@keyframes hp-shimmy {
  0% { transform: translateX(-4px) rotate(-3deg); }
  50% { transform: translateX(4px) rotate(3deg); }
  100% { transform: translateX(-2px) rotate(-1deg); }
}
@keyframes hp-boogie {
  from { transform: rotate(-16deg) translateY(0) scale(1.08); }
  to { transform: rotate(16deg) translateY(-10px) scale(1.16); }
}

@media (max-width: 680px) {
  #mainContent #hp-main .hp-variants {
    gap: 5px;
  }
  #mainContent #hp-main .hp-variants a {
    padding: 6px 8px;
  }
}
#mainContent #hp-main .hp-icon[hidden] {
  display: none;
}

/* ---------- Wide openings: the drawing spans the whole window ---------- */

/* data-hp-field="wide" spreads the opening's drawing across the window, behind and beside the text
   column. The background options use it now; it began as the preview's full-width galaxy (6e47d3f),
   which field.js still draws with it, dimmed behind the words: --hp-f-keep is how much of the stars,
   glow, and nebulae stays there. */
#mainContent #hp-main[data-hp-field="wide"] .hp-hero {
  --hp-f-keep: .3;
  --hp-f-dust: .8;
  --hp-f-neb: .4;
}
html:not(.theme_dark) #mainContent #hp-main[data-hp-field="wide"] .hp-hero {
  --hp-f-keep: .4;
}
html:not(.theme_dark):not(.style_minimal) #mainContent #hp-main[data-hp-field="wide"] .hp-hero {
  --hp-f-ink-amt: .3;
}
html.theme_dark:not(.style_minimal) #mainContent #hp-main[data-hp-field="wide"] .hp-hero {
  --hp-f-gain: .85;
}
/* The caption sits over the field too, so it uses the body text color (field.js keeps the field
   behind the words within what the body text, headline, and accent colors allow). */
#mainContent #hp-main[data-hp-field="wide"] .hp-figcap {
  color: var(--hp-text);
}
/* The track's label stays readable above the drifting icons (and below the words and tooltips),
   here and on the preview, where it hangs on the lit icons. */
#mainContent #hp-main:is([data-hp-field="wide"], [data-hp-field="icons"]) .hp-probe {
  z-index: 2;
}
/* Platformer colors its headline's accent words with the theme color itself, and the lightest ones
   (blue, #0798FF) fall under 3:1 over the light page and the faint field. Cap their lightness
   (the preview keeps the same headline colors). */
@supports (color: oklch(from red l c h)) {
  html.style_platformer:not(.theme_dark) #mainContent #hp-main:is([data-hp-field="wide"], [data-hp-field="icons"]) {
    --hp-glow-a: oklch(from var(--hp-accent) min(l, .6) c h);
    --hp-glow-b: oklch(from var(--hp-accent) min(l, .6) c h);
  }
}
/* Narrower windows: the label sits next to its track in the band above the words, with a short
   line back to the track. --hp-anchor-y is where that line meets the label. */
#mainContent #hp-main:is([data-hp-field="wide"], [data-hp-field="icons"]) .hp-probe--beside {
  display: grid;
}
#mainContent #hp-main:is([data-hp-field="wide"], [data-hp-field="icons"]) .hp-probe--beside::before {
  top: var(--hp-anchor-y, 50%);
  right: auto;
  bottom: auto;
  left: -38px;
  width: 38px;
  height: 0;
  border: 0;
  border-top: 1px solid var(--cc, var(--hp-accent));
}
#mainContent #hp-main:is([data-hp-field="wide"], [data-hp-field="icons"]) .hp-probe--beside::after {
  top: calc(var(--hp-anchor-y, 50%) - 3px);
  right: auto;
  bottom: auto;
  left: -41px;
}
#mainContent #hp-main:is([data-hp-field="wide"], [data-hp-field="icons"]) .hp-probe--beside.hp-probe--flip::before {
  right: -38px;
  left: auto;
}
#mainContent #hp-main:is([data-hp-field="wide"], [data-hp-field="icons"]) .hp-probe--beside.hp-probe--flip::after {
  right: -41px;
  left: auto;
}

/* ---------- Preview: just the icons ---------- */

/* index_preview.htm is Mix without the field (data-hp-field="icons"): the sparse icon layer is all
   that moves. icons.js hangs the tour's label on the lit icons, and it fades between tracks. */
#mainContent #hp-main[data-hp-field="icons"] .hp-probe {
  transition: opacity .3s ease, visibility 0s linear .3s;
}
#mainContent #hp-main[data-hp-field="icons"] .hp-probe.is-on {
  opacity: 1;
  transition: opacity .3s ease;
}
/* Near the bottom of the window, the label can sit over its icon instead, with the line going down. */
#mainContent #hp-main[data-hp-field="icons"] .hp-probe--above {
  display: grid;
}
#mainContent #hp-main[data-hp-field="icons"] .hp-probe--above::before {
  top: 100%;
  bottom: auto;
  left: var(--hp-anchor, 50%);
  width: 0;
  height: 36px;
  border: 0;
  border-left: 1px solid var(--cc, var(--hp-accent));
}
#mainContent #hp-main[data-hp-field="icons"] .hp-probe--above::after {
  top: calc(100% + 33px);
  bottom: auto;
  left: calc(var(--hp-anchor, 50%) - 3px);
}
/* Track colors color text across the page (the question cards' numbers and active explainer names,
   the label's track name, the map's counts, and the feed links), so they need 4.5:1. Ukiyo-e's paper
   and Platformer's sky are darker than white, so by day the colors mix a little deeper there;
   Ukiyo-e's night panels need them a little lighter. */
html:is(.style_ukiyoe, .style_platformer):not(.theme_dark) #mainContent #hp-main[data-hp-field="icons"] {
  --hp-cmix: 44%;
}
html.style_ukiyoe.theme_dark #mainContent #hp-main[data-hp-field="icons"] {
  --hp-cmix: 80%;
  --hp-cbase: #fff;
}
/* Minimal mutes the track colors toward a dark base, which leaves them short of 4.5:1 on its dark
   page. There, they mute toward the ink instead. */
html.style_minimal.theme_dark #mainContent #hp-main[data-hp-field="icons"] {
  --hp-cbase: var(--hp-ink);
}
/* On phones, Platformer's headline drops under 24px, where it counts as regular text (4.5:1), and its
   light accents (blue, pink, and green) fall short of that even on the plain page. Deepen them a
   little more, as the background options do. */
@container hp-col (max-width: 470px) {
  @supports (color: oklch(from red l c h)) {
    html.style_platformer:not(.theme_dark) #mainContent #hp-main[data-hp-field="icons"] .hp-hero {
      --hp-glow-a: oklch(from var(--hp-accent) min(l, .54) c h);
      --hp-glow-b: oklch(from var(--hp-accent) min(l, .54) c h);
    }
  }
}
