/* TTCF. Mobile first: the base is a 360px-wide phone; short landscape
   phones get a max-height query, desktop and TV a min-width one. Sizes
   follow the screen (vmin / dvh) up to a 4K TV. */
:root {
  /* Watercolour meadow (assets/): tile colours sampled from the mockups,
     ink colours dark enough for text on them. */
  --theme-improbable: #b38cc7;
  --theme-mature: #87c2dc;
  --theme-plaisir: #fea969;
  --theme-scolaire: #aac7ad;
  --theme-challenge: #e55954;
  --theme-superbe: #ffacc8;
  --theme-debuter: #feda66;
  --theme-gagner: #d8b264;
  --ink-improbable: #5b2d82;
  --ink-mature: #1f5f86;
  --ink-plaisir: #a24a0c;
  --ink-scolaire: #2f6b36;
  --ink-challenge: #a3221d;
  --ink-superbe: #b03468;
  --ink-debuter: #8a6200;
  --ink-gagner: #7a5600;
  --ink: #3b2a1a;
  --paper: #fbf3df;
  --paper-edge: #d9c49a;
  --wood: #8a5a35;
  --wood-dark: #5e3b20;
  --leaf: #5f9a46;
  --leaf-dark: #3f6f2e;
  --nav-h: 60px;
}

html {
  font-size: clamp(16px, 2.4vmin, 64px);
}

[hidden],
.hidden {
  display: none !important;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  margin: 0;
  overscroll-behavior: none;
  background: #6fa24f url("./assets/meadow.webp") center / cover no-repeat;
  color: var(--ink);
  font-family: "Segoe Print", "Comic Sans MS", "Chalkboard SE", var(--font-sans);
}

.game-nav {
  flex: 0 0 auto;
  background: transparent;
  border-bottom: none;
  box-shadow: none;
}

.back-button,
.options-button {
  background: var(--wood);
  border: 2px solid var(--wood-dark);
  box-shadow: 0 2px 0 var(--wood-dark);
}

.nav-title {
  color: var(--paper);
  text-shadow: 0 1px 0 var(--wood-dark), 0 0 6px rgba(0, 0, 0, 0.45);
}

/* Android bars can cover the bottom even when the safe-area inset is 0. */
.container {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 12px max(24px, env(safe-area-inset-right, 0px))
    max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px))
    max(24px, env(safe-area-inset-left, 0px));
}

.screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

/* Parchment panels with a dashed vine border. */
.setup-card,
.modal-content {
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, 0.55), transparent 70%),
    var(--paper);
  border: 3px solid var(--paper-edge);
  outline: 2px dashed rgba(95, 154, 70, 0.55);
  outline-offset: -9px;
  border-radius: 14px;
  box-shadow: 0 6px 0 rgba(94, 59, 32, 0.35), 0 10px 30px rgba(0, 0, 0, 0.3);
}

.setup-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
  width: min(100%, 26em);
  max-height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 1rem 1.25rem 1.25rem;
  text-align: center;
}

.setup-hero {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0.25rem;
}

.setup-hero img {
  flex: 0 1 auto;
  min-width: 0;
  height: 3rem;
  max-width: 12.5%;
  object-fit: contain;
  margin: 0 -0.15rem;
}

.setup-hero img:nth-child(odd) {
  transform: translateY(-0.2rem) rotate(-4deg);
}

.setup-hero img:nth-child(even) {
  transform: rotate(4deg);
}

.setup-title {
  margin: 0;
  font-size: 1.6rem;
  color: var(--leaf-dark);
}

.setup-label,
.setup-status {
  margin: 0;
  color: var(--wood);
  font-weight: bold;
}

.teams-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* 5 to 8 teams: 1-4 in the left column, 5-8 in the right one, so Up /
   Down still follow the page order. */
.setup-card:has(.is-two-columns) {
  width: min(100%, 34em);
}

/* On a narrow phone, 5-8 teams stay in one column of shorter rows when
   the screen is tall enough; a short one (320x568) keeps two compact
   columns, below. */
