:root {
  --paper: #f6efe3;
  --ink: #2b211a;
  --muted: #6d5f52;
  --wood: #8a5a32;
  --wood-dark: #5e3a1d;
  --pit: #4a2c14;
  --seed: #efe3c8;
  --line: #d9c9b0;
  --focus: #1f6feb;
  --card: #fffaf2;
  --rim: transparent; /* an edge round the logo, needed on a dark page */
  /* The page has its own dark look: phones must not darken it themselves (that recolours the
     seeds and the logo) */
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1d1914;
    --ink: #f2e8da;
    --muted: #b3a493;
    --line: #3d342b;
    --card: #27211b;
    --rim: rgb(255 255 255 / 0.18);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font:
    16px/1.5 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

.top,
main,
footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  font-size: 1.6rem;
  margin: 18px 0 8px;
}

h2 {
  font-size: 1.15rem;
  margin: 12px 0;
}

nav {
  display: flex;
  gap: 16px;
}

a,
.link {
  color: inherit;
}

button {
  font: inherit;
  cursor: pointer;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
}

.primary {
  background: var(--wood-dark);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 22px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 12px;
}

legend {
  padding: 0;
  margin-bottom: 4px;
}

.panel h2 {
  margin-top: 0;
}

.panel .controls {
  margin: 8px 0 16px;
}

.players label {
  margin-right: 14px;
}

.seat {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
}

/* drop-down menus drawn like the text boxes, the same in every browser */
select {
  font: inherit;
  color: var(--ink);
  appearance: none;
  padding: 5px 30px 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b5a4a' stroke-width='1.5'/%3E%3C/svg%3E")
    no-repeat right 10px center;
}

select:disabled {
  opacity: 0.5;
}

.problems {
  color: #b42318;
  margin: 8px 0;
}

.problems:empty {
  display: none;
}

.hint {
  color: var(--muted);
  font-size: 0.92rem;
}

/* Player cards */
.cards {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: 8px;
}

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

/* a person's card at this device: tap it to change their name and picture */
.card.editable {
  cursor: pointer;
}

.card.editable:hover,
.card.editable:focus-visible {
  border-color: var(--colour);
}

.edit-hint {
  display: inline-flex;
  margin-left: 6px;
  color: var(--muted);
}

.edit-hint svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}

.picker-name {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 10px 0 4px;
}

.picker-name[hidden] {
  display: none;
}

.picker-name label {
  display: grid;
  flex: 1;
  gap: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.picker-name input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

.picker-name button {
  padding: 9px 16px;
  border-radius: 8px;
  font: inherit;
}

.card.current {
  border-color: var(--colour);
}

/* at the end of a game: the winner's card, or the leader's when it was stopped */
.card.winner {
  border-color: #c99a2e;
  background: #fff6dc;
}

.card.winner .name::after {
  content: " 🏆";
}

.card.out {
  opacity: 0.45;
}

.card .name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card .meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.timer {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  margin-top: 6px;
  overflow: hidden;
}

.timer span {
  display: block;
  height: 100%;
  background: var(--colour);
  transform-origin: left;
}

/* The game, top to bottom: whose turn, the players, the board, the moves. */
.play:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  margin-top: 12px;
}

.info {
  display: contents;
}
#headline {
  order: 0;
  margin: 0;
}
.cards {
  order: 2;
  margin: 0;
}
.board-area {
  order: 3;
}
.moves {
  order: 4;
}

/* Learn to play: the lesson's text and buttons under its heading; no game controls, players or
   moves */
.lesson {
  order: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px 14px;
}

.lesson-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.lesson-top .link {
  color: var(--muted);
  font-size: 0.9rem;
}

.lesson .dot {
  width: 10px;
  height: 10px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--line);
}

.lesson .dot.done {
  background: var(--muted);
}

.lesson .dot.on {
  background: #c0522b; /* the learner's colour, clear on a light or dark page */
  transform: scale(1.3);
}

.lesson p {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.lesson .lesson-kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* what to do now, set off from the rule */
.lesson .lesson-tap {
  margin: 0;
  padding: 8px 12px;
  border-left: 4px solid #c0522b; /* the learner's colour */
  border-radius: 4px;
  background: var(--paper);
  font-weight: 600;
}

.lesson .controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px; /* clear of the text above (the game's button row sits closer) */
}

.lesson .lesson-tap:not([hidden]) + .controls {
  display: none;
}

/* the pit to tap breathes, so a beginner finds it at once */
.play.learning .pit.legal {
  animation: lesson-pulse 1.6s ease-in-out infinite;
}

@keyframes lesson-pulse {
  50% {
    box-shadow:
      inset 0 5px 8px rgb(0 0 0 / 0.7),
      inset 0 0 0 3px rgb(255 210 122 / 0.95),
      0 0 22px 4px rgb(255 210 122 / 0.55);
  }
}

@media (prefers-reduced-motion: reduce) {
  .play.learning .pit.legal {
    animation: none;
  }
}

.play.learning .info > .controls,
.play.learning .cards,
.play.learning .moves {
  display: none;
}

/* The start screen: the two things most people want, then everything else folded away */
.quick {
  display: grid;
  gap: 12px;
  margin: 4px 0 14px;
}

.quick-box {
  display: grid;
  gap: 12px;
}

/* The start screen's picture: the board as a game starts, smaller than the board played on */
.board.hero {
  width: min(85%, 460px);
  margin: 20px auto 28px;
  pointer-events: none;
}

.board.hero .pit {
  position: relative;
}

/* the owners' dots, smaller on the picture than on the board played on */
.board.hero .pit::before {
  width: 6px;
  height: 6px;
}

