/* Mise en page : une table de feutre plein écran ; joueurs en haut, pli au centre, main en bas. */
:root {
  --felt: #123f35;
  --felt-deep: #0b2b24;
  --felt-line: rgba(255, 255, 255, .10);
  --chip: rgba(0, 0, 0, .24);
  --text: #eef3ea;
  --muted: #a9c0b4;
  --ivory: #fbf6ea;
  --ivory-edge: #d9cfb8;
  --ink: #1c1b18;
  --red: #c0342a;
  --gold: #e2b04d;
  --gold-ink: #7a5410;
  --turn: #f4d27a;
  --good: #8fdc9a;
  --bad: #ff9a8a;
  --display: "Young Serif", Georgia, "Times New Roman", serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  --cw: 64px;
  background: radial-gradient(120% 80% at 50% 35%, var(--felt) 0%, var(--felt-deep) 100%) fixed, var(--felt-deep);
  color: var(--text);
  font: 15px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; text-wrap: balance; margin: 0; }
:focus-visible { outline: 2px solid var(--turn); outline-offset: 2px; }
[hidden] { display: none !important; }

#app {
  min-height: 100%;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
}

/* ---------- Boutons & champs ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  padding: 12px 18px; border-radius: 12px;
  background: var(--ivory); color: var(--ink);
  font-weight: 700; font-size: 15px; letter-spacing: .01em;
  box-shadow: 0 2px 0 var(--ivory-edge), 0 6px 16px rgba(0,0,0,.25);
  transition: transform .08s ease;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.gold { background: var(--gold); color: #2b1d02; box-shadow: 0 2px 0 #a9802f, 0 6px 16px rgba(0,0,0,.25); }
.btn.ghost { background: var(--chip); color: var(--text); box-shadow: inset 0 0 0 1px var(--felt-line); }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.field {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--felt-line); background: rgba(0,0,0,.28); color: var(--text);
  font: 16px var(--body);
}
.field::placeholder { color: var(--muted); }
label.lbl { display: block; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.err { color: var(--bad); min-height: 1.4em; font-size: 14px; }
.muted { color: var(--muted); }

/* ---------- Accueil ---------- */
.home { width: 100%; max-width: 460px; margin: 0 auto; padding-block: 28px 40px; display: flex; flex-direction: column; gap: 22px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.hero-cards { display: flex; justify-content: center; height: 150px; position: relative; width: 220px; margin-top: 14px; }
.hero-cards .card { position: absolute; top: 10px; --cw: 72px; transform-origin: 50% 120%; }
.hero h1 { font-size: clamp(34px, 9vw, 46px); line-height: 1.05; }
.hero p { margin: 0; color: var(--muted); max-width: 34ch; }
.panel { background: rgba(0,0,0,.22); border: 1px solid var(--felt-line); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .field { flex: 1; min-width: 0; }
details.rules { background: rgba(0,0,0,.16); border-radius: 14px; padding: 12px 16px; border: 1px solid var(--felt-line); }
details.rules summary { cursor: pointer; font-weight: 600; }
details.rules ul { padding-left: 18px; margin: 10px 0 2px; color: var(--muted); display: grid; gap: 6px; }
details.rules b { color: var(--text); font-weight: 600; }

/* ---------- Salon ---------- */
.lobby { width: 100%; max-width: 520px; margin: 0 auto; padding-block: 22px 40px; display: flex; flex-direction: column; gap: 18px; }
.code-big { font-family: var(--display); font-size: 34px; letter-spacing: .14em; }
.linkbox { display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,.3); border-radius: 12px; padding: 8px 8px 8px 12px; }
.linkbox code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); user-select: all; }
.plist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.plist li .ctl { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.plist li { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-width: 0; padding: 10px 12px; border-radius: 12px; background: rgba(0,0,0,.2); }
.plist li .nm { flex: 1 1 6em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tag { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,.1); color: var(--muted); white-space: nowrap; }
.tag.gold { background: var(--gold); color: #2b1d02; }
select.lvl { font: 600 13px/1 var(--body); color: var(--text); background: var(--chip); border: 1px solid var(--felt-line); border-radius: 10px; padding: 8px 26px 8px 10px; min-height: 36px;
  appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 13px center, right 8px center; background-size: 5px 5px; background-repeat: no-repeat; }
.addbots { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.addbots .lbl { width: 100%; margin: 0; }
.addbots .btn { flex: 1 1 0; min-width: 0; padding-left: 6px; padding-right: 6px; }
.lvl-help { font-size: 12.5px; color: var(--muted); margin: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--ivory); color: var(--felt); flex: none; }

/* ---------- Jeu ---------- */
.game { flex: 1; display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 900px; margin: 0 auto; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding-top: 8px; }
.brand { font-family: var(--display); font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { font-family: var(--body); color: var(--muted); font-size: 12px; letter-spacing: .1em; margin-left: 6px; }
/* Les autres joueurs : une rangée au-dessus du tapis, de gauche à droite comme autour de la table */
.seats { display: flex; gap: 6px; justify-content: center; padding-top: 6px; }
.seat {
  display: flex; flex-direction: column; gap: 2px; align-items: center;
  min-width: 0; flex: 1 1 0; max-width: 170px;
  padding: 7px 8px; border-radius: 12px; background: var(--chip);
  border: 1px solid transparent; position: relative;
}
.seat.turn { border-color: var(--turn); box-shadow: 0 0 0 3px rgba(244,210,122,.18); }
.seat .nm { font-weight: 700; font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; font-variant-numeric: tabular-nums; }
.seat .role { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; background: rgba(255,255,255,.12); }
.seat .role.taker { background: var(--gold); color: #2b1d02; }
.seat .role.partner { background: var(--ivory); color: var(--felt); }
.dealer { position: absolute; top: -6px; right: -4px; width: 18px; height: 18px; border-radius: 50%; background: var(--ivory); color: var(--felt); font-size: 10px; font-weight: 800; display: grid; place-items: center; }

.contract { text-align: center; font-size: 13px; color: var(--muted); min-height: 1.3em; }
.contract b { color: var(--gold); font-weight: 700; }
.center { flex: 1; min-height: 190px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.status { font-family: var(--display); font-size: clamp(19px, 5vw, 24px); text-align: center; }
.status.me { color: var(--turn); }
.sub { color: var(--muted); font-size: 13px; text-align: center; }
.trick { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; min-height: calc(var(--tw) * 1.74 + 22px); --tw: clamp(54px, 15vw, 86px); }
.trick .slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.trick .slot.new { animation: drop .22s ease-out; }
.trick .slot .who { font-size: 12px; color: var(--muted); max-width: var(--tw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trick .slot.win .who { color: var(--turn); font-weight: 700; }
.trick .slot.win .card { box-shadow: 0 0 0 3px var(--turn), 0 8px 18px rgba(0,0,0,.35); }
.trick .card { --cw: var(--tw); }
@keyframes drop { from { transform: translateY(-14px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 46px; align-items: center; }

.hand-wrap { padding-top: 14px; padding-bottom: 10px; }
.trick.chien { --tw: clamp(42px, 12.6vw, 80px); gap: 6px; }
.hand { display: flex; flex-direction: column; align-items: center; gap: 6px; --cw: clamp(54px, 15.6vw, 80px); }
.hand .hrow { display: flex; justify-content: center; }
.hand .hrow .card + .card { margin-left: calc(var(--cw) * -0.38); }
.hand .card { transition: transform .12s ease, opacity .12s ease; cursor: pointer; }
.hand .card.sel { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--turn), 0 10px 20px rgba(0,0,0,.4); }
.hand .card.off { filter: brightness(.55) saturate(.6); cursor: default; }
.hand .card.fromchien { box-shadow: 0 0 0 2.5px var(--gold), 0 6px 14px rgba(0,0,0,.3); }
.hand .card.fromchien::after { content: "chien"; position: absolute; left: calc(var(--cw) * .04); bottom: calc(var(--cw) * .05); font: 700 calc(var(--cw) * .15)/1.3 var(--body); letter-spacing: .04em; padding: 0 calc(var(--cw) * .05); border-radius: 4px; background: var(--gold); color: #2b1d02; }
.hand .card.arrive { animation: arrive .45s ease-out; }
@keyframes arrive { from { transform: translateY(-40px) scale(.9); opacity: .2; } to { transform: none; opacity: 1; } }
.trick .slot.empty { width: var(--tw); height: calc(var(--tw) * 1.74); border: 2px dashed rgba(255,255,255,.22); border-radius: calc(var(--tw) * .09); }
.trick .slot button.card { cursor: pointer; }
.hand .card.picked { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--bad), 0 10px 20px rgba(0,0,0,.4); }

/* ---------- La table : joueurs autour du tapis, pli au milieu ---------- */
.statusbar { text-align: center; min-height: 2.2em; display: flex; flex-direction: column; justify-content: center; }
.felt {
  /* Hauteur calculée pour que le pli tienne en entier sur le tapis, sans rien par-dessus */
  position: relative; --tw: clamp(50px, 14vw, 84px); height: calc(var(--tw) * 3.84 + 40px);
  --x-me: 0px; --y-me: calc(var(--tw) * 1);
  --x-left: calc(var(--tw) * -1.9); --y-left: calc(var(--tw) * -.25);
  --x-right: calc(var(--tw) * 1.9); --y-right: calc(var(--tw) * -.25);
  --x-top: 0px; --y-top: calc(var(--tw) * -1.05);
  --x-top-left: calc(var(--tw) * -.8); --y-top-left: calc(var(--tw) * -1.05);
  --x-top-right: calc(var(--tw) * .8); --y-top-right: calc(var(--tw) * -1.05);
}
.felt::before {
  content: ""; position: absolute; inset: 1% 1%; border-radius: 50% / 46%;
  background: radial-gradient(ellipse at 50% 45%, rgba(255,255,255,.07), rgba(0,0,0,.14) 72%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.07), inset 0 12px 40px rgba(0,0,0,.28);
}
.game.big-hand .felt { --tw: clamp(46px, 12.5vw, 80px); }
.seat .botmark { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.tc { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) translate(var(--x), var(--y)); display: flex; flex-direction: column; align-items: center; gap: 3px; z-index: 1; }
.tc .card { --cw: var(--tw); }
.tc .who { font-size: 11.5px; color: var(--muted); max-width: calc(var(--tw) * 1.3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc.win .card { box-shadow: 0 0 0 3px var(--turn), 0 8px 18px rgba(0,0,0,.35); }
.tc.win .who { color: var(--turn); font-weight: 700; }
.tc.new { animation: fly .34s cubic-bezier(.2, .8, .3, 1); }
@keyframes fly { from { transform: translate(-50%, -50%) translate(calc(var(--x) * 2.4), calc(var(--y) * 2.4)) scale(.85); opacity: .25; } }
.tc.collect { animation: collect .55s ease-in 2.5s forwards; }
@keyframes collect { to { transform: translate(-50%, -50%) translate(calc(var(--wx) * 2.3), calc(var(--wy) * 2.3)) scale(.55); opacity: 0; } }
.felt .midrow { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); display: flex; gap: 6px; justify-content: center; z-index: 1; }
.felt .midrow .slot { display: flex; flex-direction: column; align-items: center; }
.felt .midrow .card { --cw: var(--mw, var(--tw)); }
.felt .midrow .card.mini { --cw: 36px; }
.felt .midrow .cards-row { flex-wrap: nowrap; }
.felt .midrow.chien { --mw: clamp(40px, 12.4vw, 78px); }
.felt .midrow .slot.empty { width: var(--mw); height: calc(var(--mw) * 1.74); border: 2px dashed rgba(255,255,255,.22); border-radius: calc(var(--mw) * .09); }
.felt .midrow button.card { cursor: pointer; }
.felt .hint { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center; color: var(--muted); font-size: 13px; }
.bubble {
  position: absolute; z-index: 5; left: 50%; top: calc(100% + 4px); transform: translateX(-50%);
  background: var(--ivory); color: var(--ink); font-weight: 700; font-size: 13px; white-space: nowrap;
  padding: 5px 10px; border-radius: 12px; box-shadow: 0 8px 18px rgba(0,0,0,.35); animation: pop .25s ease-out;
}
.bubble::before { content: ""; position: absolute; left: 50%; top: -5px; width: 10px; height: 10px; background: var(--ivory); transform: translateX(-50%) rotate(45deg); }
.bubble.me { top: auto; bottom: 2px; }
.bubble.me::before { top: auto; bottom: -5px; }
@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } }
.reacts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 12px; background: rgba(0,0,0,.2); }
.opt-row .lab { display: flex; flex-direction: column; min-width: 0; }
.opt-row .lab small { color: var(--muted); font-size: 12.5px; }
.switch { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: rgba(255,255,255,.18); position: relative; cursor: pointer; flex: none; border: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--ivory); transition: left .15s ease; }
.switch[aria-checked="true"] { background: var(--gold); }
.switch[aria-checked="true"]::after { left: 21px; }
.stats td:first-child { color: var(--text) !important; font-weight: 600; }
.tables-list { display: grid; gap: 8px; }
.tables-list button { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; }
@media (min-width: 700px) {
  .felt { --tw: 88px; }
}

/* ---------- Cartes (Tarot Nouveau, Grimaud 1898, domaine public) ---------- */
.card {
  width: var(--cw); height: calc(var(--cw) * 1.74);
  border-radius: calc(var(--cw) * .09);
  background: var(--ivory); color: var(--ink);
  border: 1px solid var(--ivory-edge);
  box-shadow: 0 1px 0 rgba(0,0,0,.2), 0 6px 14px rgba(0,0,0,.28);
  position: relative; flex: none; padding: 0; overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  display: block;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.card .corner {
  position: absolute; top: calc(var(--cw) * .04); left: calc(var(--cw) * .04);
  min-width: calc(var(--cw) * .34); padding: 0 calc(var(--cw) * .04);
  font: 700 calc(var(--cw) * .2)/1.25 var(--body); text-align: center; letter-spacing: -.02em;
  background: rgba(251, 246, 234, .94); color: var(--ink);
  border-radius: calc(var(--cw) * .06); box-shadow: 0 0 0 1px rgba(0,0,0,.12);
  font-variant-numeric: tabular-nums;
}
.card.red .corner { color: var(--red); }
.card.trump .corner { background: rgba(242, 222, 170, .96); color: var(--gold-ink); }
.card.back { border-color: #8a7f6a; }
.card.mini { --cw: 40px; }
.card.mini .corner { display: none; }
.cards-row { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }

/* ---------- Feuilles ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(4, 16, 13, .62); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet-bg.anim { animation: fade .15s ease-out; }
.sheet-bg.anim .sheet { animation: up .2s ease-out; }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  background: #173f36; border: 1px solid var(--felt-line); border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 14px;
}
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 20px; border-bottom: 1px solid var(--felt-line); } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet > * { flex-shrink: 0; }
.sheet h2 { font-size: 24px; }
.verdict { font-family: var(--display); font-size: 28px; }
.btn.danger { background: #c94a3d; color: #fff6f2; box-shadow: 0 2px 0 #8f2e25, 0 6px 16px rgba(0,0,0,.25); }
@media (max-width: 420px) {
  .brand small { display: none; }
  .brand { font-size: 15px; }
  .topbar { gap: 5px; }
  .topbar .btn.small { padding: 7px 9px; font-size: 12.5px; }
}
.game { min-width: 0; overflow-x: hidden; }
.verdict.good { color: var(--good); } .verdict.bad { color: var(--bad); }
.calc { background: rgba(0,0,0,.22); border-radius: 12px; padding: 12px 14px; display: grid; gap: 4px; font-variant-numeric: tabular-nums; }
.calc div { display: flex; justify-content: space-between; gap: 12px; }
.calc div span:first-child { color: var(--muted); }
.table-wrap { overflow-x: auto; }
table.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
table.scores th, table.scores td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--felt-line); white-space: nowrap; }
table.scores th:first-child, table.scores td:first-child { text-align: left; color: var(--muted); }
table.scores thead th { font-weight: 700; color: var(--text); max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
table.scores tfoot td { font-weight: 800; color: var(--text); border-bottom: 0; font-size: 15px; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ivory); color: var(--ink); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 40; box-shadow: 0 10px 24px rgba(0,0,0,.35); max-width: calc(100% - 32px); text-align: center; }
.log { font-size: 12.5px; color: var(--muted); text-align: center; display: grid; gap: 2px; }

@media (min-width: 700px) {
  .hand { --cw: 86px; }
  .hand .hrow .card + .card { margin-left: calc(var(--cw) * -0.42); }
  .trick { --tw: 92px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