@media (max-width: 480px) and (orientation: portrait) and (min-height: 820px) {
  .setup-card .teams-list.is-two-columns {
    display: flex;
    gap: 0.3rem;
  }

  .is-two-columns .team-input-row input {
    min-height: 2.2rem;
    padding: 0.2rem 0.75rem;
  }

  .is-two-columns .team-avatar {
    height: 2rem;
    width: 2rem;
  }

  .setup-card:has(.is-two-columns) .setup-hero {
    display: none;
  }

  .setup-card:has(.is-two-columns) .setup-title {
    font-size: 1.3rem;
  }
}

.teams-list.is-two-columns {
  display: grid;
  grid-template-rows: repeat(4, auto);
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 0.4rem 0.6rem;
}

.is-two-columns .team-avatar {
  height: 2.2rem;
  width: 2.2rem;
}

.is-two-columns .team-input-row {
  gap: 0.3rem;
}

.is-two-columns .team-input-row input {
  padding: 0.5rem 0.6rem;
}

@media (max-width: 480px) {
  .teams-list.is-two-columns {
    gap: 0.3rem 0.4rem;
  }

  .is-two-columns .team-avatar {
    height: 1.6rem;
    width: 1.6rem;
  }

  .is-two-columns .team-input-row {
    gap: 0.15rem;
  }

  .is-two-columns .team-input-row input {
    padding: 0.4rem 0.45rem;
    font-size: 0.9rem;
  }

  .setup-card:has(.is-two-columns) {
    padding: 0.75rem 0.9rem 1rem;
  }

  .setup-card:has(.is-two-columns) .setup-hero {
    display: none;
  }
}

.team-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.team-avatar {
  flex: 0 0 auto;
  height: 2.75rem;
  width: 2.75rem;
  object-fit: contain;
}

.team-input-row input {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  box-sizing: border-box;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  border: 2px solid var(--paper-edge);
  background: #fffaf0;
  color: var(--ink);
  font: inherit;
}

.team-input-row input::placeholder {
  color: #a08a6a;
}

/* --- Board --- */
.board-header {
  flex: 0 0 auto;
  text-align: center;
}

/* Wooden sign: the playing team's acorn and name. */
.board-header h2 {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.15rem 1rem 0.15rem 0.3rem;
  font-size: 1.2rem;
  color: var(--paper);
  background: var(--wood);
  border: 2px solid var(--wood-dark);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--wood-dark);
}

.turn-avatar {
  height: 2.2rem;
  width: 2.2rem;
  object-fit: contain;
}

/* 43 spaces: 7 x 7 in portrait, 11 x 4 in landscape. The space size is the
   largest that fits the free area in both directions. */
.board-area {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  container-type: size;
  display: grid;
  place-items: center;
}

.board-track {
  --cols: 7;
  --rows: 7;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--row-gap) var(--gap);
  justify-content: center;
  align-content: center;
  --gap: 6px;
  /* Rows sit a little further apart than columns. */
  --row-gap: calc(var(--gap) * 4);
  --cell: min(calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols)), calc((100cqh - (var(--rows) - 1) * var(--row-gap)) / var(--rows)));
}

/* The snake: each space is shifted by --dy rows (set in board.js) so the bends
   are arcs and the rows ripple a little. */
.board-space {
  transform: translateY(calc(var(--dy, 0) * (var(--cell) + var(--row-gap))));
}

/* Pastel tiles with a white line icon (assets/icons/); the start and end
   spaces show their medallion. */
.board-space {
  --tile: var(--theme-improbable);
  border-radius: 22%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.35), transparent 60%),
    var(--tile);
  border: max(1.5px, calc(var(--cell) * 0.035)) solid rgba(59, 42, 26, 0.75);
  box-shadow: 0 calc(var(--cell) * 0.05) 0 rgba(59, 42, 26, 0.45);
  box-sizing: border-box;
}

.board-space.improbable { --tile: var(--theme-improbable); }
.board-space.mature { --tile: var(--theme-mature); }
.board-space.plaisir { --tile: var(--theme-plaisir); }
.board-space.scolaire { --tile: var(--theme-scolaire); }
.board-space.challenge { --tile: var(--theme-challenge); }
.board-space.superbe { --tile: var(--theme-superbe); }
.board-space.debuter { --tile: var(--theme-debuter); }
.board-space.gagner {
  --tile: var(--theme-gagner);
  box-shadow: 0 0 calc(var(--cell) * 0.35) rgba(255, 220, 110, 0.9);
}

