/* ── Touti — palette : nuit de Fès ─────────────────────────────
   Cadre sombre  #14100F   Feutre zellige  #123F38 / #0E332D
   Laiton safran #D9A441   Crème carte     #F7F0DE
   Oros #C08A1E  Copas #B23A2E  Espadas #2F5B93  Bastos #3E7A3A */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #14100F; --felt: #123F38; --felt-dark: #0E332D;
  --brass: #D9A441; --brass-dim: #8a6a2c; --cream: #F7F0DE;
  --ink: #2A211C; --error: #E07856;
}
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: 'Nunito Sans', system-ui, sans-serif;
  background: var(--bg); color: var(--cream);
  user-select: none; -webkit-user-select: none;
}
h1, h2, h3, .score, .code, output { font-family: 'Marcellus', serif; font-weight: 400; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

/* ── Lobby ── */
#lobby, #waiting { align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(ellipse at 50% -10%, #1e2a24 0%, var(--bg) 65%); }
.lobby-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; }
.brand { text-align: center; margin-bottom: 10px; }
.brand h1 { font-size: 56px; letter-spacing: 6px; color: var(--brass); }
.tagline { color: #b8ab90; font-size: 14px; letter-spacing: 1px; }
.brand-star { width: 54px; height: 54px; margin: 0 auto 8px;
  background: var(--brass);
  clip-path: polygon(50% 0, 61% 20%, 80% 10%, 79% 32%, 100% 39%, 85% 55%, 96% 74%, 74% 74%, 66% 95%, 50% 80%, 34% 95%, 26% 74%, 4% 74%, 15% 55%, 0 39%, 21% 32%, 20% 10%, 39% 20%);
}
label { font-size: 13px; color: #b8ab90; text-transform: uppercase; letter-spacing: 1.5px; }
input {
  background: #221B18; border: 1px solid #3a2f28; color: var(--cream);
  padding: 14px 16px; border-radius: 12px; font-size: 17px; font-family: inherit; width: 100%;
}
input:focus { outline: 2px solid var(--brass); outline-offset: 1px; border-color: transparent; }
#code-input { text-transform: uppercase; letter-spacing: 6px; text-align: center; width: 130px; }
.join-row { display: flex; gap: 10px; }
.join-row .btn { flex: 1; }

.btn {
  background: #2A211C; color: var(--cream); border: 1px solid #4a3b2e;
  padding: 15px 18px; border-radius: 12px; font-size: 16px; font-weight: 700;
  font-family: inherit; cursor: pointer; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brass); color: #241a08; border: none; }
.btn.primary:active { background: #c4922f; }
.btn .sub { display: block; font-size: 12px; font-weight: 600; opacity: .75; }
.btn.round { width: 52px; padding: 12px 0; font-size: 20px; border-radius: 50%; }
.btn:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }
.divider { display: flex; align-items: center; gap: 12px; color: #6f6350; font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: #3a2f28; }
.error { color: var(--error); font-size: 14px; text-align: center; min-height: 20px; }
.hint { color: #b8ab90; font-size: 14px; line-height: 1.5; }
.code { color: var(--brass); letter-spacing: 5px; }
.seats { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.seats li { background: #221B18; border-radius: 10px; padding: 12px 16px; display: flex; justify-content: space-between; font-size: 15px; }
.seats .tag { color: #8b7c5e; font-size: 13px; }

/* ── Table ── */
#table { background: var(--bg); }
.scorebar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px calc(10px); gap: 10px;
  background: linear-gradient(#1d1613, #14100F); border-bottom: 1px solid #2c231d;
}
.team { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.team-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: #8b7c5e; }
.score { font-size: 26px; color: var(--cream); }
.team.us .score { color: var(--brass); }
.center-info { text-align: center; font-size: 13px; color: #b8ab90; display: flex; flex-direction: column; gap: 2px; }
.contract { color: var(--brass); font-weight: 700; }

.felt {
  flex: 1; position: relative;
  background:
    radial-gradient(ellipse at 50% 40%, var(--felt) 0%, var(--felt-dark) 75%);
  box-shadow: inset 0 0 60px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* Adversaires */
.opponent { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 4px; z-index: 2; }
.opponent.top { top: 12px; left: 50%; transform: translateX(-50%); }
.opponent.left { left: 8px; top: 34%; }
.opponent.right { right: 8px; top: 34%; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: #2A211C; border: 2px solid #4a3b2e;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Marcellus', serif; font-size: 20px; color: var(--brass);
}
.opponent .pname, .me-info .pname { font-size: 12px; font-weight: 700; max-width: 90px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opponent .cards-left { font-size: 11px; color: #9fc3ae; }
.turn-glow .avatar { border-color: var(--brass); box-shadow: 0 0 14px rgba(217,164,65,.55); }
.bot-tag { font-size: 10px; color: #8b7c5e; }

/* Médaillon central — signature zellige */
.medallion {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -58%);
  width: min(62vw, 300px); aspect-ratio: 1;
  background: var(--brass-dim);
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
  display: flex; align-items: center; justify-content: center;
}
.medallion::before {
  content: ''; position: absolute; inset: 2px;
  background: linear-gradient(160deg, #0F3A33, #0B2C27);
  clip-path: inherit;
}
.trick { position: relative; width: 100%; height: 100%; z-index: 1; }
.trick .card { position: absolute; transition: transform .25s ease, opacity .25s; }
.trick .pos-0 { bottom: 8%;  left: 50%; transform: translateX(-50%); }
.trick .pos-1 { left: 8%;   top: 50%;  transform: translateY(-50%) rotate(-6deg); }
.trick .pos-2 { top: 8%;    left: 50%; transform: translateX(-50%) rotate(2deg); }
.trick .pos-3 { right: 8%;  top: 50%;  transform: translateY(-50%) rotate(6deg); }
.table-msg { position: absolute; width: 80%; text-align: center; font-size: 14px; color: #cfe3d4;
  left: 50%; top: 50%; transform: translate(-50%,-50%); pointer-events: none; line-height: 1.4; }

/* Cartes */
.card {
  width: 58px; height: 86px; border-radius: 8px;
  background: var(--cream); color: var(--ink);
  border: 1px solid #cbbfa4;
  box-shadow: 0 3px 8px rgba(0,0,0,.35);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-family: 'Marcellus', serif;
}
.card .rank { font-size: 24px; line-height: 1; }
.card .suit-icon { width: 22px; height: 22px; }
.card .figure { font-size: 10px; font-family: 'Nunito Sans', sans-serif; font-weight: 800;
  text-transform: uppercase; letter-spacing: .5px; }
.card.oros    { color: #C08A1E; }
.card.copas   { color: #B23A2E; }
.card.espadas { color: #2F5B93; }
.card.bastos  { color: #3E7A3A; }

/* Main du joueur */
.me-info { position: absolute; bottom: 118px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; z-index: 2; }
.me-info.turn-glow .pname { color: var(--brass); text-shadow: 0 0 10px rgba(217,164,65,.6); }
.hand {
  position: absolute; bottom: 6px; left: 0; right: 0; height: 112px;
  display: flex; justify-content: center; align-items: flex-end; z-index: 3;
}
.hand .card { margin: 0 -14px; transition: transform .15s, opacity .2s; position: relative; }
.hand .card.playable { cursor: pointer; }
.hand .card.playable:active, .hand .card.playable:hover { transform: translateY(-16px); }
.hand .card.disabled { filter: brightness(.55) saturate(.6); }
.hand .card.trump-card::after {
  content: ''; position: absolute; top: 4px; right: 4px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--brass);
}

/* Panneaux */
.panel[hidden] { display: none !important; }
.panel {
  position: fixed; left: 50%; bottom: 176px; transform: translateX(-50%);
  width: min(440px, 94%); background: #1d1613; border-radius: 18px;
  border: 1px solid #3a2f28;
  box-shadow: 0 10px 40px rgba(0,0,0,.55);
  padding: 18px 20px 20px; z-index: 20;
  display: flex; flex-direction: column; gap: 14px;
  animation: slide-up .25s ease;
}
@keyframes slide-up { from { transform: translate(-50%, 12%); opacity: 0; } }
.panel h3 { color: var(--brass); font-size: 20px; text-align: center; }
.panel p { text-align: center; color: #b8ab90; font-size: 14px; }
.bid-controls { display: flex; justify-content: center; align-items: center; gap: 22px; }
#bid-amount { font-size: 40px; color: var(--cream); min-width: 90px; text-align: center; }
.panel-actions { display: flex; gap: 12px; }
.panel-actions .btn { flex: 1; }
.trump-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.trump-grid button { background: var(--cream); border: none; border-radius: 12px; padding: 14px 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer;
  font-family: inherit; font-size: 12px; font-weight: 800; }
.trump-grid svg { width: 30px; height: 30px; }
#round-detail { font-size: 15px; line-height: 1.7; text-align: center; color: var(--cream); }
#round-detail .ok { color: #8fd49a; } #round-detail .ko { color: var(--error); }

.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: rgba(20,16,15,.92); border: 1px solid var(--brass-dim);
  color: var(--cream); padding: 10px 18px; border-radius: 30px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 30;
  max-width: 88%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.ad-slot {
  height: 50px; background: #0d0a09; color: #5c5142;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; letter-spacing: 1px; border-top: 1px solid #241d18;
}

@media (max-height: 700px) {
  .card { width: 50px; height: 74px; } .card .rank { font-size: 20px; }
  .hand { height: 96px; } .me-info { bottom: 102px; }
  .panel { bottom: 156px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
