:root {
  --bg: #14102a; --bg2: #1d1740; --card: #231c4a; --line: #3a3170;
  --text: #f4f1ff; --muted: #a9a2cf; --accent: #ffc23d; --accent2: #ff5d8f; --ok: #3ddc97;
  --felt: #0f5a3c; --felt2: #0a3f2a;
  --cw: 62px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); overflow: hidden; user-select: none; -webkit-user-select: none;
  height: 100dvh; display: flex; flex-direction: column;
}
[hidden] { display: none !important; }
button { font-family: inherit; }

/* ---------- barre du haut ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: max(6px, env(safe-area-inset-top)) 10px 6px;
  background: linear-gradient(180deg, #1d1740, #16112f); border-bottom: 1px solid var(--line); flex: none;
}
.topbar .title { font-weight: 900; font-size: 17px; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; white-space: nowrap; }
.topbar .score { flex: 1; text-align: center; font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .score b { color: var(--accent); }
.iconbtn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #2a2257; color: var(--text); font-size: 18px; cursor: pointer; flex: none; }

/* ---------- boutons ---------- */
.btn {
  min-height: 44px; padding: 0 14px; border: 0; border-radius: 12px; font-weight: 800; font-size: 15px; cursor: pointer;
  color: var(--text); background: #2f2760; box-shadow: 0 3px 0 #1a1540; white-space: nowrap;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #1a1540; }
.btn.main { color: #1b1300; background: linear-gradient(180deg, #ffd56b, var(--accent)); box-shadow: 0 3px 0 #b27d00; }
.btn.red { color: #fff; background: linear-gradient(180deg, #ff6b8f, #e0456b); box-shadow: 0 3px 0 #8f2440; }
.btn:disabled { opacity: .4; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

/* ---------- salon ---------- */
#lobby { flex: 1; overflow-y: auto; padding: 16px; }
.lobbywrap { max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.box { background: linear-gradient(180deg, var(--card), var(--bg2)); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.box h2 { margin: 0 0 10px; font-size: 18px; }
.invite { text-align: center; }
.invite .code { font-size: 38px; font-weight: 900; letter-spacing: 8px; color: var(--accent); margin: 4px 0; }
.invite .link { font-size: 13px; word-break: break-all; background: #0d0a1e; border: 1px solid var(--line); border-radius: 10px; padding: 8px; user-select: all; -webkit-user-select: all; margin: 8px 0; }
.warn { color: #ffb86b; font-size: 13px; margin: 6px 0; }
.team { margin-bottom: 10px; }
.team h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.seat {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: #0d0a1e; border: 1px solid var(--line); margin-bottom: 6px; min-height: 52px;
}
.seat.me { border-color: var(--accent); }
.seat .av { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 900; background: #3a3170; flex: none; }
.seat .nm { flex: 1; font-weight: 700; }
.seat .nm small { color: var(--muted); font-weight: 600; }
.seat.empty .nm { color: var(--muted); font-style: italic; font-weight: 600; }
.seat .sbtn { min-height: 34px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line); background: #2a2257; color: var(--text); font-weight: 700; cursor: pointer; font-size: 13px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.choices button { flex: 1 1 auto; min-height: 38px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: #0d0a1e; color: var(--text); font-weight: 700; font-size: 14px; cursor: pointer; }
.choices button.on { background: var(--accent); color: #1b1300; border-color: var(--accent); }
.choices button:disabled { opacity: .45; }
.lbl { font-size: 13px; color: var(--muted); font-weight: 700; margin: 4px 0 6px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.45; }

/* ---------- table ---------- */
#table { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.contract { flex: none; text-align: center; font-size: 13px; font-weight: 700; padding: 5px 8px; color: #dfffe9; background: #0b4a31; min-height: 26px; }
.felt { position: relative; flex: 1; min-height: 0; background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt2) 75%); overflow: hidden; }
.opp { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 3px; width: 92px; z-index: 5; }
.opp .av { position: relative; width: 44px; height: 44px; border-radius: 50%; background: #2f2760; border: 3px solid #1a1540; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 18px; transition: border-color .2s, box-shadow .2s; }
.opp.turn .av { border-color: var(--accent); box-shadow: 0 0 0 5px rgba(255,194,61,.25); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px rgba(255,194,61,.08); } }
.opp .nm { font-size: 12px; font-weight: 800; max-width: 92px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px #000; }
.opp .sub { font-size: 11px; color: #cfe; opacity: .9; display: flex; gap: 4px; align-items: center; }
.badge { font-size: 10px; font-weight: 900; padding: 2px 6px; border-radius: 999px; background: #000a; }
.badge.dealer { position: absolute; right: -8px; bottom: -6px; background: #fff; color: #222; padding: 1px 5px; font-size: 10px; }
.badge.taker { background: var(--accent); color: #1b1300; }
.badge.mate { background: #7bd3ff; color: #062a3d; }
.bubble {
  position: absolute; left: 50%; top: -12px; transform: translate(-50%, -100%); background: #fff; color: #222; font-weight: 800; font-size: 13px;
  padding: 5px 10px; border-radius: 12px; white-space: nowrap; box-shadow: 0 4px 10px rgba(0,0,0,.35); animation: pop .2s ease-out; z-index: 9;
}
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); border: 6px solid transparent; border-top-color: #fff; border-bottom: 0; }
@keyframes pop { from { transform: translate(-50%, -100%) scale(.6); opacity: 0; } }
.minicards { display: flex; }
.minicards i { width: 9px; height: 14px; border-radius: 2px; background: linear-gradient(135deg, #b8324f, #6d1730); border: 1px solid #fff8; margin-left: -4px; }
.minicards i:first-child { margin-left: 0; }

.center { position: absolute; inset: 0; pointer-events: none; }
.tc { position: absolute; transform: translate(-50%, -50%); transition: left .25s, top .25s; }
.tc .card { box-shadow: 0 6px 14px rgba(0,0,0,.45); }
.tc.win .card { outline: 3px solid var(--accent); }
.midinfo { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; }
.midinfo .lab { font-size: 12px; font-weight: 800; color: #dfffe9; margin-top: 6px; text-shadow: 0 1px 2px #000; }
.chien { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; max-width: 90vw; }

/* ---------- actions et main ---------- */
.panel { flex: none; padding: 8px 10px 4px; background: #120e28; min-height: 56px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.panel .say { text-align: center; font-weight: 800; font-size: 15px; }
.panel .say small { display: block; color: var(--muted); font-weight: 600; font-size: 12px; }
.bids { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.bids .btn { flex: 1 1 auto; min-height: 42px; padding: 0 10px; font-size: 14px; }
.suitbtn.r { color: #ff5b6e; }
.hand { flex: none; position: relative; background: #120e28; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.hand .card { position: absolute; transition: transform .15s, top .15s, left .2s, opacity .15s; cursor: pointer; }
.hand .card.sel { transform: translateY(-18px); }
.hand .card.no { filter: brightness(.55) saturate(.6); }
.hand .card.ecart { transform: translateY(-18px); outline: 3px solid var(--accent2); }
.hand.myturn::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: linear-gradient(90deg, transparent, var(--accent), transparent); }

/* ---------- cartes ---------- */
.card {
  width: var(--cw); height: calc(var(--cw) * 1.45); border-radius: calc(var(--cw) * .1); background: #fffdf7; color: #1d1d1d; position: relative;
  box-shadow: 0 2px 5px rgba(0,0,0,.35), inset 0 0 0 1px #0002; font-weight: 800; overflow: hidden; flex: none;
}
.card.r { color: #d4213d; }
.card .cor { position: absolute; left: 4%; top: 2%; display: flex; flex-direction: column; align-items: center; line-height: 1; font-size: calc(var(--cw) * .27); letter-spacing: -1px; }
.card .cor span:last-child { font-size: calc(var(--cw) * .25); }
.card .cor.b { left: auto; top: auto; right: 4%; bottom: 2%; transform: rotate(180deg); }
.card .mid { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * .62); }
.card .mid.fig { font-size: calc(var(--cw) * .5); font-weight: 900; }
.card .mid.fig span { display: flex; align-items: center; justify-content: center; width: 62%; height: 52%; border-radius: 8px; background: #f3ead2; border: 2px solid currentColor; font-size: calc(var(--cw) * .42); }
.card.trump { background: linear-gradient(160deg, #fffaf0, #f2e6c9); color: #2b2b6e; }
.card.trump .mid { font-size: calc(var(--cw) * .5); font-weight: 900; }
.card.trump .mid span { width: 70%; height: 60%; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle, #e9e2ff, #c9bdf5); border: 2px solid #2b2b6e; }
.card.trump.oud .mid span { background: radial-gradient(circle, #fff3c4, #ffd25e); border-color: #a66d00; color: #6a4300; }
.card.exc { background: linear-gradient(160deg, #fff6f9, #ffd9e6); color: #8a1846; }
.card.exc .mid { flex-direction: column; font-size: calc(var(--cw) * .45); }
.card.exc .mid small { font-size: calc(var(--cw) * .17); font-weight: 900; }
.card.back { background: repeating-linear-gradient(45deg, #b8324f 0 6px, #a12a45 6px 12px); border: 3px solid #fff; }
.card.mini { --cw: 40px; }

/* ---------- fenêtres ---------- */
.modal { position: fixed; inset: 0; background: rgba(8,6,20,.74); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 14px; backdrop-filter: blur(3px); }
.sheet { width: min(460px, 100%); max-height: 92dvh; overflow-y: auto; background: linear-gradient(180deg, var(--card), var(--bg2)); border: 1px solid var(--line); border-radius: 20px; padding: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.sheet h2 { margin: 0 0 6px; font-size: 22px; text-align: center; }
.sheet .big { font-size: 26px; font-weight: 900; text-align: center; color: var(--accent); margin: 2px 0 8px; }
.sheet .big.bad { color: #ff7a8f; }
.sheet input[type=text] { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: #0d0a1e; color: var(--text); font-size: 16px; font-family: inherit; margin-bottom: 12px; }
.sheet .row { margin-top: 12px; }
table.sc { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; font-variant-numeric: tabular-nums; }
table.sc th, table.sc td { padding: 6px 6px; text-align: right; border-bottom: 1px solid #ffffff14; }
table.sc th:first-child, table.sc td:first-child { text-align: left; }
table.sc th { color: var(--muted); font-size: 12px; font-weight: 700; }
table.sc tr.tot td { font-weight: 900; color: var(--accent); border-bottom: 0; }
.pos { color: var(--ok); } .neg { color: #ff7a8f; }
.lines { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 14px; margin: 8px 0; }
.lines span:nth-child(odd) { color: var(--muted); }
.lines span:nth-child(even) { font-weight: 800; text-align: right; }
.podium { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.podium div { display: flex; align-items: center; gap: 10px; background: #0d0a1e; border-radius: 12px; padding: 9px 12px; }
.podium b { flex: 1; } .podium em { font-style: normal; color: var(--muted); font-size: 13px; display: block; font-weight: 600; }
.menu { display: flex; flex-direction: column; gap: 8px; }

.toast {
  position: fixed; left: 50%; top: calc(max(6px, env(safe-area-inset-top)) + 52px); transform: translate(-50%, -20px); opacity: 0; z-index: 70;
  background: #2f2760; color: #fff; border: 1px solid #5a4bb0; padding: 9px 15px; border-radius: 12px; font-weight: 800; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: transform .25s, opacity .25s; max-width: 92vw; text-align: center; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.conn { position: fixed; right: 10px; bottom: 10px; z-index: 60; background: #5a1e2a; color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; }

.watchopt { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; font-size: 15px; cursor: pointer; }
.watchopt input { width: 20px; height: 20px; accent-color: #ffc23d; }
