/* Games: a wooden games box and a felt card table (DESIGN.md). */
:root {
  --felt: #1f5f46;
  --felt-deep: #174a36;
  --wood: #8a5a2b;
  --wood-deep: #6d4520;
  --paper: #f7f4ec;
  --card: #fffdf7;
  --ink: #1b1b1b;
  --red: #c0392b;
  --red-deep: #9e2e22;
  --blue: #2457a6;
  --blue-deep: #173d78;
  --yellow: #e0a800;
  --green: #2e8b57;

  --bg: var(--paper);
  --text: var(--ink);
  --muted: #4d483f;
  --surface: var(--card);
  --line: #cfc6b0;
  --focus: var(--blue);
  --table: var(--felt);
  --on-table: var(--paper);
  --glow: var(--yellow);

  --gap: clamp(0.5rem, 2vw, 1rem);
  --target: 44px;
  --radius: 10px;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 100%;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0f231a;
    --text: var(--paper);
    --muted: #cfc8b8;
    --surface: #173327;
    --line: #3b5a4b;
    --focus: var(--yellow);
    --table: #174a36;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f231a;
  --text: var(--paper);
  --muted: #cfc8b8;
  --surface: #173327;
  --line: #3b5a4b;
  --focus: var(--yellow);
  --table: #174a36;
  color-scheme: dark;
}
:root[data-theme="contrast"] {
  --bg: #000;
  --text: #fff;
  --muted: #fff;
  --surface: #000;
  --line: #fff;
  --focus: #ffd500;
  --table: #000;
  --on-table: #fff;
  --glow: #ffd500;
  --wood: #000;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3 {
  line-height: 1.15;
  margin: 0 0 0.5rem;
}
h1 {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 800;
}
h2 {
  font-size: 1.25rem;
}
p {
  margin: 0 0 0.75rem;
}

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

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

