@font-face {
  font-family: "Wordplay";
  src: url("./assets/fonts/Wordplay2-Regular.otf") format("opentype");
  font-display: swap;
}

:root {
  --sky: #75c7e9;
  --sky-deep: #3ea6d2;
  --ocean: #2c9fd0;
  --ink: #12394f;
  --paper: #fff7da;
  --accent: #f04d92;
  --focus: #fff36b;
  --shadow: rgba(9, 57, 82, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--sky-deep);
}

body,
button {
  font-family: "Wordplay", sans-serif;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.09), transparent 38%),
    linear-gradient(180deg, var(--sky) 0 55%, var(--ocean) 55% 100%);
}

.wide-background {
  position: absolute;
  inset-block: 0;
  width: max(0px, calc((100vw - 225dvh) / 2 + 3px));
  pointer-events: none;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.07) 0 2px,
      transparent 2px 26px
    );
}

.wide-background--left {
  left: 0;
}

.wide-background--right {
  right: 0;
  transform: scaleX(-1);
}

.stage {
  position: relative;
  width: min(100vw, 225dvh);
  /* The calibrated recording is exactly 960×448 (15:7).  Keep that recorded
     game ratio on other devices; the remaining height stays paper-coloured. */
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: #f6e4c8;
  box-shadow: 0 0 44px var(--shadow);
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 15 / 7;
  outline: none;
  touch-action: none;
}

#game-canvas:focus-visible {
  box-shadow: inset 0 0 0 5px var(--focus);
}

.overlay,
.video-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
}

.overlay {
  background: transparent;
}

.overlay[hidden],
.video-overlay[hidden],
[hidden] {
  display: none !important;
}

.eyebrow {
  margin: 0;
  color: #397995;
  font-size: 13px !important;
  letter-spacing: 0.16em;
}

.corner-button {
  border: 0;
  color: white;
  background: var(--accent);
  box-shadow: 0 7px 0 #b52966;
  cursor: pointer;
}

.start-surface {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.start-surface:disabled {
  cursor: wait;
}

.map-load-status {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 8%;
  width: max-content;
  max-width: 85%;
  margin: 0;
  padding: 16px 24px;
  transform: translateX(-50%);
  border: 2px solid rgba(18, 57, 79, 0.24);
  border-radius: 18px;
  background: rgba(255, 249, 233, 0.96);
  color: #12394f;
  font-size: clamp(14px, 2vw, 22px);
  text-align: center;
  pointer-events: none;
}

.resource-notice {
  z-index: 35;
}

.corner-button:active,
.story-icon:active,
.story-next:active {
  transform: translateY(4px);
}

.start-surface:focus-visible,
.corner-button:focus-visible,
.story-icon:focus-visible,
.story-next:focus-visible {
  outline: 5px solid var(--focus);
  outline-offset: 5px;
}

.video-overlay {
  display: grid;
  /* A video's intrinsic aspect ratio must not grow the single grid track
     beyond the stage. Overflow here can scroll the absolute story controls
     offscreen as well as crop the movie. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  overflow: hidden;
  background: #07151d;
}

.video-overlay canvas {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.story-loading-panel {
  position: absolute;
  z-index: 31;
  width: min(70%, 620px);
  padding: 18px;
  border-radius: 18px;
  background: #fff8df;
  color: #234653;
  text-align: center;
  overflow-wrap: anywhere;
}

.story-loading-panel button {
  padding: 10px 18px;
  border: 2px solid #ffffff;
  border-radius: 12px;
  color: white;
  background: #237c80;
  cursor: pointer;
}

.story-loading-panel button:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.story-sound-recovery {
  position: absolute;
  z-index: 32;
  left: 50%;
  /* Keep the recovery action above the caption panel, not across its text. */
  bottom: max(21%, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 12px 20px;
  border: 3px solid #fff;
  border-radius: 999px;
  color: #fff;
  background: #176c73;
  font: inherit;
  cursor: pointer;
}

.story-sound-recovery:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

.video-overlay.is-story {
  background: #dff5fb;
}

.video-overlay.is-story canvas {
  width: 100%;
  height: 100%;
  object-fit: fill;
}

#story-video {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.corner-button {
  position: absolute;
  z-index: 30;
  top: max(16px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  padding: 11px 20px 9px;
  border: 4px solid white;
  border-radius: 999px;
  font-size: clamp(14px, 1.8vw, 20px);
}

.corner-button--back {
  right: auto;
  left: max(18px, env(safe-area-inset-left));
}

.story-icon,
.story-next {
  position: absolute;
  z-index: 32;
  display: grid;
  place-items: center;
  border: 0;
  cursor: pointer;
}

.story-icon--sound {
  top: 2.2%;
  left: 7.1%;
  width: clamp(48px, 7%, 72px);
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  background: transparent;
}

/* The shared portal button occupies this corner outside the story scene.
   Move it to the free lower-left area so it cannot cover the speaker control. */
.story-active #endless-portal-home {
  top: auto;
  right: auto;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
}

.story-icon--menu {
  top: 0;
  right: 8.3%;
  width: clamp(52px, 6.2%, 72px);
  aspect-ratio: 90 / 81;
  padding: 0;
  overflow: hidden;
  background: transparent;
}

.story-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.story-caption {
  position: absolute;
  z-index: 32;
  right: 20.8%;
  bottom: 1.8%;
  left: 20.8%;
  height: 16.3%;
  min-height: 0;
  margin: 0;
  padding: 6px 4%;
  color: #4f91a8;
  background: #fff8da;
  border: 3px solid rgba(173, 153, 96, 0.24);
  border-radius: 22px;
  font-size: clamp(18px, 2.8vw, 32px);
  line-height: 1;
  text-align: left;
}

.word-map {
  color: #a54ca6;
}

.word-lap {
  color: #e84291;
}

.word-nap {
  color: #e84291;
}

.story-next {
  right: 3.5%;
  bottom: 0.5%;
  width: clamp(54px, 7%, 76px);
  aspect-ratio: 1;
  padding: 0;
  color: white;
  background-color: transparent;
  background-image: url("./assets/monster_bundles/global_bundle/monster_bundles/Accessories/forward.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  border: 0;
  box-shadow: none;
  font-family: sans-serif;
  font-size: 0;
  line-height: 1;
}

.intro-skip {
  position: absolute;
  z-index: 33;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  min-height: 48px;
  padding: 10px 18px 9px;
  color: #12394f;
  background: rgba(255, 249, 233, 0.94);
  border: 3px solid rgba(255, 255, 255, 0.96);
  border-radius: 999px;
  box-shadow: 0 5px 0 rgba(18, 57, 79, 0.3), 0 8px 24px rgba(18, 57, 79, 0.2);
  font: 700 clamp(14px, 2vw, 22px) / 1 "Wordplay", sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

.intro-skip:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(18, 57, 79, 0.3), 0 5px 14px rgba(18, 57, 79, 0.18);
}

.intro-skip:focus-visible {
  outline: 5px solid var(--focus);
  outline-offset: 4px;
}

.level-picker {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 4%;
  background: rgba(8, 49, 70, 0.72);
}

.level-picker-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(94%, 1040px);
  height: min(90%, 690px);
  overflow: hidden;
  color: var(--ink);
  background: #fff8df;
  border: 7px solid white;
  border-radius: 28px;
  box-shadow: 0 24px 60px rgba(4, 36, 53, 0.42);
  touch-action: pan-y;
}

.level-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px 14px;
  background: #d9f4fb;
  border-bottom: 3px solid rgba(18, 57, 79, 0.12);
}

