/* Game screen: header strip, picture stage, caption (upright phones), chunky button tray.
   Everything is scoped under .game so it can't leak into other screens. */
.game {
  --g-paper: #fbf4e2;
  --g-paper-2: #f3e7c8;
  --g-ink: #3b2a1e;
  --g-leaf: #5f9e45;
  --g-sky: #3d7fd6;
  --g-sun: #f0a040;
  --g-berry: #d8453b;
  --g-plum: #8a56b8;
  --g-display: "Chalkboard SE", "Comic Sans MS", "Marker Felt", cursive;
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 10px;
  padding: max(10px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
           max(10px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--g-paper); color: var(--g-ink);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; overscroll-behavior: none;
}
.game *, .game *::before, .game *::after { box-sizing: border-box; }
.game [hidden] { display: none !important; }

/* Top bar */
.g-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.g-title { flex: 1; min-width: 0; margin: 0; line-height: 1.1; }
.g-name { display: block; font-family: var(--g-display); font-size: 1.35rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-step { display: block; font-size: .9rem; font-weight: 700; color: #7a6a5a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-chip {
  font: inherit; font-size: 1.05rem; font-weight: 700; color: var(--g-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; min-width: 56px; padding: 6px 16px; flex: none;
  background: var(--g-paper-2); border: 3px solid var(--g-ink); border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.g-chip[aria-pressed="false"] { opacity: .6; }
.g-chip:focus-visible, .g-act:focus-visible { outline: 4px dashed var(--g-sun); outline-offset: 4px; }

/* Picture stage: 16:9, as big as fits */
.g-stagewrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; container-type: size; }
.g-stage {
  position: relative; aspect-ratio: 16 / 9;
  width: min(100cqw, 100cqh * 16 / 9); max-width: 100%; max-height: 100%;
  border: 4px solid var(--g-ink); border-radius: 18px; overflow: hidden; background: #2c231d;
}
.g-canvas { display: block; width: 100%; height: 100%; object-fit: contain; touch-action: none; }
.g-help {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 24px);
  background: var(--g-paper); border: 3px solid var(--g-ink); border-radius: 999px;
  padding: 6px 18px; font-size: clamp(.9rem, 1.8vw, 1.25rem); font-weight: 700; text-align: center;
  pointer-events: none;
}
.g-overlay {
  position: absolute; inset: 0; background: var(--g-paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; text-align: center; overflow: auto;
}
.g-big {
  font-family: var(--g-display); font-size: clamp(2.2rem, 7vw, 4.4rem); font-weight: 700; line-height: 1.05;
  color: var(--g-sun); -webkit-text-stroke: 2px var(--g-ink); margin: 0; overflow-wrap: anywhere;
}
.g-sub { margin: 0; font-size: clamp(1.05rem, 2.4vw, 1.4rem); font-weight: 700; }
.g-sub strong { color: var(--g-berry); }
.g-muted { color: #7a6a5a; font-size: clamp(.95rem, 2vw, 1.15rem); }
.g-castrow { margin: 0; font-size: clamp(2.2rem, 6vw, 3.6rem); line-height: 1.1; }
.g-stars { margin: 0; font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.1; animation: g-pop .6s ease-out; }
@keyframes g-pop { from { transform: scale(.3); } 70% { transform: scale(1.15); } }
/* Chapter cards: a short pause between parts of the story */
.game.g-chap .g-overlay { background: radial-gradient(circle at 50% 40%, #fffaf0 0%, var(--g-paper) 55%, var(--g-paper-2) 100%); }
.g-chapno {
  margin: 0; font-family: var(--g-display); font-weight: 700; font-size: clamp(1rem, 2.6vw, 1.4rem);
  letter-spacing: .12em; text-transform: uppercase; color: var(--g-berry);
}
.g-chapter { color: var(--g-sky); animation: g-chap-in .5s ease-out; }
@keyframes g-chap-in { from { opacity: 0; transform: translateY(18px); } }
@media (prefers-reduced-motion: reduce) { .g-chapter { animation: none; } }

/* Caption: only shown when a phone is held upright */
.g-caption { display: none; }
.g-who { display: block; font-size: .62em; letter-spacing: .08em; text-transform: uppercase; color: var(--g-sky); }
.g-caption.quiet { text-align: center; }

/* Button tray */
.g-controls { display: flex; justify-content: center; align-items: center; gap: 14px; flex-wrap: wrap; min-height: 96px; }
.g-act {
  font: inherit; font-family: var(--g-display); font-weight: 700; font-size: clamp(1.3rem, 2.8vw, 1.9rem);
  color: #fff; -webkit-text-stroke: .5px var(--g-ink); text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
  min-width: 170px; min-height: 72px; padding: 12px 26px; border-radius: 22px; cursor: pointer;
  border: 4px solid var(--g-ink); background: var(--g-sky);
  box-shadow: 0 7px 0 var(--g-ink); transition: transform .06s, box-shadow .06s;
  touch-action: manipulation; position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
}
.g-icon { font-size: 1.2em; -webkit-text-stroke: 0; text-shadow: none; }
.g-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 11em; }
.g-act kbd { flex-basis: 100%; font-family: system-ui, sans-serif; font-size: .45em; font-weight: 700; opacity: .9; -webkit-text-stroke: 0; margin-top: -4px; }
.g-act:active, .g-act.pressed { transform: translateY(6px); box-shadow: 0 1px 0 var(--g-ink); }
.g-act.green { background: var(--g-leaf); }
.g-act.orange { background: var(--g-sun); }
.g-act.red { background: var(--g-berry); }
.g-act.purple { background: var(--g-plum); }
.g-act.gray { background: #8a7a6a; }
.g-act[disabled] { cursor: default; filter: grayscale(.6); }
.g-fill { position: absolute; left: 0; bottom: 0; height: 8px; width: 0; background: rgba(255, 255, 255, .7); }
.g-pulse { animation: g-pulse 1s ease-in-out infinite; }
/* The pulse is a glowing ring, not a size change, so the button never moves under a finger. */
@keyframes g-pulse { 50% { box-shadow: 0 7px 0 var(--g-ink), 0 0 0 7px rgba(255, 215, 94, .9); filter: brightness(1.12); } }
@media (prefers-reduced-motion: reduce) { .g-pulse, .g-stars { animation: none; } }
@media (hover: none) { .g-act kbd { display: none; } }
@media (max-width: 700px) {
  .g-lbl { display: none; }
  .g-act { min-width: 130px; padding: 10px 18px; }
}

/* Phone held upright: 4:3 picture on top, big caption text, two columns of big buttons */
@media (orientation: portrait) and (max-width: 600px) {
  .game { gap: 8px; }
  .g-chip { min-height: 52px; min-width: 52px; padding: 4px 10px; font-size: 1.15rem; }
  .g-name { font-size: 1.15rem; }
  .g-step { font-size: .8rem; }
  .g-stagewrap { flex: none; display: block; container-type: normal; }
  .g-stage { width: 100%; aspect-ratio: 4 / 3; max-height: 44dvh; border-width: 3px; border-radius: 14px; }
  .g-canvas { object-fit: cover; }
  .game.g-story .g-canvas { object-fit: contain; }
  .game.g-story .g-stage { background: var(--g-paper-2); }
  .g-help { display: none !important; }
  .g-caption {
    display: flex; flex-direction: column; justify-content: center; position: relative;
    flex: 1; min-height: 0; overflow-y: auto;
    background: #fff; border: 3px solid var(--g-ink); border-radius: 20px;
    padding: 10px 16px; font-family: var(--g-display); font-size: clamp(1.25rem, 6vw, 1.75rem); line-height: 1.3; font-weight: 700;
    overflow-wrap: anywhere;
  }
  .game.g-over .g-stagewrap { flex: 1; min-height: 0; }
  .game.g-over .g-stage { height: 100%; max-height: none; aspect-ratio: auto; }
  .game.g-over .g-caption { display: none; }
  .g-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; min-height: 0; padding-bottom: 6px; }
  .g-controls > .g-act:only-child, .g-controls > .g-act:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .g-act { min-width: 0; min-height: 68px; padding: 10px 8px; font-size: clamp(1.25rem, 6vw, 1.75rem); border-radius: 20px; box-shadow: 0 6px 0 var(--g-ink); }
}

/* Phone held sideways: picture on the left, big buttons on the right */
@media (orientation: landscape) and (max-height: 520px) {
  .game {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); gap: 8px;
    padding-block: max(6px, env(safe-area-inset-top, 0px)) max(6px, env(safe-area-inset-bottom, 0px));
  }
  .g-top { grid-column: 1 / -1; gap: 8px; }
  .g-chip { min-height: 44px; min-width: 48px; padding: 2px 12px; font-size: .95rem; border-width: 2.5px; }
  .g-name { font-size: 1.05rem; }
  .g-step { font-size: .78rem; }
  .g-stage { border-width: 3px; border-radius: 12px; }
  .g-controls {
    display: grid; grid-auto-rows: min-content; align-content: center; gap: 12px;
    min-height: 0; overflow-y: auto; padding: 8px 8px 10px;
  }
  .g-controls:has(> :nth-child(3)) { grid-template-columns: 1fr 1fr; gap: 10px; }
  .g-controls:has(> :nth-child(3)) > .g-act:last-child:nth-child(odd) { grid-column: 1 / -1; width: auto; }
  .g-act {
    min-width: 0; min-height: 64px; width: clamp(108px, 18vw, 170px); padding: 8px 6px;
    font-size: clamp(1rem, 2.6vw, 1.3rem); border-width: 3px; border-radius: 16px; box-shadow: 0 5px 0 var(--g-ink);
    flex-direction: column; gap: 0;
  }
  .g-icon { font-size: 1.3em; }
  .g-label { max-width: 100%; }
  .g-act:active, .g-act.pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--g-ink); }
  .g-big { font-size: 2.2rem; }
  .g-castrow { font-size: 2rem; }
  .g-stars { font-size: 1.8rem; }
  .g-overlay { gap: 6px; padding: 8px; }
  .g-help { font-size: .8rem; padding: 3px 12px; bottom: 4px; border-width: 2px; }
}
