/*
 * "See how it works" demo loop (src/ui/DemoLoop.ts). Used on
 * nex-playground-alternative.html, landing.html and teachers.html; works on
 * the dark article hero, the light landing hero and the purple teachers hero
 * (text colors inherit).
 */
.demo-loop {
  margin: 24px auto 0;
  max-width: 560px;
  width: 100%;
  min-width: 0;
  text-align: center;
}

/* Grid parents (the landing hero) would otherwise size the column to the
   video's intrinsic 800px width and scroll sideways on phones. */
.hero-visual:has(.demo-loop) {
  min-width: 0;
  width: 100%;
}

.demo-loop-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 18px;
  overflow: hidden;
  background: #1f2937;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.demo-loop-video {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Pause / play: bottom-left, clear of the game's own buttons (top) and the
   camera-view inset (bottom-right). */
.demo-loop-toggle {
  position: absolute;
  /* A 44px tap target drawn as the same 36px circle: the transparent 4px
     border is part of the button but not painted. */
  left: 6px;
  bottom: 6px;
  box-sizing: border-box;
  width: 44px;
  height: 44px;
  border: 4px solid transparent;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.62);
  background-clip: padding-box;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.demo-loop-toggle::before {
  content: '';
  display: block;
  /* play triangle */
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent #fff;
  margin-left: 4px;
}

.demo-loop-toggle[data-state='playing']::before {
  /* pause bars */
  width: 12px;
  height: 13px;
  border: 0;
  margin: 0;
  background: linear-gradient(90deg, #fff 0 4px, transparent 4px 8px, #fff 8px 12px);
}

.demo-loop-toggle:focus-visible {
  outline: 3px solid #fbbf24;
  outline-offset: 2px;
}

.demo-loop-caption {
  margin: 12px auto 0;
  max-width: 520px;
  font-size: 0.95rem;
  line-height: 1.45;
  opacity: 0.85;
}

.demo-loop-caption strong {
  opacity: 1;
}

.demo-loop-play {
  margin-top: 14px;
}

/* Wide screens: video beside its caption and Play button, so the button is
   above the fold on a laptop too. */
@media (min-width: 900px) {
  .demo-loop--split {
    max-width: 880px;
    display: grid;
    grid-template-columns: minmax(0, 480px) minmax(0, 320px);
    column-gap: 32px;
    justify-content: center;
    align-items: center;
    text-align: left;
  }

  .demo-loop--split .demo-loop-frame {
    grid-row: 1 / span 2;
  }

  .demo-loop--split .demo-loop-caption {
    margin: 0;
    align-self: end;
    font-size: 1.05rem;
  }

  .demo-loop--split .demo-loop-play {
    align-self: start;
    justify-content: flex-start;
    margin: 20px 0 0;
  }
}

@media (max-width: 640px) {
  .demo-loop {
    margin-top: 18px;
  }

  .demo-loop-frame {
    border-radius: 14px;
  }

  .demo-loop-caption {
    font-size: 0.9rem;
  }
}

/* Longer description for screen readers (teachers.html has no landing.css). */
.demo-loop .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* "Try it here" pill: bottom-left beside the pause button, clear of the inset. */
.demo-loop-try {
  position: absolute;
  left: 54px;
  bottom: 10px;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: #F59E0B;
  color: #1f2937;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.35);
}

/* Drawn 36px tall; the hit area reaches 44px. */
.demo-loop-try::after {
  content: '';
  position: absolute;
  inset: -4px 0;
}

.demo-loop-try:hover {
  background: #FBBF24;
}

.demo-loop-try:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.demo-loop-video {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Tap-to-pop preview (src/ui/BubblePopPreview.ts), in the same frame. */
.demo-loop-frame.is-previewing .demo-loop-video,
.demo-loop-frame.is-previewing .demo-loop-toggle,
.demo-loop-frame.is-previewing .demo-loop-try {
  visibility: hidden;
}

.demo-preview {
  position: absolute;
  inset: 0;
  text-align: center;
  font-family: inherit;
}

.demo-preview[hidden] {
  display: none;
}

.demo-preview-canvas {
  display: block;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

.demo-preview-canvas:focus-visible {
  outline: 3px solid #fbbf24;
  outline-offset: -3px;
}

.demo-preview-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  color: #fff;
  font-weight: 800;
}

.demo-preview-score {
  display: grid;
  place-items: center;
  min-width: 46px;
  height: 46px;
  padding: 0 6px;
  border-radius: 999px;
  background: #1e1b3a;
  border: 4px solid #60a5fa;
  font-size: 1.3rem;
}

.demo-preview-goal {
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(30, 27, 58, 0.85);
  font-size: 1rem;
}

.demo-preview-time {
  margin-left: auto;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(30, 27, 58, 0.85);
  font-variant-numeric: tabular-nums;
}

.demo-preview-end {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  background: rgba(30, 27, 75, 0.82);
  color: #fff;
}

.demo-preview-end[hidden] {
  display: none;
}

.demo-preview-result {
  margin: 0;
  font-size: clamp(1.3rem, 4.5vw, 1.8rem);
  font-weight: 900;
}

.demo-preview-play {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 16px 28px;
  border-radius: 14px;
  background: #F59E0B;
  color: #1f2937;
  font-size: clamp(1.1rem, 4vw, 1.35rem);
  font-weight: 900;
  text-decoration: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.demo-preview-play:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.demo-preview-more {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.demo-preview-more button {
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

/* Section placement on the article pages (below the hero). */
.demo-section {
  padding: 48px 0 8px;
  background: white;
  text-align: center;
}

.demo-section h2 {
  margin: 0 0 4px;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.demo-section .demo-loop-play {
  display: flex;
  justify-content: center;
}

@media (min-width: 900px) {
  .demo-section .demo-loop-play {
    justify-content: flex-start;
  }
}

/* Phones: the short label keeps the pill clear of the camera-view inset. */
@media (max-width: 560px) {
  .demo-loop-try-more {
    display: none;
  }
}


/* Phones (marketing.ts mountPhoneTryBar): one big "Try it here" button under
   the hero clip takes over from the small pill on the video. */
.demo-try-bar {
  display: block;
  width: 100%;
  min-height: 56px;
  margin: 12px 0 4px;
  border: 0;
  border-radius: 16px;
  background: #F59E0B;
  color: #1f2937;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.35);
  -webkit-tap-highlight-color: transparent;
}

.demo-try-bar:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.demo-loop.has-try-bar .demo-loop-try {
  display: none;
}