.space-icon {
  width: 68%;
  height: 68%;
}

.space-medallion {
  width: 92%;
  height: 92%;
  border-radius: 50%;
}

.space-badge {
  position: absolute;
  top: 3%;
  left: 6%;
  font-family: var(--font-sans);
  font-weight: bold;
  font-size: calc(var(--cell) * 0.22);
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 2px rgba(59, 42, 26, 0.9), 0 1px 1px rgba(59, 42, 26, 0.9);
}

/* Acorn tokens stand on the tile, overlapping when several share it. */
.space-tokens {
  position: absolute;
  inset: auto 0 4% 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

/* An occupied tile lightens and its icon fades, so the acorn stands out. */
.board-space:has(.team-token) {
  background:
    radial-gradient(ellipse at 50% 72%, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.45) 75%),
    var(--tile);
}

.board-space:has(.team-token) .space-icon,
.board-space:has(.team-token) .space-medallion {
  opacity: 0.3;
}

/* The playing team's tile glows gold. */
.board-space:has(.is-current) {
  box-shadow:
    0 0 0 max(2px, calc(var(--cell) * 0.04)) #ffd75e,
    0 0 calc(var(--cell) * 0.3) rgba(255, 200, 60, 0.9);
}

/* White sticker outline and a shadow at the acorn's feet. */
.team-token {
  --line: max(1px, calc(var(--cell) * 0.018));
  width: 60%;
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(var(--line) 0 0 #fff) drop-shadow(calc(var(--line) * -1) 0 0 #fff)
    drop-shadow(0 var(--line) 0 #fff) drop-shadow(0 calc(var(--line) * -1) 0 #fff)
    drop-shadow(0 calc(var(--cell) * 0.04) calc(var(--cell) * 0.03) rgba(40, 25, 10, 0.6));
}

/* Overlap so n tokens of 60% fill at most the tile's width. */
.team-token + .team-token {
  margin-left: calc(min(20%, 40% / max(1, var(--n) - 1)) - 60%);
}

/* 5 to 8 tokens: two rows of four, each token overlapping its neighbours. */
.space-tokens.is-crowded {
  inset: 4%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  place-items: center;
}

.is-crowded .team-token {
  width: 180%;
  max-width: none;
}

.is-crowded .team-token + .team-token {
  margin-left: 0;
}

/* The walking token passes over the next tiles, backwards too. */
.board-space:has(.is-walking) {
  z-index: 2;
}

.team-token.is-walking {
  z-index: 1;
}

.team-token.is-current {
  z-index: 1;
  animation: ttcf-hop 1.2s ease-in-out infinite;
  filter: drop-shadow(var(--line) 0 0 #fff) drop-shadow(calc(var(--line) * -1) 0 0 #fff)
    drop-shadow(0 var(--line) 0 #fff) drop-shadow(0 calc(var(--line) * -1) 0 #fff)
    drop-shadow(0 0 calc(var(--cell) * 0.06) #ffd75e)
    drop-shadow(0 calc(var(--cell) * 0.04) calc(var(--cell) * 0.03) rgba(40, 25, 10, 0.6));
}

@media (prefers-reduced-motion: reduce) {
  .team-token.is-current,
  .win-token {
    animation: none;
  }
}

.board-actions {
  flex: 0 0 auto;
  text-align: center;
}

/* Off (card open, token walking): invisible but still sized. */
.board-actions .btn.is-off {
  visibility: hidden;
}

/* --- Card dialog: below the header, so the quit button stays reachable;
   it only fades in (no slide that could scroll the page). --- */
.modal {
  position: fixed;
  top: var(--nav-h);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(40, 60, 25, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  box-sizing: border-box;
  padding: 8px max(24px, env(safe-area-inset-right, 0px))
    max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px))
    max(24px, env(safe-area-inset-left, 0px));
  animation: ttcf-fade 0.2s ease;
  /* The card, and the timer bar under it. */
  flex-direction: column;
  gap: 0.6rem;
}

.modal-content {
  --tile: var(--theme-improbable);
  --theme-ink: var(--ink-improbable);
  width: 100%;
  max-width: 34em;
  max-height: 100%;
  min-height: 0;
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

[data-theme="mature"] .modal-content { --tile: var(--theme-mature); --theme-ink: var(--ink-mature); }
[data-theme="plaisir"] .modal-content { --tile: var(--theme-plaisir); --theme-ink: var(--ink-plaisir); }
[data-theme="scolaire"] .modal-content { --tile: var(--theme-scolaire); --theme-ink: var(--ink-scolaire); }
[data-theme="challenge"] .modal-content { --tile: var(--theme-challenge); --theme-ink: var(--ink-challenge); }
[data-theme="superbe"] .modal-content { --tile: var(--theme-superbe); --theme-ink: var(--ink-superbe); }
[data-theme="debuter"] .modal-content { --tile: var(--theme-debuter); --theme-ink: var(--ink-debuter); }
[data-theme="gagner"] .modal-content { --tile: var(--theme-gagner); --theme-ink: var(--ink-gagner); }

/* The card's theme band: medallion and theme name. */
.card-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  border-radius: 11px 11px 0 0;
  background: var(--tile);
  border-bottom: 3px solid var(--paper-edge);
  text-align: center;
  font-weight: bold;
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-medallion {
  height: 3.2rem;
  width: 3.2rem;
  border-radius: 50%;
  filter: drop-shadow(0 2px 0 rgba(59, 42, 26, 0.4));
}

.card-theme {
  color: #fff;
  text-shadow: 0 1px 0 var(--theme-ink), 0 0 4px var(--theme-ink);
}

.card-body {
  padding: 0.75rem 1rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.card-body > div {
  width: 100%;
}

.card-subject {
  margin: 0 0 0.75rem 0;
  font-size: 1.4rem;
  color: var(--theme-ink);
}

.eval-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* Rating 1-10: wooden discs. */
.eval-btn {
  background: radial-gradient(circle at 35% 30%, #b98252, var(--wood));
  border: 2px solid var(--wood-dark);
  box-shadow: 0 3px 0 var(--wood-dark);
  color: var(--paper);
  min-height: 2.75rem;
  padding: 0.5rem 0;
  border-radius: 999px;
  font: inherit;
  font-weight: bold;
  font-size: 1.2rem;
  cursor: pointer;
}
.eval-btn:hover { filter: brightness(1.1); }
.eval-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood-dark); }

.selected-note {
  font-size: 1.8rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
  color: var(--theme-ink);
}

.card-text {
  font-size: 1.2rem;
  margin: 0 0 1rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.answer-label {
  margin: 0;
  color: var(--wood);
  font-size: 0.9rem;
  text-transform: uppercase;
}

.validation-buttons {
  display: flex;
  gap: 1rem;
  margin-top: auto;
  width: 100%;
}

.validation-buttons button {
  flex: 1;
}

.manual-move-ui {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: auto;
  width: 100%;
}

.manual-move-ui p {
  margin: 0;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stepper-val {
  color: var(--ink);
  font-size: 2rem;
  font-weight: bold;
  min-width: 3rem;
}

.full-width {
  width: 100%;
}

/* Timer: the orange gauge in a wooden frame. */
.timer-bar {
  flex: 0 0 auto;
  width: 100%;
  max-width: 34em;
  height: 0.9rem;
  background: #fffaf0;
  border: 2px solid var(--wood-dark);
  border-radius: 999px;
  box-sizing: border-box;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(#ffb44a, #e9861d);
  width: 100%;
  transition: width 1s linear;
}

/* Buttons: leaf green (main), wood (secondary), berry red (missed). */
.btn {
  --btn: var(--leaf);
  --btn-edge: var(--leaf-dark);
  min-height: 2.75rem;
  padding: 0.6rem 1.5rem;
  border-radius: 999px;
  border: 2px solid var(--btn-edge);
  box-shadow: 0 4px 0 var(--btn-edge);
  background: linear-gradient(rgba(255, 255, 255, 0.22), transparent 60%), var(--btn);
  color: #fff;
  text-shadow: 0 1px 0 var(--btn-edge);
  font: inherit;
  font-weight: bold;
  cursor: pointer;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-edge); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.secondary { --btn: var(--wood); --btn-edge: var(--wood-dark); }
.btn.danger { --btn: #d9534f; --btn-edge: #8e2b27; }

/* Win screen: the winner's acorn in front of the Gagner medallion. */
.win-hero {
  position: relative;
  display: grid;
  place-items: center;
  height: 9rem;
}

.win-medallion {
  height: 8rem;
  width: 8rem;
  border-radius: 50%;
  box-shadow: 0 0 2.5rem rgba(255, 220, 110, 0.9);
}

.win-token {
  position: absolute;
  bottom: -0.5rem;
  left: calc(50% + 1rem);
  height: 6rem;
  width: auto;
  animation: ttcf-hop 1.2s ease-in-out infinite;
}

#winnerName {
  margin: 0.5rem 0 0;
  font-size: 1.8rem;
  color: var(--leaf-dark);
}

.win-card p {
  margin: 0 0 0.5rem;
}

.langWrap {
  display: flex;
  gap: 8px;
}

/* Bottom of the screen, under the card: the flags of the other two
   languages. The auto margins keep the card near the middle. */
.card-lang {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: auto;
}

.modal-content {
  margin-top: auto;
}

.card-lang-btn {
  padding: 0;
  border: 2px solid var(--paper);
  border-radius: 6px;
  background: none;
  line-height: 0;
  overflow: hidden;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.card-lang-btn img {
  display: block;
  width: 2.6rem;
  height: 1.75rem;
  object-fit: cover;
}

:focus-visible,
html.tv :focus {
  outline: max(3px, 0.4dvh) solid #ff7a00;
  outline-offset: max(2px, 0.3dvh);
}

@keyframes ttcf-fade {
  from { opacity: 0; }
}

@keyframes ttcf-hop {
  50% { transform: translateY(-12%); }
}

/* Wider than tall: the 43 spaces in 11 columns, the draw button beside. */
@media (orientation: landscape) {
  .board-track {
    --cols: 12;
    --rows: 4;
  }

  .eval-grid {
    grid-template-columns: repeat(10, 1fr);
  }
}

/* Landscape phones are ~360px tall. */
@media (orientation: landscape) and (max-height: 500px) {
  .container {
    padding-top: 4px;
  }

  .screen {
    gap: 0.4rem;
  }

  /* Dashboard in two columns: title and buttons left, teams right. */
  .setup-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-auto-flow: dense;
    width: 100%;
    gap: 0.4rem 1rem;
    align-items: center;
  }

  .setup-card > * {
    grid-column: 1;
  }

  /* Teams alone on the right, spanning the left column's rows, so 4 of
     them still fit 360px. */
  .setup-card {
    align-content: center;
  }

  .setup-card > .setup-label {
    grid-column: 2;
    grid-row: 1;
  }

  .setup-card > .teams-list {
    grid-column: 2;
    grid-row: 2 / span 3;
    gap: 0.35rem;
  }

  .teams-list.is-two-columns {
    gap: 0.25rem 0.5rem;
  }

  .is-two-columns .team-input-row input {
    min-height: 2.4rem;
    padding: 0.3rem 0.6rem;
  }

  .setup-card:has(.is-two-columns) {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  }

  /* Win: the medallion left, the name and buttons right. */
  .win-card > .win-hero {
    grid-row: 1 / span 4;
  }

  .win-card > :not(.win-hero) {
    grid-column: 2;
  }

  .setup-title {
    font-size: 1.3rem;
  }

  .setup-card {
    padding: 0.5rem 1rem;
    outline-offset: -6px;
  }

  .setup-hero img {
    height: 2rem;
  }

  .card-header {
    padding: 0.15rem 1rem;
    font-size: 1rem;
  }

  .card-medallion {
    height: 1.7rem;
    width: 1.7rem;
  }

  .card-body {
    padding: 0.4rem 1rem 0.6rem;
  }

  .card-subject {
    margin-bottom: 0.3rem;
  }

  .selected-note {
    margin-bottom: 0.2rem;
  }

  .timer-bar {
    height: 0.7rem;
  }

  .win-hero {
    height: 6rem;
  }

  .win-medallion {
    height: 5.5rem;
    width: 5.5rem;
  }

  .win-token {
    height: 4rem;
  }

  .turn-avatar {
    height: 1.6rem;
    width: 1.6rem;
  }

  #boardScreen {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    align-items: center;
  }

  #boardScreen .board-header {
    grid-column: 1 / -1;
  }

  #boardScreen .board-area,
  #boardScreen .wheel-area {
    height: 100%;
  }

  #boardScreen.is-wheel .wheel-scores {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    gap: 0.15rem;
  }

  .mode-row {
    gap: 0.35rem;
  }

  .mode-chip {
    min-height: 2.4rem;
    font-size: 0.9rem;
  }

  .board-track {
    --gap: 4px;
  }

  .card-subject,
  .selected-note {
    font-size: 1.2rem;
  }

  .card-text {
    font-size: 1rem;
    margin-bottom: 0.5rem;
  }
}

/* A 960x540 TV: four teams need the acorn row's height. */
@media (orientation: landscape) and (min-height: 501px) and (max-height: 600px) {
  .setup-hero {
    display: none;
  }
}

/* Desktop and TV, 960x540 up to 3840x2160: sizes follow the screen and
   everything stays 3% away from the edges (TV overscan). */
@media (min-width: 960px) and (min-height: 500px) {
  :root {
    --nav-h: calc(3dvh + max(36px, 6dvh) + 1dvh);
  }

  .game-nav {
    height: auto;
    padding: 3dvh max(3vw, env(safe-area-inset-right, 0px)) 1dvh
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .back-button,
  .options-button {
    width: max(36px, 6dvh);
    height: max(36px, 6dvh);
    font-size: max(1rem, 3dvh);
  }

  .back-button svg,
  .options-button svg {
    width: 50%;
    height: 50%;
  }

  .nav-title {
    font-size: 1.2rem;
  }

  .container,
  .modal {
    padding: 2dvh max(3vw, env(safe-area-inset-right, 0px)) max(40px, 4dvh)
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .board-track {
    --gap: 1dvh;
  }

  .btn {
    min-height: max(44px, 5.5dvh);
  }
}

/* --- Débuter card: instruction and answer together, answer in italics. --- */
.is-opening #answerStep .answer-label {
  display: none;
}

.is-opening #cardAnswer {
  font-style: italic;
  color: var(--wood);
}

.is-opening #showAnswerBtn,
.is-opening .selected-note {
  display: none;
}

/* --- Game mode chips on the dashboard. With Resume shown too, the acorn
   row makes room. --- */
.setup-card:has([data-id="ttcf-resume-button"]:not([hidden])) .setup-hero {
  display: none;
}

/* Short screens: no acorn row at all, smaller dashboard controls. */
@media (orientation: landscape) and (max-height: 500px), (orientation: portrait) and (max-height: 600px) {
  .setup-hero {
    display: none;
  }

  .setup-card {
    gap: 0.3rem 1rem;
  }

  .setup-card .btn,
  .setup-card .mode-chip {
    min-height: 2.4rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.85rem;
    box-shadow: 0 3px 0 var(--btn-edge, var(--wood-dark));
  }

  .setup-card .mode-chip {
    box-shadow: none;
  }

  .setup-title {
    font-size: 1.15rem;
  }
}

/* A 960x540 TV: the dashboard in two columns as on landscape phones. */
@media (orientation: landscape) and (min-height: 501px) and (max-height: 600px) {
  .setup-card {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    grid-auto-flow: dense;
    width: min(100%, 52em);
    gap: 0.5rem 1.25rem;
    align-items: center;
    align-content: center;
  }

  .setup-card > * {
    grid-column: 1;
  }

  .setup-card > .setup-label {
    grid-column: 2;
    grid-row: 1;
  }

  .setup-card > .teams-list {
    grid-column: 2;
    grid-row: 2 / span 3;
  }
}

.mode-row {
  display: flex;
  gap: 0.5rem;
}

.mode-chip {
  flex: 1;
  min-height: 2.75rem;
  padding: 0.3rem 0.6rem;
  line-height: 1.15;
  border-radius: 999px;
  border: 2px solid var(--paper-edge);
  background: #fffaf0;
  color: var(--wood);
  font: inherit;
  font-weight: bold;
  cursor: pointer;
}

.mode-chip.active {
  background: var(--wood);
  border-color: var(--wood-dark);
  color: var(--paper);
}

/* --- Wheel mode: the wheel and each team's progress. --- */
.wheel-area {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.wheel-stage {
  position: relative;
  /* The turning square must not widen the page. */
  overflow: hidden;
  flex: 1 1 0;
  align-self: stretch;
  min-height: 0;
  min-width: 0;
  container-type: size;
  display: grid;
  place-items: center;
}

.wheel {
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
}

.wheel svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0.4rem 0 rgba(59, 42, 26, 0.35));
}

.wheel-segment {
  stroke: rgba(59, 42, 26, 0.6);
  stroke-width: 1;
}

.wheel-segment.improbable { fill: var(--theme-improbable); }
.wheel-segment.mature { fill: var(--theme-mature); }
.wheel-segment.plaisir { fill: var(--theme-plaisir); }
.wheel-segment.scolaire { fill: var(--theme-scolaire); }
.wheel-segment.challenge { fill: var(--theme-challenge); }
.wheel-segment.superbe { fill: var(--theme-superbe); }

.wheel-rim {
  fill: none;
  stroke: var(--wood-dark);
  stroke-width: 5;
}

.wheel-hub {
  fill: var(--wood);
  stroke: var(--wood-dark);
  stroke-width: 3;
}

/* Wooden pointer at 12 o'clock, over the wheel. */
.wheel-pointer {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 1;
  width: 1.6rem;
  height: 2rem;
  transform: translate(-50%, -20%);
  background: var(--wood);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  filter: drop-shadow(0 2px 0 var(--wood-dark));
}

.wheel-scores {
  flex: 0 1 auto;
  max-height: 40%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: 0.3rem 0.6rem;
  width: 100%;
  margin: 0;
  padding: 0.4rem 0.6rem;
  list-style: none;
  box-sizing: border-box;
  background: rgba(251, 243, 223, 0.92);
  border: 2px solid var(--paper-edge);
  border-radius: 12px;
}

.wheel-score {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 0.35rem;
  font-size: 0.85rem;
}

.wheel-score.is-current {
  font-weight: bold;
  color: var(--leaf-dark);
}

.wheel-score-token {
  grid-row: 1 / span 2;
  width: 1.8rem;
  height: 1.8rem;
  object-fit: contain;
}

.wheel-score.is-current .wheel-score-token {
  animation: ttcf-hop 1.2s ease-in-out infinite;
}

.wheel-score-name {
  grid-column: 2;
  grid-row: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wheel-score-pos {
  grid-column: 3;
  grid-row: 1;
  font-size: 0.8em;
  color: var(--wood);
}

.wheel-score-bar {
  grid-column: 2 / span 2;
  grid-row: 2;
  height: 0.4rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--leaf) calc(var(--progress) * 100%), rgba(94, 59, 32, 0.18) 0);
}

/* Category guide in the options panel. */
.category-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.category-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  line-height: 1.35;
}

.category-item img {
  flex: 0 0 auto;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
}

@media (orientation: landscape) {
  #boardScreen.is-wheel .wheel-area {
    flex-direction: row;
  }

  #boardScreen.is-wheel .wheel-scores {
    flex: 0 0 auto;
    max-height: 100%;
    width: min(18rem, 40%);
    grid-template-columns: 1fr;
    align-self: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .wheel-score.is-current .wheel-score-token {
    animation: none;
  }
}

