/* Jeux de table (public/js/tables.js) et bornes d'arcade (public/js/arcade.js). Mêmes jetons que
   app.css : verre, rayons concentriques, typographie à la manière d'Apple ; les scènes de jeu sont
   en pixel art, agrandies sans lissage. */

/* --- Fenêtre des jeux de table ------------------------------------------------------------ */

.modal.table-game {
  width: min(760px, 100%);
  gap: 14px;
}
.tg-rules {
  font-size: var(--fs-sub);
  color: var(--text-2);
  background: var(--fill);
  border-radius: var(--r-lg);
  padding: 8px 14px;
  line-height: 1.45;
}
.tg-rules p {
  margin: 6px 0;
}

.tg-board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}
.tg-player {
  --side: var(--accent);
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 12px 8px 14px;
  border-radius: var(--r-lg);
  background: var(--fill);
  transition: background var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.tg-player::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--side);
}
.tg-board > .tg-player:last-child {
  flex-direction: row-reverse;
  text-align: right;
  padding: 8px 14px 8px 12px;
}
.tg-board > .tg-player:last-child::before {
  left: auto;
  right: 0;
  border-radius: 3px 0 0 3px;
}
.tg-player.me {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--side) 60%, transparent);
}
.tg-player.turn {
  background: color-mix(in srgb, var(--side) 14%, var(--fill));
}
.tg-player.empty {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--hairline);
}
.tg-player.empty::before {
  opacity: 0.35;
}
/* Déconnecté, sa place gardée une minute : son avatar pâlit. */
.tg-player.away .tg-avatar {
  opacity: 0.45;
  filter: grayscale(1);
}
.tg-avatar {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--text-3);
  background: color-mix(in srgb, var(--side) 16%, var(--glass-strong));
}
.tg-avatar canvas {
  margin-top: 6px;
}
.tg-avatar .ic svg {
  width: 18px;
  height: 18px;
  display: block;
}
.tg-who {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.tg-who b {
  font-size: var(--fs-body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tg-who span {
  font-size: var(--fs-footnote);
  color: var(--text-3);
}
.tg-score {
  margin-left: auto;
  font: 700 var(--fs-display) / 1 var(--font);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.tg-board > .tg-player:last-child .tg-score {
  margin-left: 0;
  margin-right: auto;
}
.tg-player.won .tg-score {
  color: var(--side);
}
.tg-middle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 92px;
}
.tg-vs,
.tg-series small {
  font-size: var(--fs-caption);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.tg-series {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
.tg-series b {
  font-size: var(--fs-headline);
  font-variant-numeric: tabular-nums;
}
.tg-mode {
  font-size: var(--fs-sub);
  font-weight: 600;
  color: var(--text-2);
}

/* Terrains : jusqu'à quatre joueurs sur une rangée. */
.tg-players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.tg-players .tg-score {
  font-size: var(--fs-title-lg);
}

.tg-stage {
  position: relative;
  width: 100%;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #4c4382;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.tg-stage.tg-morpion {
  background: none;
  box-shadow: none;
  overflow: visible;
}
/* Deux pixels d'écran par pixel du jeu (quatre sur un écran Retina) : des pixels nets. */
.tg-canvas {
  display: block;
  width: min(100%, 672px);
  height: auto;
  max-height: calc(100vh - 340px);
  margin: 0 auto;
  object-fit: contain;
  image-rendering: pixelated;
}

.tg-babyfoot .tg-canvas,
.tg-pingpong .tg-canvas {
  cursor: row-resize;
  touch-action: none;
}

/* Grand message sur la table : compte à rebours, but, point, vainqueur. */
.tg-banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}
.tg-banner.show {
  opacity: 1;
}
.tg-banner b {
  font: 800 34px / 1.05 var(--font);
  letter-spacing: -0.02em;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.28),
    0 8px 28px rgba(0, 0, 0, 0.4);
}
.tg-banner.show b {
  animation: tg-pop 0.5s var(--ease-spring) both;
}
.tg-banner .tg-count {
  font-size: 72px;
}
.tg-banner span,
.tg-banner em {
  font: 600 var(--fs-sub) / 1.2 var(--font);
  font-style: normal;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  background: rgba(22, 15, 40, 0.58);
  -webkit-backdrop-filter: var(--glass-blur, blur(12px) saturate(1.6));
  backdrop-filter: var(--glass-blur, blur(12px) saturate(1.6));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
/* Sans l'effet verre (app.css) : plus sombres, le jeu ne s'efface plus derrière. */
:root[data-glass="off"] .tg-banner span,
:root[data-glass="off"] .court-modes {
  background: rgba(22, 15, 40, 0.82);
}
.tg-banner em {
  background: rgba(224, 169, 46, 0.85);
  color: #2a1c00;
}
.tg-banner.red b {
  color: #ffe1dd;
}
.tg-banner.blue b {
  color: #e0e9ff;
}
.tg-banner.gold b {
  color: #ffd64a;
  font-size: 44px;
}
.tg-banner.soft {
  place-content: end center;
  padding-bottom: 14px;
}
@keyframes tg-pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

.tg-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  flex-wrap: wrap;
}
.tg-foot .activity-status {
  flex: 1;
  min-width: 220px;
  text-align: left;
}
.tg-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: var(--fs-footnote);
  color: var(--text-3);
}

/* Pétanque : pointer ou tirer, posé sur la piste. */
.court-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
}
.court-modes {
  background: rgba(20, 14, 36, 0.55);
  -webkit-backdrop-filter: var(--glass-blur, blur(12px) saturate(1.6));
  backdrop-filter: var(--glass-blur, blur(12px) saturate(1.6));
}
.court-modes button {
  color: rgba(255, 255, 255, 0.75);
}
.court-modes button.active {
  color: var(--text);
}
.court-canvas {
  cursor: crosshair;
  touch-action: none;
}

/* --- Morpion : un plateau net, des symboles épais ----------------------------------------- */

.morpion-wrap {
  position: relative;
  width: min(100%, 360px);
  margin: 0 auto;
}
.morpion-wrap:has(.big) {
  width: min(100%, 460px);
}
.morpion-grid {
  --n: 3;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n), minmax(0, 1fr));
  gap: 8px;
  aspect-ratio: 1;
  padding: 8px;
  border-radius: var(--r-xl);
  background: var(--fill-2);
}
.morpion-grid.big {
  gap: 3px;
  padding: 6px;
  border-radius: var(--r-lg);
}
.morpion-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: var(--glass-strong);
  box-shadow: 0 1px 2px rgba(31, 23, 53, 0.08);
  cursor: default;
  transition:
    background var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform var(--dur-press) var(--ease-out);
}
.morpion-grid.big .morpion-cell {
  border-radius: 5px;
  box-shadow: none;
}
.morpion-cell.playable {
  cursor: pointer;
}
.morpion-cell.playable:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--glass-strong));
}
.morpion-cell.playable:active {
  transform: scale(0.94);
}
.morpion-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.morpion-cell.last {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 50%, transparent);
}
.morpion-cell.win {
  background: color-mix(in srgb, #ffd23f 34%, var(--glass-strong));
}
.morpion-cell .mark {
  width: 66%;
  height: 66%;
  fill: none;
  stroke-width: 5.5;
  stroke-linecap: round;
  overflow: visible;
  transition:
    opacity var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out);
}
.morpion-grid.big .mark {
  width: 80%;
  height: 80%;
  stroke-width: 6.5;
}
.mark.cross {
  stroke: #3e63dd;
}
.mark.nought {
  stroke: #e5484d;
}
:root[data-theme="dark"] .mark.cross {
  stroke: #86a0ff;
}
:root[data-theme="dark"] .mark.nought {
  stroke: #ff7d84;
}
.mark.fresh path {
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: ink 0.26s ease-out forwards;
}
.mark.fresh path + path {
  animation-delay: 0.12s;
}
/* Express : le pion qui s'effacera au prochain coup pâlit. */
.morpion-cell.fade .mark {
  opacity: 0.3;
  transform: scale(0.84);
}
.mark.gone {
  position: absolute;
  width: 66%;
  height: 66%;
  animation: gone 0.5s ease-out forwards;
}
.morpion-line {
  position: absolute;
  inset: 8px;
  width: calc(100% - 16px);
  height: calc(100% - 16px);
  pointer-events: none;
  overflow: visible;
}
.morpion-wrap:has(.big) .morpion-line {
  inset: 6px;
  width: calc(100% - 12px);
  height: calc(100% - 12px);
}
.morpion-line line {
  stroke-width: 0.16;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  opacity: 0.9;
  animation: ink 0.45s 0.1s ease-out forwards;
}
@keyframes ink {
  to {
    stroke-dashoffset: 0;
  }
}
@keyframes gone {
  to {
    opacity: 0;
    transform: scale(1.3);
    filter: blur(2px);
  }
}

