/* ===== Base ===================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --felt: #14532d;
  --felt-dark: #0d3a1f;
  --felt-light: #1a6b3a;
  --cream: #fffdf5;
  --ink: #26221c;
  --team-a: #2563eb;
  --team-a-soft: #dbeafe;
  --team-b: #ea580c;
  --team-b-soft: #ffedd5;
  --gold: #fbbf24;
  --danger: #dc2626;
  --radius: 14px;

  /* Matière des dominos (face, tranche, pastilles). */
  --tile-hi: #fffefa;
  --tile-mid: #f7f1e1;
  --tile-lo: #e4d9c0;
  --tile-edge-hi: #cdbf9f;
  --tile-edge-lo: #9c8f74;
  --pip-deep: #16130f;
  --pip-mid: #2e2823;
  --pip-rim: #6b6154;
  --pip-gloss: #ffffff;
  --back-hi: #f0e7d2;
  --back-lo: #cdbf9f;
  --back-edge: #8d8168;
  --back-line: #a6997c;
}

/* ===== Thèmes de table ========================================= */

:root[data-table="wood"] {
  --felt: #6b3f1d;
  --felt-dark: #46280f;
  --felt-light: #8a5527;
  --table-grain:
    repeating-linear-gradient(92deg, rgba(0, 0, 0, .09) 0 3px, transparent 3px 11px),
    repeating-linear-gradient(92deg, rgba(255, 220, 170, .05) 0 1px, transparent 1px 17px);
}
:root[data-table="neon"] {
  --felt: #17103a;
  --felt-dark: #0b0720;
  --felt-light: #2a1b63;
  --gold: #22d3ee;
  --table-grain:
    repeating-linear-gradient(0deg, rgba(34, 211, 238, .05) 0 1px, transparent 1px 26px),
    repeating-linear-gradient(90deg, rgba(232, 121, 249, .05) 0 1px, transparent 1px 26px);
}
:root[data-table="marble"] {
  --felt: #2f3237;
  --felt-dark: #1b1d21;
  --felt-light: #474c54;
  --table-grain:
    repeating-linear-gradient(63deg, rgba(255, 255, 255, .045) 0 2px, transparent 2px 40px),
    repeating-linear-gradient(-47deg, rgba(255, 255, 255, .03) 0 1px, transparent 1px 63px);
}

/* ===== Skins de dominos ======================================== */

