/* Home page: the runner strip and play-in-place thread cards.
   Loaded after the main stylesheet and thread-card.css, and built on their tokens. */

/* --------------------------------------------------------------- runner */
/* Without JavaScript this block is just the page heading: every game part is
   hidden and the heading keeps its normal place. */
.runner-canvas,
.runner-hit,
.runner-bar,
.runner-prompt { display: none; }

/* With it, the heading becomes the game's backdrop. The strip takes only the
   height of its ground line; the heading stands on that line, and the sky the
   mark jumps through is the site header. The canvas is laid over both, one
   step above the header and below the mobile drawer, and lets clicks through. */
.js .runner {
  --sky: 40px; /* the gap between the header and the ground */
  position: relative;
  margin: 0 0 30px;
  padding-top: 22px;
}

/* The heading stands on the ground line, right after the mark, which waits
   flush with the left edge of the thread cards. */
.js .runner h1 {
  position: absolute;
  left: 36px;
  bottom: 100%;
  margin: 0 0 1px;
  white-space: nowrap;
}
/* While a run is on, the heading is gone: the script turns it to dust on the
   canvas, and it fades back when the run ends. */
.js .runner h1 { transition: opacity 0.5s; }
.js .runner.is-running h1 { opacity: 0; transition-duration: 0.12s; }
@media (prefers-reduced-motion: reduce) {
  .js .runner.is-running h1 { transition-duration: 0.5s; }
}

.js .runner-canvas {
  display: block;
  position: absolute;
  /* Overhangs the column a little, so the mark can stand flush with the cards
     below and still spin without being cut off. */
  left: -14px;
  top: -110px;
  z-index: 51;
  width: calc(100% + 28px);
  height: 132px;
  pointer-events: none;
}

/* What the visitor taps: the band between the header and the readout. */
.js .runner-hit {
  display: block;
  position: absolute;
  left: 0;
  top: calc(-1 * var(--sky));
  width: 100%;
  height: calc(var(--sky) + 22px);
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.runner-hit:focus { outline: none; }
.runner-hit:focus-visible:not(.by-pointer) {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* "Tap to play", in the middle of the game while nothing is running. */
.js .runner-prompt {
  display: flex;
  align-items: center;
  position: absolute;
  left: 50%;
  top: calc(-1 * var(--sky));
  height: var(--sky);
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
  pointer-events: none;
}
.js .runner-prompt[hidden] { display: none; }
.js .runner-prompt { animation: runner-blink 1.1s steps(1, end) infinite; }
@keyframes runner-blink {
  50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .js .runner-prompt { animation: none; }
}

.js .runner-bar {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 2px;
  line-height: 1.2;
  /* Tapping the readout jumps, so it reads as part of the game. */
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.runner-score {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 400;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.runner-best {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
}

/* Wide screens: the readout moves out of the reading column into the empty
   third column, level with the game. */
@media (min-width: 1240px) {
  .js .runner { margin-bottom: 26px; }
  .js .runner-bar {
    position: absolute;
    top: calc(-1 * var(--sky));
    left: calc(100% + 24px);
    width: 172px;
    height: calc(var(--sky) + 22px);
    box-sizing: border-box;
    margin: 0;
    padding: 0 16px 0 14px;
    align-items: center;
    justify-content: flex-start;
  }
  .runner-score { order: 1; font-size: 28px; }
  .runner-best { order: 2; }
}

/* Narrow screens: the heading fills the band, so the prompt drops to the
   readout row, and the strip keeps a little more sky for the heading. */
@media (max-width: 760px) {
  .js .runner { --sky: 36px; margin-top: 12px; }
  .js .runner-prompt {
    left: 0;
    top: auto;
    bottom: 3px;
    height: auto;
    transform: none;
  }
}

/* ------------------------------------------------- play inside the card */
.home-thread-stage {
  position: relative;
  max-width: 420px;
  margin: 12px 0 10px;
}
.home-thread-stage .home-thread-preview { margin: 0; }
.home-thread-stage .home-thread-preview[hidden] { display: none; }

.home-thread-play {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: #14110e;
  background: #ffffff;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(20, 17, 14, 0.35);
}
.home-thread-play:hover { background: #f1ece6; }
.home-thread-play:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Playing: the stage takes the card's full width and the button moves below. */
.home-thread-stage.is-playing { max-width: none; }
.home-thread-stage iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  background: #14110e;
}
.home-thread-stage.is-playing .home-thread-play {
  position: static;
  margin-top: 10px;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border-secondary);
  box-shadow: none;
}

@media (max-width: 640px) {
  .home-thread-stage { max-width: none; }
}