.board.hero .plank.far .pit::before {
  top: -15px;
}

.board.hero .plank.near .pit::before {
  bottom: -15px;
}

/* on a phone, the learn box is just its button */
.quick-learn h3,
.quick-learn p {
  display: none;
}

/* on wider screens: play and learn side by side, as two boxes filling the width */
@media (min-width: 700px) {
  /* the extra room above the computer's level is for phones only (more specific than the
     general rule for the label further down, which would otherwise win) */
  .quick .levels-label {
    margin-top: 0;
  }
  /* without the panel, the picture needs room below the header */
  #setup .board.hero {
    margin-top: 36px;
  }
  /* no panel round the start screen: its boxes sit on the page */
  #setup {
    padding: 0;
    border: 0;
    background: none;
  }
  .quick {
    grid-template-columns: 3fr 2fr;
    gap: 16px;
  }
  .quick-box {
    align-content: start;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
  }
  /* (by id, to come before the general rules for the box further down) */
  #continue {
    grid-template-columns: 1fr auto auto;
    align-items: center;
    background: var(--card);
  }
  #continue h3,
  #continue p {
    grid-column: 1;
  }
  #continue p {
    margin-bottom: 0;
  }
  #continue button {
    grid-row: 1 / 3;
  }
  #continue-game {
    grid-column: 2;
  }
  #forget-game {
    grid-column: 3;
  }
  .quick-learn {
    grid-template-rows: auto 1fr auto;
  }
  .quick-learn h3,
  .quick-learn p {
    display: block;
    margin: 0;
  }
  .quick-learn h3 {
    font-size: 1.05rem;
  }
  .quick-learn p {
    color: var(--muted);
  }
  /* the box's heading already asks */
  #learn-open .lead {
    display: none;
  }
}

.quick .big {
  width: 100%;
  padding: 15px 16px;
  border-radius: 12px;
  font-size: 1.12rem;
  font-weight: 600;
}

/* Play with friends lands on the setup below the sticky header, not under it */
#more-options {
  scroll-margin-top: 84px;
}

.quick .secondary {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0 0.3em;
  border: 1px solid var(--wood-dark);
  background: var(--card);
  color: var(--ink);
}

/* the computer's level: one selector in three parts, each marked with one to three seeds */
.levels-label {
  margin: 5px 0 -6px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--wood-dark);
  border-radius: 12px;
  overflow: hidden;
}

.levels label {
  position: relative;
}

.levels input {
  position: absolute;
  opacity: 0;
}

.levels label > span {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 9px 4px 8px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.levels label + label > span {
  border-left: 1px solid var(--line);
}

.levels b {
  font-weight: 600;
  text-transform: capitalize;
}

.pips {
  display: flex;
  gap: 4px;
}

.pips i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
}

.lvl-easy .pips i:nth-child(-n + 1),
.lvl-medium .pips i:nth-child(-n + 2),
.lvl-hard .pips i {
  background: var(--wood);
}

.levels input:checked + span {
  background: var(--wood-dark);
  color: #fff;
}

.levels input:checked + span .pips i {
  background: rgb(255 255 255 / 0.3);
}

.lvl-easy input:checked + span .pips i:nth-child(-n + 1),
.lvl-medium input:checked + span .pips i:nth-child(-n + 2),
.lvl-hard input:checked + span .pips i {
  background: #ffd27a;
}

