/*
 * The page is a frame around one canvas, plus the DOM card that carries the
 * things a rotated canvas cannot: text entry and real links.
 *
 * The canvas is fixed and centred; lib/pixel/screen.js sets its pixel size and
 * supplies the translate/rotate transform, so sizing lives in one place rather
 * than being split between CSS and JS.
 */

* {
  box-sizing: border-box;
}

html,
body {
  /*
   * dvh, not vh or 100%. On mobile the URL bar collapses as you scroll, and vh
   * is locked to the LARGEST viewport — so the game would size itself to space
   * that isn't there yet and sit partly off-screen. dvh tracks the real one.
   */
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  /* No pull-to-refresh or rubber-banding while someone is shouting at a game. */
  overscroll-behavior: none;
}

body {
  background: #2a2a28;
  color: #b79a89;
  font: 13px/1.5 ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed;
  left: 50%;
  top: 50%;
  /* transform comes from screen.js — it owns the rotation decision */
  display: block;
  /* No pixelated upscale: the backing store is now device-resolution (see the
     renderScale note in lib/pixel/screen.js), so there is nothing to upscale. */
  image-rendering: auto;
  background: #f6d6c2;
  cursor: pointer;
  /* none, not manipulation: no scrolling or zooming should reach the game. */
  touch-action: none;
}

/* ── the DOM card ──────────────────────────────────────────────────────── */

#panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  /* Click-through: a tap outside the card still reaches the canvas, which is
     what makes tap-to-replay work while the results card is up. */
  pointer-events: none;
  z-index: 2;
}

#panel[hidden] {
  display: none;
}

#panel-card {
  pointer-events: auto;
  user-select: auto;
  -webkit-user-select: auto;
  /*
   * --game-w is the canvas's CSS width, published by main.js on every resize.
   * Matching it means the card is never wider than the game it sits on — and in
   * rotated portrait, where this box turns 90 degrees, its footprint is exactly
   * as tall as the canvas is wide, so it still fits.
   */
  width: var(--game-w, 320px);
  padding: 0.9rem 1rem 1rem;
  border: 1px solid #4a4a47;
  border-radius: 10px;
  background: rgb(42 42 40 / 94%);
  box-shadow: 0 12px 40px rgb(0 0 0 / 55%);
  text-align: center;
}

/* Match the canvas, or the card sits sideways relative to the game. */
body[data-rotated="1"] #panel-card {
  transform: rotate(90deg);
}

.panel-view[hidden] {
  display: none;
}

.panel-q {
  margin: 0 0 0.7rem;
  color: #fff4e9;
  font-size: 15px;
  line-height: 1.35;
}

.panel-note {
  margin: 0.6rem 0 0;
  font-size: 11px;
  color: #a08672;
  min-height: 1.2em;
}

.panel-label {
  display: block;
  margin: 0.2rem 0 0.3rem;
  font-size: 11px;
  color: #a08672;
  text-align: left;
}

.panel-row {
  display: flex;
  gap: 0.5rem;
}

.btn {
  flex: 1 1 0;
  display: block;
  padding: 0.6rem 0.7rem;
  border: 1px solid #55554f;
  border-radius: 7px;
  background: #3a3a37;
  color: #fff4e9;
  font: inherit;
  font-size: 13px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  /* A mistap on a phone should not scroll or zoom the page behind the card. */
  touch-action: manipulation;
}

.btn:hover {
  background: #4a4a45;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid #9AE200;
  outline-offset: 2px;
}

.btn-primary {
  /* Brand lime, with dark text: #9AE200 is far too bright to carry white type. */
  border-color: #9AE200;
  background: #9AE200;
  color: #2c3d00;
  font-weight: 600;
}

.btn-primary:hover {
  background: #aaf200;
}

.btn-cta {
  margin-top: 0.5rem;
  /* Outlined rather than filled, so it reads as the considered second action
     next to the lime replay button instead of competing with it. */
  border-color: #9AE200;
  background: transparent;
  color: #d8f78a;
  font-size: 12px;
}

.btn-cta:hover {
  background: rgb(154 226 0 / 12%);
}

#player-name {
  width: 100%;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.6rem;
  border: 1px solid #55554f;
  border-radius: 7px;
  background: #201f1e;
  color: #fff4e9;
  font: inherit;
  font-size: 14px;
}

#player-name:focus-visible {
  outline: 2px solid #9AE200;
  outline-offset: 1px;
}

/* ── page furniture ────────────────────────────────────────────────────── */

#hint {
  position: fixed;
  left: 50%;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  width: min(52ch, calc(100vw - 2rem));
  text-align: center;
  font-size: 12px;
  pointer-events: none;
}

/* Turn-your-phone nudge. Only rendered while the canvas is actually rotated,
   and it fades out on its own — the rotated game is already the instruction. */
#rotate-hint {
  position: fixed;
  left: 50%;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  /* Deliberately NOT rotated with the canvas: this is the one thing that must
     be readable in the orientation the phone is currently being held in. */
  transform: translateX(-50%);
  margin: 0;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: rgb(42 42 40 / 85%);
  color: #fff4e9;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 400ms ease;
  z-index: 3;
}

body[data-rotated="1"] #rotate-hint {
  animation: rotate-nudge 4.5s ease forwards;
}

@keyframes rotate-nudge {
  0%, 68% { opacity: 1; }
  100% { opacity: 0; }
}

/*
 * Desktop keeps the framed-artefact look. On a phone every pixel of border,
 * shadow and helper text is pixels the game doesn't get, so they go.
 */
@media (pointer: fine) {
  #game {
    border: 2px solid #4a4a47;
    box-shadow: 0 0 0 1px #000, 0 10px 40px rgb(0 0 0 / 60%);
  }
}

@media (pointer: coarse), (max-height: 460px) {
  #hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  body[data-rotated="1"] #rotate-hint {
    animation: none;
    opacity: 1;
  }
}