/* Buttons and fields */
button,
input,
select {
  font: inherit;
  color: inherit;
}
button {
  min-height: var(--target);
  min-width: var(--target);
  padding: 0.5rem 1rem;
  border: 2px solid var(--text);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
button.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
button.primary:hover:not(:disabled) {
  background: var(--red-deep);
}
:root[data-theme="contrast"] button.primary {
  background: #000;
  border-color: #fff;
}
button.big {
  font-size: 1.15rem;
  padding: 0.75rem 1.5rem;
}
button.ghost {
  background: transparent;
  border-color: currentColor;
}
input:not([type]),
input[type="text"],
select {
  min-height: var(--target);
  font-size: 1rem;
  padding: 0.4rem 0.6rem;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  max-width: 100%;
}
input[type="checkbox"],
input[type="radio"] {
  width: 1.4rem;
  height: 1.4rem;
  accent-color: var(--red);
}
label {
  font-weight: 600;
}
.choice {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: var(--target);
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}
.warn {
  color: var(--red);
  font-weight: 600;
}
:root[data-theme="dark"] .warn,
:root[data-theme="contrast"] .warn {
  color: #ffb4a8;
}

/* The wooden bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(env(safe-area-inset-top) + 0.4rem) var(--gap) 0.4rem;
  background: var(--wood);
  color: #fff;
  border-bottom: 4px solid var(--wood-deep);
}
.brand {
  color: inherit;
  font-size: 1.4rem;
  font-weight: 900;
  text-decoration: none;
  letter-spacing: 0.01em;
  padding: 0.4rem 0;
  margin-right: auto;
}
.offline-mark {
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
}
.update {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: center;
  padding: 0.5rem var(--gap);
  background: var(--yellow);
  color: var(--ink);
  font-weight: 700;
}
.update[hidden] {
  display: none;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--gap);
  outline: none;
}
.loading {
  font-size: 1.2rem;
  padding: 2rem 0;
}

/* Hub: the shelf of game boxes */
.hub-title {
  margin-top: 0.5rem;
}
.welcome {
  border: 2px dashed var(--wood);
  border-radius: var(--radius);
  padding: var(--gap);
  margin-bottom: var(--gap);
}
.welcome .row input {
  flex: 1 1 10rem;
}
.shelf {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
  column-gap: calc(var(--gap) * 2);
}
.box {
  display: grid;
  grid-template-columns: 72px 1fr;
  grid-template-areas: "lid text" "lid play";
  gap: 0.25rem 0.9rem;
  align-items: start;
  padding: 1rem 0 0.9rem;
  border-bottom: 6px solid var(--wood);
}
.lid {
  grid-area: lid;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  background: var(--felt);
  padding: 4px;
}
.box.type-board .lid {
  background: var(--wood);
}
.box.type-kids .lid {
  background: var(--blue);
}
:root[data-theme="contrast"] .lid {
  border: 2px solid #fff;
}
.emblem {
  width: 100%;
  height: 100%;
}
.box-text {
  grid-area: text;
}
.box h2 {
  font-size: 1.35rem;
  font-weight: 800;
  margin: 0;
}
.box .about {
  margin: 0.15rem 0;
}
.box .meta {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}
.box .needs {
  color: var(--red);
  font-weight: 700;
  margin: 0;
}
.box button {
  grid-area: play;
  justify-self: start;
  padding-inline: 2rem;
}
.offline-row,
.scores,
.install {
  margin: 1.5rem 0;
  max-width: 44rem;
}
.scores table {
  border-collapse: collapse;
  min-width: min(100%, 22rem);
}
.scores th,
.scores td {
  text-align: left;
  padding: 0.35rem 1rem 0.35rem 0;
  border-bottom: 1px solid var(--line);
}
.scores td {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.recent {
  padding-left: 1.2rem;
}
.install {
  border-left: 6px solid var(--felt);
  padding-left: 1rem;
}

/* Setup */
.setup {
  max-width: 36rem;
}
.setup fieldset {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 1rem;
  padding: 0.75rem 1rem 1rem;
}
.setup legend {
  font-weight: 800;
  padding: 0 0.4rem;
}
.seats {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}
.seat {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.5rem;
}
.seat-name {
  display: grid;
  gap: 0.2rem;
  flex: 1 1 12rem;
}
.seat-name.cpu {
  font-weight: 800;
  align-self: center;
}
.levels {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
}
.hint-text {
  width: 100%;
  margin: 0;
  color: var(--muted);
}
.kid {
  margin-bottom: 1rem;
}

/* Match */
.match {
  display: grid;
  gap: var(--gap);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "bar" "chips" "board" "msg";
}
.match-bar {
  grid-area: bar;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
}
.match-bar h1 {
  font-size: 1.4rem;
  margin: 0;
}
.turn {
  margin: 0;
  font-weight: 800;
  font-size: 1.1rem;
  flex: 1 1 auto;
}
.kid-tools {
  display: flex;
  gap: 0.5rem;
}
.chips {
  grid-area: chips;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
}
.chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  padding: 0.35rem 0.75rem;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-size: 0.95rem;
}
.chip.active {
  border-color: var(--glow);
  background: color-mix(in srgb, var(--glow) 22%, transparent);
}
.dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
}
.board {
  grid-area: board;
  container-type: inline-size;
  background: var(--table);
  color: var(--on-table);
  border-radius: 16px;
  padding: clamp(0.6rem, 2.5vw, 1.25rem);
  min-height: 12rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  align-items: center;
  --card-w: clamp(52px, 16cqi, 104px);
}
:root[data-theme="contrast"] .board {
  border: 2px solid #fff;
}
.board button {
  color: var(--ink);
}
.msg {
  grid-area: msg;
  min-height: 1.5em;
  font-weight: 700;
  margin: 0;
}
.side {
  display: none;
  grid-area: side;
}
.log {
  margin: 0;
  padding-left: 1.2rem;
  max-height: 60vh;
  overflow: auto;
  font-size: 0.95rem;
}
.log li:first-child {
  font-weight: 700;
}

body[data-layout="wide"] .match {
  grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr);
  grid-template-areas: "bar bar" "chips board" "msg msg";
  align-items: start;
}
body[data-layout="wide"] .chips,
body[data-layout="desk"] .chips {
  flex-direction: column;
}
body[data-layout="desk"] .match {
  grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr) minmax(12rem, 18rem);
  grid-template-areas: "bar bar bar" "chips board side" "msg msg side";
  align-items: start;
}
body[data-layout="desk"] .side {
  display: block;
}

