/* PuzzleFit styling: a black page, one rounded panel that Phaser draws into,
   and that app's die colours around it.

   This stylesheet owns the *chrome* only — clock, budget, buttons, overlay, the
   panel the canvas sits in. The board and the palette are inside the canvas, so
   their colours live in COLORS in game.js instead: CSS variables mean nothing to
   a WebGL renderer. The two are not independent, and they must not drift — the
   client suite reads both and checks that every role declared here exists there
   under the same name and the same value. Change a role in one, change it in
   the other. */
:root {
  --bg: #0a0a0a;
  --board-panel: #242424;      /* the panel the canvas fills */
  --card: #000000;             /* outlined cards over the board */
  --outline: rgba(255, 255, 255, .92);
  --op: #efbc4a;
  --player: #5cc8f7;
  --tile: #4ed35e;
  --accent: #ab8dfa;
  --bad: #ff5722;
  --light: #e3e3e3;            /* the primary button */
  --primary-text: #0a0a0a;     /* ...and the text on it */
  --text: #ffffff;
  --muted: #9b9b9b;

  /* The palette the board is painted in, and the order is load-bearing: a
     level takes the *first* n of them, so the four an easy board is played on
     are warm-light, cool-light, warm-dark, cool-mid. Reordering the list
     changes which colours a four-colour board asks the player to separate.
     They are stated again as COLORS.paint in game.js — the canvas cannot read
     a variable — and the suite pins the two lists together. */
  --c0: #efbc4a;
  --c1: #5cc8f7;
  --c2: #ff5722;
  --c3: #4ed35e;
  --c4: #ab8dfa;
  --c5: #f56aa8;
}

/* A PGSDK host can report that it is running light; the die colours are the
   brand and stay put, everything around them inverts. Set by applyDarkMode(),
   which also hands the new palette to the scene — the canvas cannot inherit. */
body.light {
  --bg: #f1f1f4;
  --board-panel: #dededf;
  --card: #ffffff;
  --outline: rgba(0, 0, 0, .88);
  --light: #14141a;
  --primary-text: #f4f4f6;
  --text: #101014;
  --muted: #5c5c66;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;                       /* the game owns the viewport */
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* One screenful: the header takes what it needs, the canvas gets the rest.
   Anything added to .app comes straight off the board. */
.app {
  max-width: 460px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;                        /* narrow phones drop the tools to a second line */
}

.tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

[hidden] { display: none; }

select {
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--outline);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 700;
}

.clock {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* The moves left. It goes orange-red on the last one, which is the only warning
   a board budgeted at its own optimum can honestly give. */
.left {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 1.6em;
  text-align: center;
  color: var(--player);
}

.left.last { color: var(--bad); }

/* Phaser's canvas is appended here and resized to it. `touch-action: none` is
   what keeps a finger on the board from scrolling the page, and the pointer
   handlers in game.js are bound to this element rather than to the canvas — the
   canvas is replaced when the renderer restarts, this element is not. */
.viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;                          /* let it shrink inside the column */
  overflow: hidden;
  border-radius: 26px;
  background: var(--board-panel);
  touch-action: none;
  overscroll-behavior: contain;
}

.viewport canvas { display: block; border-radius: 26px; }

/* A board that can no longer be finished shudders rather than saying so in
   words — the refusal belongs to the board, which is what the player is
   reading. */
.viewport.shake { animation: shake .3s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.btn {
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--outline);
  border-radius: 999px;
  padding: 16px 20px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

/* The header row: small enough that three of them cost the board a few pixels. */
.btn.mini {
  padding: 5px 9px;
  font-size: 12px;
  border-width: 1px;
}

.btn:active { transform: scale(.97); }
.btn.primary { background: var(--light); border-color: var(--light); color: var(--primary-text); }
.btn.hidden { display: none; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .72);
  display: grid;
  place-items: center;
  padding: 20px;
}

.overlay.hidden { display: none; }

.panel {
  background: var(--card);
  border-radius: 22px;
  border: 2px solid var(--outline);
  padding: 26px 22px;
  text-align: center;
  max-width: 320px;
  width: 100%;
}

.panel h2 { margin: 0 0 8px; font-size: 28px; font-weight: 800; }
.panel p { margin: 0 0 18px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.panel .btn { width: 100%; }
.panel .btn + .btn { margin-top: 10px; }