.levels input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.more-options > summary {
  padding: 12px 0 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.more-options[open] > summary {
  margin-bottom: 8px;
}

/* Restart and Stop, in one Game menu beside Pause */
.game-menu {
  position: relative;
}

.game-menu > summary {
  list-style: none;
  padding: 6px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.game-menu > summary::-webkit-details-marker {
  display: none;
}

.game-menu > summary::after {
  content: " ▾";
}

.game-menu-items {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  display: grid;
  gap: 6px;
  min-width: 150px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 10px 24px rgb(0 0 0 / 0.2);
}

body.tv #game-menu {
  display: none;
}

/* The More sheet (phones): About and Feedback */
.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet h2 {
  margin: 0;
}

.sheet-items {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

/* More: rows with the top bar's icons, and the languages to tap */
.sheet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sheet-row:hover {
  border-color: var(--wood);
}

.sheet-row svg,
.sheet-language h3 svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sheet-row span {
  flex: 1;
}

.sheet-row .go {
  color: var(--muted);
}

.sheet-language h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

.sheet-languages {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sheet-languages button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.sheet-languages button[aria-pressed="true"] {
  border-color: var(--wood-dark);
  background: var(--wood-dark);
  color: #fff;
}

.sheet-languages button[aria-pressed="true"]::before {
  content: "✓ ";
}

/* on a computer, the panel opens under the More button ... */
@media (min-width: 641px) {
  .sheet[open] {
    position: fixed;
    inset: var(--top, 64px) var(--right, 16px) auto auto;
    margin: 0;
    width: 320px;
    animation: none;
  }
  .rules-card.sheet::backdrop {
    background: transparent;
    backdrop-filter: none;
  }
}

/* ... and on a phone it is a sheet from the bottom */
@media (max-width: 640px) {
  .sheet[open] {
    inset: auto 0 0 0;
    margin: 0;
    width: auto;
    max-width: none;
    border-radius: 20px 20px 0 0;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* More gathers About, Feedback and the language where the menu has no room for them: on phones
   (the bottom bar) and tablets */
#more-tool {
  display: none;
}

@media (max-width: 900px) {
  .toolbar #more-tool {
    display: inline-flex;
  }
  .toolbar #about-open,
  .toolbar #feedback-open,
  .toolbar #language-tool {
    display: none;
  }
}

.start-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.start-row button:not(.primary) {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--wood-dark);
  background: var(--card);
  color: var(--ink);
}

.lesson .controls .primary {
  background: var(--wood-dark);
  border-color: var(--wood-dark);
  color: #fff;
}

.board-area {
  display: flex;
  justify-content: center;
  padding: 22px 4px;
  position: relative;
}

/* A short notice over the board: a new round and who starts it */
.banner {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 90%;
  padding: 12px 20px;
  border-radius: 12px;
  background: rgb(32 22 14 / 0.9);
  color: #fff;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.35);
}

.banner[hidden] {
  display: none;
}

/* The coin toss: a gold coin with thickness, turning end over end in 3D; each face has a raised
   rim, the player's initials engraved, and a ring in the player's colour */
.coin {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  width: 100px;
  height: 100px;
  margin: -50px 0 0 -50px;
  perspective: 600px;
  filter: drop-shadow(0 14px 14px rgb(0 0 0 / 0.35));
}

.coin-body {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

/* the edge: thin discs stacked through the coin's thickness */
.coin-body i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(90deg, #8a6418, #c99a2e 50%, #8a6418);
}

.coin-body i:nth-child(1) {
  transform: translateZ(-4.5px);
}
.coin-body i:nth-child(2) {
  transform: translateZ(-3px);
}
.coin-body i:nth-child(3) {
  transform: translateZ(-1.5px);
}
.coin-body i:nth-child(4) {
  transform: translateZ(0);
}
.coin-body i:nth-child(5) {
  transform: translateZ(1.5px);
}
.coin-body i:nth-child(6) {
  transform: translateZ(3px);
}
.coin-body i:nth-child(7) {
  transform: translateZ(4.5px);
}

.coin-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  backface-visibility: hidden;
  background:
    radial-gradient(
      circle at 32% 28%,
      rgb(255 255 255 / 0.55),
      transparent 38%
    ),
    radial-gradient(circle, #f2d77c 0 58%, #d9b24a 60% 66%, #b98d2c 68% 100%);
  /* the raised rim, then a ring in the player's colour inside it */
  box-shadow:
    inset 0 0 0 4px #b8892a,
    inset 0 0 0 7px #f4dc8a,
    inset 0 0 0 11px var(--face),
    inset 0 0 0 12px #9c7322;
  color: #8a6418;
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  /* engraved: a light edge below the letters, a dark one above */
  text-shadow:
    0 1px 0 rgb(255 245 205 / 0.9),
    0 -1px 0 rgb(90 60 10 / 0.6);
}

.coin-face.front {
  transform: translateZ(5px);
}

.coin-face.back {
  transform: rotateX(180deg) translateZ(5px);
}

.coin[hidden] {
  display: none;
}

/* The winner: a card that pops up over the board, and seeds raining down */
.celebration {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: none;
}

.celebration[hidden] {
  display: none;
}

.celebration-card {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 18px 28px;
  border: 3px solid var(--colour);
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.35);
  animation: win-pop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.celebration-card .avatar {
  width: 68px;
  height: 68px;
  font-size: 1.4rem;
}

.celebration-line {
  margin: 2px 0 0;
  opacity: 0.85;
}

#celebration-name {
  margin: 0;
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 800;
}

@keyframes win-pop {
  from {
    opacity: 0;
    transform: scale(0.3);
  }
}

.confetti {
  position: absolute;
  top: -24px;
  width: var(--size);
  height: calc(var(--size) * 0.85);
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset -2px -2px 3px rgb(0 0 0 / 0.18);
  animation: seed-fall var(--d) ease-in var(--delay) both;
}

@keyframes seed-fall {
  to {
    transform: translateY(900px) rotate(540deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .celebration-card {
    animation: none;
  }
}

/* The board, after a real Ọpọ́n: two long, dark, matte planks rounded at both ends, joined along
   a seam; six round wells in each plank; pale green seeds. It lies flat on wide screens and stands
   upright on phones (.upright). */
.board {
  width: min(100%, 760px);
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  filter: drop-shadow(0 12px 16px rgb(0 0 0 / 0.3));
}

.plank {
  display: flex;
  gap: 1.6%;
  padding: 1.6% 3%;
  border-radius: 9999px;
  background: linear-gradient(
    180deg,
    #2e2723 0%,
    #221d1a 30%,
    #1a1613 70%,
    #241e1b 100%
  );
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.07),
    inset 0 -1px 0 rgb(0 0 0 / 0.4),
    inset 2px 0 3px rgb(255 255 255 / 0.05);
}

.pit {
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  padding: 0;
  position: relative;
  background: radial-gradient(
    circle at 50% 42%,
    #1b1714 0 52%,
    #151210 78%,
    #2a2420 100%
  );
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 -2px 2px rgb(255 255 255 / 0.07);
  color: #fff;
}

/* Whose pit: a dot just outside the board, in the owner's colour */
.pit::before {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--owner);
}

.plank.far .pit::before {
  left: 50%;
  top: -18px;
  transform: translateX(-50%);
}

.plank.near .pit::before {
  left: 50%;
  bottom: -18px;
  transform: translateX(-50%);
}

/* Upright on phones */
.board.upright {
  /* Small enough that the whole board fits on a typical phone (80 px a pit), narrower on
     narrow screens */
  --plank: min(80px, 27vw);
  width: auto;
  flex-direction: row;
}

.board.upright .plank {
  width: var(--plank);
  flex-direction: column;
  gap: calc(var(--plank) * 0.07);
  padding: calc(var(--plank) * 0.1) calc(var(--plank) * 0.07);
  background: linear-gradient(
    90deg,
    #2e2723 0%,
    #221d1a 30%,
    #1a1613 70%,
    #241e1b 100%
  );
}

.board.upright .pit {
  flex: none;
  width: 100%;
}

.plank.left .pit::before {
  top: 50%;
  left: calc(var(--plank) * -0.07 - 17px);
  transform: translateY(-50%);
}

.plank.right .pit::before {
  top: 50%;
  right: calc(var(--plank) * -0.07 - 17px);
  transform: translateY(-50%);
}

.pit:disabled {
  cursor: default;
}

.pit.legal {
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 0 0 1.5px rgb(255 236 190 / 0.28),
    0 0 6px rgb(255 236 190 / 0.1);
}

.pit.legal:hover,
.pit.legal:focus-visible {
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 0 0 2px rgb(255 236 190 / 0.65),
    0 0 8px rgb(255 236 190 / 0.22);
}

/* your turn: the pits you can play pulse twice */
.board.your-turn .pit.legal {
  animation: your-turn 0.8s ease-in-out 2;
}

@keyframes your-turn {
  50% {
    box-shadow:
      inset 0 5px 8px rgb(0 0 0 / 0.7),
      inset 0 0 0 2px rgb(255 236 190 / 0.6),
      0 0 10px rgb(255 236 190 / 0.25);
  }
}

@media (prefers-reduced-motion: reduce) {
  .board.your-turn .pit.legal {
    animation: none;
  }
}

.pit.active {
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 0 0 1.5px rgb(255 210 122 / 0.6);
}

.pit.taken {
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 0 0 2px var(--taker),
    0 0 6px var(--taker);
}

.seed {
  position: absolute;
  aspect-ratio: 1 / 0.86;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background-image: radial-gradient(
    circle at 35% 30%,
    rgb(255 255 255 / 0.5),
    transparent 48%
  );
  box-shadow:
    inset -1px -2px 2px rgb(0 0 0 / 0.22),
    0 1px 2px rgb(0 0 0 / 0.65);
}

.moves {
  margin: 14px 0 0;
}

#log {
  max-height: 260px;
  overflow-y: auto;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
}

