/*
 * Maths HQ topic gallery. This is the only stylesheet for the ten topic cards.
 *
 * One continuous black surface holds a grid of topics. Each topic is the complete
 * original artwork, scaled proportionally (never cropped, stretched or overlaid),
 * with a compact rank line and a slim XP meter underneath.
 *
 * On the desktop dashboard the two rows share the height Maths HQ has left, so the
 * art shrinks to fit rather than pushing the second row off screen. Elsewhere each
 * card takes the column width and the page scrolls as normal.
 */

body.mission-mode #screen-home .mission-topic-section,
body.mission-mode #screen-home .mission-all-topics {
  background: #000;
}

body.mission-mode #screen-home .mission-all-topics {
  --topic-meta: 33px;
  /* Topic art is about 193 x 240 (width / height). */
  --topic-art-ratio: .8;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  column-gap: 10px;
  row-gap: 7px;
  align-items: start;
  padding: 10px 12px;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card {
  position: relative;
  /* Shields size themselves to this card width in windowed Maths HQ. */
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: inherit;
  font: inherit;
  text-align: center;
  cursor: pointer;
  transform-origin: 50% 70%;
  transition: transform .28s cubic-bezier(.34, 1.56, .64, 1);
  animation: topic-pop-in .45s cubic-bezier(.34, 1.56, .64, 1) backwards;
}

/* Cards pop in one after another when Maths HQ opens. */
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(2) { animation-delay: .04s; }
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(3) { animation-delay: .08s; }
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(4) { animation-delay: .12s; }
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(5) { animation-delay: .16s; }
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(6) { animation-delay: .20s; }
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(7) { animation-delay: .24s; }
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(8) { animation-delay: .28s; }
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(9) { animation-delay: .32s; }
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(10) { animation-delay: .36s; }

@keyframes topic-pop-in {
  0% { opacity: 0; transform: translateY(18px) scale(.82); }
  100% { opacity: 1; transform: none; }
}

/* Hover: the card springs up, brightens, glows toxic green and a shine sweeps across it. */
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover,
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):focus-visible {
  z-index: 2;
  transform: translateY(-7px) scale(1.08) rotate(-1.5deg);
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(even):not(:disabled):hover,
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(even):not(:disabled):focus-visible {
  transform: translateY(-7px) scale(1.08) rotate(1.5deg);
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):active {
  transform: translateY(-2px) scale(.96);
  transition-duration: .08s;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover .gb-story-art-img,
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):focus-visible .gb-story-art-img {
  animation: topic-glow 1.2s ease-in-out infinite;
}

@keyframes topic-glow {
  0%, 100% { filter: brightness(1.22) saturate(1.2) drop-shadow(0 0 8px rgba(120, 255, 70, .55)) drop-shadow(0 10px 14px rgba(0, 0, 0, .6)); }
  50% { filter: brightness(1.35) saturate(1.3) drop-shadow(0 0 18px rgba(150, 255, 80, .9)) drop-shadow(0 10px 14px rgba(0, 0, 0, .6)); }
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-story-art {
  position: relative;
  /* Hot-topic pill sizes itself to this art box, not the whole browser window. */
  container-type: inline-size;
  width: 100%;
}

/* Baked into every topic PNG: three green “status” lights on the bottom lip.
   Cover them with a metal patch in % units so it scales on fullscreen. */
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-story-art::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 2.4%;
  z-index: 2;
  width: 22%;
  height: 4.2%;
  transform: translateX(-50%);
  border-radius: 2px;
  background:
    linear-gradient(180deg, #3a3e42 0%, #23262a 45%, #181a1c 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -1px 0 rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-story-art::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, .55) 48%, rgba(200, 255, 150, .25) 52%, transparent 65%) no-repeat;
  background-size: 250% 100%;
  background-position: 140% 0;
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover .gb-story-art::after,
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):focus-visible .gb-story-art::after {
  animation: topic-shine .7s ease-out forwards;
}

@keyframes topic-shine {
  0% { opacity: 1; background-position: 140% 0; }
  100% { opacity: 1; background-position: -40% 0; }
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:focus-visible {
  outline: 2px solid #ffcf68;
  outline-offset: 1px;
}

body.mission-mode #screen-home .mission-all-topics .gb-story-locked {
  opacity: .4;
  cursor: not-allowed;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-story-art {
  display: flex;
  justify-content: center;
  width: 100%;
  overflow: visible;
}

/* The source art already holds the frame and artwork: show every pixel of it. */
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-story-art-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  object-position: center;
  filter: none;
  transform: none;
}

body.mission-mode #screen-home .mission-all-topics .gb-story-locked .gb-story-art-img {
  filter: grayscale(.85) brightness(.55);
}

body.mission-mode #screen-home .mission-all-topics .gb-story-art-emoji {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  font-family: var(--font-display);
  font-size: 2.5rem;
  color: rgba(255, 255, 255, .85);
}

