/* The game's own two typefaces, bundled so every device shows the same text.
   Baloo 2 for headings, Nunito for everything else. Both SIL Open Font License. */
@font-face { font-family: "Baloo 2"; src: url("assets/fonts/baloo2.woff2") format("woff2"); font-weight: 400 800; font-style: normal; font-display: swap; }
@font-face { font-family: Nunito; src: url("assets/fonts/nunito.woff2") format("woff2"); font-weight: 200 1000; font-style: normal; font-display: swap; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #0d1428;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: grid;
  place-items: center;
}

/* The page controls are placed inside this box: the 480-wide layout in the middle
   of the stage. On a wide phone the picture runs past it on both sides. */
#ui {
  position: absolute;
  top: 0;
  left: var(--ox, 0px);
  width: calc(var(--u, 1px) * 480);
  height: 100%;
  pointer-events: none;
}
#ui > * { pointer-events: auto; }

/* The stage is sized in JS to fill the window: 16:9 at least, wider on a wide screen. */
#stage {
  position: relative;
  width: 480px;
  height: 270px;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #9cc4ee;
}

#buttons {
  position: absolute;
  top: 3%;
  right: 1.8%;
  display: flex;
  gap: clamp(6px, 1.2vmin, 12px);
}

#buttons button {
  width: clamp(32px, 6.4vmin, 54px);
  height: clamp(32px, 6.4vmin, 54px);
  padding: 0;
  display: grid;
  place-items: center;
  color: #18223d;
  background: #fbf6ea;
  border: clamp(2px, 0.45vmin, 4px) solid #18223d;
  border-radius: 28%;
  box-shadow: 0 clamp(2px, 0.5vmin, 4px) 0 #18223d;
  cursor: pointer;
  outline: none;
  transition: transform 0.06s, box-shadow 0.06s, background 0.12s;
}

#buttons button:hover { background: #ffe9b0; }
#buttons button:active {
  transform: translateY(clamp(2px, 0.5vmin, 4px));
  box-shadow: 0 0 0 #18223d;
}
#buttons svg { width: 58%; height: 58%; display: block; }

/* Copy result, shown on the win screen only */
#btn-copy {
  position: absolute;
  left: 28.3%;
  top: 60.5%;
  transform: translate(-50%, -50%);
  display: none;
  padding: 0.42em 1.2em;
  font: 800 clamp(11px, 2.7vmin, 22px) Nunito, "Trebuchet MS", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: #18223d;
  background: #ffd257;
  border: clamp(2px, 0.45vmin, 4px) solid #18223d;
  border-radius: 999px;
  box-shadow: 0 clamp(2px, 0.5vmin, 4px) 0 #18223d;
  cursor: pointer;
  outline: none;
  white-space: nowrap;
}
#btn-copy:hover { background: #ffe08a; }
#btn-copy:active { box-shadow: 0 0 0 #18223d; margin-top: clamp(2px, 0.5vmin, 4px); }

/* The player's name, on the start screen only */
#namebox {
  position: absolute;
  left: 25.8%;
  top: 70.6%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  gap: 0.5em;
  font: 800 clamp(16px, 3vmin, 24px) Nunito, "Trebuchet MS", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
#name-input {
  font: inherit;
  width: 9.5em;
  padding: 0.34em 0.7em;
  color: #18223d;
  background: #fbf6ea;
  border: clamp(2px, 0.45vmin, 4px) solid #18223d;
  border-radius: 0.6em;
  box-shadow: 0 clamp(2px, 0.5vmin, 4px) 0 #18223d;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
#name-input::placeholder { color: #8a93ad; font-weight: 700; }
#name-input:focus { background: #ffffff; border-color: #f4b93a; }
#btn-start {
  font: inherit;
  padding: 0.34em 1em;
  color: #18223d;
  background: #ffd257;
  border: clamp(2px, 0.45vmin, 4px) solid #18223d;
  border-radius: 999px;
  box-shadow: 0 clamp(2px, 0.5vmin, 4px) 0 #18223d;
  cursor: pointer;
  outline: none;
}
#btn-start:hover { background: #ffe08a; }
#btn-start:active { box-shadow: 0 0 0 #18223d; transform: translateY(clamp(2px, 0.5vmin, 4px)); }

/* On-screen controls. Hidden until the game sees a phone or tablet, and on the start screen. */
#pad { display: none; }
body.touch #pad.show { display: block; }

