/* The games (games-*.html): the game stage, the nickname, the end-of-game panel, the leaderboard and the histogram of
   the scores (arcade.js), and each game's own pieces (freaks.js, tiles.js, divide-and-conquer.js).
   Every colour comes from the tokens of main.css. */

/* 16 px gutters at phone width */
@media (max-width: 560px) { .games-page .container { width: calc(100% - 32px); } }

/* the stage: the head (round, running total, nickname) above the game */
.game-stage { min-height: 360px; }
.game-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px; margin-bottom: 18px; }
.game-progress { display: flex; align-items: baseline; gap: 14px; font-size: 0.92rem; color: var(--muted); }
.game-progress b { color: var(--strong); font-family: var(--mono); }
/* the time left of a game, urgent in its last 30 s */
.countdown { font-family: var(--mono); color: var(--strong); padding: 1px 8px; border-radius: 999px;
  border: 1px solid rgba(var(--ink-rgb), 0.18); }
.countdown::before { content: '⏱ '; color: var(--muted); }
.countdown.urgent { color: var(--red); border-color: rgba(var(--red-rgb), 0.55); }
.game-dots { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.game-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); }
.game-dots i.done { background: rgba(var(--accent-rgb), 0.6); border-color: transparent; }
.game-dots i.now { background: var(--accent); box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.8); border-color: transparent; }
.game-intro { display: grid; gap: 16px; justify-items: start; }
.game-intro p { margin: 0; color: var(--prose); max-width: 70ch; }
.game-offline { padding: 14px 16px; border-radius: 12px; border: 1px solid rgba(var(--red-rgb), 0.45); background: rgba(var(--red-rgb), 0.07); color: var(--error-text); font-size: 0.92rem; }
.game-stage .status { margin-top: 14px; }

/* the nickname, with one reroll */
.nick { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 0.88rem; color: var(--muted); }
.nick b { color: var(--strong); }
.nick .btn { padding: 5px 12px; font-size: 0.8rem; }

/* the end of a game: the score, the rank and "play again" */
.game-end { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 30px; padding: 20px 22px; border-radius: var(--radius); border: 1px solid rgba(var(--accent-rgb), 0.45); background: rgba(var(--accent-rgb), 0.06); margin-bottom: 22px; }
.game-end .score { font-size: clamp(2rem, 6vw, 2.8rem); font-weight: 800; line-height: 1; color: var(--strong); font-family: var(--mono); }
.game-end .score small { font-size: 0.45em; color: var(--muted); font-weight: 600; }
.game-end .rank { color: var(--text); }
.game-end .rank b { color: var(--accent); }
.game-end .note { margin-top: 4px; }
.game-end .btn { margin-left: auto; }
@media (max-width: 560px) { .game-end .btn { margin-left: 0; } }

/* a review table */
.game-review { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.game-review th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border-strong); }
.game-review td { padding: 5px 8px; border-bottom: 1px solid var(--border); font-family: var(--mono); }
.game-review td.thumb { padding: 3px 8px; }
.game-review canvas { width: 40px; height: 40px; display: block; }
.game-review .num { text-align: right; }
.review-wrap { overflow-x: auto; }

/* a field on a canvas, pixelated only when enlarged beyond its grid */
.field-canvas { display: block; width: 100%; height: auto; aspect-ratio: 1; image-rendering: auto; }

/* the leaderboard: the top ten and the histogram of every score */
.board-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 22px; margin-top: 22px; }
@media (max-width: 860px) { .board-grid { grid-template-columns: minmax(0, 1fr); } }
.board-grid .card { padding: 22px; }
.board-grid h3 { margin: 0 0 4px; font-size: 1.05rem; }
.board-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 10px; }
.board-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border-strong); }
.board-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.board-table td.r, .board-table td.s { font-family: var(--mono); }
.board-table td.s, .board-table th.s { text-align: right; }
.board-table td.d { color: var(--muted); white-space: nowrap; }
.board-table tbody tr { cursor: zoom-in; transition: background 0.2s; }
.board-table tbody tr:hover, .board-table tbody tr:focus-visible { background: var(--surface-2); outline: none; }
.board-table tbody tr.mine td { color: var(--strong); }
.board-table tbody tr.mine td:first-child { box-shadow: 3px 0 0 var(--accent) inset; }
.board-table .empty td { cursor: default; color: var(--faint); text-align: center; }
.board-hist { display: block; width: 100%; height: 190px; margin-top: 10px; }
/* the histogram's title, and the records (attempts, median, best) as a small table in its top corner */
.board-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.board-records { border-collapse: collapse; font-size: 0.88rem; }
.board-records th { text-align: left; color: var(--muted); font-weight: 600; padding: 1px 12px 1px 0; }
.board-records td { text-align: right; font-family: var(--mono); color: var(--strong); padding: 1px 0; }