/* Glow for kid mode and hints */
.board .legal {
  box-shadow: 0 0 0 3px var(--glow);
}
.board .hint {
  box-shadow: 0 0 0 5px #fff, 0 0 0 9px var(--glow);
  animation: pulse 1s ease-in-out 3;
}
@keyframes pulse {
  50% {
    transform: translateY(-6%) scale(1.04);
  }
}
.match.kid {
  --target: 56px;
}
.match.kid .board {
  --card-w: clamp(64px, 19cqi, 120px);
}

/* Cards */
.card,
.die,
.tile,
.token {
  display: block;
  width: 100%;
  height: 100%;
}
.card text,
.emblem text {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.table {
  display: flex;
  gap: clamp(1rem, 6cqi, 3rem);
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}
.card-slot {
  display: block;
  width: var(--card-w);
  aspect-ratio: 60 / 84;
}
.stock,
.pile,
.pond,
.roll {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  background: none;
  border: 0;
  padding: 4px;
  border-radius: 10px;
}
.board .stock,
.board .roll {
  color: var(--on-table);
}
.label {
  font-weight: 800;
  color: var(--on-table);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.suit-icon {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  background: var(--card);
  border-radius: 4px;
  padding: 2px;
}
.suit-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}
.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  row-gap: 0.6rem;
  padding: 0.5rem calc(var(--card-w) * 0.45) 0 0;
  margin-top: auto;
}
.card-btn {
  width: var(--card-w);
  aspect-ratio: 60 / 84;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 8px;
  margin-right: calc(var(--card-w) * -0.45);
  transition: transform 0.15s ease-out;
}
.card-btn:hover,
.card-btn:focus-visible,
.card-btn.picked {
  transform: translateY(-14%);
  position: relative;
  z-index: 1;
}
.slide {
  animation: slide 0.3s ease-out;
}
@keyframes slide {
  from {
    transform: translateY(45%) rotate(-8deg);
    opacity: 0.3;
  }
}
.suits,
.ask {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}
.suits button,
.ask button,
.pass-btn {
  background: var(--card);
  border-color: var(--card);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.ask {
  flex: 1 1 14rem;
  align-self: center;
}
.books {
  margin: 0;
  font-weight: 700;
}

/* Four in a Row */
.c4 {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  width: min(100%, 34rem, 62dvh);
  padding: 6px;
  background: var(--blue);
  border-radius: 12px;
  border-bottom: 10px solid var(--blue-deep);
}
.c4 .col {
  padding: 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  min-width: 0;
}
.c4 .col:hover {
  background: rgb(255 255 255 / 0.12);
}
.c4 svg {
  display: block;
  width: 100%;
  overflow: visible;
}
.c4 .hole {
  fill: var(--felt-deep);
}
.c4 .drop {
  animation: drop 0.35s cubic-bezier(0.5, 0, 0.9, 0.6);
}
@keyframes drop {
  from {
    translate: 0 var(--from);
  }
}
.c4 .win circle:first-child {
  stroke: #fff;
  stroke-width: 10;
}

/* Memory */
.memory {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: clamp(4px, 1.5cqi, 12px);
  width: min(100%, 36rem, 80dvh);
}
.tile {
  aspect-ratio: 1;
}
button.tile {
  padding: 0;
  border: 0;
  background: none;
  border-radius: 8px;
}
.tile.gone {
  display: block;
  border: 2px dashed rgb(255 255 255 / 0.25);
  border-radius: 8px;
}
.flip {
  animation: flip 0.3s ease-out;
}
@keyframes flip {
  from {
    transform: rotateY(90deg);
  }
}

/* Ludo */
.ludo {
  width: min(100%, 36rem, 68dvh);
}
.ludo-wrap {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 3px solid var(--ink);
}
.ludo-board {
  display: block;
  width: 100%;
  height: 100%;
}
.piece {
  position: absolute;
  width: calc(100% / 15);
  height: calc(100% / 15);
  padding: 0;
  margin: 0;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  scale: 1.3;
  transition:
    left 0.25s ease-out,
    top 0.25s ease-out;
}
.match.kid .piece {
  scale: 1.6;
}
button.piece {
  z-index: 2;
}
.roll .die-face {
  display: block;
  width: 64px;
  height: 64px;
}

/* Quiz Race */
.question {
  font-size: clamp(1.6rem, 8cqi, 2.8rem);
  font-weight: 800;
  text-align: center;
  margin: 0.5rem 0;
}
.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: min(100%, 32rem);
}
.answer {
  min-height: 4rem;
  font-size: 1.3rem;
  background: var(--card);
  border-color: var(--card);
}
.race {
  list-style: none;
  padding: 0;
  margin: 0;
  width: min(100%, 32rem);
  display: grid;
  gap: 0.4rem;
}
.lane {
  display: grid;
  grid-template-columns: 6rem 1fr;
  align-items: center;
  gap: 0.5rem;
}
.lane-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}
.steps {
  display: grid;
  grid-template-columns: repeat(var(--steps), 1fr);
  gap: 3px;
}
.step {
  height: 1.1rem;
  border-radius: 4px;
  background: rgb(255 255 255 / 0.2);
}
.step.done {
  background: var(--lane);
}
.step.here {
  box-shadow: 0 0 0 2px #fff;
}

