/* ==========================================================================
   EduPlayZone — game page shell
   Shares the token set with src/css/home.css so a game page and the home page
   feel like one product. Applied to Games/guess-word/ first; the older
   src/css/gamepage.css still serves the other game pages untouched.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
  --brand: #7c4dff;
  --brand-600: #6a35ff;
  --brand-700: #5a22e8;
  --brand-soft: #f0eaff;
  --brand-ring: rgba(124, 77, 255, 0.35);

  --bg: #f7f5ff;
  --bg-alt: #efeaff;
  --surface: #ffffff;
  --surface-2: #faf8ff;
  --border: rgba(26, 16, 51, 0.09);
  --border-strong: rgba(26, 16, 51, 0.16);

  --ink: #1a1033;
  --ink-2: #514873;
  --ink-3: #7d76a0;

  --shadow-sm: 0 1px 2px rgba(26, 16, 51, 0.06), 0 2px 8px rgba(26, 16, 51, 0.05);
  --shadow-md: 0 4px 12px rgba(26, 16, 51, 0.07), 0 12px 28px rgba(26, 16, 51, 0.07);
  --shadow-lg: 0 12px 24px rgba(26, 16, 51, 0.1), 0 28px 60px rgba(26, 16, 51, 0.12);
  --shadow-brand: 0 10px 24px rgba(124, 77, 255, 0.28);

  --r-xs: 10px;
  --r-sm: 14px;
  --r-md: 18px;
  --r-lg: 24px;
  --r-xl: 32px;
  --r-pill: 999px;

  --container: 1200px;
  --pad-x: clamp(1rem, 4vw, 2rem);
  --header-h: 64px;

  --font: "Lexend Deca", ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  --fs-h1: clamp(1.5rem, 3.2vw, 2.125rem);
  --fs-h2: clamp(1.15rem, 2.2vw, 1.4rem);
  --fs-body: clamp(0.9375rem, 1.4vw, 1rem);
  --fs-sm: 0.875rem;
  --fs-xs: 0.75rem;

  --ease: cubic-bezier(0.22, 0.9, 0.28, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #9270ff;
    --brand-600: #8259ff;
    --brand-700: #6f43ff;
    --brand-soft: rgba(146, 112, 255, 0.16);
    --brand-ring: rgba(146, 112, 255, 0.5);

    --bg: #0f0b1d;
    --bg-alt: #15102a;
    --surface: #191330;
    --surface-2: #1f183a;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.18);

    --ink: #f4f1ff;
    --ink-2: #c2bade;
    --ink-3: #948cb6;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
  }
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1.5rem);
}

body {
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

img, svg, iframe { display: block; max-width: 100%; }
img { height: auto; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
ul, ol { list-style: none; padding: 0; }
h1, h2, h3 { line-height: 1.2; font-weight: 800; letter-spacing: -0.02em; }

:where(a, button, [tabindex]):focus-visible {
  outline: 3px solid var(--brand-ring);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

.wrap {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--pad-x);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

.skip-link {
  position: fixed; top: 0.75rem; left: 0.75rem; z-index: 200;
  padding: 0.7rem 1.1rem; border-radius: var(--r-pill);
  background: var(--brand); color: #fff; font-weight: 700;
  box-shadow: var(--shadow-md);
  transform: translateY(-160%); transition: transform 0.2s var(--ease);
}
.skip-link:focus-visible { transform: translateY(0); }

.icon-sprite { position: absolute; width: 0; height: 0; }
.icon { width: 1.15em; height: 1.15em; flex: none; }
.icon--lg { width: 1.6em; height: 1.6em; }

/* --------------------------------------------------------------------------
   3. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.7rem 1.25rem;
  border-radius: var(--r-pill);
  font-weight: 700; font-size: var(--fs-sm); white-space: nowrap;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease),
              background-color 0.18s var(--ease), color 0.18s var(--ease),
              border-color 0.18s var(--ease);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn--lg { padding: 0.95rem 1.9rem; font-size: 1.0625rem; }
.btn--sm { padding: 0.5rem 0.95rem; font-size: var(--fs-xs); }

.btn--primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-700));
  color: #fff; box-shadow: var(--shadow-brand);
}
.btn--primary:hover { box-shadow: 0 14px 30px rgba(124, 77, 255, 0.38); }

.btn--ghost {
  background: var(--surface); color: var(--brand);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-sm);
}
.btn--ghost:hover { border-color: var(--brand); background: var(--brand-soft); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 2.5rem; height: 2.5rem;
  border-radius: var(--r-sm);
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--border);
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease),
              border-color 0.18s var(--ease);
}
.icon-btn:hover { background: var(--brand); border-color: var(--brand); color: #fff; }

/* --------------------------------------------------------------------------
   4. Header
   -------------------------------------------------------------------------- */