/* Freaks */
.freq-layout { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 26px; align-items: start; }
@media (max-width: 860px) { .freq-layout { grid-template-columns: minmax(0, 1fr); } .freq-layout .freq-field { max-width: 420px; width: 100%; margin: 0 auto; } }
.freq-field canvas { border-radius: 12px; }
.freq-controls { display: grid; gap: 16px; }
.freq-value { font-family: var(--mono); font-size: 1.6rem; color: var(--strong); width: 6.5ch; padding: 4px 10px; margin-top: 4px;
  background: rgba(var(--ink-rgb), 0.04); border: 1px solid rgba(var(--ink-rgb), 0.18); border-radius: 10px; outline: none; }
.freq-value:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.18); }
.freq-value.invalid { border-color: var(--red); }
.freq-value:disabled { opacity: 0.6; }
.freq-slider { position: relative; display: flex; align-items: center; }
/* the speed mode's mark of the last field's truth over the slider (as wide as the slider, the reset button beside it
   excluded), and the band of a hit around it */
.freq-truth { position: absolute; left: 0; right: 30px; top: 0; bottom: 0; pointer-events: none; }
.freq-truth .band { position: absolute; top: 50%; height: 14px; margin-top: -7px; border-radius: 7px; background: color-mix(in srgb, var(--green) 22%, transparent); }
.freq-truth .mark { position: absolute; top: 50%; width: 4px; height: 24px; margin: -12px 0 0 -2px; border-radius: 2px; background: var(--green);
  box-shadow: 0 0 8px color-mix(in srgb, var(--green) 80%, transparent); animation: freq-truth-in 0.35s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes freq-truth-in { from { transform: scaleY(0); opacity: 0; } }
/* the speed mode's last verdict, on the slider and above it, fading away */
.freq-truth, .speed-verdict { transition: opacity 0.5s ease; }
.freq-truth.fade, .speed-verdict.fade { opacity: 0; }
.freq-ticks { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 0.72rem; color: var(--faint); margin: 4px 30px 0 0; }
/* the calibration examples, one row of four at every width */
.ref-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; width: 100%; }
.ref-strip figure { margin: 0; text-align: center; }
.ref-strip figcaption { font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
/* on the intro: two by two, on the right of the panel */
.ref-strip.large { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; gap: 14px; }
.ref-strip.small { max-width: 400px; gap: 6px; }
.ref-strip.small figcaption { font-size: 0.74rem; margin-top: 3px; }

/* Tiles */
.tr-layout { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 26px; align-items: start; }
@media (max-width: 920px) { .tr-layout { grid-template-columns: minmax(0, 1fr); } .tr-board { max-width: 520px; margin: 0 auto; } }
.tr-board { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; width: 100%; }
.tr-cell { position: relative; aspect-ratio: 1; border-radius: 8px; background: var(--inset); border: 1px dashed var(--border-strong); overflow: hidden; touch-action: none; }
.tr-cell.corner { border: 2px solid rgba(var(--yellow-rgb), 0.9); }
.tr-cell .corner-tag { position: absolute; top: 3px; left: 3px; z-index: 1; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 6px; display: grid; place-items: center; background: var(--tag-bg); color: var(--tag-text); font-size: 0.7rem; font-weight: 700; pointer-events: none; }
.tr-cell.over { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.6) inset; }
/* a drop's verdict, flashed: a tile locked on its own cell, or a wrong cell shaking */
.tr-cell.correct { border: 3px solid var(--green); }
.tr-cell.hinted { outline: 3px solid var(--yellow); outline-offset: -3px; }
.tr-cell.wrong { border: 3px solid var(--red); animation: tr-shake 0.35s ease; }
@keyframes tr-shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@media (prefers-reduced-motion: reduce) { .tr-cell.wrong { animation: none; } }
.tr-tile { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.tr-cell .tr-tile { cursor: default; }
.tr-tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.tr-tile.lifted { opacity: 0.25; }
.tr-tray { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; padding: 8px; min-height: 80px; border-radius: 12px; background: var(--inset); border: 1px solid var(--border); }
.tr-tray.over { border-color: var(--accent); }
/* a tray place: it keeps its spot, empty once its tile is placed, so the tray never reorders */
.tr-spot { aspect-ratio: 1; border-radius: 6px; background: rgba(var(--ink-rgb), 0.04); }
/* a tile in the tray keeps its square (on the board its cell sets the size; in the tray the row would stretch it) */
.tr-tray .tr-tile { height: auto; aspect-ratio: 1; border-radius: 6px; }
.tr-ghost { position: fixed; z-index: 60; pointer-events: none; border-radius: 8px; box-shadow: 0 16px 40px -10px var(--shadow); opacity: 0.92; }
.tr-side { display: grid; gap: 14px; align-content: start; }
.tr-side p { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* Divide and Conquer */
.pp-layout { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 26px; align-items: start; }
@media (max-width: 860px) { .pp-layout { grid-template-columns: minmax(0, 1fr); } .pp-layout .pp-field { max-width: 420px; width: 100%; margin: 0 auto; } }
.pp-field canvas { border-radius: 12px; }
.pp-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.pp-choices .btn { justify-content: center; padding: 10px 6px; font-family: var(--mono); border-radius: 12px; }
.pp-choices .btn:hover { border-color: var(--accent); }
.pp-review { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 760px) { .pp-review { grid-template-columns: minmax(0, 1fr); } }
.pp-item { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 12px; padding: 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); }
.pp-item canvas.field-canvas { width: 88px; border-radius: 8px; }
.pp-item .pp-facts { font-size: 0.84rem; color: var(--muted); }
.pp-item .pp-facts b { color: var(--strong); font-family: var(--mono); }
.pp-item .chart { height: 110px; margin-top: 4px; }
.pp-item .pts { font-family: var(--mono); color: var(--accent); }

/* the partition count typed instead of clicked */
.pp-type { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.pp-typed { width: 6ch; font-size: 1.1rem; }

/* the frequency game's speed mode: the verdict of the last guess, and the review of every guess */
.speed-verdict { font-size: 0.95rem; color: var(--muted); min-height: 1.6em; }
.speed-verdict.hit b { color: var(--green); }
.speed-verdict.miss b { color: var(--red); }
.speed-review { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; margin-top: 12px; }
.speed-item { margin: 0; text-align: center; font-size: 0.8rem; font-family: var(--mono); }
.speed-item canvas { width: 64px; margin: 0 auto 4px; }
.speed-item.hit figcaption { color: var(--green); }
.speed-item.miss figcaption { color: var(--red); }

/* the speed mode's misses left */
.hearts { display: inline-flex; gap: 1px; font-size: 1.05rem; line-height: 1; letter-spacing: 0; }
.hearts i { font-style: normal; }
.hearts .full { color: var(--red); }
.hearts .lost { color: rgba(var(--ink-rgb), 0.28); }
/* the heart the last guess lost: it swells, shakes and fades from full to empty */
.hearts .breaking { display: inline-block; animation: heart-break 0.9s ease both; }
@keyframes heart-break {
  0% { color: var(--red); transform: scale(1); }
  25% { color: var(--red); transform: scale(1.7) rotate(-12deg); }
  45% { transform: scale(1.4) rotate(12deg); }
  65% { transform: scale(1.2) rotate(-6deg); }
  100% { color: rgba(var(--ink-rgb), 0.28); transform: none; }
}
@media (prefers-reduced-motion: reduce) { .hearts .breaking, .freq-truth .mark { animation: none; } }

/* the tabs of a game's modes over its leaderboard */
.board-tabs { margin: 16px 0 0; }

/* the frequency game's intro: the mode picker (it only selects the mode and its leaderboard), the mode's description
   and the start button after it, set apart from the calibration below */
.game-modes { width: auto; }
.game-modes button { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 560px) { .game-modes { width: 100%; } .game-modes button { flex: 1 1 auto; white-space: normal; } }

/* an intro with a held-out example on its right (Tiles, Divide and Conquer), stacked on a phone */
/* the intro of every game: on the left the description in a narrow measure and the start button right after it, on
   the right the held-out examples, one width for all three games */
.intro-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); gap: 28px; align-items: start; }
.intro-split > .game-intro { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; }
.intro-split > .game-intro p { max-width: 44ch; }
.intro-split > .game-intro > .btn.primary { margin-top: 6px; }
@media (max-width: 760px) { .intro-split { grid-template-columns: minmax(0, 1fr); } .intro-split > .game-intro p { max-width: 70ch; } }
.game-example { margin: 0; display: grid; gap: 8px; justify-items: center; width: 380px; max-width: 100%; }
.game-example figcaption { font-size: 0.8rem; color: var(--muted); text-align: center; }
.tr-mini { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; width: 100%; }
.tr-mini canvas { width: 100%; height: auto; aspect-ratio: 1; display: block; border-radius: 3px; }
.pp-examples { display: grid; gap: 10px; width: 100%; }
.pp-examples .pp-item { grid-template-columns: 72px minmax(0, 1fr); padding: 10px; }
.pp-examples .pp-item canvas.field-canvas { width: 72px; }
.pp-examples .chart { height: 84px; }

/* the right of a game's head: the nickname and the exit button, which turns red once armed */
.head-side { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; }
.btn.exit.armed { color: var(--red); border-color: rgba(var(--red-rgb), 0.6); }

/* the Divide and Conquer game's last guess and truth, marked on its choices until they fade with the verdict */
.pp-choices .btn { transition: border-color 0.5s, box-shadow 0.5s, color 0.5s; }
.pp-choices .btn.pp-truth { border-color: var(--green); box-shadow: 0 0 0 2px var(--green) inset; color: var(--green); }
.pp-choices .btn.pp-guess:not(.pp-truth) { border-color: var(--red); box-shadow: 0 0 0 2px var(--red) inset; }
.pp-type .pp-typed { width: 8ch; flex: none; }
.pp-type .note { white-space: nowrap; }
