:root {
  --felt: #0f5c34;
  --felt-dark: #0a3f24;
  --gold: #f4c542;
  --ink: #f3f6f2;
  --muted: #b9d3c2;
  --panel: rgba(0, 0, 0, .35);
  --red: #c8102e;
  --cw: min(17vw, 74px, 11vh);
  --ov: 4px;
  --sw: calc(var(--cw) * .42);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%) fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, select { font: inherit; }
.hidden { display: none !important; }

.screen { display: none; height: 100dvh; height: 100vh; }
@supports (height: 100dvh) { .screen { height: 100dvh; } }
.screen.active { display: flex; }

/* ---------- Menu / salon ---------- */
#menu, #lobby { overflow-y: auto; justify-content: center; align-items: flex-start; padding: 16px; }
.menu-box { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; margin: auto 0; }
.logo { text-align: center; font-size: 2.4rem; margin: 8px 0 0; letter-spacing: .02em; }
.logo .r, .r { color: #ff5a6e; }
.sub { text-align: center; color: var(--muted); margin: 0 0 6px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
.field input, .field select, .join-row input {
  padding: 11px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25); color: var(--ink); font-size: 1rem;
}
.card-box { background: var(--panel); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card-box h2 { margin: 0; font-size: 1.05rem; }
details.card-box summary { cursor: pointer; font-weight: 600; }
details.card-box[open] summary { margin-bottom: 6px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
.msg { color: var(--gold); margin: 0; min-height: 1.2em; text-align: center; font-size: .92rem; }
.msg.small { color: var(--muted); font-size: .8rem; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer; font-weight: 600;
  background: #f3f6f2; color: #123; box-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.big { padding: 15px; font-size: 1.1rem; background: var(--gold); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; border: 1px solid rgba(255,255,255,.3); }
.btn.warn { background: #ff7043; color: #fff; }
.btn.small { padding: 7px 12px; font-size: .88rem; }
.btn.sel { background: var(--gold); outline: 2px solid #fff; }

.code-box { text-align: center; background: var(--panel); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.code { font-size: 2.6rem; font-weight: 800; letter-spacing: .3em; color: var(--gold); padding-left: .3em; }
.seats { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto auto auto; gap: 8px; }
.seat {
  background: var(--panel); border-radius: 12px; padding: 10px 6px; text-align: center; font-size: .9rem;
  border: 2px solid transparent; min-height: 58px; display: flex; flex-direction: column; justify-content: center;
}
.seat small { color: var(--muted); display: block; font-size: .72rem; }
.seat.me { border-color: var(--gold); }
.seat.picked { border-color: #fff; background: rgba(255,255,255,.15); }
.seat.clickable { cursor: pointer; }
.seat[data-seat="2"] { grid-column: 2; grid-row: 1; }
.seat[data-seat="3"] { grid-column: 1; grid-row: 2; }
.seat-mid { grid-column: 2; grid-row: 2; display: flex; align-items: center; justify-content: center; color: var(--muted); border: 1px dashed rgba(255,255,255,.25); border-radius: 50%; }
.seat[data-seat="1"] { grid-column: 3; grid-row: 2; }
.seat[data-seat="0"] { grid-column: 2; grid-row: 3; }

/* ---------- Table ---------- */
#table { flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top));
  background: rgba(0,0,0,.3); flex: none;
}
.icon { background: rgba(255,255,255,.12); color: var(--ink); border: 0; border-radius: 10px; width: 38px; height: 38px; cursor: pointer; font-size: 1.05rem; flex: none; }
.scores { display: flex; align-items: center; gap: 6px; }
.sc { display: flex; flex-direction: column; align-items: center; line-height: 1.05; background: rgba(0,0,0,.25); border-radius: 8px; padding: 3px 8px; min-width: 50px; }
.sc span { font-size: .68rem; color: var(--muted); }
.sc b { font-size: 1.05rem; }
.sc.us b { color: #8fe3a8; }
.sc.them b { color: #ffb4a8; }
.target { font-size: .75rem; color: var(--muted); }
.contract { flex: 1; text-align: center; font-size: .88rem; font-weight: 600; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contract .big-suit { font-size: 1.2rem; vertical-align: -2px; }
.contract .x { color: #ff7043; }

.felt { position: relative; flex: 1; min-height: 0; }
.player { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 3px; z-index: 2; }
.p-top { top: 6px; left: 50%; transform: translateX(-50%); }
.p-left { left: 6px; top: 42%; transform: translateY(-50%); align-items: flex-start; }
.p-right { right: 6px; top: 42%; transform: translateY(-50%); align-items: flex-end; }
.p-bottom { bottom: 4px; left: 50%; transform: translateX(-50%); }
.pname {
  background: rgba(0,0,0,.45); padding: 3px 9px; border-radius: 20px; font-size: .82rem; white-space: nowrap;
  max-width: 34vw; overflow: hidden; text-overflow: ellipsis; transition: background .2s;
}
.pname .dealer { background: #fff; color: #123; border-radius: 50%; font-size: .65rem; padding: 0 4px; margin-left: 4px; font-weight: 800; }
.player.turn .pname { background: var(--gold); color: #1a1a1a; font-weight: 700; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(244,197,66,.35); } }
.backs { display: flex; }
.backs .card { width: var(--sw); }
.backs .card + .card { margin-left: calc(var(--sw) * -.62); }
.bubble {
  background: #fff; color: #123; border-radius: 12px; padding: 3px 10px; font-weight: 700; font-size: .9rem;
  white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.35); visibility: hidden;
}
.bubble.show { visibility: visible; }
.bubble.redtxt { color: var(--red); }
.bubble.hot { background: #ff7043; color: #fff; }
.bubble.belote { background: var(--gold); animation: pop .3s; }
@keyframes pop { from { transform: scale(.5); } }

/* Cartes */
.card {
  width: var(--cw); aspect-ratio: 5 / 7; background: #fff; border-radius: calc(var(--cw) * .1);
  box-shadow: 0 1px 4px rgba(0,0,0,.45); position: relative; color: #161616; flex: none;
  user-select: none; -webkit-user-select: none; font-family: Georgia, "Times New Roman", serif; font-weight: 700;
}
.card.red { color: var(--red); }
.card .c-tl { position: absolute; top: 4%; left: 7%; font-size: calc(var(--cw) * .27); line-height: .95; text-align: center; }
.card .c-br { position: absolute; bottom: 4%; right: 7%; font-size: calc(var(--cw) * .27); line-height: .95; text-align: center; transform: rotate(180deg); }
.card .c-mid { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * .55); }
.card .c-mid.fig { font-size: calc(var(--cw) * .5); border: 2px solid currentColor; inset: 22% 20%; border-radius: 6px; opacity: .85; }
.card.back { background: repeating-linear-gradient(45deg, #1b4f8c 0 3px, #2a66ad 3px 6px); border: 2px solid #fff; }
.card.trump::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 2px var(--gold); }

.hand {
  flex: none; display: flex; justify-content: center; align-items: flex-end;
  padding: 10px 8px; padding-bottom: max(10px, env(safe-area-inset-bottom)); min-height: calc(var(--cw) * 1.4 + 24px);
}
.hand .card + .card { margin-left: var(--ov); }
.hand .card { transition: transform .12s; }
.hand.myturn .card.playable { cursor: pointer; transform: translateY(-8px); }
.hand.myturn .card.playable:hover { transform: translateY(-14px); }
.hand.myturn .card.disabled { filter: brightness(.55); }

.trick { position: absolute; left: 50%; top: 46%; width: 0; height: 0; }
.trick .card { position: absolute; transition: transform .25s, opacity .25s; }
.trick .pos-0 { transform: translate(-50%, 12%); }
.trick .pos-2 { transform: translate(-50%, -112%); }
.trick .pos-3 { transform: translate(-155%, -50%); }
.trick .pos-1 { transform: translate(55%, -50%); }
.trick .card.win { box-shadow: 0 0 0 3px var(--gold), 0 4px 10px rgba(0,0,0,.5); z-index: 3; }

.center-msg {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); text-align: center;
  background: rgba(0,0,0,.4); padding: 8px 14px; border-radius: 12px; font-size: .95rem; max-width: 80%;
}
.center-msg:empty { display: none; }

/* Panneau d'enchères */
.bid-panel { flex: none; background: rgba(0,0,0,.45); padding: 8px; display: flex; flex-direction: column; gap: 7px; }
.bid-values { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.bid-values .btn { padding: 7px 0; width: 3.2em; font-size: .92rem; }
.bid-suits { display: flex; gap: 8px; justify-content: center; }
.bid-suits .btn { font-size: 1.7rem; padding: 2px 0; width: 3.4rem; line-height: 1.3; }
.bid-suits .btn.r { color: var(--red); }
.bid-actions { display: flex; gap: 8px; justify-content: center; }
.bid-actions .btn { flex: 1; max-width: 160px; padding: 10px 6px; }

/* Modale */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box {
  background: #fdfdf8; color: #182; color: #1c2a22; border-radius: 16px; padding: 18px; width: 100%; max-width: 440px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.modal-box h2 { margin: 0 0 10px; font-size: 1.2rem; }
.modal-box h3 { margin: 14px 0 4px; font-size: 1rem; }
.modal-box p, .modal-box li { line-height: 1.45; font-size: .92rem; }
.modal-box ul { padding-left: 20px; margin: 4px 0; }
.modal-box table { width: 100%; border-collapse: collapse; font-size: .92rem; margin-top: 6px; }
.modal-box th, .modal-box td { padding: 6px 4px; border-bottom: 1px solid #dde3dc; text-align: center; }
.modal-box th:first-child, .modal-box td:first-child { text-align: left; }
.modal-box tr.total td { font-weight: 800; border-bottom: 0; }
.modal-btns { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; flex-wrap: wrap; }
.modal-btns .btn { background: #0f5c34; color: #fff; }
.modal-btns .btn.ghost { background: transparent; color: #0f5c34; border-color: #0f5c34; }
.verdict { font-size: 1.05rem; font-weight: 800; }
.verdict.ok { color: #138a3e; }
.verdict.ko { color: #c62828; }
.red-s { color: var(--red); }
.mini-trick { display: grid; grid-template-columns: repeat(3, auto); grid-template-rows: repeat(3, auto); gap: 4px; justify-content: center; --cw: 54px; margin: 8px 0; }
.mini-trick .lbl { font-size: .72rem; text-align: center; color: #555; }

.toast {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%) translateY(-20px); opacity: 0; pointer-events: none;
  background: #1c2a22; color: #fff; padding: 9px 16px; border-radius: 20px; z-index: 60; transition: .25s; max-width: 90vw; text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 900px) {
  :root { --cw: min(96px, 12vh); }
}
