/* PuzzleFit styling, the same palette the other games use: a black page, the
   board on a lighter grey rounded panel, one light pill button, and that app's
   die colours — sky, amber, orange-red, purple, green.

   The roles here are Knight's: sky `--player` for the knight and for the
   squares it may jump to, amber `--op` for a king, orange-red `--bad` for every
   square a king covers and for a jump into one. Purple `--accent` is the
   keyboard's cursor, as it is the selection everywhere else. Green stays off
   the board entirely, exactly as it does in the other three — nothing here ever
   says "correct", only "reachable" and "deadly". */
:root {
  --bg: #0a0a0a;
  --board-panel: #242424;      /* the tray the dice sit on */
  --card: #000000;             /* outlined cards */
  --outline: rgba(255, 255, 255, .92);
  --light-square: #5a5a5a;     /* the pale half of the chequer */
  --dark-square: #333333;      /* ...and the other half */
  --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;
}

/* 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);
  --light-square: #d5d5db;
  --dark-square: #a8a8b2;
  --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 board gets the rest. */
.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;
  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 move count, which is the score here — the clock is only company. */
.moves {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary-text);
  background: var(--light);
  border-radius: 999px;
  padding: 2px 10px;
}

/* The board is laid out at a fixed square size; the viewport transform below
   is what scales it to fit, so type never has to be recomputed. */
.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.panning { cursor: grabbing; }

.stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.stage.animating { transition: transform .22s ease; }

/* No gap between squares: it is a chess board, and the pieces are absolutely
   positioned over it, so one step of that geometry is exactly one square. */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 6), var(--cell));
  padding: var(--pad);
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  background: var(--dark-square);
}

.cell.pale { background: var(--light-square); }

/* Every square a living king can reach. Landing on one is the knight being
   taken, so this is the one thing on the board that has to read at a glance. */
.cell.guarded::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bad);
  opacity: .34;
}

/* Where the knight may jump from where it stands. A dot, not a fill, so it
   never hides whether the square underneath is also covered. */
.cell.move::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  margin: -13% 0 0 -13%;
  border-radius: 999px;
  background: var(--player);
  opacity: .85;
}

/* ...and the jumps that lose the game. They stay offered — being taken has to
   be something you can do — but nothing about them looks inviting. */
.cell.move.fatal::after {
  background: var(--bad);
  opacity: 1;
}

/* The keyboard's cursor. There is no pointer equivalent: a finger taps the
   square it means. */
.cell.cursor {
  box-shadow: inset 0 0 0 3px var(--accent);
  z-index: 1;
}

/* The pieces, over the grid. Positioned by game.js in the same units the board
   is laid out in, so one place decides the geometry. */
.pieces {
  position: absolute;
  top: var(--pad);
  left: var(--pad);
  pointer-events: none;                   /* the viewport handles every gesture */
}

.piece {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  display: grid;
  place-items: center;
  font-size: calc(var(--cell) * .78);
  line-height: 1;
  text-shadow: 0 2px 3px rgba(0, 0, 0, .55);
}

.piece.king { color: var(--op); }

.piece.knight {
  color: var(--player);
  z-index: 2;
  transition: left .18s ease, top .18s ease;
}

/* A king that has been taken. It leaves rather than vanishing, so the move that
   took it is legible after the fact. */
.piece.taken {
  opacity: 0;
  transform: scale(.4);
  transition: opacity .25s ease, transform .25s ease;
}

/* The knight, taken. The board is lost the moment it lands covered; this is the
   king reaching it. */
.piece.knight.lost { color: var(--bad); }

.piece.shake { animation: shake .3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

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