/* Result */
.result {
  max-width: 34rem;
}
.places {
  font-size: 1.25rem;
  padding-left: 0;
  list-style: none;
}
.places li {
  padding: 0.4rem 0;
  border-bottom: 2px solid var(--line);
}
.places strong {
  display: inline-block;
  min-width: 3.2rem;
}

/* Pass screen */
.pass {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: var(--felt);
  color: var(--paper);
}
.pass-card {
  text-align: center;
  max-width: 26rem;
}
.pass h2 {
  font-size: clamp(2rem, 9vw, 3rem);
}

/* Settings: a bottom sheet on phones, a panel elsewhere */
.sheet {
  border: 2px solid var(--text);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  padding: 1.25rem;
  width: min(100% - 1rem, 30rem);
  max-height: 90dvh;
}
.sheet::backdrop {
  background: rgb(0 0 0 / 0.5);
}
.sheet form {
  display: grid;
  gap: 0.5rem;
}
.sheet h3 {
  margin-top: 0.75rem;
}
body[data-layout="compact"] .sheet {
  margin: auto 0 0;
  width: 100%;
  max-width: 100%;
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
}

/* Online rooms (change 0002) */
a.button {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  padding: 0.5rem 1rem;
  border: 2px solid var(--text);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}
a.button.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.online-row {
  margin: 0 0 1rem;
  max-width: 44rem;
  border-left: 6px solid var(--red);
  padding-left: 1rem;
}
.box-actions {
  grid-area: play;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.badge {
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 0.8rem;
  vertical-align: middle;
}
.lobby {
  display: grid;
  justify-items: start;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.who {
  flex: 1 1 12rem;
}
.room-code {
  margin: 0;
  font-size: clamp(2.2rem, 10vw, 3.5rem);
  font-weight: 900;
  letter-spacing: 0.2em;
  font-variant-numeric: tabular-nums;
}
.qr {
  width: min(60vw, 220px);
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.qr svg {
  display: block;
  width: 100%;
  height: auto;
}
.room-link {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
}
.room-bar {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  font-size: 0.95rem;
}
.room-status {
  margin: 0;
  font-weight: 700;
  color: var(--red);
}
:root[data-theme="dark"] .room-status,
:root[data-theme="contrast"] .room-status {
  color: #ffb4a8;
}
/* A big screen as the table (AC9.1): the board large, no side panel. */
.match.big-table .board {
  --card-w: clamp(72px, 18cqi, 160px);
  min-height: 60vh;
  font-size: 1.3rem;
}
body[data-layout="desk"] .match.big-table {
  grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr);
  grid-template-areas: "bar bar" "chips board" "msg msg";
}
.match.big-table .side {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