:root[data-tiles="bone"], .preview-bone {
  --tile-hi: #f6ecd2;
  --tile-mid: #e8d9b4;
  --tile-lo: #cbb88c;
  --tile-edge-hi: #b8a276;
  --tile-edge-lo: #8a7752;
  --pip-deep: #2a2015;
  --pip-mid: #453422;
  --pip-rim: #7a6647;
  --back-hi: #e2d3ae;
  --back-lo: #bda884;
  --back-edge: #7d6c4c;
  --back-line: #96835e;
}
:root[data-tiles="obsidian"], .preview-obsidian {
  --tile-hi: #4a4f57;
  --tile-mid: #2b3037;
  --tile-lo: #15181d;
  --tile-edge-hi: #5d646e;
  --tile-edge-lo: #0a0c0f;
  --pip-deep: #ffffff;
  --pip-mid: #dfe6ef;
  --pip-rim: #92a0b3;
  --pip-gloss: #1b1f25;
  --back-hi: #3a4048;
  --back-lo: #1d2126;
  --back-edge: #0a0c0f;
  --back-line: #626b78;
}
:root[data-tiles="neon"], .preview-neon {
  --tile-hi: #2c2360;
  --tile-mid: #1b1546;
  --tile-lo: #0e0a2b;
  --tile-edge-hi: #7c3aed;
  --tile-edge-lo: #4c1d95;
  --pip-deep: #a5f3fc;
  --pip-mid: #22d3ee;
  --pip-rim: #0e7490;
  --pip-gloss: #f0abfc;
  --back-hi: #2a2064;
  --back-lo: #140f3a;
  --back-edge: #4c1d95;
  --back-line: #8b5cf6;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    var(--table-grain, none),
    radial-gradient(circle at 50% 30%, var(--felt-light), var(--felt) 60%, var(--felt-dark));
  background-attachment: fixed;
  color: var(--cream);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app { height: 100dvh; display: flex; flex-direction: column; }

.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen[hidden] { display: none; }

/* ===== Cartes / formulaires ==================================== */

.center-card {
  margin: auto;
  width: min(92vw, 420px);
  background: rgba(255, 253, 245, .07);
  border: 1px solid rgba(255, 253, 245, .15);
  border-radius: calc(var(--radius) + 4px);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  backdrop-filter: blur(4px);
}

.logo {
  font-size: 2rem;
  background: linear-gradient(100deg, var(--cream) 20%, var(--gold) 40%, #fff7d6 50%, var(--gold) 60%, var(--cream) 80%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 3.5s linear infinite;
}
@keyframes shimmer {
  0% { background-position: 120% 0; }
  100% { background-position: -80% 0; }
}
.tagline { opacity: .8; margin-bottom: 8px; }
.hint { font-size: .82rem; opacity: .75; }
.error { color: #fecaca; font-weight: 600; font-size: .9rem; }

label { text-align: left; font-size: .85rem; opacity: .85; margin-bottom: -6px; }

input {
  font-size: 1.05rem;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  background: var(--cream);
  color: var(--ink);
  width: 100%;
}
input:focus { outline: none; border-color: var(--gold); }
input.invalid { border-color: var(--danger); animation: shake .3s; }
@keyframes shake { 25% { translate: -4px 0; } 75% { translate: 4px 0; } }

.spinner {
  width: 42px;
  height: 42px;
  margin: 8px auto;
  border-radius: 50%;
  border: 4px solid rgba(255, 253, 245, .2);
  border-top-color: var(--gold);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.join-row { display: flex; gap: 8px; margin-top: 10px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .15em; text-align: center; }

.btn {
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  background: rgba(255, 253, 245, .15);
  color: var(--cream);
  transition: transform .08s, background .15s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); background: rgba(255, 253, 245, .22); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(160deg, #fcd34d, var(--gold) 55%, #d97706);
  color: #442c00;
  box-shadow: 0 4px 14px rgba(251, 191, 36, .3);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(160deg, #fde68a, #fcd34d 55%, var(--gold));
  box-shadow: 0 6px 18px rgba(251, 191, 36, .45);
}
.btn-small { font-size: .85rem; padding: 8px 12px; }

.room-code {
  font-family: ui-monospace, "Cascadia Mono", monospace;
  letter-spacing: .2em;
  background: rgba(0, 0, 0, .25);
  padding: 2px 8px;
  border-radius: 8px;
}
.room-code.small { font-size: .78rem; letter-spacing: .1em; }

/* ===== Lobby ==================================================== */

.lobby-title { font-size: 1.15rem; }
.teams { display: flex; gap: 10px; margin-top: 6px; }
.team {
  flex: 1;
  border-radius: var(--radius);
  padding: 10px;
  text-align: left;
}
.team h3 { font-size: .85rem; margin-bottom: 6px; }
.team-a { background: rgba(37, 99, 235, .25); border: 1px solid var(--team-a); }
.team-b { background: rgba(234, 88, 12, .25); border: 1px solid var(--team-b); }
.seat-line {
  padding: 8px 10px;
  margin: 4px 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, .2);
  font-size: .92rem;
  min-height: 36px;
}
.seat-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.seat-line i { opacity: .5; }
.seat-btn {
  font-size: .78rem;
  font-weight: 700;
  padding: 4px 9px;
  border: none;
  border-radius: 8px;
  background: rgba(251, 191, 36, .22);
  color: var(--gold);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .1s, background .15s;
}
.seat-btn:hover { background: rgba(251, 191, 36, .35); }
.seat-btn:active { transform: scale(.92); }
.seat-btn.del { background: rgba(220, 38, 38, .25); color: #fca5a5; padding: 4px 8px; }

.join-seats { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.seat-chip {
  font-size: .8rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid;
}
.seat-chip.team-0 { border-color: var(--team-a); }
.seat-chip.team-1 { border-color: var(--team-b); }
.seat-chip.free { opacity: .55; font-style: italic; }

/* ===== Table : structure ======================================= */

.screen-table {
  flex-direction: row;
  gap: 10px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.table-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.table-side { display: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
}
.score-pills { flex: 1; text-align: center; }
.pill-btn { background: none; border: none; cursor: pointer; display: inline-flex; gap: 6px; }
.pill {
  font-size: .85rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--cream);
}
.pill-a { background: var(--team-a); }
.pill-b { background: var(--team-b); }

/* La culotte rouge de l'équipe larguée. */
.panty {
  display: inline-block;
  width: 17px;
  height: 12px;
  vertical-align: -1px;
  margin-right: 3px;
  animation: panty-sway 2.2s ease-in-out infinite;
  transform-origin: 50% 0;
}
.panty[hidden] { display: none; }
.panty svg { display: block; width: 100%; height: 100%; }
@keyframes panty-sway {
  0%, 100% { transform: rotate(-9deg); }
  50% { transform: rotate(9deg); }
}

/* Le double-six qui s'abat sur la table. */
.quake { animation: quake .6s cubic-bezier(.36, .07, .19, .97); }
@keyframes quake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  12% { transform: translate(-7px, 5px) rotate(-.7deg); }
  26% { transform: translate(6px, -4px) rotate(.6deg); }
  40% { transform: translate(-5px, 3px) rotate(-.5deg); }
  55% { transform: translate(4px, -2px) rotate(.35deg); }
  70% { transform: translate(-2px, 2px) rotate(-.2deg); }
  85% { transform: translate(1px, -1px) rotate(.1deg); }
}
/* Séisme majeur : l'impact de l'appui-long et de la pierre gagnante. */
.quake-strong { animation: quake-strong .85s cubic-bezier(.36, .07, .19, .97); }
@keyframes quake-strong {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  8% { transform: translate(-16px, 11px) rotate(-1.6deg) scale(1.015); }
  20% { transform: translate(15px, -10px) rotate(1.4deg); }
  33% { transform: translate(-13px, 8px) rotate(-1.1deg); }
  47% { transform: translate(10px, -7px) rotate(.9deg); }
  61% { transform: translate(-7px, 5px) rotate(-.6deg); }
  75% { transform: translate(4px, -3px) rotate(.4deg); }
  88% { transform: translate(-2px, 1px) rotate(-.2deg); }
}
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  position: relative;
  background: rgba(255, 253, 245, .12);
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  padding: 6px 9px;
  cursor: pointer;
  color: var(--cream);
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: rgba(255, 253, 245, .22); }
.icon-btn:active { transform: scale(.92); }

.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--danger);
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 5px;
  min-width: 16px;
  animation: badge-pop .25s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes badge-pop { from { transform: scale(0); } }

.banner {
  background: rgba(0, 0, 0, .45);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: .85rem;
  text-align: center;
  padding: 6px;
  border-radius: 10px;
}

/* ===== Adversaires ============================================= */

.table-area { flex: 1; display: flex; flex-direction: column; min-height: 0; gap: 4px; }
.table-mid { flex: 1; display: flex; min-height: 0; gap: 4px; }

.opponent { display: flex; align-items: center; justify-content: center; }
.opp-top { min-height: 52px; }
.opp-left, .opp-right { width: 62px; flex-shrink: 0; }

.opp-card {
  position: relative;
  border-radius: 12px;
  padding: 6px 8px;
  text-align: center;
  background: rgba(0, 0, 0, .25);
  border: 2px solid transparent;
  font-size: .8rem;
  max-width: 100%;
}
.opp-left .opp-card, .opp-right .opp-card { width: 100%; padding: 8px 4px; }
.opp-card.team-0 { border-color: rgba(37, 99, 235, .55); }
.opp-card.team-1 { border-color: rgba(234, 88, 12, .55); }
.opp-card.is-turn { border-color: var(--gold); animation: glow 1.6s ease-in-out infinite; }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 8px rgba(251, 191, 36, .35); }
  50% { box-shadow: 0 0 20px rgba(251, 191, 36, .7); }
}
.opp-card.is-away { opacity: .55; }

.opp-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
  margin: 0 auto;
}
.opp-team {
  font-size: .62rem;
  vertical-align: middle;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(255, 253, 245, .18);
}
/* Main adverse : de vrais dominos face cachée, bien lisibles et espacés.
   En haut ils sont debout côte à côte, sur les côtés couchés et empilés,
   comme une main tenue face à soi. */
