/* Look: the claymation subway ads. Peach and powder-blue worlds, a black tight grotesque for every
   word (even the tiny ones), and clay-colored buttons. One typeface throughout: Inter Tight. */
:root {
  --ink: #1F1510;
  --paper: #FFFBF1;
  --mustard: #F4BE38;
  --mustard-deep: #B8741A;
  --display: "Inter Tight", "Helvetica Neue", system-ui, sans-serif;
  --body: "Inter Tight", "Helvetica Neue", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

/* The page is one flat color that slowly drifts through four from the ads (peach, powder blue,
   butter, sage), with a gentle pulse of white laid over it. */
body {
  background-color: #EDC9A3;
  animation: drift 44s ease-in-out infinite;
  color: var(--ink);
  font-family: var(--body);
  font-weight: 500;
  overflow: hidden;
  /* phone behaviour: no double-tap zoom, no pull-to-refresh bounce, no text selection mid-game */
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
@keyframes drift {
  0%, 100% { background-color: #EDC9A3; }
  25%      { background-color: #BAD8E9; }
  50%      { background-color: #F3DC9C; }
  75%      { background-color: #C9DFA2; }
}

/* the pulse: a flat wash of white that breathes in and out, so it brightens the whole page evenly */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  animation: breathe 4.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes breathe {
  0%, 100% { opacity: 0; }
  50%      { opacity: 0.16; }
}

.shell {
  position: relative;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  /* env() keeps things clear of notches and the home-bar on phones */
  padding: max(8px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* On phones the side panel dissolves, so header, tray and cast card stack in order. */
.side { display: contents; }
.top { order: 1; padding: 0 8px; }
.stage { order: 2; }
.cast-wrap { order: 3; }

.top {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  margin: 0 auto 0 0;
  white-space: nowrap;
  font-family: var(--display);
  font-weight: 700;
  font-size: 46px;
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--ink);
}
.logo span { display: inline-block; }

.stats { display: flex; align-items: center; gap: 12px; }

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.stat-name { font-size: 0.78rem; font-weight: 600; opacity: 0.7; letter-spacing: -0.01em; }
.stat-num { font-family: var(--display); font-weight: 700; font-size: 28px; line-height: 1.05; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }

.next { align-items: center; }
.next canvas { margin-top: -10px; margin-bottom: -18px; }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  justify-content: center;
}

/* game.js sets --game-aspect (width / height) and --game-ratio (height / width), because the
   tray is wider on big screens than on phones. */
#game {
  height: 100%;
  max-width: 100%;
  aspect-ratio: var(--game-aspect, 440 / 780);
  touch-action: none;   /* keep the page from scrolling while aiming */
  cursor: crosshair;
}

.over {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 100%;
  aspect-ratio: var(--game-aspect, 440 / 780);   /* same box as the canvas, so the message sits on the tray */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(237, 201, 163, 0.95);
  text-align: center;
}
.over[hidden] { display: none; }
.over-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(46px, 12vw, 72px);
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--ink);
}
.over-score { margin: 8px 0 20px; max-width: 16em; padding: 0 16px; font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
.over-why { display: block; margin-top: 6px; font-size: 0.95rem; font-weight: 500; opacity: 0.7; }
button {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  background: radial-gradient(circle at 30% 25%, #F9D673, var(--mustard) 55%, #E3A52B);
  border: 0;
  border-radius: 6.25rem;
  padding: 13px 30px 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--mustard-deep), 0 9px 16px rgba(70, 40, 20, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--mustard-deep), 0 4px 8px rgba(70, 40, 20, 0.25); }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

#next { width: 76px; height: 76px; }

/* "Meet the cast": one character at a time, like credits. game.js draws it; on phones it's a slim
   strip under the tray, on desktop a tall card in the side panel. */
.cast-wrap { position: relative; width: 100%; max-width: 440px; padding: 0 6px; }
#cast { display: block; width: 100%; height: auto; aspect-ratio: 440 / 100; cursor: pointer; }

/* sound on/off: a small round button on the corner of the cast card */
.icon-button {
  position: absolute;
  top: 6px;
  right: 12px;
  width: 44px;   /* 44px is the smallest comfortable thumb target */
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: radial-gradient(circle at 30% 25%, #FFFFFF, #F1E6D0);
  border-radius: 50%;
  font-size: 0;
  box-shadow: 0 2px 0 rgba(120, 80, 40, 0.3), 0 5px 10px rgba(70, 40, 20, 0.2);
}
.icon-button:hover { transform: none; filter: brightness(1.04); }
.icon-button:active { transform: scale(0.94); box-shadow: 0 1px 0 rgba(120, 80, 40, 0.3); }
.icon-button .slash { display: none; }
.icon-button.muted .slash { display: block; }
.icon-button.muted .waves { display: none; }

/* phones: a slimmer header so four-digit scores don't push "next" off the edge */
@media (max-width: 440px) {
  .top { gap: 6px; padding: 0 4px; }
  .logo { font-size: 36px; }
  .stats { gap: 8px; }
  .stat-num { font-size: 22px; }
  #next { width: 62px; height: 62px; }
}
@media (max-width: 340px) {
  #next { width: 52px; height: 52px; }
}

/* Wide screens: game on the right using the full window height, everything else in a side panel. */
@media (min-width: 900px) and (min-height: 680px) {
  .shell {
    max-width: none;
    flex-direction: row;
    justify-content: center;
    align-items: stretch;
    gap: 56px;
    padding: 16px 28px;
  }
  .side {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 22px;
    width: 260px;
  }
  .top { order: 0; flex-direction: column; align-items: flex-start; gap: 14px; }
  .logo { font-size: 86px; margin: 0; }
  .stats { gap: 22px; align-items: flex-end; }
  .stat { align-items: flex-start; }
  .stat-num { font-size: 36px; }
  .next { align-items: flex-start; }
  .next canvas { margin: -8px 0 -18px -10px; }
  .cast-wrap { order: 0; width: 260px; padding: 0; }
  #cast { aspect-ratio: auto; }
  .icon-button { right: 10px; top: 10px; }
  .stage { order: 0; flex: 0 0 auto; width: auto; align-self: center; }
  /* as tall as the window allows, but never so wide it pushes past the side panel */
  #game {
    width: auto;
    max-width: none;
    height: min(calc(100dvh - 32px), calc((100vw - 420px) * var(--game-ratio, 1.75)));
  }
}

/* Landscape and short (a phone on its side, a squat window): game in the middle, tiny panel beside it. */
@media (orientation: landscape) and (max-height: 679px) and (min-width: 560px) {
  .shell {
    max-width: none;
    flex-direction: row;
    justify-content: center;
    align-items: stretch;
    gap: 24px;
    padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .side { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 12px; width: 160px; }
  .top { order: 0; flex-direction: column; align-items: flex-start; gap: 10px; }
  .logo { font-size: 38px; margin: 0; }
  .stats { gap: 16px; align-items: flex-end; }
  .stat { align-items: flex-start; }
  .next { align-items: flex-start; }
  .next canvas { margin: -10px 0 -18px -12px; }
  .cast-wrap { order: 0; width: auto; padding: 0; }
  #cast { display: none; }   /* just the sound button stays */
  .icon-button { position: static; }
  .stage { order: 0; flex: 0 0 auto; width: auto; align-self: center; }
  #game {
    width: auto;
    max-width: none;
    height: min(calc(100dvh - 16px), calc((100vw - 230px) * var(--game-ratio, 1.75)));
  }
}

@media (prefers-reduced-motion: reduce) {
  body { animation: none; }
  body::before { animation: none; }
  button { transition: none; }
}
