/* ============================================================================
   CODE QUEST — layout.css
   Page shells, the background media stack, the 16:9 game stage, and the
   arrangement primitives every page composes with.
   ========================================================================== */

/* ============================================================================
   1. PAGE SHELL
   ========================================================================== */

.cq-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  z-index: var(--z-base);
}

.cq-main {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-block: var(--gap-section) var(--sp-8);
}

.cq-main--narrow { max-width: var(--content-narrow); }
.cq-main--wide { max-width: var(--content-wide); }
.cq-main--flush { padding-block: 0; }
.cq-main--full { max-width: none; }

/* ============================================================================
   2. BACKGROUND MEDIA STACK
   Real project artwork sits at the bottom, then a scrim, then the ambient FX
   layer (fx.css), then the page. Nothing here can intercept a pointer.
   ========================================================================== */

.cq-bg {
  position: fixed;
  inset: 0;
  z-index: var(--z-bg);
  overflow: hidden;
  background-color: var(--bg-abyss);
  pointer-events: none;
}

/* The artwork is scaled slightly beyond the viewport so parallax has room to
   move without exposing an edge. `cover` is safe here: nothing informational
   lives in a background plate. */
.cq-bg__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0.6;
  transform: scale(1.06);
  transition: opacity var(--dur-cinematic) var(--ease-out-expo);
  will-change: transform;
}

/* Slow ambient drift — the "cinematic" background movement. */
.cq-bg--drift .cq-bg__img {
  animation: cq-bg-drift 44s var(--ease-in-out-soft) infinite;
}

@keyframes cq-bg-drift {
  0%, 100% { transform: scale(1.06) translate3d(0, 0, 0); }
  50%      { transform: scale(1.12) translate3d(-1.4%, -1%, 0); }
}

.cq-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--scrim-page);
  pointer-events: none;
}

/* Applied when the declared background asset could not load: the scrim and the
   body's own ground remain, so the page still reads as designed. */
.cq-bg--fallback .cq-bg__img {
  display: none;
}

/* A dimmer scrim variant for pages with dense text over artwork. */
.cq-bg--dim::after {
  background: linear-gradient(
    180deg,
    rgba(3, 6, 15, 0.62) 0%,
    rgba(3, 6, 15, 0.8) 45%,
    rgba(3, 6, 15, 0.96) 100%
  );
}

/* ============================================================================
   3. GAME STAGE — the 16:9 scene frame
   ========================================================================== */

.cq-stage {
  position: relative;
  width: 100%;
  aspect-ratio: var(--stage-ratio);
  max-height: 70vh;
  margin-inline: auto;
  overflow: hidden;
  border: var(--border-hair) solid var(--glass-edge);
  border-radius: var(--r-lg);
  background-color: var(--bg-abyss);
  box-shadow: var(--elev-3), inset 0 0 70px rgba(3, 6, 15, 0.62);
  isolation: isolate;
}

/* A bright inner hairline, so the frame reads as a physical viewport. */
.cq-stage::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(122, 221, 255, 0.12);
  pointer-events: none;
  z-index: 5;
}

.cq-stage__layer {
  position: absolute;
  inset: 0;
}

/* Scenic plates fill the frame. */
.cq-stage__scene {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transform: scale(1.02);
}

/* Diagrams, question art and anything with readable content inside it is
   CONTAINED — never cropped. */
.cq-stage__contain {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.cq-stage__veil {
  position: absolute;
  inset: 0;
  background: var(--scrim-stage);
  pointer-events: none;
  z-index: 2;
}

/* Character / VFX video overlays. */
.cq-stage__actor {
  position: absolute;
  bottom: 3%;
  width: clamp(78px, 15%, 178px);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  pointer-events: none;
  mix-blend-mode: screen;
  z-index: 3;
  filter: drop-shadow(0 8px 26px rgba(3, 6, 15, 0.8));
}

.cq-stage__actor--left { left: 5%; }
.cq-stage__actor--right { right: 5%; transform: scaleX(-1); }
.cq-stage__actor--center { left: 50%; transform: translateX(-50%); }

.cq-stage__vfx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  mix-blend-mode: screen;
  opacity: 0.5;
  pointer-events: none;
  z-index: 4;
}

.cq-stage__caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: var(--sp-4);
  z-index: 6;
  background: var(--scrim-caption);
}

/* Corner ticks on the stage — cheap, and they sell the "viewport" idea. */
.cq-stage__ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.cq-stage__ticks span {
  position: absolute;
  width: 20px;
  height: 20px;
  border: var(--border-thin) solid var(--cyan-400);
  opacity: 0.5;
}

.cq-stage__ticks span:nth-child(1) { top: 10px; left: 10px; border-right: 0; border-bottom: 0; }
.cq-stage__ticks span:nth-child(2) { top: 10px; right: 10px; border-left: 0; border-bottom: 0; }
.cq-stage__ticks span:nth-child(3) { bottom: 10px; left: 10px; border-right: 0; border-top: 0; }
.cq-stage__ticks span:nth-child(4) { bottom: 10px; right: 10px; border-left: 0; border-top: 0; }

/* ============================================================================
   4. SECTION HEADER — the repeated "eyebrow + title + actions" block
   ========================================================================== */

.cq-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--gap-panel);
}

.cq-section-head__text {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
}

.cq-section-head__title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-black);
  margin: 0;
  line-height: var(--lh-tight);
}

.cq-section-head__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

/* ============================================================================
   5. ARRANGEMENT PRIMITIVES
   ========================================================================== */

.cq-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.cq-row--between { justify-content: space-between; }
.cq-row--center { justify-content: center; }
.cq-row--end { justify-content: flex-end; }
.cq-row--wrap { flex-wrap: wrap; }
.cq-row--top { align-items: flex-start; }

.cq-col {
  display: flex;
  flex-direction: column;
  gap: var(--gap-panel);
}

.cq-grid {
  display: grid;
  gap: var(--gap-panel);
}

.cq-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cq-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cq-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.cq-grid--auto {
  grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
}

.cq-grid--auto-sm {
  grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr));
}

.cq-split {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: var(--gap-section);
  align-items: start;
}

.cq-split--even {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cq-stack > * + * { margin-top: var(--gap-panel); }
.cq-stack-sm > * + * { margin-top: var(--sp-2); }
.cq-stack-lg > * + * { margin-top: var(--gap-section); }

/* ============================================================================
   6. FOOTER
   ========================================================================== */

.cq-footer {
  padding: var(--sp-5) var(--gutter) var(--sp-6);
  text-align: center;
  font-size: var(--fs-2xs);
  color: var(--text-muted);
  border-top: var(--border-hair) solid rgba(122, 221, 255, 0.08);
  background: linear-gradient(180deg, transparent, rgba(3, 6, 15, 0.42));
}

.cq-footer p {
  margin: 0;
  line-height: var(--lh-relaxed);
}