/* the arrow that shows the list can be opened (the heading's own layout loses the default) */
.moves > summary {
  list-style: none;
}

.moves > summary::-webkit-details-marker {
  display: none;
}

.moves > summary::before {
  content: "▸";
}

.moves[open] > summary::before {
  content: "▾";
}

/* the move list's heading: on a phone, folded, it shows the latest move */
.moves > summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
}

.last-move {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.moves[open] .last-move {
  display: none;
}

/* a move: the mover, the pit (and relays), and a chip per capture in the taker's colour */
#log .move {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

.move-who {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--ink);
}

.move-who .avatar {
  width: 22px;
  height: 22px;
  font-size: 0.6rem;
}

.move-who b {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.move-gains {
  display: flex;
  gap: 4px;
}

.chip {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--colour);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
}

.chip.all {
  box-shadow: 0 0 0 2px #ffd27a;
}

/* on wider screens the pit follows the name, and the chips sit at the end */
@media (min-width: 700px) {
  #log .move {
    grid-template-columns: minmax(0, 14rem) minmax(0, 1fr) auto;
  }
}

/* rounds, passes and the result, between the moves; a round is a divider: a thin rule with
   its name in small letters */
#log .round {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  padding: 4px 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: center;
}

#log .round::before,
#log .round::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

#log .note {
  padding: 4px 2px;
  font-size: 0.85rem;
  font-style: italic;
}

#log .result {
  padding: 6px 0;
  color: var(--ink);
  font-weight: 700;
  text-align: center;
}