.pad-left, .pad-right {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 3vmin);
  z-index: 5;
  height: 36vmin;
  pointer-events: none;          /* only the buttons themselves take touches */
}
.pad-left { left: calc(env(safe-area-inset-left, 0px) + 3vmin); width: 36vmin; }
.pad-right { right: calc(env(safe-area-inset-right, 0px) + 3vmin); width: 42vmin; }

.pb {
  position: absolute;
  width: 16vmin;
  height: 16vmin;
  padding: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.2vmin;
  color: #18223d;
  background: rgba(251, 246, 234, 0.55);
  border: 0.55vmin solid #18223d;
  border-radius: 50%;
  font: 900 2.3vmin Nunito, "Trebuchet MS", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0.04em;
  outline: none;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.pb svg { width: 6.2vmin; height: 6.2vmin; display: block; }
.pb span { display: block; line-height: 1; }
.pb.on { background: #ffd257; transform: scale(0.93); }

.pb-up   { left: 10vmin; top: 0; }
.pb-left { left: 0;      bottom: 0; }
.pb-down { left: 20vmin; bottom: 0; }
.pb-jump { right: 0; bottom: 0; width: 21vmin; height: 21vmin; background: rgba(255, 210, 87, 0.7); font-size: 2.7vmin; }
.pb-jump svg { width: 8vmin; height: 8vmin; }
.pb-dash { right: 23vmin; bottom: 9vmin; }

/* Held upright on a phone, the game is replaced by a rotate screen and does not play. */
#rotate-hint { display: none; }
@media (orientation: portrait) {
  body.touch #stage, body.touch #pad { visibility: hidden; }
  body.touch #rotate-hint {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 20;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5vmin;
    padding: 8vmin;
    text-align: center;
    color: #fbf6ea;
    background: #12183a;
    font-family: Nunito, "Trebuchet MS", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  }
  .rotate-phone { width: 26vmin; height: 26vmin; color: #ffd257; animation: rotate-phone 2.4s ease-in-out infinite; }
  .rotate-title { font-size: 7vmin; font-weight: 900; }
  .rotate-sub { font-size: 4vmin; font-weight: 700; color: #ffd257; }
}
@keyframes rotate-phone {
  0%, 25% { transform: rotate(0deg); }
  55%, 85% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

/* Watch the story again: shown on the start screen once the story has been seen */
#btn-story {
  display: none;
  font: inherit;
  padding: 0.34em 0.8em;
  color: #18223d;
  background: #fbf6ea;
  border: clamp(2px, 0.45vmin, 4px) solid #18223d;
  border-radius: 999px;
  box-shadow: 0 clamp(2px, 0.5vmin, 4px) 0 #18223d;
  cursor: pointer;
  outline: none;
}
#btn-story:hover { background: #ffe9b0; }
#btn-story:active { box-shadow: 0 0 0 #18223d; transform: translateY(clamp(2px, 0.5vmin, 4px)); }
#name-input { width: 8em; }

/* The name row: a wider name box (10em, up from 8em), sized from the game area itself
   so it always fits between the brief and the leaderboard. */
#namebox {
  top: 67.2%;
  transform: none;
  gap: 0.45em;
  flex-wrap: wrap;
  max-width: 41%;
  font-size: calc(var(--u, 1.6px) * 8.1);
}
body.touch #namebox { font-size: max(16px, calc(var(--u, 1.6px) * 8.1)); }   /* 16px stops phones zooming in on the box */
#name-input { width: 10em; }
#btn-start, #btn-story { font-size: 0.9em; }

/* In full screen the page keeps its dark backdrop */
:fullscreen, :-webkit-full-screen { background: #0d1428; }

/* The desk's stamp: appears above the jump button only while a paper is waiting. */
.pb-stamp {
  position: absolute; right: 0; bottom: 24vmin; width: 21vmin; height: 11vmin;
  display: none; place-items: center; padding: 0;
  border: 0.5vmin solid #1b2142; border-radius: 6vmin;
  background: #ffd257; color: #1b2142; box-shadow: 0 0.8vmin 0 #1b2142;
  font: 900 3vmin Nunito, "Trebuchet MS", "Segoe UI", sans-serif; letter-spacing: 0.04em;
  pointer-events: auto; touch-action: none; -webkit-tap-highlight-color: transparent;
  animation: stamp-pulse 0.5s ease-in-out infinite alternate;
}
.pb-stamp.show { display: grid; }
@keyframes stamp-pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
