/* ==========================================================================
   The Activity world: the game room and the "All games" sheet (Builder R).
   Two things live here:
     .wroom  the game room. A full-stage panel that hosts the real games. It wears the live
             Activity page's own style sheets (previews/story-world/activity.css and
             activity-<id>.css, loaded from the live folder by js/world/room.js), so it carries
             the class "activity-page" and defines the World tokens those sheets expect.
     .wlist  the "All games" sheet and the calm-mode page, in the storybook site's own style:
             thick navy outlines, hard offset shadows, big rounded paper cards.
   Layering: the site's bar (z 60) and menu stay on top; the room (50) and the sheet (55) cover
   the whole stage below the bar, above the land, its HUD and its touch buttons.
   ========================================================================== */

/* The top of the stage: the bar's bottom edge. The land's page may define --bar-space; otherwise it
   is measured from the site's own bar tokens (top + height + the bar's shadow and a little air). */
.wroom, .wlist {
  --wr-top: var(--bar-space, calc(var(--nav-top, 24px) + var(--nav-h, 68px) + 10px));
}

/* ------------------------------------------------------------------------ */
/* 1. The game room                                                          */
/* ------------------------------------------------------------------------ */

/* The World tokens the live styles read (world-shell.css :root and world-universe.css). They are set
   here, on the room itself, because this page's own --ink and friends have other values. */
.wroom {
  --body-max: 13px;
  --ink: #1a2f5e; --ink-deep: #10244a; --deep: #10244a;
  --blue: #0f7daf; --pink: #ff4f8b; --gold: #ffc75f; --saffron: #f6a313; --cream: #fff7e8;
  --radius: 16px;
  --sans: 'Nunito', sans-serif; --display: 'Baloo 2', sans-serif; --label: 'Big Shoulders Display', sans-serif;
  --focus: #ffda87;           /* the site's focus ring is navy; on this navy panel it must be gold */
  --room-bg: #10244a;

  position: fixed; inset: 0; z-index: 50;
  overflow: hidden;
  background: var(--room-bg);
  color: var(--cream);
  font-size: 16px; font-weight: 400; line-height: 1.5;
  text-align: start;
  animation: wroom-in .42s cubic-bezier(.34, 1.3, .64, 1) both;
}
@media (max-width: 760px) { .wroom { --body-max: 11px; } }
.wroom[hidden] { display: none; }
.wroom.wroom--wait .wroom__scroll { visibility: hidden; }   /* until the live style sheet has arrived */
@keyframes wroom-in { from { opacity: 0; transform: translateY(18px) scale(.985); } to { opacity: 1; transform: none; } }

/* A thin gold rule where the room meets the site's bar, so the room reads as a page of the book. */
.wroom::before {
  content: ""; position: absolute; left: 0; right: 0; top: var(--wr-top);
  height: 4px; margin-top: -4px; background: #f6a313; pointer-events: none; z-index: 2;
}

/* The room scrolls inside itself when a game is taller than the screen. The site's bar is above it. */
.wroom__scroll {
  position: absolute; inset: var(--wr-top) 0 0 0;
  overflow-x: hidden; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 0 5vw calc(40px + env(safe-area-inset-bottom));
  scrollbar-width: thin; scrollbar-color: #fff7e866 transparent;
}
.wroom .play-view { --play-header: 0px; padding: 0; }

/* Desktop and tablet: the bar with "Back to the world" and the stars stays at the top while the game
   scrolls beneath it. The solid fill reaches the room's edges so nothing shows past the 880px column. */