/* The end of a game: each player's seeds and pits, the rounds and moves, play again */
.result {
  order: 1;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.result[hidden] {
  display: none;
}

/* the result in a line at the top of the box */
/* the Game menu's time per move */
.game-menu-items .menu-time {
  display: grid;
  gap: 4px;
  padding: 6px 4px 2px;
  font-size: 0.88rem;
  color: var(--muted);
}

.game-menu-items .menu-time select {
  font: inherit;
  color: var(--ink);
}

.result-title {
  margin: 0 0 6px;
  color: var(--muted);
}

.result-title b {
  color: var(--ink);
  font-size: 1.05rem;
}

.result-summary {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* what to do next, on a tidy grid: Play again and New game side by side, Rate the game below in
   full width (New game takes the row alone when there is no Play again) */
.result .controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.result .controls button {
  width: 100%;
  padding: 8px 10px;
}

.result .controls button[hidden] + button,
.result .controls .quiet {
  grid-column: 1 / -1;
}

.result .controls .quiet {
  border-color: transparent;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.result .controls .quiet:hover {
  color: var(--ink);
}

.result .controls .primary {
  background: var(--wood-dark);
  border-color: var(--wood-dark);
  color: #fff;
}

/* No moves yet: no empty band under "Moves" */
#log:empty {
  display: none;
}

footer {
  color: var(--muted);
  font-size: 0.9rem;
  padding-block: 24px;
}

/* The page's footer (the copyright line): close under the page's content */
body > footer {
  font-size: 0.85rem;
  padding-block: 5px 16px; /* 5 px under every screen's content */
}

/* Setup: names and the agreed time per move */
.seat input[type="text"] {
  font: inherit;
  width: min(14em, 100%);
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}

.time {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

/* Pause, restart and the time rule, under whose turn it is */
.controls {
  order: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: -6px;
}

.controls button {
  font: inherit;
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.controls button[aria-pressed="true"] {
  background: var(--wood-dark);
  border-color: var(--wood-dark);
  color: #fff;
}

.continue {
  /* a box of its own, like the start screen's other choices: what the saved game is, and its
     two buttons (beside it on wider screens) */
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 4px 8px;
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
}

.continue[hidden] {
  display: none;
}

.continue h3,
.continue p {
  grid-column: 1 / -1;
  margin: 0;
}

.continue p {
  margin-bottom: 8px;
  color: var(--muted);
}

.continue button:not(.primary) {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.standings {
  margin: 4px 0 0;
  padding-left: 1.4em;
}

.controls .rate {
  background: var(--wood-dark);
  border-color: var(--wood-dark);
  color: #fff;
}

.feedback form {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}

.feedback fieldset {
  margin: 0;
}

#feedback-questions {
  display: grid;
  gap: 12px;
}

.feedback legend {
  font-weight: 600;
  margin-bottom: 6px;
}

.star-row {
  display: flex;
  gap: 4px;
}

.star {
  position: relative;
  cursor: pointer;
  font-size: 2rem;
  line-height: 1;
  color: var(--line);
  padding: 0 2px;
}

.star input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.star.on {
  color: #d99a1e;
}

.star:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.feedback-text {
  display: grid;
  gap: 6px;
}

.feedback textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
}

.feedback-status {
  margin: 0;
  min-height: 1.2em;
  color: var(--muted);
}

.feedback-status.bad {
  color: #b42318;
}

.feedback .primary {
  justify-self: start;
}

.link-button {
  font: inherit;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.credits-note {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.credits-list {
  max-height: min(60vh, 520px);
  overflow-y: auto;
  font-size: 0.88rem;
}

.credits-list h3 {
  margin: 12px 0 4px;
  font-size: 0.95rem;
}

.credits-list ul {
  margin: 0;
  padding-left: 1.1em;
}

.credits-list li {
  margin: 3px 0;
}

.share {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 10px 0 16px; /* room before the Start button */
  color: var(--muted);
  font-size: 0.9rem;
}

.share input {
  margin-top: 3px;
}

.time-rule {
  color: var(--muted);
  font-size: 0.9rem;
  margin-left: 4px;
}

.play.paused .board {
  opacity: 0.55;
  filter: grayscale(0.4) drop-shadow(0 12px 16px rgb(0 0 0 / 0.3));
}

/* The rules: a floating card over the dimmed page, one topic per page */
.rules-card {
  width: min(460px, calc(100vw - 32px));
  border: 0;
  border-radius: 18px;
  padding: 18px 22px 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow:
    0 24px 60px rgb(0 0 0 / 0.35),
    0 2px 8px rgb(0 0 0 / 0.2);
}

.rules-card::backdrop {
  background: rgb(20 14 10 / 0.55);
  backdrop-filter: blur(2px);
}

.rules-card[open] {
  animation: card-in 0.18s ease-out;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rules-card[open] {
    animation: none;
  }
}

.rules-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rules-step {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.rules-card .close {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 6px;
}

.rules-card h2 {
  margin: 6px 0 8px;
  font-size: 1.3rem;
}

.rules-body {
  min-height: 9.5em;
}

/* a long page (Privacy) scrolls inside the card, keeping the title and buttons in view */
.rules-card[open] {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 32px);
}

.rules-card .rules-body {
  min-height: min(9.5em, 30dvh);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* The Rules and About card keeps one size on every page, so the buttons stay put; a longer
   page scrolls inside it */
#card {
  height: min(480px, calc(100dvh - 32px));
}

#card .rules-body {
  flex: 1;
}

.rules-body p {
  margin: 0 0 10px;
}

.rules-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
  color: inherit;
  font-size: 1rem;
}

.rules-card footer button {
  font: inherit;
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.rules-card footer .primary {
  background: var(--wood-dark);
  border-color: var(--wood-dark);
  color: #fff;
}

.rules-card footer button:disabled {
  opacity: 0.4;
  cursor: default;
}

.dots {
  display: flex;
  gap: 6px;
}

.rules-card footer .dot {
  width: 9px;
  height: 9px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--line);
}

.rules-card footer .dot.on {
  background: var(--wood-dark);
  transform: scale(1.25);
}

.rules-more {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Players' pictures: a photo, or initials on the player's colour */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  flex: none;
  overflow: hidden;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-pick {
  cursor: pointer;
  border-radius: 50%;
}

.photo-pick .avatar {
  width: 40px;
  height: 40px;
  font-size: 0.9rem;
  box-shadow:
    0 0 0 2px var(--card),
    0 0 0 3px var(--line);
}

.photo-pick:hover .avatar,
.photo-pick:focus-within .avatar {
  box-shadow:
    0 0 0 2px var(--card),
    0 0 0 3px var(--focus);
}

.card .name .avatar {
  width: 30px;
  height: 30px;
}

/* The picture card: avatars, a photo, or initials */
.photo-pick {
  border: 0;
  padding: 0;
  background: none;
}

.picker h2 {
  margin: 0;
  font-size: 1.15rem;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.picker-option {
  border: 0;
  padding: 3px;
  border-radius: 50%;
  background: none;
  justify-self: center;
}

.picker-option .avatar {
  width: 56px;
  height: 56px;
  font-size: 0.9rem;
}

.picker-option.selected,
.picker-option:hover,
.picker-option:focus-visible {
  box-shadow: 0 0 0 3px var(--wood-dark);
}

.picker-photo {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  background: var(--wood-dark);
  color: #fff;
  cursor: pointer;
}

.picker-photo:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.picker-group {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.picker .picker-grid {
  max-height: min(52vh, 420px);
  overflow-y: auto;
  padding: 4px;
}

/* The header: the name with a seed on the left, the menu as a toolbar on the right. It stays at
   the top as the page scrolls. */
.top {
  position: sticky;
  top: 0;
  z-index: 25;
  background: var(--paper);
  padding-top: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  white-space: nowrap;
}

.brand img {
  border-radius: 8px;
  box-shadow: 0 0 0 1.5px var(--rim); /* the dark tile stays visible on a dark page */
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1;
  white-space: nowrap;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.tool:hover {
  border-color: var(--wood);
  background: color-mix(in srgb, var(--card), var(--wood) 8%);
}

.tool svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool .when-off,
.tool.off .when-on {
  display: none;
}

.tool.off .when-off {
  display: block;
}

.tool.off {
  color: var(--muted);
}

@media (max-width: 640px) {
  /* The header stays at the top as the page scrolls, like an app's title bar (the menu is the
     bar at the bottom) */
  .top {
    flex-wrap: wrap;
    row-gap: 8px;
    position: sticky;
    top: 0;
    z-index: 25;
    background: var(--paper);
  }
  .brand {
    font-size: 1.35rem;
  }
  /* The menu as an app's bottom bar on phones: dark wood (as the phone's top bar in the app),
     in reach of a thumb, with New game as the main action */
  .toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    padding: 8px 4px calc(10px + env(safe-area-inset-bottom));
    background: var(--wood-dark);
    box-shadow: 0 -6px 18px rgb(0 0 0 / 0.18);
  }
  .tool {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 2px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: rgb(246 239 227 / 0.88);
    font-size: 0.75rem;
    font-weight: 500;
  }
  .tool svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
    padding: 4px 14px;
    border-radius: 999px;
    box-sizing: content-box;
  }
  .tool:hover svg,
  .tool:focus-visible svg {
    background: rgb(246 239 227 / 0.14);
  }
  .tool:focus-visible {
    outline-color: #ffd27a;
  }
  #new-game {
    color: #ffe7b3;
    font-weight: 700;
  }
  #new-game svg {
    background: #ffd27a;
    stroke: #3b2616;
  }
  .tool[hidden] {
    display: none;
  }
  /* the bar: Play (New game), Learn, Rules, Sound, More; About and Feedback are under More */
  #new-game {
    order: 1;
  }
  #learn-tool {
    order: 2;
  }
  #rules-open {
    order: 3;
  }
  #sound {
    order: 4;
  }
  .toolbar #more-tool {
    display: flex;
    order: 5;
  }
  .toolbar #about-open,
  .toolbar #feedback-open {
    display: none;
  }
  /* on the bar, the sound button says only "Sound": its icon shows on or off */
  .tool #sound-label {
    display: none;
  }
  .tool #sound-short {
    display: inline;
  }
  .tool.off {
    color: rgb(246 239 227 / 0.6);
  }
  /* room under the page for the bar, also when a pit is scrolled into view */
  body {
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
  }
  html {
    scroll-padding-top: 64px; /* below the header */
    scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }
}