.opp-hand {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin: 4px 0 3px;
}
.opp-top .opp-hand { flex-direction: row; flex-wrap: wrap; }
.opp-left .opp-hand, .opp-right .opp-hand { flex-direction: column; gap: 3px; }

.back-tile {
  display: block;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .45));
}
.opp-top .back-tile { width: 22px; height: 42px; }
.opp-left .back-tile, .opp-right .back-tile { width: 46px; height: 23px; }
.back-tile svg { display: block; width: 100%; height: 100%; }
.tile-back { fill: #ede4cf; stroke: #9c8f74; stroke-width: 4; }
.tile-back-inner { fill: none; stroke: #c3b79a; stroke-width: 4; }
.opp-count {
  font-size: .68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .35);
  vertical-align: middle;
}
.opp-away { font-size: .68rem; color: var(--gold); letter-spacing: 0; }

.turn-dot {
  position: absolute;
  top: -5px; right: -5px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--gold);
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { transform: scale(1.5); opacity: .5; } }

/* ===== Plateau (chaîne) ======================================== */

.board {
  flex: 1;
  min-width: 0;
  position: relative;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 253, 245, .14);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  /* Feutre : grain fin, éclairage doux au centre, vignettage sur les bords. */
  background:
    radial-gradient(ellipse at 50% 38%, rgba(255, 255, 255, .09), transparent 62%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0, 0, 0, .38) 100%),
    repeating-linear-gradient(48deg, rgba(255, 255, 255, .022) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-48deg, rgba(0, 0, 0, .022) 0 2px, transparent 2px 4px),
    rgba(0, 0, 0, .2);
  box-shadow: inset 0 2px 18px rgba(0, 0, 0, .35);
}