@media (min-width: 761px) {
  .wroom .play-bar {
    position: sticky; top: 0; z-index: 30;
    padding: 14px 0 10px; background: var(--room-bg);
    box-shadow: 0 0 0 100vmax var(--room-bg); clip-path: inset(0 -100vmax);
  }
  /* The friend's strip stays in view too, directly under the bar, so a reaction is seen wherever the game is scrolled to. */
  .wroom .play-friend { position: sticky; top: var(--wr-bar-h, 72px); z-index: 25; min-height: 112px; }
  .wroom .friend-sticker { width: 100px; height: 100px; }
  .wroom .play-friend { background: #1d3763; backdrop-filter: none; }
}
/* A short, wide screen (a phone on its side): only the bar stays; the friend's strip scrolls with the game. */
@media (min-width: 761px) and (max-height: 640px) {
  .wroom .play-friend { position: static; min-height: 84px; }
  .wroom .friend-sticker { width: 76px; height: 76px; }
  .wroom .play-bar { padding: 8px 0 6px; }
}
/* Phones: the live styles make bar and friend one sticky panel; it now sticks to the top of the room. */
@media (max-width: 760px) {
  .wroom__scroll { padding: 0 20px calc(4px + env(safe-area-inset-bottom)); scroll-padding-top: 170px; scroll-padding-bottom: 24px; }
  .wroom .play-top { top: 0; margin-top: 8px; }
  /* One row for the bar: the room's back button is longer than the live "All games". */
  .wroom .play-top .play-bar { flex-wrap: nowrap; }
  .wroom .play-top .wroom__back { min-height: 44px; padding: 0 10px; font-size: 14px; flex: 0 1 auto; white-space: nowrap; }
  .wroom .play-top .g-pill { padding: 0 9px; font-size: 12px; }
  .wroom .play-top .play-meter { gap: 5px; flex: none; }
}
.wroom .play-stage { margin-bottom: calc(24px + env(safe-area-inset-bottom)); scroll-margin-bottom: 24px; }
.wroom .play-heading h2 { color: var(--cream); }
/* The game's line under its heading is body text: the live sheet sets 13px at 760px and narrower; here it follows
   the site's limit (11px on phones). One more class than the live rule, which loads later. */
.wroom.activity-page .play-heading p { font-size: var(--body-max); }
/* The failure panel's two buttons ("Try again", "Back to the world") have air between them. */
.wroom .play-message-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
/* The back button is the main way out: easy to see and easy to hit. */
.wroom .wroom__back { min-height: 48px; font-size: 15px; background: #fff7e824; border-color: #fff7e86b; }

/* Games reflow cleanly inside the room: nothing may be wider than the column. */
.wroom .play-stage { max-width: 100%; }

@media (prefers-reduced-motion: reduce) { .wroom { animation: none; } }
html.calm .wroom { animation: none; }


/* ------------------------------------------------------------------------ */
/* 2. The "All games" sheet and the calm-mode page                           */
/* ------------------------------------------------------------------------ */

.wlist {
  --wl-ink: #10244a; --wl-ink-deep: #071631; --wl-paper: #fffdf7; --wl-cream: #fff7e8;
  --wl-gold: #f6a313; --wl-gold-light: #ffcf6b; --wl-pink: #ff4f8b; --wl-blue: #0f7daf; --wl-muted: #3b4d75;
  --wl-display: 'Baloo 2', sans-serif; --wl-label: 'Big Shoulders Display', sans-serif; --wl-body: 'Nunito', sans-serif;
  --wl-pop: cubic-bezier(.34, 1.56, .64, 1);
  position: fixed; inset: 0; z-index: 55;
  pointer-events: none;
  font-family: var(--wl-body); font-size: var(--body-max); font-weight: 700; line-height: 1.6; color: var(--wl-ink);
  text-align: left;
}
.wlist[hidden] { display: none; }
.wlist *, .wlist *::before, .wlist *::after { box-sizing: border-box; }
/* Resets: :where() keeps them at zero specificity so every class below wins over them. */
:where(.wlist) :focus { outline: none; }
:where(.wlist) :focus-visible { outline: 3px solid var(--wl-ink); outline-offset: 3px; }
.wlist [tabindex="-1"]:focus { outline: none; }
:where(.wlist) h1, :where(.wlist) h2, :where(.wlist) p, :where(.wlist) ul { margin: 0; padding: 0; }
:where(.wlist) ul { list-style: none; }
:where(.wlist) img { display: block; max-width: 100%; height: auto; }
:where(.wlist) button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
:where(.wlist) a { color: inherit; -webkit-tap-highlight-color: transparent; }

/* The dim behind the sheet, and the sheet itself (a gold page that slides up). */
.wlist__scrim { position: absolute; inset: 0; background: #071631; opacity: 0; transition: opacity .3s ease; pointer-events: none; }
.wlist.is-open .wlist__scrim { opacity: .5; pointer-events: auto; }
.wlist__panel {
  position: absolute; inset: var(--wr-top) 0 0 0;
  display: flex; flex-direction: column;
  background: var(--wl-gold);
  border: 3px solid var(--wl-ink); border-bottom: 0;
  border-radius: 40px 40px 0 0;
  box-shadow: 0 -8px 0 var(--wl-ink);
  transform: translateY(105%); pointer-events: auto;
  transition: transform .45s cubic-bezier(.3, 1.15, .45, 1);
  overflow: hidden;
}
.wlist.is-open .wlist__panel { transform: none; }
.wlist__scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 0 0 calc(56px + env(safe-area-inset-bottom));
  scrollbar-width: thin; scrollbar-color: #10244a66 transparent;
}
.wlist__wrap { width: min(100% - 2 * var(--wl-gutter, 80px), 1180px); margin-inline: auto; }
.wlist { --wl-gutter: 80px; }
@media (max-width: 1099px) { .wlist { --wl-gutter: 40px; } }
@media (max-width: 760px) { .wlist { --wl-gutter: 16px; } }

/* The close button sits at the top of the scrolling sheet and stays there. */
.wlist__top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: flex-start;
  padding: 16px var(--wl-gutter) 10px;
  background: linear-gradient(var(--wl-gold) 86%, #f6a31300);
}
.wlist__top:empty { display: none; }
.wlist__close {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 0 24px;
  border-radius: 999px; border: 2.5px solid var(--wl-ink);
  background: var(--wl-paper); color: var(--wl-ink);
  box-shadow: 0 4px 0 var(--wl-ink);
  font: 700 18px/1 var(--wl-display);
  transition: translate .15s ease, box-shadow .15s ease;
}
.wlist__close:hover { translate: 0 -2px; }
.wlist__close:active { translate: 0 3px; box-shadow: 0 1px 0 var(--wl-ink); }

.wlist__head { position: relative; padding: 14px 0 30px; }
.wlist__h1 { font: 800 clamp(44px, 6vw, 84px)/.98 var(--wl-display); letter-spacing: -.02em; color: var(--wl-ink); max-width: 11ch; }
.wlist__h2 { font: 800 clamp(40px, 5vw, 64px)/1 var(--wl-display); letter-spacing: -.02em; color: var(--wl-ink); }
.wlist__head .wlist__h1 + .wlist__friends + .wlist__h2 { margin-top: 28px; }

/* The five friends say hello (the calm page only). They are still pictures when motion is off. */
.wlist__friends { position: absolute; right: 0; top: 0; display: flex; align-items: flex-end; }
.wlist__friends li { width: clamp(70px, 9vw, 150px); margin-left: -14px; }
.wlist__friends img { width: 100%; filter: drop-shadow(0 6px 0 #10244a33); }
@media (max-width: 760px) { .wlist__friends { position: static; margin-top: 12px; } .wlist__friends li { width: 64px; margin-left: -10px; } .wlist__friends li:first-child { margin-left: 0; } }

/* The seven game cards: big rounded paper, thick navy outline, a hard shadow. */
.wlist__games { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 26px 22px; padding: 14px 0 6px; }
.wlist__card {
  position: relative;
  display: flex; flex-direction: column; width: 100%; height: 100%;
  padding: 18px;
  border-radius: 30px; border: 3px solid var(--wl-ink);
  background: var(--wl-paper); color: var(--wl-ink);
  box-shadow: 0 8px 0 var(--wl-ink);
  text-align: left; text-decoration: none; touch-action: manipulation;
  transition: transform .2s var(--wl-pop);
}
@media (hover: hover) { .wlist__card:hover { transform: translateY(-8px); } }
.wlist__card:active { transform: translateY(3px); }
.wlist__tile { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: 22px; overflow: hidden; background: var(--tile, var(--wl-gold-light)); }
.wlist__tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.wlist__meta { display: flex; flex-direction: column; flex: 1 1 auto; gap: 6px; margin-top: 14px; min-width: 0; }
.wlist__name { font: 800 30px/1 var(--wl-display); letter-spacing: -.02em; }
.wlist__blurb { font: 700 var(--body-max)/1.5 var(--wl-body); color: var(--wl-muted); max-width: 32ch; }
.wlist__ages { margin-top: auto; padding-top: 8px; font: 800 14px/1.2 var(--wl-label); letter-spacing: .1em; text-transform: uppercase; color: var(--wl-ink); }
.wlist__go { position: absolute; right: 18px; bottom: 18px; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--wl-ink); color: var(--wl-cream); }
.wlist__item { position: relative; }
.wlist__arrow { flex: none; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

/* Make something */
.wlist__make { margin-top: 64px; }
.wlist__row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-top: 22px; }
.wlist__link {
  display: flex; align-items: center; gap: 16px; min-height: 96px; padding: 14px 20px 14px 14px;
  border-radius: 28px; border: 3px solid var(--wl-ink); background: var(--wl-paper); color: var(--wl-ink);
  box-shadow: 0 6px 0 var(--wl-ink); text-decoration: none;
  transition: transform .2s var(--wl-pop);
}
@media (hover: hover) { .wlist__link:hover { transform: translateY(-6px); } }
.wlist__link:active { transform: translateY(2px); }
.wlist__link img { flex: none; width: 68px; height: 68px; object-fit: contain; }
.wlist__link strong { display: block; font: 800 23px/1.1 var(--wl-display); }
.wlist__link small { display: block; margin-top: 4px; font: 700 var(--body-max)/1.4 var(--wl-body); color: var(--wl-muted); }

.wlist__compete {
  position: relative; display: flex; align-items: center; gap: 22px; margin-top: 26px; padding: 20px 24px 20px 20px;
  border-radius: 30px; border: 3px solid var(--wl-ink); background: var(--wl-ink); color: var(--wl-cream);
  box-shadow: 0 8px 0 var(--wl-ink-deep);
}
.wlist__pinki { flex: none; width: 110px; height: 110px; margin: -34px 0 -6px; object-fit: contain; }
.wlist__compete-copy { flex: 1 1 auto; min-width: 0; }
.wlist__compete-copy strong { display: block; font: 800 26px/1.1 var(--wl-display); color: var(--wl-gold-light); }
.wlist__compete-copy p { margin-top: 6px; max-width: 46em; font: 700 var(--body-max)/1.6 var(--wl-body); color: #fff7e8e6; }
.wlist__cta {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; flex: none;
  min-height: 52px; padding: 0 24px; border-radius: 999px; border: 2.5px solid var(--wl-cream);
  background: var(--wl-gold); color: var(--wl-ink); text-decoration: none;
  box-shadow: 0 4px 0 var(--wl-gold-deep, #a86a00);
  font: 700 18px/1 var(--wl-display); white-space: nowrap;
  transition: translate .15s ease, box-shadow .15s ease;
}
.wlist__cta:hover { translate: 0 -2px; }
.wlist__cta:active { translate: 0 3px; box-shadow: 0 1px 0 #a86a00; }
.wlist .wlist__compete :focus-visible { outline-color: var(--wl-gold-light); }
.wlist__note { margin-top: 20px; font: 700 var(--body-max)/1.6 var(--wl-body); color: var(--wl-ink); }
.wlist__note a { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }

.wlist__lines { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 34px; margin-top: 36px; padding: 18px 22px; border-radius: 24px; border: 3px solid var(--wl-ink); background: var(--wl-paper); box-shadow: 0 6px 0 var(--wl-ink); }
.wlist__lines p { font: 700 var(--body-max)/1.6 var(--wl-body); color: var(--wl-ink); max-width: 70ch; }
.wlist__lines strong { font-weight: 800; }

@media (max-width: 1099px) {
  .wlist__panel { border-radius: 32px 32px 0 0; }
  .wlist__row { grid-template-columns: 1fr; gap: 16px; }
  .wlist__lines { grid-template-columns: 1fr; }
  .wlist__compete { flex-wrap: wrap; }
  .wlist__compete-copy { flex-basis: calc(100% - 140px); }
}
@media (max-width: 760px) {
  .wlist__panel { border-radius: 28px 28px 0 0; box-shadow: 0 -6px 0 var(--wl-ink); }
  .wlist__h1 { font-size: 46px; }
  .wlist__h2 { font-size: 40px; }
  .wlist__games { grid-template-columns: 1fr; gap: 18px; }
  .wlist__card { flex-direction: row; align-items: center; gap: 14px; padding: 12px 70px 12px 12px; border-radius: 26px; box-shadow: 0 6px 0 var(--wl-ink); min-height: 112px; }
  .wlist__tile { flex: none; width: 88px; aspect-ratio: 1; border-radius: 18px; }
  .wlist__meta { margin-top: 0; gap: 4px; }
  .wlist__name { font-size: 26px; }
  .wlist__ages { padding-top: 2px; font-size: 13px; }
  .wlist__go { right: 12px; bottom: auto; top: 50%; margin-top: -22px; }
  .wlist__make { margin-top: 48px; }
  .wlist__link { min-height: 88px; }
  .wlist__compete { padding: 18px 16px 18px 12px; gap: 14px; }
  .wlist__pinki { width: 84px; height: 84px; margin: -28px 0 0; }
  .wlist__compete-copy { flex-basis: calc(100% - 100px); }
  .wlist__compete-copy strong { font-size: 24px; }
  .wlist__cta { width: 100%; }
  .wlist__top { padding-top: 14px; }
}

/* Calm-mode page, and the page shown when the land cannot start: the same content in the normal flow. */
.wlist--page { position: relative; inset: auto; z-index: 1; min-height: 100vh; pointer-events: auto; background: var(--wl-gold); }
.wlist--page .wlist__panel { position: relative; inset: auto; display: block; min-height: 100vh; transform: none; border: 0; border-radius: 0; box-shadow: none; overflow: visible; transition: none; padding-top: var(--wr-top); }
.wlist--page .wlist__scroll { overflow: visible; padding-bottom: 72px; }
.wlist--page .wlist__scrim { display: none; }
.wlist--page .wlist__head { padding-top: 26px; }

@media (prefers-reduced-motion: reduce) {
  .wlist__panel, .wlist__scrim, .wlist__card, .wlist__link, .wlist__close, .wlist__cta { transition: none; }
}
html.calm .wlist__panel, html.calm .wlist__scrim, html.calm .wlist__card, html.calm .wlist__link, html.calm .wlist__close, html.calm .wlist__cta { transition: none; }
@media (forced-colors: active) {
  .wlist__card, .wlist__link, .wlist__compete, .wlist__lines, .wlist__cta, .wlist__close { border: 2px solid CanvasText; }
}