/* Backup title ONLY for a topic whose source image is missing. */
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-story-title {
  display: block;
  margin: 4px auto 0;
  padding: 0 4px;
  font-family: var(--font-display);
  font-size: .8rem;
  line-height: 1.05;
  color: #ffe09d;
  text-shadow: 0 2px 5px #000;
}

/* Brag board: six level shields. Soft path = light up L1; flex = fill through L6.
   Scale to the card so L6 never crashes into the next topic in windowed mode. */
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-topic-shields {
  display: flex;
  position: static;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: clamp(18px, 22cqi, 28px);
  justify-content: center;
  align-items: center;
  gap: clamp(1px, 1.2cqi, 3px);
  padding: 0 0 2px;
  overflow: hidden;
  pointer-events: none;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-level-shield {
  flex: 0 1 auto;
  width: clamp(11px, 13.2cqi, 20px);
  height: clamp(13px, 15.8cqi, 24px);
  min-width: 0;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-level-shield-num {
  font-size: clamp(0.42rem, 5.2cqi, 0.58rem);
  padding-top: 1px;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card .gb-level-shield.is-earned .gb-level-shield-img {
  filter: drop-shadow(0 0 4px rgba(255, 200, 80, 0.75));
}

/* Today's hot topic: a flame banner across the top of the art and a warm glow. */
body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card.is-hot .gb-story-art-img {
  filter: drop-shadow(0 0 10px rgba(255, 140, 40, .75));
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-hot {
  position: absolute;
  /* Sit on the metal plaque, not the transparent padding around the PNG. */
  top: 6%;
  left: 50%;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.12em;
  box-sizing: border-box;
  max-width: 78%;
  padding: 0.28em 0.72em 0.28em 0.28em;
  border: 2px solid #fff;
  border-radius: 999px;
  overflow: visible;
  background: linear-gradient(180deg, #ffb340, #ff5a1f);
  color: #2a0d00;
  /* Scale with the card art (cqi), not the browser width (vw). */
  font-size: clamp(0.62rem, 11cqi, 1.05rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1.15;
  white-space: nowrap;
  box-shadow:
    0 0 0 1px rgba(40, 10, 0, 0.25),
    0 0 14px rgba(255, 110, 30, .75);
  transform: translateX(-50%);
  pointer-events: none;
  animation: hot-flicker 1.6s ease-in-out infinite;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-hot::before,
body.mission-mode #screen-home .mission-all-topics .gb-topic-hot::after {
  content: none;
}

/* Real emoji flame + rising sparks/smoke (taller than the pill). */
body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-flame {
  position: relative;
  flex: 0 0 auto;
  width: 1.55em;
  height: 1.7em;
  margin: -0.55em 0.08em -0.35em -0.22em;
  overflow: visible;
  z-index: 3;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-flame-emoji {
  position: absolute;
  left: 50%;
  bottom: -0.08em;
  display: block;
  font-size: 1.55em;
  line-height: 1;
  transform: translateX(-50%);
  transform-origin: 50% 85%;
  /* Soft heat glow + a crisp offset shadow so the flame sits off the pill. */
  filter:
    drop-shadow(0 0 3px rgba(255, 100, 0, 0.75))
    drop-shadow(1px 2px 0 rgba(40, 10, 0, 0.55))
    drop-shadow(0 3px 2px rgba(0, 0, 0, 0.45));
  animation: hot-flame-wobble 0.55s ease-in-out infinite alternate;
}

/* Soft smoke wisps drifting up from the tip. */
body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke,
body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke::before,
body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke::after {
  content: '';
  position: absolute;
  left: 42%;
  top: -0.15em;
  width: 0.55em;
  height: 0.7em;
  border-radius: 60% 40% 55% 45%;
  background: radial-gradient(ellipse at 50% 70%, rgba(220, 220, 230, 0.45) 0%, rgba(180, 180, 190, 0.18) 45%, transparent 72%);
  filter: blur(1.5px);
  pointer-events: none;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke {
  animation: hot-smoke-a 2.4s ease-out infinite;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke::before {
  left: 0.1em;
  top: 0.05em;
  width: 0.45em;
  height: 0.55em;
  animation: hot-smoke-b 2.8s ease-out infinite 0.6s;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke::after {
  left: -0.15em;
  top: 0.1em;
  width: 0.4em;
  height: 0.5em;
  animation: hot-smoke-c 2.2s ease-out infinite 1.1s;
}

/* Default to the short label so Chrome on a windowed laptop never shows "HOT TOPI…". */
body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-full {
  display: none;
}

body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-short {
  display: inline;
}

/* Fullscreen / big cards only: room for the full wording. */
@container (min-width: 200px) {
  body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-full {
    display: inline;
  }

  body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-short {
    display: none;
  }
}

@keyframes hot-flicker {
  0%, 100% { box-shadow: 0 0 0 1px rgba(40, 10, 0, 0.25), 0 0 10px rgba(255, 110, 30, .6); }
  50% { box-shadow: 0 0 0 1px rgba(40, 10, 0, 0.25), 0 0 20px rgba(255, 150, 40, .95); }
}

@keyframes hot-flame-wobble {
  0% { transform: translateX(-50%) scale(1) rotate(-4deg); }
  100% { transform: translateX(-50%) scale(1.06, 0.96) rotate(5deg); }
}

@keyframes hot-smoke-a {
  0% { transform: translate(0, 0.15em) scale(0.6); opacity: 0; }
  20% { opacity: 0.55; }
  100% { transform: translate(0.35em, -1.35em) scale(1.35); opacity: 0; }
}

@keyframes hot-smoke-b {
  0% { transform: translate(0, 0.1em) scale(0.5); opacity: 0; }
  25% { opacity: 0.4; }
  100% { transform: translate(-0.4em, -1.5em) scale(1.5); opacity: 0; }
}

@keyframes hot-smoke-c {
  0% { transform: translate(0, 0.2em) scale(0.55); opacity: 0; }
  22% { opacity: 0.35; }
  100% { transform: translate(0.15em, -1.2em) scale(1.25); opacity: 0; }
}

/* Desktop dashboard: two rows of five share the height Maths HQ has left (see
   ten-topic-dashboard.css). Each card measures its own cell, and the square art
   takes the largest size that fits above the rank line, so nothing is cut off.
   On a very short window the art stops shrinking at 120px tall and Maths HQ scrolls. */
@media (min-width: 1321px) and (min-height: 600px) {
  body.mission-mode #screen-home .mission-home:not(:has(.mission-map-details[open])) .mission-topic-section {
    --topic-head: 0px;
    display: flex;
    flex-direction: column;
    container-type: size;
    min-height: calc(var(--topic-head) + 2 * (120px + 33px) + 7px + 20px);
  }

  /* Each column is exactly one card wide: the largest card that fits two rows in the
     space left, 12px apart and centred. */
  body.mission-mode #screen-home .mission-home:not(:has(.mission-map-details[open])) .mission-all-topics {
    --topic-row: calc((100cqh - var(--topic-head) - 20px - 7px) / 2);
    --topic-art-w: calc(min((var(--topic-row) - var(--topic-meta)) * var(--topic-art-ratio), (100cqw - 24px - 4 * 12px) / 5));
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: repeat(5, var(--topic-art-w));
    column-gap: 12px;
    justify-content: center;
    align-content: center;
  }
}

@media (max-width: 870px) {
  body.mission-mode #screen-home .mission-all-topics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
  }
}

@media (max-width: 540px) {
  body.mission-mode #screen-home .mission-all-topics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card,
  body.mission-mode #screen-home .mission-all-topics .gb-topic-hot,
  body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-flame-emoji,
  body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke,
  body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke::before,
  body.mission-mode #screen-home .mission-all-topics .gb-topic-hot-smoke::after {
    transition: none;
    animation: none;
  }

  body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover {
    transform: none;
  }

  body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover .gb-story-art-img {
    animation: none;
    filter: brightness(1.25);
  }

  body.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover .gb-story-art::after {
    animation: none;
  }
}

/* During the onboarding tour the cards stay still, so the arrows and tips are the only things moving. */
body.coach-active.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover,
body.coach-active.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:nth-child(even):not(:disabled):hover {
  transform: none;
}

body.coach-active.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover .gb-story-art-img,
body.coach-active.mission-mode #screen-home .mission-all-topics .gb-topic-campaign-card:not(:disabled):hover .gb-story-art::after {
  animation: none;
}