.board-empty { margin: auto; opacity: .6; font-size: .85rem; text-align: center; padding: 12px; }

.chain-viewport {
  position: relative;
  margin: auto;
  flex-shrink: 0;
}
.chain {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  transition: transform .35s ease;
}
.chain .tile { position: absolute; }
/* Ombre portée décalée : le domino a l'air posé, avec son épaisseur. */
.chain .tile-svg {
  filter: drop-shadow(0 2px 0 var(--tile-edge-lo)) drop-shadow(0 5px 7px rgba(0, 0, 0, .45));
}

/* Onde de choc au point d'impact. */
.shockwave {
  position: fixed;
  border-radius: 50%;
  border: 3px solid rgba(255, 253, 245, .8);
  pointer-events: none;
  z-index: 43;
  animation: shock .55s cubic-bezier(.2, .7, .3, 1) forwards;
}
.shockwave.boom { border-color: rgba(251, 191, 36, .9); border-width: 5px; }
@keyframes shock {
  0% { transform: translate(-50%, -50%) scale(.15); opacity: .95; }
  100% { transform: translate(-50%, -50%) scale(2.6); opacity: 0; }
}

/* Emplacements jouables, marqués « + », posés à même la table. */
.slot {
  position: absolute;
  border: 3px dashed var(--gold);
  border-radius: 12px;
  background: rgba(251, 191, 36, .14);
  color: var(--gold);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: slot-pulse 1.4s ease-in-out infinite;
}
.slot::after { content: ''; position: absolute; inset: -14px; } /* zone tactile élargie */
.slot-plus { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.slot:hover, .slot:active {
  background: rgba(251, 191, 36, .34);
  animation-play-state: paused;
}
@keyframes slot-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, .45); }
  50% { box-shadow: 0 0 0 9px rgba(251, 191, 36, 0); }
}

/* Domino en vol vers son emplacement. */
.tile-flying .tile-svg { filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .5)); }
.tile-flying.epic .tile-svg {
  filter: drop-shadow(0 26px 40px rgba(0, 0, 0, .65)) drop-shadow(0 0 22px rgba(251, 191, 36, .55));
}

