:root {
  --bg: #faf8ef;
  --ink: #776e65;
  --ink-dim: #a39a8f;
  --line: #e8e1d5;
  --board: #bbada0;
  --cell: #cdc1b4;
  --accent: #f67c5f;
}
* { box-sizing: border-box; }
/* Without this a display set below would show an element marked hidden. */
[hidden] { display: none !important; }
body {
  margin: 0 auto;
  padding: 24px 16px 40px;
  max-width: 940px;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

h1 { margin: 0; font-size: 34px; line-height: 1.1; }
h2 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-dim); }
.sub { margin: 6px 0 22px; }
.sub a { color: inherit; font-weight: 700; }
main { display: grid; gap: 28px; }
@media (min-width: 820px) {
  main { grid-template-columns: 420px 1fr; gap: 40px; align-items: start; }
}
footer { margin-top: 32px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--ink-dim); font-size: 13px; }
button, select { font: inherit; color: inherit; }

.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.counters div { padding: 6px 10px; border-radius: 6px; background: var(--board); text-align: center; }
.counters span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #eee4da; }
.counters b { font-size: 20px; color: #fff; font-variant-numeric: tabular-nums; }

.replaybar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.replaybar p { flex-basis: 100%; margin: 0; font-weight: 700; }
.replaybar button { padding: 4px 10px; border: 1px solid var(--board); border-radius: 5px; background: none; cursor: pointer; }
.replaybar button[aria-pressed="true"] { background: var(--board); color: #fff; }
#speeds { display: flex; gap: 4px; margin: 0 auto; }

/* Cells and tiles share one geometry: four of --size and five of --gap make 100%. */
.board {
  --gap: 2.5%;
  --size: 21.875%;
  position: relative;
  aspect-ratio: 1;
  container-type: inline-size;
  border-radius: 8px;
  background: var(--board);
}
.cell, .tile {
  position: absolute;
  left: calc(var(--gap) + var(--c) * (var(--size) + var(--gap)));
  top: calc(var(--gap) + var(--r) * (var(--size) + var(--gap)));
  width: var(--size);
  height: var(--size);
  border-radius: 5px;
}
.cell { background: var(--cell); }
.tile {
  display: grid;
  place-items: center;
  font-size: 10cqw;
  font-weight: 700;
  /* app.js waits out this duration in SLIDE before it merges and spawns. */
  transition: left .12s ease-in-out, top .12s ease-in-out;
}
.tile[data-len="3"] { font-size: 8cqw; }
.tile[data-len="4"] { font-size: 6.4cqw; }
.tile[data-len="5"] { font-size: 5.2cqw; }
.tile.new { animation: appear .15s ease-out; }
.tile.merged { z-index: 1; animation: pop .15s ease-out; }
.instant .tile { transition: none; animation: none; }
@keyframes appear { from { transform: scale(0); } }
@keyframes pop { 50% { transform: scale(1.15); } }

/* The colour of a tile on the board and of its badge in the lists. Past 2048 stays dark. */
.tile, .badge { background: #3c3a32; color: #f9f6f2; }
.v2 { background: #eee4da; color: var(--ink); }
.v4 { background: #ede0c8; color: var(--ink); }
.v8 { background: #f2b179; }
.v16 { background: #f59563; }
.v32 { background: #f67c5f; }
.v64 { background: #f65e3b; }
.v128 { background: #edcf72; }
.v256 { background: #edcc61; }
.v512 { background: #edc850; }
.v1024 { background: #edc53f; }
.v2048 { background: #edc22e; }

.note { min-height: 1.45em; margin: 8px 0 14px; font-weight: 700; }

.probs { display: grid; gap: 7px; }
.prob { display: grid; grid-template-columns: 1.2em 3em 1fr 5.4em; align-items: center; gap: 8px; }
.track { height: 12px; border-radius: 6px; background: var(--line); overflow: hidden; }
.fill { display: block; width: 0; height: 100%; border-radius: 6px; background: var(--board); transition: width .2s; }
.pct { text-align: right; font-variant-numeric: tabular-nums; }
.prob.chosen { font-weight: 700; }
.prob.chosen .fill { background: var(--accent); }
.prob.blocked { color: var(--ink-dim); }

details { margin-top: 22px; }
summary { font-weight: 700; cursor: pointer; }
details p { margin: 10px 0; }
details h2 { margin-top: 16px; }
pre {
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: #f1ebdf;
  font: 12px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
select { padding: 2px 4px; border: 1px solid var(--board); border-radius: 5px; background: var(--bg); }
.games { margin: 0 0 26px; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.games button {
  display: grid;
  grid-template-columns: 1.4em 4.6em 3.6em 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}
.games button:hover { background: #f1ebdf; }
.games .rank { color: var(--ink-dim); }
.games .score { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.games .badge { padding: 1px 0; border-radius: 4px; font-size: 13px; font-weight: 700; text-align: center; }
.games .meta { color: var(--ink-dim); font-size: 13px; }
.games .empty { padding: 6px 4px; color: var(--ink-dim); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: right; }
th { font-size: 13px; font-weight: 400; color: var(--ink-dim); }
th:first-child, td:first-child { text-align: left; }