/* The wheel turns with a swipe: no page scroll or zoom on it. */
.wheel {
  touch-action: none;
  cursor: grab;
}

.wheel:active {
  cursor: grabbing;
}

/* Card dialog: ✕ top right cancels the question, "Passer la question"
   at the bottom draws another one. */
.modal-content {
  position: relative;
}

.card-close,
.card-flip {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  z-index: 1;
  display: grid;
  place-items: center;
  width: max(2.2rem, 5dvh);
  height: max(2.2rem, 5dvh);
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--wood-dark);
  background: var(--wood);
  color: var(--paper);
  box-shadow: 0 2px 0 var(--wood-dark);
  font: inherit;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

/* Superbe card: its theme (set or free) and rule, then a button per theme
   it allows; the card played under it keeps the rule in a pink box. */
.bonus-theme {
  margin: 0 0 0.5rem;
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--theme-ink);
}

.bonus-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.btn.bonus-choice {
  --btn: var(--theme-improbable);
  --btn-edge: var(--ink-improbable);
  flex: 1 1 8rem;
  color: var(--btn-edge);
  text-shadow: none;
}

.btn.bonus-choice.mature { --btn: var(--theme-mature); --btn-edge: var(--ink-mature); }
.btn.bonus-choice.plaisir { --btn: var(--theme-plaisir); --btn-edge: var(--ink-plaisir); }
.btn.bonus-choice.scolaire { --btn: var(--theme-scolaire); --btn-edge: var(--ink-scolaire); }