/* Appui long : la pierre grossit petit à petit, de plus en plus haut et
   lumineuse, façon bouton « J'aime » qu'on garde enfoncé. Le second sélecteur
   bat le :hover, qui sinon mettrait la charge en pause. */
.hand-tile.charging,
.hand-tile.playable.charging {
  position: relative;
  /* Croissance régulière (linéaire) : on voit les 3 secondes s'écouler. */
  animation: charging 3s linear forwards;
  animation-play-state: running;
  z-index: 30;
}
@keyframes charging {
  0% { transform: translateY(0) scale(1); filter: none; }
  33% { transform: translateY(-22px) scale(1.45); filter: drop-shadow(0 0 12px rgba(251, 191, 36, .75)); }
  66% { transform: translateY(-46px) scale(1.9); filter: drop-shadow(0 0 22px rgba(249, 115, 22, .92)) brightness(1.15); }
  100% {
    transform: translateY(-72px) scale(2.4);
    filter: drop-shadow(0 0 34px rgba(220, 38, 38, 1)) brightness(1.3);
  }
}
/* Petite trépidation superposée pendant la charge. */
.hand-tile.charging .tile-svg { animation: charging-shake .12s linear infinite; }
@keyframes charging-shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-1.5px, 1px); }
  75% { transform: translate(1.5px, -1px); }
}
/* Explosion au bout des 3 s. */
.hand-tile.gag-blast { animation: gag-blast .6s cubic-bezier(.2, 1.4, .3, 1); z-index: 6; }
@keyframes gag-blast {
  0% { transform: scale(1.5); filter: drop-shadow(0 0 30px rgba(251, 191, 36, 1)) brightness(1.6); }
  40% { transform: scale(.9); }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); filter: none; }
}

/* Éclair blanc plein écran. */
.big-flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 53;
  animation: big-flash .3s ease-out forwards;
}
@keyframes big-flash {
  0% { opacity: calc(var(--flash, .5) * 1); }
  100% { opacity: 0; }
}

/* Fissures de la table. */
.table-crack {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 51;
}
.crack-line {
  fill: none;
  stroke: rgba(0, 0, 0, .7);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, .25));
  animation: crack .95s ease-out forwards;
}
@keyframes crack {
  0% { opacity: 0; stroke-width: 6; }
  15% { opacity: 1; }
  70% { opacity: .9; }
  100% { opacity: 0; stroke-width: 2; }
}

