/* Picnic quest's styles, on top of the site's style.css. The page never scrolls: the window fills the screen's
   height, spacing and pictures shrink on short screens, and room-canvas.js sizes the room to fit. Each screen's
   small-screen rules sit with it; the layouts that put the game pad beside the window come last. */

/* ---------- page and window ---------- */
/* one spacing scale for every screen; the larger steps shrink on short screens */
.play-page {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: clamp(10px, 2vh, 16px);
  --space-5: clamp(12px, 3vh, 24px);
  --space-6: clamp(16px, 3.5vh, 32px);
  --friend-height: clamp(36px, min(10vh, 12vw), 84px); /* friend pictures on the title and map */
  height: 100dvh;
  overflow: hidden;
}

.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  height: 100dvh;
  padding: max(var(--space-4), env(safe-area-inset-top)) var(--space-4) max(var(--space-4), env(safe-area-inset-bottom));
}
.game-window { display: flex; flex-direction: column; width: min(100%, 680px); flex: 1 1 auto; min-height: 0; }
.game-window .titlebar-close { text-decoration: none; }
.mute-button { background: #fff; }
/* the pad toggle is a word label, so it's easy to find */
.game-window .pad-toggle { width: auto; padding: 0 var(--space-2); font-size: 13px; background: #fff; }

.game-screen { display: flex; flex: 1; min-height: 0; flex-direction: column; padding: var(--space-5); overflow: auto; }
.game-screen > * { margin: auto; text-align: center; }
.game-screen .window-title { font-size: clamp(1.5rem, min(6.5vh, 9vw), 2.6rem); }

/* phones: less padding, so the room can be bigger */
@media (max-width: 480px) {
  .game { padding-inline: var(--space-3); }
  .game-screen { padding: var(--space-4) var(--space-3); }
}

.text-button {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 0;
  font: 700 1.15rem var(--pixel-font);
  color: var(--ink-soft);
  background: none;
  cursor: pointer;
}
.text-button:hover { color: var(--pink-deep); }
a.text-button { display: inline-block; text-decoration: none; }

.title-friends img, .island-friend img { width: auto; height: var(--friend-height); }

/* ---------- title ---------- */
.title-friends { display: flex; justify-content: center; align-items: flex-end; flex-wrap: wrap; gap: var(--space-3); margin: var(--space-5) 0; }
/* how to play folds to a button on screens too short for it (title.js) */
.how-to-play-box { width: min(100%, 34rem); margin: 0 auto var(--space-5); }
.how-to-play-box summary { display: inline-block; list-style: none; }
.how-to-play-box summary::-webkit-details-marker { display: none; }
.how-to-play-box[open] summary { display: none; }
.how-to-play { padding: var(--space-4); background: #fff; box-shadow: var(--pixel-border-2); }
.how-goal { margin: 0 0 var(--space-4); font-size: 1rem; line-height: 1.45; text-wrap: balance; }
.how-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); margin: 0; text-align: left; }
.how-controls div { display: flex; align-items: center; gap: var(--space-2); }
.how-controls dd { margin: 0; font-size: .95rem; line-height: 1.3; }
.key { flex: none; width: 4.6em; padding: 3px 0; font: 700 1rem/1.1 var(--pixel-font); text-align: center; color: var(--ink); background: #fff; box-shadow: var(--pixel-border-2); }
.key-arrows { background: #ffd6e7; }
.key-a { color: #fff; background: var(--pink-deep); }
.key-b { color: #fff; background: var(--blue-deep); }
.key-stuck { background: var(--lavender); }
/* narrow or portrait screens: one column of controls */
@media (max-width: 480px), (orientation: portrait) {
  .how-controls { grid-template-columns: minmax(0, max-content); justify-content: center; gap: var(--space-3); }
  .how-controls div { gap: var(--space-3); }
}
/* keyboard keys, hidden on touch-only devices */
.how-controls .keys { display: block; font-size: .8rem; color: var(--ink-soft); }
@media (hover: none) and (pointer: coarse) { .how-controls .keys { display: none; } }
.title-buttons { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: var(--space-4); }
.start-over { color: var(--ink-soft); }
.title-links { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-1) var(--space-5); margin-top: var(--space-5); }
.title-links .text-button { margin: 0; }
/* the shortest screens (small phones in landscape) */
@media (max-height: 420px) {
  .title-screen .lead { display: none; }
  .title-friends { margin-block: var(--space-4); }
}

/* ---------- world map: world cards two by two ---------- */
.map-screen { display: flex; flex-direction: column; align-items: center; gap: var(--space-6); }
.map-screen .title-links { margin: 0; }
.islands {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: var(--space-4);
  width: min(100%, 460px);
  margin: 0;
  padding: 0;
  list-style: none;
}
.island {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-4) var(--space-3);
  background: var(--island-colour, #fff);
  box-shadow: var(--pixel-border-3);
}
.island.locked { background: #eee8f2; }
.island-garden { --island-colour: #dff4cf; }
.island-snow { --island-colour: #eef4ff; }
.island-night { --island-colour: #dcd6f5; }
.island-bamboo { --island-colour: #e8f5d4; }
.island-friend { margin-bottom: var(--space-2); }
.island-name { margin: 0; font: 700 1.4rem var(--pixel-font); }
.island-who { flex: 1; margin: var(--space-1) 0 var(--space-4); font-size: 1rem; line-height: 1.4; color: var(--ink-soft); text-wrap: balance; }
.room-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); }
.room-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  font: 700 1.2rem var(--pixel-font);
  color: var(--ink);
  background: #fff;
  box-shadow: var(--pixel-border-2), 0 4px 0 0 var(--lavender);
  cursor: pointer;
}
.room-button:hover:not(:disabled) { transform: translateY(-2px); }
.room-button:active:not(:disabled) { transform: translateY(3px); box-shadow: var(--pixel-border-2); }
.room-button:disabled { cursor: default; opacity: .45; box-shadow: var(--pixel-border-2); }
.room-button:focus-visible { outline: 3px dashed var(--blue-deep); outline-offset: 4px; }
.room-button.cleared { color: #fff; background: var(--pink-deep); }
.room-button.skipped { background: var(--lavender); }
.room-button.next { color: #fff; background: var(--blue-deep); animation: nextRoom 1s steps(2) infinite; }
@keyframes nextRoom { 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .room-button.next { animation: none; } }

/* short screens: each card lies on its side, friend on the left */
@media (max-height: 860px) and (min-width: 560px) {
  .islands { width: 100%; }
  .island {
    display: grid;
    /* names and room buttons line up across cards; extra space goes between them */
    grid-template: "friend name" auto "friend who" 1fr "friend rooms" auto / auto minmax(0, 1fr);
    align-content: stretch;
    justify-items: start;
    column-gap: var(--space-4);
    padding: var(--space-4);
    text-align: left;
  }
  .island-friend { grid-area: friend; align-self: center; margin: 0; }
  .island-name { grid-area: name; }
  .island-who { grid-area: who; align-self: start; margin: 0 0 var(--space-3); }
  .room-buttons { grid-area: rooms; justify-content: flex-start; }
}
/* the taller of those screens */
@media (max-height: 860px) and (min-height: 700px) and (min-width: 560px) { .island { padding-block: var(--space-6); } }
/* phones: the friend's name gets its own line */
@media (max-width: 480px) {
  .island { padding-inline: var(--space-1); }
  .island-who-name { display: block; }
  .island-who-dot { display: none; }
}
/* short screens: drop the friend's move to keep the cards small */
@media (max-height: 600px), (max-width: 480px) and (max-height: 760px) {
  .island-who { display: none; }
  .island-name { margin-bottom: var(--space-3); }
}
/* short screens and phones: smaller room buttons, kept on one row */
@media (max-height: 600px), (max-width: 480px) {
  .room-buttons { flex-wrap: nowrap; gap: 7px; } /* clears the borders, which are drawn outside the buttons */
  .room-button { width: 28px; height: 30px; font-size: 1.05rem; }
}

/* the smallest phones */
@media (max-width: 360px) and (max-height: 600px) {
  .map-screen { gap: var(--space-4); }
  .map-heading .lead { display: none; }
  .islands { --friend-height: 30px; gap: var(--space-3); }
  .island { padding-block: var(--space-3); }
}

/* ---------- room ---------- */
.room-screen { display: flex; flex-direction: column; width: 100%; height: 100%; margin: 0; }
.room-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.room-name { flex: 1; min-width: 0; margin: 0; font: 700 1.8rem/1.15 var(--pixel-font); color: var(--ink); text-wrap: balance; }
.room-number { display: block; margin-bottom: var(--space-1); font-size: 1.1rem; color: var(--ink-soft); }
.room-counter { flex: none; padding: var(--space-1) var(--space-3); font: 700 1.3rem var(--pixel-font); background: #fff; box-shadow: var(--pixel-border-2); }
.room-tip { max-width: 34rem; margin: var(--space-4) auto 0; font-size: 1.05rem; line-height: 1.5; text-wrap: balance; }
.room-tools { display: flex; justify-content: center; flex-wrap: wrap; gap: var(--space-3); margin: var(--space-4) 0 var(--space-5); }
.tool-button {
  padding: var(--space-2) var(--space-4);
  border: 0;
  font: 700 1.2rem var(--pixel-font);
  color: var(--ink);
  background: #fff;
  box-shadow: var(--pixel-border-2), 0 4px 0 0 var(--lavender);
  cursor: pointer;
}
.tool-button:active { transform: translateY(3px); box-shadow: var(--pixel-border-2); }
.tool-button.skip { background: #ffe0ee; }
.tool-button.nudge { animation: nope .45s steps(2); }
.room-stage { position: relative; display: grid; place-items: center; flex: 1; min-height: 0; }
.room-canvas { display: block; image-rendering: pixelated; box-shadow: var(--pixel-border-3); }
.room-message { min-height: 1.5em; margin: var(--space-3) 0 0; font-size: .95rem; line-height: 1.5; color: var(--ink-soft); }

/* the result card over the room */
.room-card {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-6) var(--space-6) var(--space-5);
  background: #fff;
  box-shadow: var(--pixel-border-4), 8px 10px 0 0 rgba(170, 130, 220, .35);
  animation: cardPop .3s steps(3);
}
.room-card-title { max-width: 16em; margin: 0; font: 700 1.5rem/1.3 var(--pixel-font); color: var(--pink-deep); }
.room-card .pixel-button { font-size: 1.2rem; }
@keyframes cardPop { from { transform: scale(.6); } }

/* short, wide screens: the tools move up between "‹ map" and the counter, leaving the height to the room */
@media (max-height: 700px) and (min-width: 560px) {
  .room-screen {
    display: grid;
    grid-template: "map tools counter" auto "name name name" auto "tip tip tip" auto "stage stage stage" 1fr / auto 1fr auto;
    align-items: center;
  }
  .room-header { display: contents; }
  .room-header [data-back] { grid-area: map; }
  .room-counter { grid-area: counter; }
  .room-tools { grid-area: tools; margin: 0; }
  .room-name { grid-area: name; margin-top: var(--space-4); font-size: 1.5rem; }
  .room-number { display: inline; margin: 0 var(--space-2) 0 0; font-size: .75em; }
  .room-tip { grid-area: tip; margin-top: var(--space-2); }
  .room-stage { grid-area: stage; align-self: stretch; margin-top: var(--space-4); }
}
/* short screens: the hint message floats over the room instead of reserving a line */
@media (max-height: 700px) {
  .room-screen { position: relative; }
  .room-message {
    position: absolute;
    right: var(--space-3);
    bottom: var(--space-2);
    left: var(--space-3);
    z-index: 1;
    width: fit-content;
    min-height: 0;
    margin: 0 auto;
    padding: var(--space-1) var(--space-3);
    text-align: center;
    color: var(--ink);
    background: #fff;
    box-shadow: var(--pixel-border-2);
  }
  .room-message:empty { display: none; }
}
/* phones */
@media (max-width: 480px) {
  .room-name { font-size: 1.5rem; }
  .tool-button { padding: var(--space-2) var(--space-3); }
}
/* short phones */
@media (max-width: 480px) and (max-height: 760px), (max-height: 420px) {
  .room-number { display: none; }
  .room-name { font-size: 1.3rem; }
  .room-tip { margin-top: var(--space-3); font-size: .9rem; line-height: 1.4; }
  .room-tools { gap: var(--space-2); margin-block: var(--space-3); }
  .tool-button { padding: var(--space-1) var(--space-3); font-size: 1rem; }
}
/* the shortest screens */
@media (max-height: 420px) {
  .room-tip { font-size: .8rem; line-height: 1.35; }
  .room-tools .tool-button { padding: 2px var(--space-2); font-size: .9rem; }
}

/* ---------- ending ---------- */
/* the friends and blanket both shrink with the window, so the picnic always fits across it */
.picnic { display: grid; justify-items: center; width: min-content; max-width: 100%; margin: var(--space-6) auto var(--space-4); }
.ending-screen .lead { margin: 0 auto var(--space-6); line-height: 1.45; }
.picnic-friends { display: flex; justify-content: center; align-items: flex-end; gap: var(--space-2); padding-inline: var(--space-5); margin-bottom: calc(-1 * var(--space-3)); }
.picnic-friends img { width: auto; height: clamp(36px, min(12vh, 19vw), 112px); }
.picnic-blanket {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  box-sizing: border-box;
  width: 100%;
  padding: var(--space-5) var(--space-4) var(--space-4);
  background: repeating-conic-gradient(#ffb3cf 0 25%, #fff0f6 0 50%) 0 0 / 24px 24px;
  box-shadow: var(--pixel-border-3);
}
.picnic-row { display: flex; justify-content: space-evenly; align-items: center; gap: var(--space-2); }
.picnic-blanket img { width: auto; height: clamp(20px, min(5vh, 7vw), 48px); image-rendering: pixelated; }
.picnic-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); }
/* phones and short screens: smaller, so they stay side by side */
@media (max-width: 480px), (max-height: 600px) {
  .picnic-buttons { gap: var(--space-2); }
  .picnic-buttons .pixel-button { margin: 4px 2px; padding: .6em .7em; font-size: .9rem; }
}
/* the link back to the site gets a line of its own */
.ending-screen .title-links { gap: 0 var(--space-3); margin-top: var(--space-5); }
.ending-screen .title-links a.text-button { flex-basis: 100%; }
@media (max-width: 480px) {
  .ending-screen .title-links .text-button { padding: var(--space-1) var(--space-2); font-size: 1rem; }
}
/* short screens */
@media (max-height: 600px) {
  .ending-screen .lead { margin-bottom: var(--space-4); font-size: .95rem; }
  .ending-screen .title-links { margin-top: var(--space-3); }
  .ending-screen .title-links .text-button { padding: 2px var(--space-2); font-size: .95rem; }
}
/* short, wide windows: the picnic left, its words and buttons right */
@media (max-height: 560px) and (min-width: 560px) {
  .ending-screen { display: grid; grid-template: "title title" auto "picnic words" auto / auto minmax(0, 22rem); justify-content: center; align-items: center; gap: var(--space-3) var(--space-5); }
  .ending-screen .window-title { grid-area: title; margin: 0; }
  .picnic { grid-area: picnic; margin: 0; }
  .picnic-words { grid-area: words; }
  .ending-screen .title-links { gap: 0 var(--space-2); margin-top: var(--space-4); }
  .ending-screen .title-links .text-button { padding: var(--space-1) var(--space-2); font-size: 1rem; }
}

/* ---------- game pad ---------- */
.game-pad { --pad-size: clamp(42px, 6.5vh, 52px); display: flex; flex: none; justify-content: space-between; align-items: center; width: min(100%, 680px); padding: 0 var(--space-2); user-select: none; -webkit-user-select: none; }
.game-pad[hidden] { display: none; }
.arrow-pad { display: grid; grid-template: repeat(3, var(--pad-size)) / repeat(3, var(--pad-size)); }
.pad-up { grid-area: 1 / 2; }
.pad-left { grid-area: 2 / 1; }
.pad-right { grid-area: 2 / 3; }
.pad-down { grid-area: 3 / 2; }
.pad-button {
  display: grid;
  place-items: center;
  border: 0;
  font: 700 1.1rem var(--pixel-font);
  color: var(--ink);
  background: #fff;
  box-shadow: var(--pixel-border-3), 0 5px 0 0 var(--lavender);
  touch-action: none;
  cursor: pointer;
}
.pad-button:active { transform: translateY(4px); box-shadow: var(--pixel-border-3); }
/* laid out like a handheld: B lower left, A upper right */
.action-pad {
  --switch-size: calc(var(--pad-size) * 1.3);
  --action-size: calc(var(--pad-size) * 1.45);
  display: grid;
  grid-template: repeat(3, calc(var(--pad-size) * .85)) / var(--switch-size) var(--action-size);
  gap: 0 var(--space-3);
  align-items: center;
  justify-items: center;
}
.pad-round { width: var(--switch-size); height: var(--switch-size); border-radius: 50%; font-size: 1.5rem; color: #fff; }
.pad-action { grid-area: 1 / 2 / 3 / 3; width: var(--action-size); height: var(--action-size); font-size: 1.6rem; background: var(--pink-deep); box-shadow: 0 0 0 4px var(--ink), 0 6px 0 4px #c94f8a; }
.pad-action:active { box-shadow: 0 0 0 4px var(--ink); }
.pad-switch { grid-area: 2 / 1 / 4 / 2; background: var(--blue-deep); box-shadow: 0 0 0 4px var(--ink), 0 6px 0 4px #4f8fd8; visibility: hidden; }
.pad-switch:active { box-shadow: 0 0 0 4px var(--ink); }
.game-pad.can-switch .pad-switch { visibility: visible; }

/* ---------- game pad beside the window ---------- */
/* phones in landscape: arrows left, A and B right, the room beside its words, and map cards on one line each */
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) {
  .game { flex-direction: row; justify-content: center; align-items: center; gap: var(--space-3); }
  .game-window { height: 100%; width: auto; flex: 1 1 auto; }
  .game-screen { padding: var(--space-3) var(--space-4); }
  .game-pad { display: contents; }
  .arrow-pad { order: -1; }
  .action-pad { order: 1; }
  .title-screen .lead { font-size: .95rem; }
  /* map: title and links share the top row */
  .map-screen { display: grid; grid-template: "heading links" auto "islands islands" auto / minmax(0, 1fr) auto; align-items: center; gap: var(--space-3) var(--space-4); width: 100%; }
  .map-heading { grid-area: heading; text-align: left; }
  .map-heading .lead { max-width: none; margin-left: 0; }
  .map-screen .title-links { grid-area: links; flex-direction: column; align-items: flex-end; }
  .map-screen .title-links .text-button { margin: 0; padding-block: var(--space-1); }
  .islands { --friend-height: 32px; grid-area: islands; width: 100%; }
  .island { display: grid; grid-template: "friend name rooms" auto / auto minmax(0, 1fr) auto; align-items: center; padding: var(--space-2) var(--space-3); }
  .island-name { margin: 0; font-size: 1.2rem; }
  /* room: words left, room right */
  .room-screen {
    display: grid;
    grid-template: ". stage" 1fr "header stage" auto "tip stage" auto "tools stage" auto "message stage" auto ". stage" 1fr / minmax(0, 1fr) minmax(0, 1.5fr);
    column-gap: var(--space-4);
  }
  .room-header { display: flex; grid-area: header; flex-wrap: wrap; }
  .room-name { flex-basis: 100%; order: -1; margin: 0; font-size: 1.4rem; text-align: left; }
  .room-number { display: block; margin: 0 0 var(--space-1); font-size: 1.1rem; }
  .room-tip { grid-area: tip; margin-top: var(--space-3); font-size: .9rem; line-height: 1.4; text-align: left; }
  .room-tools { grid-area: tools; justify-content: flex-start; gap: var(--space-2); margin-top: var(--space-3); }
  .tool-button { padding: var(--space-1) var(--space-3); font-size: 1.05rem; }
  .room-message { position: static; grid-area: message; width: auto; margin: var(--space-2) 0 0; padding: 0; text-align: left; color: var(--ink-soft); background: none; box-shadow: none; }
  .room-stage { grid-area: stage; margin: 0; }
}
/* the smallest phones in landscape */
@media (orientation: landscape) and (max-height: 420px) and (pointer: coarse) {
  .room-number { display: none; }
  .room-tip { margin-top: var(--space-2); font-size: .85rem; line-height: 1.35; }
  .room-tools { flex-wrap: nowrap; gap: var(--space-1); margin-top: var(--space-2); }
  .room-tools .tool-button { padding-inline: var(--space-2); font-size: .95rem; }
  .ending-screen .lead { margin-bottom: var(--space-3); font-size: .85rem; line-height: 1.35; }
  .ending-screen .title-links { margin-top: var(--space-2); }
  .ending-screen .title-links .text-button { font-size: .85rem; }
  .ending-screen .title-links a.text-button { flex-basis: auto; }
}
/* wide screens: arrows left of the window, A and B right of it */
@media (min-width: 900px) {
  .game { flex-direction: row; justify-content: center; }
  .game-window { flex: 0 1 680px; height: 100%; }
  .game-pad { display: contents; }
  .arrow-pad { order: -1; }
  .action-pad { order: 1; }
}

/* off by default on computers; see setUpPadToggle in play.js */
body.pad-off .game-pad { display: none; }