.bonus-rule {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 0.75rem;
  padding: 0.4rem 0.75rem;
  border: 2px dashed var(--ink-superbe);
  border-radius: 10px;
  background: color-mix(in srgb, var(--theme-superbe) 35%, transparent);
  font-size: 0.9rem;
  line-height: 1.35;
  text-align: left;
  white-space: pre-wrap;
}

.bonus-rule strong {
  color: var(--ink-superbe);
}

/* Answer side: ↺ top left turns the card back to its question (and again). */
.card-flip {
  right: auto;
  left: 0.45rem;
}

.card-close[hidden],
.card-flip[hidden] {
  display: none;
}

.btn.card-skip {
  align-self: center;
  margin-top: 0.75rem;
  background: transparent;
  border: 2px dashed var(--wood);
  box-shadow: none;
  color: var(--wood);
  text-shadow: none;
}

/* Landscape phones: "Passer la question" beside the step's own button, so
   the card needs no scroll. */
@media (orientation: landscape) and (max-height: 500px) {
  .card-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    column-gap: 0.75rem;
  }

  .card-body > * {
    grid-column: 1 / -1;
  }

  .card-body > .btn.card-skip {
    grid-column: 2;
    grid-row: 3;
    margin: 0;
    min-height: 2.4rem;
    padding: 0.25rem 0.9rem;
    font-size: 0.85rem;
  }

  .card-body:has(> .card-skip:not([hidden])) > #questionStep,
  .card-body:has(> .card-skip:not([hidden])) > #evaluationStep,
  .card-body:has(> .card-skip:not([hidden])) > #bonusStep {
    grid-column: 1;
    grid-row: 3;
  }

  #questionStep > #showAnswerBtn {
    min-height: 2.4rem;
    padding: 0.25rem 0.9rem;
    font-size: 0.85rem;
  }
}