/* --- Bornes d'arcade ----------------------------------------------------------------------- */

.modal.arcade {
  width: min(820px, 100%);
  gap: 14px;
}
.arcade-tabs {
  min-width: 0;
}
.arcade-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 14px;
  align-items: start;
}
.arcade-cabinet {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--r-xl);
  color: #fff;
  background: linear-gradient(180deg, #2d2454, #18132f);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 18px 40px -22px rgba(20, 10, 50, 0.7);
}
.arcade-marquee {
  padding: 8px 12px 9px;
  border-radius: var(--r-md);
  text-align: center;
  background: radial-gradient(120% 150% at 50% 0%, #ff86cf 0%, #8a4fd2 42%, #2d2454 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    0 0 26px -8px rgba(255, 134, 207, 0.7);
}
.arcade-marquee b {
  display: block;
  font: 800 20px / 1.1 var(--font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow:
    0 0 12px rgba(255, 255, 255, 0.55),
    0 2px 0 rgba(0, 0, 0, 0.3);
}
.arcade-marquee span {
  font-size: var(--fs-footnote);
  opacity: 0.85;
}
.arcade-screen {
  position: relative;
  padding: 10px;
  border-radius: 14px;
  background: #0b0816;
  box-shadow:
    inset 0 0 0 2px #3b3566,
    inset 0 0 30px rgba(0, 0, 0, 0.85);
}
/* Lignes de balayage, très légères, comme un vieil écran. */
.arcade-screen::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 6px;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.13) 0 1px, transparent 1px 3px);
}
/* 192 × 160 pixels de jeu, deux fois et demie : cinq pixels d'écran Retina par pixel. */
.arcade-canvas {
  display: block;
  width: min(100%, 480px);
  height: auto;
  margin: 0 auto;
  aspect-ratio: 192 / 160;
  border-radius: 6px;
  image-rendering: pixelated;
  cursor: pointer;
  touch-action: none;
}
.arcade-keys {
  justify-content: center;
  color: rgba(255, 255, 255, 0.72);
}
.arcade-keys kbd {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}
.arcade-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.arcade-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--r-lg);
  background: var(--fill);
}
.arcade-card small {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-caption);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.arcade-card small .ic svg {
  display: block;
  width: 13px;
  height: 13px;
}
.arcade-card.best {
  background: color-mix(in srgb, #e0a92e 14%, var(--fill));
}
.arcade-card.best small .ic {
  color: #e0a92e;
}
.arcade-card > b {
  font: 700 var(--fs-display) / 1.05 var(--font);
  font-variant-numeric: tabular-nums;
}
.arcade-card > span {
  font-size: var(--fs-sub);
  color: var(--text-2);
}
.arcade-card ol {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}
.arcade-card li {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: baseline;
  padding: 3px 6px;
  border-radius: var(--r-xs);
  font-size: var(--fs-sub);
}
.arcade-card li i {
  font-style: normal;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.arcade-card li span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.arcade-card li b {
  font-variant-numeric: tabular-nums;
}
.arcade-card li.me {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
@media (max-width: 760px) {
  .arcade-body {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mark.fresh path,
  .morpion-line line {
    animation: none;
    stroke-dashoffset: 0;
  }
  .tg-banner.show b {
    animation: none;
  }
}