/* the short sound label is for the phone's bottom bar only */
#sound-short {
  display: none;
}

/* The language menu: a button like the other tools, and a list of the languages below it, each
   in its own name, the current one ticked, and a note that more are coming */
.language-menu {
  position: relative;
  display: inline-flex;
}

.language-menu[hidden] {
  display: none;
}

.tool.language .chevron {
  width: 14px;
  height: 14px;
  margin-left: -2px;
  transition: transform 0.15s;
}

.tool.language[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.language-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: grid;
  gap: 2px;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 12px 32px rgb(43 33 26 / 0.18);
}

.language-list[hidden] {
  display: none;
}

.language-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
}

.language-list button:hover,
.language-list button:focus-visible {
  background: var(--paper);
}

.language-list button[aria-checked="true"] {
  font-weight: 600;
}

.language-list button[aria-checked="true"]::after {
  content: "✓";
  color: var(--wood-dark);
}

.language-soon {
  margin: 4px 0 0;
  padding: 8px 12px 4px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

/* text for screen readers only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Online: the room panel on the setup, joining, and the lobby */
.online {
  margin: 12px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}

.online > :last-child {
  margin-bottom: 0;
}

.online h3,
#lobby h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.online button,
.controls button:disabled {
  font: inherit;
}

.online button {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--wood-dark);
  background: var(--card);
  color: var(--ink);
}

.controls button:disabled {
  opacity: 0.45;
  cursor: default;
}

.invite,
.join-name {
  display: grid;
  gap: 6px;
  margin: 8px 0;
}

.invite input,
.join-name input {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.members {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
  display: grid;
  gap: 8px;
}

.members li {
  display: flex;
  align-items: center;
  gap: 10px;
}

#lobby-guest[hidden] + *,
#lobby-host[hidden] ~ #start-online {
  display: none;
}

/* TV mode: the game on a big screen, played from phones. Wider and larger throughout, and a code
   to scan in the room. */
body.tv {
  font-size: clamp(16px, 1.35vw, 30px);
}

body.tv .top,
body.tv main,
body.tv > footer {
  max-width: min(1700px, 96vw);
}

/* On the TV the phones control the game: no buttons on the screen itself */
body.tv #pause,
body.tv #restart,
body.tv #stop {
  display: none;
}

/* the board at 60% of the TV's width, leaving room around it */
body.tv .board {
  width: 60%;
}

.tv-join {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 24px;
  margin: 8px 0 16px;
}

.tv-join[hidden] {
  display: none;
}