.pack-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--wood);
  font-weight: bold;
  cursor: pointer;
}

.pack-row input {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--wood);
  flex: none;
}

.pack-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.pack-list[hidden],
.pack-row[hidden] {
  display: none;
}

/* --- Débuter card: pick the team that starts. --- */
.starter-picker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin: 0.6rem 0;
}

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

.starter-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.5rem;
  padding: 0.2rem 0.7rem 0.2rem 0.35rem;
  border: 2px solid var(--paper-edge);
  border-radius: 999px;
  background: #fffaf0;
  color: var(--wood);
  font: inherit;
  font-weight: bold;
  cursor: pointer;
}

.starter-btn.active {
  background: var(--wood);
  border-color: var(--wood-dark);
  color: var(--paper);
}

.starter-token {
  width: 1.9rem;
  height: 1.9rem;
  object-fit: contain;
}

/* --- Extensions block on the dashboard: collapsed until opened. --- */
.ext-box {
  border: 2px solid var(--paper-edge);
  border-radius: 0.8rem;
  background: #fffaf0;
  color: var(--wood);
}

.ext-box[hidden] {
  display: none;
}

.ext-box summary {
  padding: 0.55rem 0.8rem;
  font-weight: bold;
  cursor: pointer;
}

.ext-box[open] summary {
  border-bottom: 1px solid var(--paper-edge);
}

.ext-box > .pack-row,
.ext-box > .pack-list {
  padding: 0.45rem 0.8rem;
}
