/* PuzzleFit styling, the same palette the other eight games use: a black page,
   the board on a lighter grey rounded panel, one light pill button, and that
   app's outline.

   A number that has been tapped turns sky (`--player`), which is that palette's
   "a number you put there" and is exactly what a taken number is. The reference
   app paints them green; green in this repo means "a piece still to place" and
   never "correct", so the role colour wins over the reference — see Branding in
   CLAUDE.md. `--bad` is a miss and nothing else, and it fades. */
:root {
  --bg: #0a0a0a;
  --board-panel: #242424;      /* the tray the dice sit on */
  --card: #000000;             /* outlined cards */
  --outline: rgba(255, 255, 255, .92);
  --square: #2f2f2f;           /* a number still to be tapped */
  --square-text: #ffffff;
  --player: #5cc8f7;           /* ...and one that has been */
  --player-text: #06202b;
  --accent: #ab8dfa;           /* a hint, and the keyboard's cursor */
  --bad: #ff5722;              /* a tap that was not the next number */
  --light: #e3e3e3;            /* the primary button */
  --primary-text: #0a0a0a;     /* ...and the text on it */
  --text: #ffffff;
  --muted: #9b9b9b;
}

/* 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(). */
body.light {
  --bg: #f1f1f4;
  --board-panel: #dededf;
  --card: #ffffff;
  --outline: rgba(0, 0, 0, .88);
  --square: #c9c9cf;
  --square-text: #101014;
  --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 and the board gets the rest.
   Anything added here comes straight off the board — put it in the overlay
   instead. */
.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: 10px;
}

.bar {
  display: flex;
  align-items: center;
  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);
}

.left {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* There is no pan and no zoom: every level fits — the biggest board is six
   squares across — so the square size picked by fitBoard() is the whole layout.
   That leaves the one gesture on the board free for the only thing the game
   asks for, which is a tap. */
.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;
  display: grid;
  place-items: center;
}

.stage { position: relative; }

/* Laid out in exactly the geometry game.js publishes: `--cell` is the square,
   `--gap` the space between two, `--pad` the margin round the lot. cellAt()
   undoes this same arithmetic to find the square under a finger, so the two
   halves cannot disagree about where a square is. */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--cell));
  gap: var(--gap);
  padding: var(--pad);
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: calc(var(--cell) * .18);
  background: var(--square);
  color: var(--square-text);
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * .42);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  /* Two digits is the most a board can ever carry — the highest number a level
     can produce is Rows*Cols*MaxGap — so one size fits every board. */
  transition: background-color .18s ease, color .18s ease, transform .12s ease;
}

/* Tapped, and out of the way. It keeps its number: the run it was part of is
   what the next comparison is against, and a board that emptied as it went
   would get easier with every tap. */
.cell.done {
  background: var(--player);
  color: var(--player-text);
}

/* A tap that was not the next number. Transient — the board never carries a
   standing mark saying anything was wrong, and the miss is on the win line. */
.cell.miss {
  background: var(--bad);
  color: #fff;
  transform: scale(.94);
}

/* A hint pulses the number it would have tapped; it never taps it. */
.cell.hint {
  box-shadow: inset 0 0 0 3px var(--accent);
  animation: pulse .5s ease-in-out 2;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* Where the keyboard is standing. */
.cell.cursor { box-shadow: inset 0 0 0 3px var(--accent); }

.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 it costs 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;
  z-index: 30;
}

.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; }