.tv-qr {
  width: min(40vh, 340px);
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
}

.tv-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.tv-step {
  font-size: 1.4em;
  font-weight: 700;
  margin: 0 0 6px;
}

/* A capture counts at once: the taker's score flashes as the seeds leave the board */
.card.scored .meta {
  animation: score-pop 0.7s ease-out;
}

@keyframes score-pop {
  0% {
    color: var(--ink);
    font-weight: 700;
    transform: scale(1.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card.scored .meta {
    animation: none;
    font-weight: 700;
  }
}

/* Computers: a page of 1040 px with the menu on one line. In a game, the board on a table on the
   left and one panel on the right, read top to bottom: whose turn, the controls, the players (or
   the lesson), the result and the moves, as board-game sites do. Not on a TV, which has its own
   layout above. */
@media (min-width: 1100px) {
  body:not(.tv) .top,
  body:not(.tv) main,
  body:not(.tv) > footer {
    max-width: 1040px;
  }
  /* a slightly tighter menu, so it keeps to one line in the languages with longer words */
  body:not(.tv) .toolbar {
    gap: 5px;
  }
  body:not(.tv) .tool {
    padding: 6px 10px 6px 8px;
    font-size: 0.87rem;
  }
  body:not(.tv) .play:not([hidden]) {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: auto auto auto auto auto 1fr;
    grid-template-areas:
      "board head"
      "board ctrl"
      "board lesson"
      "board cards"
      "board result"
      "board moves";
    column-gap: 28px;
    row-gap: 12px;
    align-items: start;
  }
  body:not(.tv) #headline {
    grid-area: head;
    font-size: 1.05rem;
    line-height: 1.35;
  }
  body:not(.tv) .info > .controls {
    grid-area: ctrl;
    margin: 0;
  }
  body:not(.tv) .lesson {
    grid-area: lesson;
  }
  /* the board on a table: a surface as tall as the panel, the board in its middle */
  body:not(.tv) .board-area {
    grid-area: board;
    align-self: stretch;
    align-items: center;
    min-height: 340px;
    padding: 36px 28px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background:
      radial-gradient(
        ellipse at 50% 45%,
        rgb(255 255 255 / 0.55),
        rgb(255 255 255 / 0) 70%
      ),
      #ece2d1;
  }
  body:not(.tv) .cards {
    grid-area: cards;
    grid-template-columns: 1fr; /* one player per row */
  }
  body:not(.tv) .result {
    grid-area: result;
  }
  /* the moves: a card of its own, each move on two short lines (who and what was taken, then the
     pit), newest first */
  body:not(.tv) .moves {
    grid-area: moves;
    margin: 0;
    padding: 10px 12px 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
  }
  body:not(.tv) .moves summary {
    font-weight: 600;
  }
  body:not(.tv) #log {
    max-height: 280px;
    margin-top: 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
  }
  body:not(.tv) #log .move {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "who gains"
      "what gains";
    row-gap: 0;
    column-gap: 8px;
    padding: 7px 0;
  }
  body:not(.tv) #log .move:last-child {
    border-bottom: 0;
  }
  body:not(.tv) #log .move-who {
    grid-area: who;
  }
  body:not(.tv) #log .move-what {
    grid-area: what;
    padding-left: 30px; /* under the name, past the picture */
    font-size: 0.82rem;
  }
  body:not(.tv) #log .move-gains {
    grid-area: gains;
  }
  /* 3 or 4 players: smaller cards and a shorter move list, so the game keeps to the screen */
  body:not(.tv) .cards:has(> li:nth-child(3)) {
    gap: 6px;
  }
  body:not(.tv) .cards:has(> li:nth-child(3)) .card {
    padding: 5px 10px 6px;
  }
  body:not(.tv) .cards:has(> li:nth-child(3)) .card .name {
    font-size: 0.92rem;
  }
  body:not(.tv) .cards:has(> li:nth-child(3)) .card .name .avatar {
    width: 22px;
    height: 22px;
  }
  body:not(.tv) .cards:has(> li:nth-child(3)) .card .meta {
    padding-left: 28px; /* under the name, past the picture */
    font-size: 0.8rem;
  }
  body:not(.tv) .cards:has(> li:nth-child(3)) .timer {
    margin-top: 4px;
  }
  body:not(.tv) .play:has(.cards > li:nth-child(3)) #log {
    max-height: 210px;
  }
}

/* small laptops and tablets held sideways: the full width, and the menu a little tighter, so it
   keeps to one line */
@media (min-width: 900px) and (max-width: 1099px) {
  body:not(.tv) .top,
  body:not(.tv) main,
  body:not(.tv) > footer {
    max-width: 100%;
    padding: 0 24px;
  }
  body:not(.tv) .top {
    padding-top: 10px;
    padding-bottom: 10px;
  }
  body:not(.tv) .tool {
    padding: 6px 10px 6px 8px;
    font-size: 0.86rem;
  }
}

/* Kiosk mode (?kiosk=1): nothing that leads out of the game, no accidental text selection, and a
   welcome screen between visitors */
body.kiosk #about-open,
body.kiosk #feedback-open,
body.kiosk #more-about,
body.kiosk #more-feedback,
body.kiosk #players-pill,
body.kiosk #online,
body.kiosk .share,
body.kiosk #rate {
  display: none !important;
}

