:root {
  --bg: #07110c;
  --panel: #0f1f17;
  --panel-2: #152a20;
  --line: #24453a;
  --text: #eef5f0;
  --muted: #9bb5a8;
  --gold: #f2b544;
  --gold-ink: #1d1404;
  --felt: #0d5a32;
  --felt-dark: #073a20;
  --red: #c9302c;
  --card-w: 64px;
  --card-h: 92px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
[hidden] { display: none !important; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.brand { color: var(--gold); font-weight: 800; letter-spacing: 2px; text-decoration: none; }
.me { display: flex; gap: 10px; align-items: center; }
.chip {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); font-size: 0.85rem;
}

.view { max-width: 1100px; margin: 0 auto; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.narrow { max-width: 420px; margin: 40px auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
h1 { font-size: 1.4rem; margin: 0 0 6px; }
h2 { font-size: 1rem; margin: 18px 0 8px; color: var(--gold); }
h2:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 6px; }
input {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 1rem;
}
input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }

.btn {
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-weight: 600; cursor: pointer; font-size: 0.92rem;
}
.btn:hover { border-color: var(--gold); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.btn.ghost { background: transparent; }
#login-form .btn { width: 100%; margin-top: 14px; }

.rooms { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rooms li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2);
}
.rooms .empty { color: var(--muted); border-style: dashed; background: transparent; }

.room-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.room-head h1 { display: inline-block; margin: 8px 10px 0 0; }
.room-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.banner { background: #3a2d0b; border: 1px solid var(--gold); padding: 10px 14px; border-radius: 10px; }

.table-wrap { margin: 8px 0 12px; }

/* Table : une grille qui place les joueurs autour du centre, sans chevauchement possible.
   Toutes les tailles découlent de --card-w, qui grandit avec l'écran. */
.felt {
  --card-w: clamp(52px, 7vw, 80px);
  --card-h: calc(var(--card-w) * 1.44);
  --dx: calc(var(--card-w) * 0.30);
  --dy: calc(var(--card-w) * 0.18);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-areas:
    ".  p2 .  p3 . "
    "p1 c  c  c  p4"
    ".  .  p0 .  . ";
  align-items: center; justify-items: center; gap: 10px 6px;
  padding: 18px 12px; border-radius: 220px / 150px;
  background: radial-gradient(circle at center, var(--felt) 0%, var(--felt-dark) 100%);
  border: 12px solid #3b2414; box-shadow: inset 0 0 70px rgba(0,0,0,0.65);
}
.pos-0 { grid-area: p0; }
.pos-1 { grid-area: p1; }
.pos-2 { grid-area: p2; }
.pos-3 { grid-area: p3; }
.pos-4 { grid-area: p4; }
.center { grid-area: c; text-align: center; min-width: 0; }

.seat {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: calc(var(--card-w) * 2.2 + 18px); max-width: 100%; padding: 8px; border-radius: 14px;
  border: 2px dashed rgba(255,255,255,0.18); background: rgba(0,0,0,0.22);
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.seat.empty { width: auto; min-width: calc(var(--card-w) * 1.6); }
.seat.turn { border: 2px solid var(--gold); box-shadow: 0 0 22px rgba(242,181,68,0.55); background: rgba(242,181,68,0.10); }
.seat.me { background: rgba(242,181,68,0.08); }
.seat-head { text-align: center; max-width: 100%; min-width: 0; }
.seat .name { font-weight: 700; font-size: 0.82rem; text-transform: uppercase; letter-spacing: .4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: rgba(7,17,12,0.85);
  padding: 2px 10px; border-radius: 10px; }
.seat .meta { color: var(--muted); font-size: 0.74rem; margin-top: 3px; }

/* Cartes jouées en éventail devant chaque joueur */
.stack {
  position: relative;
  width: calc(var(--card-w) + var(--dx) * max(var(--n) - 1, 0));
  height: calc(var(--card-h) + var(--dy) * max(var(--n) - 1, 0));
  min-height: var(--card-h); min-width: var(--card-w);
}
.stack .playing-card {
  position: absolute; left: calc(var(--dx) * var(--k)); top: calc(var(--dy) * var(--k));
  z-index: calc(var(--k) + 1);
}

.status-line { font-weight: 700; color: var(--gold); margin-bottom: 8px; min-height: 1.3em; font-size: 1.05rem; }
.trick { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.trick .chip { background: rgba(0,0,0,0.45); }
.trick .chip.suit.red { color: #ff8a80; }
.result { background: rgba(0,0,0,0.6); border: 1px solid var(--gold); border-radius: 12px; padding: 10px; margin-top: 8px; }
.result strong { color: var(--gold); }
.result .trick { margin-top: 8px; }

/* Cartes : valeur dans les coins, symboles au centre ; tout suit la largeur de la carte */
.playing-card {
  --card-w: inherit; --card-h: inherit;
  position: relative; width: var(--card-w); height: var(--card-h); border-radius: calc(var(--card-w) * 0.11); background: #fff;
  border: 1px solid #cbd5e1; color: #0f172a; display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(var(--card-w) * 0.06) calc(var(--card-w) * 0.07); font-weight: 800; box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  user-select: none; transition: transform .15s ease, box-shadow .15s ease; flex: none;
}
.playing-card.red { color: #dc2626; }
.playing-card .corner { font-size: calc(var(--card-w) * 0.2); line-height: 1; text-align: left; }
.playing-card .corner.br { transform: rotate(180deg); }
.playing-card .pips {
  flex: 1; display: flex; flex-wrap: wrap; align-content: center; justify-content: center;
  gap: 0 calc(var(--card-w) * 0.04); padding: 0 calc(var(--card-w) * 0.03); font-size: calc(var(--card-w) * 0.19); line-height: 1.05;
}
.playing-card.badged.lead { border: 2px solid var(--gold); box-shadow: 0 0 14px var(--gold); }
.playing-card.badged.won { border: 2px solid #3ad07a; box-shadow: 0 0 12px rgba(58,208,122,0.8); }
.card-badge {
  position: absolute; top: -9px; right: -8px; font-size: max(0.5rem, calc(var(--card-w) * 0.11)); font-weight: 900; letter-spacing: .3px;
  padding: 2px 5px; border-radius: 4px; background: var(--gold); color: #000;
}
.badged.won .card-badge { background: #3ad07a; }
button.playing-card { cursor: pointer; font: inherit; font-weight: 800; }
button.playing-card:not(:disabled):hover, button.playing-card:not(:disabled):focus-visible {
  transform: translateY(-16px) scale(1.05); box-shadow: 0 12px 24px rgba(242,181,68,0.45); border-color: var(--gold); outline: none; z-index: 5;
}
button.playing-card:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(.2); }
.mini { --card-w: 46px; --card-h: 66px; }

.hand-bar {
  position: sticky; bottom: 0; z-index: 20; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; display: grid; gap: 10px;
}
.controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; }
.hand { --card-w: clamp(60px, 8.5vw, 92px); --card-h: calc(var(--card-w) * 1.44); display: flex; gap: 12px; justify-content: center; min-height: calc(var(--card-h) + 20px); align-items: flex-end; padding-top: 16px; }
.members { margin-top: 12px; }
.members ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.members li { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 0.85rem; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: #3b1111; border: 1px solid #e05252; padding: 10px 16px; border-radius: 10px;
}

@media (max-width: 760px) {
  /* Téléphone : deux colonnes, le centre passe au-dessus des joueurs du milieu */
  .felt {
    --card-w: clamp(44px, 14.5vw, 64px);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "p2 p3" "c c" "p1 p4" "p0 p0";
    gap: 10px 6px; padding: 12px 6px; border-radius: 36px; border-width: 8px;
    --dy: calc(var(--card-w) * 0.16);
  }
  .room-head { gap: 6px; margin-bottom: 8px; }
  .room-head h1 { font-size: 1.15rem; }
  .room-actions { gap: 6px; }
  .room-actions .btn { padding: 7px 10px; font-size: 0.8rem; }
  .seat { width: calc(var(--card-w) * 2.2 + 12px); padding: 5px; }
  .seat .name { font-size: 0.7rem; padding: 2px 6px; }
  .seat .meta { font-size: 0.66rem; }
  .status-line { font-size: 0.95rem; margin-bottom: 4px; }
  /* Main : cartes plus grandes qui se chevauchent un peu pour tenir à 5 */
  .hand { --card-w: min(19vw, 76px); gap: 0; }
  .hand .playing-card + .playing-card { margin-left: calc(var(--card-w) * -0.12); }
}

/* Liens discrets (renvoyer le code, déconnexion) */
.btn.link { background: none; border: 0; padding: 0 .25rem; color: inherit; opacity: .8; text-decoration: underline; cursor: pointer; box-shadow: none; }
.btn.link:hover { opacity: 1; }
#code-login-form .row { gap: 1rem; justify-content: space-between; margin-top: .5rem; }
#login-code { letter-spacing: .4em; font-size: 1.4rem; text-align: center; }

/* Connexion Google */
.google-btn { display: flex; justify-content: center; min-height: 44px; margin: 14px 0 4px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.8rem; margin: 14px 0 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: currentColor; opacity: 0.3; }