/* Pose d'un domino : il s'écrase à l'atterrissage puis se stabilise. */
.tile-new { animation: tile-land .38s cubic-bezier(.2, 1.5, .35, 1); }
@keyframes tile-land {
  0% { transform: scale(1.16, .82); }
  45% { transform: scale(.96, 1.05); }
  75% { transform: scale(1.02, .99); }
  100% { transform: scale(1); }
}
.tile-new .tile-body { animation: tile-glow 1.2s ease-out; }
@keyframes tile-glow {
  0% { stroke: var(--gold); stroke-width: 10; }
  100% { stroke: #b8ab8d; }
}

.end-badge {
  position: sticky;
  top: 4px;
  z-index: 2;
  align-self: flex-start;
  background: var(--gold);
  color: #442c00;
  font-size: .8rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.end-left { position: absolute; left: 6px; }
.end-right { position: absolute; right: 6px; }

/* ===== Dominos ================================================= */

.tile { flex-shrink: 0; }
.tile-svg { display: block; width: 100%; height: 100%; }

/* Matière du domino : ivoire dégradé, biseau intérieur qui accroche la
   lumière, pastilles creusées avec leur reflet. */
.tile-body {
  fill: url(#tileFace);
  stroke: var(--tile-edge-lo);
  stroke-width: 2.5;
}
.tile-bevel {
  fill: none;
  stroke: var(--tile-hi);
  stroke-width: 2;
  opacity: .55;
}
.tile-divider {
  stroke: var(--tile-edge-lo);
  stroke-width: 3.5;
  stroke-linecap: round;
  opacity: .75;
}
.pip { fill: url(#pipHole); }
.pip-gloss { fill: var(--pip-gloss); opacity: .5; }

.tile-back { fill: url(#tileBackFace); stroke: var(--back-edge); stroke-width: 3; }
.tile-back-inner { fill: none; stroke: var(--back-line); stroke-width: 3.5; opacity: .8; }
.tile-back-core { fill: none; stroke: var(--back-line); stroke-width: 2; opacity: .4; }

.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.chain-end-left .tile-body, .chain-end-right .tile-body { stroke: var(--gold); stroke-width: 6; }

.tile.mini { width: 34px; height: 17px; display: inline-block; vertical-align: middle; margin: 1px; }

/* ===== Compteur de valeurs ===================================== */

.counts {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 2px 0;
}
.count-cell {
  font-size: .68rem;
  background: rgba(0, 0, 0, .3);
  border-radius: 8px;
  padding: 2px 6px;
  display: flex;
  gap: 4px;
  align-items: baseline;
  opacity: .85;
}
.count-cell b { font-size: .78rem; }
.count-cell i { font-style: normal; opacity: .75; }
.count-cell.count-full { background: var(--felt-dark); color: var(--gold); opacity: 1; }
.count-cell.count-full i::after { content: "/7"; opacity: .6; }

/* ===== Ma main ================================================= */

.me-bar { padding: 0 2px; }
.me-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 10px;
  border: 2px solid transparent;
  background: rgba(0, 0, 0, .25);
  padding: 4px 10px;
  font-size: .85rem;
}
.me-card.team-0 { border-color: rgba(37, 99, 235, .55); }
.me-card.team-1 { border-color: rgba(234, 88, 12, .55); }
.me-card.is-turn { border-color: var(--gold); animation: glow 1.6s ease-in-out infinite; }
.me-status { font-size: .78rem; opacity: .9; }

.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 4px 2px 2px;
  min-height: 96px;
}
.hand-tile {
  width: 44px;
  height: 88px;
  transition: transform .15s;
}
.hand-tile.playable {
  cursor: pointer;
  animation: tile-float 1.8s ease-in-out infinite;
}
.hand-tile.playable .tile-body { stroke: var(--gold); stroke-width: 5; }
.hand-tile.playable .tile-svg { filter: drop-shadow(0 6px 10px rgba(251, 191, 36, .35)); }
.hand-tile.playable:hover { transform: translateY(-10px) scale(1.06); animation-play-state: paused; }
.hand-tile.playable:active { transform: translateY(-6px) scale(1.03); }
.hand-tile.dimmed { opacity: .45; filter: grayscale(.6); }

/* Distribution : chaque domino arrive de sous la table, en tournant. */
.hand-tile.deal { animation: deal-in .5s backwards cubic-bezier(.2, .9, .3, 1.1); }
@keyframes deal-in {
  from { transform: translateY(130px) rotate(-22deg) scale(.65); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.hand-tile.selected {
  transform: translateY(-12px) scale(1.08);
  animation: none;
}
.hand-tile.selected .tile-body { stroke: #fff7d6; stroke-width: 7; }
.hand-tile.selected .tile-svg { filter: drop-shadow(0 8px 14px rgba(251, 191, 36, .7)); }
@keyframes tile-float {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -5px; }
}

/* ===== Emotes, avatars, « X écrit… » =========================== */

.emote-bar {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 2px 0;
}
.emote-btn {
  font-size: 1.05rem;
  line-height: 1;
  padding: 4px 7px;
  border: none;
  border-radius: 9px;
  background: rgba(255, 253, 245, .1);
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.emote-btn:hover { background: rgba(255, 253, 245, .22); transform: translateY(-2px) scale(1.12); }
.emote-btn:active { transform: scale(.9); }

/* L'emote jaillit puis s'envole au-dessus de la place de son auteur. */
.emote-fly {
  position: fixed;
  font-size: 2.1rem;
  pointer-events: none;
  z-index: 46;
  transform: translate(-50%, -50%);
  animation: emote-fly 2s cubic-bezier(.2, .8, .3, 1) forwards;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .6));
}
@keyframes emote-fly {
  0% { transform: translate(-50%, -50%) scale(.3) rotate(-16deg); opacity: 0; }
  18% { transform: translate(-50%, -110%) scale(1.35) rotate(6deg); opacity: 1; }
  35% { transform: translate(-50%, -135%) scale(1.05) rotate(-3deg); }
  100% { transform: translate(-50%, -290%) scale(.85); opacity: 0; }
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: .68rem;
  font-weight: 800;
  color: #fff;
  margin-right: 5px;
  vertical-align: -3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}

.typing {
  font-size: .74rem;
  opacity: .7;
  font-style: italic;
  padding: 3px 6px;
}
.typing[hidden] { display: none; }

.round-stats { text-align: left; }
.round-stats[hidden] { display: none; }
.round-stats h3 { font-size: .88rem; margin-bottom: 6px; }
.stats-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.stats-table th, .stats-table td {
  padding: 5px 4px;
  border-bottom: 1px solid rgba(255, 253, 245, .12);
  text-align: left;
}
.stats-table .num { text-align: right; }
.stats-table tr.me { color: var(--gold); font-weight: 700; }

/* ===== Sélecteur d'apparence =================================== */

.theme-label { font-size: .78rem; opacity: .75; margin: 14px 0 8px; font-weight: 600; }
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-opt {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: rgba(255, 253, 245, .08);
  color: var(--cream);
  font-size: .82rem;
  cursor: pointer;
  text-align: left;
  transition: background .15s, transform .1s;
}
.theme-opt:hover { background: rgba(255, 253, 245, .16); }
.theme-opt:active { transform: scale(.97); }
.theme-opt.on { border-color: var(--gold); background: rgba(251, 191, 36, .16); }

.theme-swatch {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, .25);
}
/* Aperçu du domino en CSS pur : les dégradés SVG étant partagés, ils ne
   peuvent pas afficher quatre matières différentes côte à côte. */
.theme-tile {
  width: 22px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 5px;
  background: linear-gradient(160deg, var(--tile-hi), var(--tile-mid) 55%, var(--tile-lo));
  border: 1.5px solid var(--tile-edge-lo);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.theme-tile i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pip-mid);
}

/* ===== Annonce plein écran ===================================== */

.shout {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 55;
}
.shout[hidden] { display: none; }
.shout span {
  font-size: clamp(2.6rem, 13vw, 6rem);
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 4px 0 #8a5a00, 0 10px 30px rgba(0, 0, 0, .7);
  animation: shout-in 1.5s cubic-bezier(.2, 1.5, .3, 1) forwards;
}
@keyframes shout-in {
  0% { transform: scale(.2) rotate(-14deg); opacity: 0; }
  22% { transform: scale(1.15) rotate(3deg); opacity: 1; }
  35% { transform: scale(1) rotate(0); }
  75% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* ===== Tiroirs (journal, scores) =============================== */

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  justify-content: flex-end;
  z-index: 30;
}
.drawer[hidden] { display: none; }
.drawer-inner {
  width: min(85vw, 340px);
  background: var(--felt-dark);
  border-left: 1px solid rgba(255, 253, 245, .2);
  display: flex;
  flex-direction: column;
  padding: 14px;
  overflow: hidden;
  animation: slide-in .22s ease-out;
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

.log-list {
  overflow-y: auto;
  flex: 1;
  list-style: none;
  font-size: .88rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.log-list li { background: rgba(255, 253, 245, .08); border-radius: 8px; padding: 6px 10px; }
.log-list li.log-pass { opacity: .6; font-style: italic; }

/* ===== Chat ==================================================== */

.chat-list {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 4px 2px;
}
.chat-empty { margin: auto; }
.chat-msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 92%; }
.chat-msg.mine { align-self: flex-end; align-items: flex-end; }
.chat-author { font-size: .68rem; font-weight: 700; opacity: .85; padding: 0 6px 1px; }
.chat-author.team-0 { color: #93c5fd; }
.chat-author.team-1 { color: #fdba74; }
.chat-bubble {
  background: rgba(255, 253, 245, .12);
  border-radius: 12px 12px 12px 4px;
  padding: 6px 11px;
  font-size: .88rem;
  word-break: break-word;
  animation: bubble-pop .2s cubic-bezier(.2, 1.4, .4, 1);
}
.chat-msg.mine .chat-bubble {
  background: rgba(251, 191, 36, .22);
  border-radius: 12px 12px 4px 12px;
}
@keyframes bubble-pop { from { transform: scale(.7); opacity: 0; } }

.chat-form { display: flex; gap: 6px; margin-top: 8px; }
.chat-form input { flex: 1; font-size: .92rem; padding: 9px 12px; }
.btn-send { padding: 8px 14px; background: var(--gold); color: #442c00; flex-shrink: 0; }

/* ===== Tableau des scores ====================================== */

.score-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.score-table th, .score-table td { padding: 6px 4px; border-bottom: 1px solid rgba(255, 253, 245, .12); text-align: left; }
.score-table .num { text-align: right; }
.score-table small { opacity: .65; font-weight: 400; }

/* ===== Overlays ================================================ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.overlay-light { background: rgba(0, 0, 0, .35); z-index: 60; }
.overlay-card {
  margin: auto;
  width: min(92vw, 430px);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--felt-dark);
  border: 1px solid rgba(255, 253, 245, .25);
  border-radius: 18px;
  padding: 22px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: card-pop .3s cubic-bezier(.2, 1.4, .4, 1);
  position: relative;
  z-index: 1;
}
@keyframes card-pop { from { transform: scale(.85) translateY(20px); opacity: 0; } }

/* ===== Confettis =============================================== */

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.confetti-piece {
  position: absolute;
  top: -24px;
  display: block;
  border-radius: 3px;
  opacity: 0;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(105vh) translateX(var(--drift, 0)) rotate(740deg); opacity: .85; }
}

.round-hands { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.reveal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 253, 245, .06);
  border-radius: 10px;
  padding: 4px 8px;
}
.reveal-name {
  width: 84px;
  flex-shrink: 0;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reveal-name.team-0 { color: #93c5fd; }
.reveal-name.team-1 { color: #fdba74; }
.reveal-tiles { display: flex; flex-wrap: wrap; align-items: center; font-size: .8rem; }
.round-scores { display: flex; justify-content: center; align-items: center; gap: 8px; }

/* ===== Écrans plus larges ====================================== */

@media (min-width: 700px) {
  .hand-tile { width: 54px; height: 108px; }
  .opp-left, .opp-right { width: 96px; }
  .opp-name { max-width: 100%; }
}

/* ===== Écran large (PC) : panneau latéral permanent ============ */

@media (min-width: 950px) {
  .screen-table { padding: 10px; max-width: 1400px; margin: 0 auto; width: 100%; }
  .table-side {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 310px;
    flex-shrink: 0;
    min-height: 0;
  }
  .side-block {
    background: rgba(0, 0, 0, .25);
    border: 1px solid rgba(255, 253, 245, .15);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .side-block h3 { font-size: .9rem; margin-bottom: 8px; opacity: .85; }
  .side-block-log { flex: 1; }
  .side-block-log .log-list { flex: 1; min-height: 0; }
  .side-block-chat { flex: 1.2; min-height: 180px; }
  .side-block-chat .chat-list { min-height: 0; }
  #btn-chat { display: none; }

  /* Les tiroirs mobiles deviennent inutiles. */
  #btn-log { display: none; }
  .pill-btn { pointer-events: none; }

  .hand-tile { width: 62px; height: 124px; }
  .hand { min-height: 132px; }
  .opp-top { min-height: 60px; }
  .opp-card { font-size: .9rem; padding: 8px 14px; }
  .opp-top .back-tile { width: 30px; height: 58px; }
  .opp-left .back-tile, .opp-right .back-tile { width: 62px; height: 31px; }
  .me-card { font-size: .95rem; padding: 6px 14px; }
  .counts { gap: 8px; }
  .count-cell { font-size: .78rem; padding: 3px 9px; }
  .end-badge { font-size: .95rem; }
}

/* ===== Retour au menu des jeux ================================= */

.back-link {
  margin-top: 4px;
  font-size: .82rem;
  opacity: .7;
  color: var(--cream);
  text-decoration: none;
}
.back-link:hover { opacity: 1; color: var(--gold); }