.gp-header {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.gp-header.is-stuck { border-bottom-color: var(--border); box-shadow: var(--shadow-sm); }

.gp-header__inner {
  display: flex; align-items: center; gap: 0.75rem;
  height: var(--header-h);
}
.gp-brand img { height: 1.75rem; width: auto; }
.gp-header__actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

.back-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 0.9rem; border-radius: var(--r-pill);
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2);
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease);
}
.back-link:hover { background: var(--brand-soft); color: var(--brand-700); }

@media (min-width: 768px) { :root { --header-h: 72px; } .gp-brand img { height: 2rem; } }

/* --------------------------------------------------------------------------
   5. Page layout
   -------------------------------------------------------------------------- */
.gp-main { padding-block: clamp(1rem, 2.5vw, 1.75rem) clamp(2rem, 5vw, 3.5rem); }

.gp-grid { display: grid; gap: clamp(1.25rem, 3vw, 2rem); align-items: start; }
/* Grid children default to min-width:auto, which stops the horizontally
   scrolling related-games rail from shrinking and blows the page out. */
.gp-grid > * { min-width: 0; }
@media (min-width: 1024px) {
  .gp-grid { grid-template-columns: minmax(0, 1fr) 19rem; }
  .gp-aside { position: sticky; top: calc(var(--header-h) + 1.25rem); }
}

/* Title row above the stage ---------------------------------------------- */
.gp-title-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem;
  margin-bottom: 0.9rem;
}
.gp-title { font-size: var(--fs-h1); }
.gp-title-row .tag {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.7rem; border-radius: var(--r-pill);
  background: var(--brand-soft); color: var(--brand-700);
  font-size: var(--fs-xs); font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.gp-title-row__end { display: flex; gap: 0.5rem; margin-left: auto; }

/* --------------------------------------------------------------------------
   6. Game stage
   -------------------------------------------------------------------------- */
.stage {
  position: relative;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: linear-gradient(150deg, #2b1c63, #150e33);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  /* Sized to the gameplay's own proportions so the frame is never letterboxed
     with big empty bands. Games whose layout needs a fixed amount of room
     (a fixed-size canvas, say) override these per page:
       style="--stage-ratio: 20/19; --stage-min: 46rem; --stage-max: none" */
  aspect-ratio: var(--stage-ratio, 4 / 3);
  min-height: var(--stage-min, 0px);
  max-height: var(--stage-max, min(78vh, 720px));
  margin-inline: auto;
  width: 100%;
}
@media (max-width: 767px) {
  .stage {
    aspect-ratio: var(--stage-ratio-sm, 3 / 4);
    min-height: var(--stage-min-sm, var(--stage-min, 0px));
    max-height: var(--stage-max-sm, none);
    /* Full-bleed on phones — the game gets every pixel it can. */
    margin-inline: calc(var(--pad-x) * -1);
    width: calc(100% + var(--pad-x) * 2);
    border-radius: var(--r-md);
    border-inline: 0;
  }
}

.stage__frame {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0;
  background: transparent;
}

/* Cover / play overlay ---------------------------------------------------- */
/* Content sits toward the top rather than dead centre, so the gameplay GIF
   behind it stays visible instead of being hidden by the artwork and button. */
.stage__cover {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  gap: 0.7rem;
  padding: clamp(1.25rem, 6%, 2.5rem) 1.25rem 1.25rem;
  text-align: center;
  color: #fff;
}
/* Unblurred: this is the game actually being played, it should read clearly. */
.stage__bg {
  position: absolute; inset: 0; z-index: -2;
  background-size: cover; background-position: center;
}
/* Just enough darkening at the top for the title and button to stay legible,
   fading out over the middle where the GIF does the talking. */
.stage__scrim {
  position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(
    180deg,
    rgba(21, 14, 51, 0.82) 0%,
    rgba(21, 14, 51, 0.62) 38%,
    rgba(21, 14, 51, 0.28) 62%,
    rgba(21, 14, 51, 0.55) 100%
  );
}

.stage__art {
  width: clamp(5rem, 22vw, 8rem); aspect-ratio: 1;
  border-radius: var(--r-lg); object-fit: cover;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-lg);
}
/* Shadows rather than a heavier scrim — keeps the GIF behind them readable. */
.stage__name {
  font-size: clamp(1.25rem, 3.5vw, 1.75rem); color: #fff;
  text-shadow: 0 2px 12px rgba(11, 8, 24, 0.85), 0 1px 3px rgba(11, 8, 24, 0.9);
}
.stage__hint {
  font-size: var(--fs-sm); color: rgba(255, 255, 255, 0.88); max-width: 24rem;
  text-shadow: 0 1px 8px rgba(11, 8, 24, 0.9);
}
.stage__meta li { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

.stage__meta {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem;
  margin-top: 0.15rem;
}
.stage__meta li {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.7rem; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: var(--fs-xs); font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
}

/* Loading ---------------------------------------------------------------- */
.stage__loading {
  position: absolute; inset: auto 0 0; z-index: 3;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.85rem 1.15rem;
  background: rgba(21, 14, 51, 0.9);
  color: #fff; font-size: var(--fs-xs); font-weight: 600;
}
.stage__bar {
  flex: 1; height: 0.4rem; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.16); overflow: hidden;
}
.stage__bar span {
  display: block; height: 100%; width: 0%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--brand), #ff5c93);
  transition: width 0.25s var(--ease);
}