body.kiosk {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

.attract {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background:
    radial-gradient(
      60vmax 40vmax at 50% 30%,
      rgb(255 236 200 / 0.5),
      transparent 70%
    ),
    var(--paper);
  cursor: pointer;
  text-align: center;
}

.attract[hidden] {
  display: none;
}

.attract-card {
  display: grid;
  justify-items: center;
  gap: 1.2vmin;
  padding: 4vmin;
}

.attract-card img {
  width: clamp(64px, 11vmin, 140px);
  height: auto;
  border-radius: 22%;
}

.attract-card h1 {
  margin: 0;
  font-size: clamp(2.4rem, 8vmin, 6rem);
}

.attract-sub {
  margin: 0;
  max-width: 34ch;
  font-size: clamp(1rem, 2.6vmin, 1.7rem);
  color: var(--muted);
}

.attract-board {
  width: min(80vw, 760px);
  margin: 3vmin 0;
  pointer-events: none;
}

.attract-go {
  margin: 0;
  padding: 1.2vmin 3.2vmin;
  border-radius: 999px;
  background: var(--wood-dark);
  color: #fff;
  font-size: clamp(1.1rem, 3vmin, 2rem);
  font-weight: 600;
  animation: attract-pulse 2.4s ease-in-out infinite;
}

@keyframes attract-pulse {
  50% {
    transform: scale(1.05);
  }
}

@media (prefers-reduced-motion: reduce) {
  .attract-go {
    animation: none;
  }
}

/* Players online: the count in the top bar (every screen), its panel, and the invite card */
.players-pill {
  display: inline-flex;
  align-items: center;
  align-self: center;
  gap: 8px;
  margin-right: auto; /* the menu stays at the right */
  padding: 4px 12px 4px 10px;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.9rem;
}

.players-pill[hidden] {
  display: none;
}

.players-pill .live {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2f9e44;
  box-shadow: 0 0 0 3px rgb(47 158 68 / 0.2);
}

.players-pill[aria-expanded="true"],
.players-pill:hover {
  border-color: var(--wood);
}

body.tv .players-pill {
  display: none;
}

/* the top bar kept on one line (fitTopBar): first smaller menu buttons ... */
.top.compact .toolbar {
  gap: 4px;
}

.top.compact .tool {
  padding: 6px 10px 6px 8px;
  font-size: 0.86rem;
}

/* ... then About, Feedback and the language in More, as on narrower screens ... */
.top.fold .toolbar #more-tool {
  display: inline-flex;
}

.top.fold .toolbar #about-open,
.top.fold .toolbar #feedback-open,
.top.fold .toolbar #language-tool {
  display: none;
}

/* ... and last, the menu's names hidden but still read out */
.top.icons .tool > span:not(.sr-only) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.top.icons .tool {
  padding-inline: 9px;
}

.players-online {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* the panel: a drop-down under the pill on a computer ... */
.players-panel {
  position: fixed;
  inset: var(--top, 64px) auto auto var(--left, 16px);
  margin: 0;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - var(--top, 64px) - 16px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.25);
}

.players-panel::backdrop {
  background: transparent;
}

.players-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.players-panel h2 {
  margin: 0;
  font-size: 1.1rem;
}

/* the panel's buttons in the game's colours: the close cross as on the other cards, and Invite
   as a wood pill (muted while a game is on) */
.players-panel .close {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 6px;
}

.players-panel .close:hover {
  color: var(--ink);
  background: var(--paper);
}

.players-list button {
  padding: 6px 16px;
  border: 1px solid var(--wood);
  border-radius: 999px;
  background: var(--card);
  color: var(--wood-dark);
  font-size: 0.9rem;
  font-weight: 600;
}

.players-list button:hover:not(:disabled) {
  border-color: var(--wood-dark);
  background: var(--wood-dark);
  color: #fff;
}

/* in dark mode, a lighter wood so Invite reads on the dark panel */
@media (prefers-color-scheme: dark) {
  .players-list button {
    border-color: #c9a26b;
    color: #e8c896;
  }
  .players-list button:hover:not(:disabled) {
    border-color: #c9a26b;
    background: #c9a26b;
    color: #1d1914;
  }
}

.players-list button:disabled {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
  cursor: default;
}

.players-panel .players-list li {
  background: var(--paper);
}

/* ... and a sheet from the bottom on a phone, over the game dimmed */
@media (max-width: 640px) {
  .players-pill {
    margin: 0 0 0 auto;
  }
  .players-panel {
    inset: auto 0 0 0;
    width: auto;
    max-width: none;
    max-height: 80vh;
    border-radius: 20px 20px 0 0;
    padding: 10px 18px calc(24px + env(safe-area-inset-bottom));
  }
  .players-panel::before {
    content: "";
    display: block;
    width: 44px;
    height: 5px;
    margin: 0 auto 10px;
    border-radius: 3px;
    background: var(--line);
  }
  .players-panel::backdrop {
    background: rgb(20 14 10 / 0.45);
  }
}

.players-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.players-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--card);
}

.players-list .who {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.players-list .who b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.players-list .busy {
  color: var(--muted);
  font-size: 0.9rem;
}

.invite-card h2 {
  margin: 0 0 8px;
}

.invite-card .controls {
  margin-top: 14px;
}

/* the More and players-online panels take the focus themselves when they open: no ring round
   the whole panel (their buttons still show one) */
#more-sheet:focus,
#players-panel:focus {
  outline: none;
}

/* the row under the headline (Pause, Game, the time per move, the room) takes no room once all of
   it is hidden, as at the end of a game played on one device */
.info > .controls:not(:has(> :not([hidden]):not(:empty))) {
  display: none;
}

/* at the end of a game (.over) the row under the headline is empty: no double gap above the cards */
@media (min-width: 1100px) {
  body:not(.tv) .play.over #cards {
    margin-top: -12px;
  }
}