.level-picker-header h2 {
  margin: 4px 0 0;
  font-size: clamp(28px, 4vw, 48px);
}

.level-picker-close {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  color: white;
  background: var(--accent);
  border: 4px solid white;
  border-radius: 50%;
  box-shadow: 0 5px 0 #b52966;
  font: 42px/1 sans-serif;
  cursor: pointer;
}

.level-grid {
  overflow: auto;
  padding: 18px 22px 28px;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.world-group + .world-group {
  margin-top: 22px;
}

.world-group h3 {
  position: sticky;
  top: -18px;
  z-index: 1;
  margin: 0 0 10px;
  padding: 10px 6px 8px;
  color: #1b6685;
  background: #fff8df;
  font-size: clamp(20px, 2.5vw, 30px);
}

.world-levels {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.level-button {
  min-height: 72px;
  padding: 9px 6px 7px;
  white-space: pre-line;
  color: #164d68;
  background: white;
  border: 3px solid #8bc8dc;
  border-radius: 15px;
  box-shadow: 0 4px 0 #68a9bf;
  font: inherit;
  font-size: clamp(13px, 1.7vw, 20px);
  line-height: 1.15;
  cursor: pointer;
}

.level-button.is-selected {
  color: white;
  background: #ef5596;
  border-color: #ffb9d8;
  box-shadow: 0 4px 0 #b52966;
}

.level-button.is-full-locked {
  color: #896f5a;
  background: #f3ead5;
  border-color: #d9c5a0;
  box-shadow: 0 4px 0 #bba47d;
}

.level-button.is-full-locked::before {
  content: "★ ";
  color: #df6d2f;
}

.level-button.is-complete::after {
  content: " ✓";
  color: #4b9a3f;
}

.level-button:focus-visible,
.level-picker-close:focus-visible {
  outline: 5px solid var(--focus);
  outline-offset: 3px;
}

.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;
}

@media (max-aspect-ratio: 1 / 1) {
  .story-caption {
    right: 12%;
    left: 12%;
  }

  .world-levels {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