/* Control bar ------------------------------------------------------------- */
.stage-bar {
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.stage-bar__name {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: var(--fs-sm); font-weight: 700; padding-inline: 0.35rem;
}
.stage-bar__name img { width: 1.6rem; height: 1.6rem; border-radius: 0.5rem; }
.stage-bar__end { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; }

.stage-bar .icon-btn { width: 2.25rem; height: 2.25rem; border-radius: var(--r-pill); }

.controls-hint {
  display: none; align-items: center; gap: 0.5rem;
  font-size: var(--fs-xs); color: var(--ink-3);
  padding-inline: 0.5rem;
}
@media (min-width: 600px) { .controls-hint { display: flex; } }
.controls-hint b { color: var(--ink-2); font-weight: 600; }

/* Fullscreen: let the stage fill the screen instead of staying 4:3. */
.stage:fullscreen,
.stage:-webkit-full-screen {
  aspect-ratio: auto;
  max-height: none;
  width: 100%; height: 100%;
  border-radius: 0; border: 0;
}

/* --------------------------------------------------------------------------
   7. Content panels
   -------------------------------------------------------------------------- */
.panel {
  margin-top: clamp(1.25rem, 3vw, 2rem);
  padding: clamp(1.25rem, 3vw, 1.9rem);
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.panel > * + * { margin-top: 0.9rem; }
.panel h2 { font-size: var(--fs-h2); }
.panel h3 { font-size: 1rem; margin-top: 1.35rem; }
.panel p { color: var(--ink-2); }
.panel a { color: var(--brand-700); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

.steps { counter-reset: step; display: grid; gap: 0.75rem; }
.steps li {
  position: relative;
  display: flex; gap: 0.85rem; align-items: start;
  padding: 0.85rem 1rem;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-2); font-size: var(--fs-sm);
}
.steps li::before {
  counter-increment: step; content: counter(step);
  display: grid; place-items: center; flex: none;
  width: 1.75rem; height: 1.75rem; border-radius: var(--r-pill);
  background: var(--brand); color: #fff;
  font-size: var(--fs-xs); font-weight: 800;
}
.steps b { color: var(--ink); }

.facts {
  display: grid; gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
}
.facts div {
  padding: 0.85rem 1rem;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.facts dt { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.facts dd { font-size: var(--fs-sm); font-weight: 600; margin-top: 0.15rem; }

.skills { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.skills li {
  padding: 0.35rem 0.8rem; border-radius: var(--r-pill);
  background: var(--brand-soft); color: var(--brand-700);
  font-size: var(--fs-xs); font-weight: 700;
}

/* --------------------------------------------------------------------------
   8. Related games
   -------------------------------------------------------------------------- */
.aside-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.85rem;
}
.aside-head h2 { font-size: 1.0625rem; }
.aside-head a { font-size: var(--fs-xs); font-weight: 700; color: var(--brand-700); }

.related { display: grid; gap: 0.75rem; }
@media (max-width: 1023px) {
  /* Becomes a swipeable rail once the sidebar collapses. */
  .related {
    grid-auto-flow: column;
    grid-auto-columns: clamp(9rem, 34vw, 11rem);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    margin-inline: calc(var(--pad-x) * -1);
    padding: 0.25rem var(--pad-x) 1rem;
    scrollbar-width: thin;
  }
  .related > * { scroll-snap-align: start; }
}

.rgame {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease),
              box-shadow 0.2s var(--ease);
}
.rgame:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: var(--shadow-md); }
.rgame img {
  width: 3.25rem; height: 3.25rem; flex: none;
  border-radius: var(--r-sm); object-fit: cover;
  background: var(--bg-alt);
}
/* These are spans inside a span, so they need to be told to stack. */
.rgame__body { min-width: 0; display: block; }
.rgame__name {
  display: block;
  font-size: var(--fs-sm); font-weight: 700; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rgame__cat {
  display: block;
  font-size: var(--fs-xs); color: var(--brand); font-weight: 600; line-height: 1.3;
}

@media (max-width: 1023px) {
  /* Card form reads better than a row when it is a rail. */
  .rgame { flex-direction: column; align-items: stretch; gap: 0.5rem; text-align: left; }
  .rgame img { width: 100%; height: auto; aspect-ratio: 1; }
  .rgame__name { white-space: normal; }
}

/* --------------------------------------------------------------------------
   9. Ads

   Slots are transparent and disappear when no ad renders — but they are never
   `display:none` up front. AdSense measures the slot's available *width* when
   it initialises; hiding the container reports 0 and the unit errors out and
   never fills, which would quietly kill the placement.

   So: keep the slot in the layout and measurable, strip all of its own chrome,
   and collapse it once we know nothing is coming — either because AdSense said
   "unfilled", or because game.js waited and nothing ever rendered (script
   blocked, consent refused, offline).
   -------------------------------------------------------------------------- */
.ad-slot {
  margin-top: clamp(1.25rem, 3vw, 2rem);
  background: transparent;
  border: 0;
  text-align: center;
}

/* Nothing injected at all. */
.ad-slot:empty { display: none; margin: 0; }

/* AdSense reported back that it had no ad to serve. */
.ad-slot:has(ins.adsbygoogle[data-ad-status="unfilled"]) { display: none; margin: 0; }
.ad-slot ins.adsbygoogle[data-ad-status="unfilled"] { display: none !important; }

/* game.js sets this when the grace period passed with nothing rendered. */
.ad-slot.is-blank { display: none; margin: 0; }

/* Never paint anything behind the unit itself. */
.ad-slot ins.adsbygoogle { background: transparent !important; }

/* --------------------------------------------------------------------------
   10. Footer
   -------------------------------------------------------------------------- */
.gp-footer {
  margin-top: clamp(2rem, 5vw, 3.5rem);
  padding-block: clamp(2rem, 4vw, 2.75rem) 1.25rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--ink-2); font-size: var(--fs-sm);
}
.gp-footer__inner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 1.25rem; padding-bottom: 1.25rem;
}
.gp-footer__links { display: flex; flex-wrap: wrap; gap: 0.35rem 1.25rem; }
.gp-footer__links a { transition: color 0.18s var(--ease); }
.gp-footer__links a:hover { color: var(--brand); }
.gp-social { display: flex; gap: 0.5rem; }
.gp-social a {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem;
  border-radius: var(--r-pill); background: var(--brand-soft); color: var(--brand);
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease), transform 0.18s var(--ease);
}
.gp-social a:hover { background: var(--brand); color: #fff; transform: translateY(-2px); }
.gp-footer__legal {
  padding-top: 1.15rem; border-top: 1px solid var(--border);
  font-size: var(--fs-xs); color: var(--ink-3); text-align: center;
}

/* --------------------------------------------------------------------------
   11. Motion preferences
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
