:root {
  --felt: #13543f;
  --felt-dark: #0b3527;
  --gold: #f2c14e;
  --gold-dark: #c99a2e;
  --cream: #fff8ea;
  --ink: #1c1c1c;
  --red: #c8102e;
  --muted: rgba(255, 248, 234, 0.7);
  --danger: #e2574c;
  --ok: #4cc38a;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--cream);
  background:
    radial-gradient(ellipse at 50% 30%, #1d7356 0%, var(--felt) 45%, var(--felt-dark) 100%) fixed;
  min-height: 100dvh;
  overscroll-behavior: none;
  user-select: none;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
h1, h2, h3, .display { font-family: 'Fredoka', 'Nunito', sans-serif; letter-spacing: 0.01em; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
}

/* ---------- Boutons ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 800;
  background: var(--gold);
  color: #3a2a00;
  box-shadow: 0 4px 0 var(--gold-dark), 0 6px 16px rgba(0,0,0,.25);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark); }
.btn.ghost { background: rgba(255,255,255,.12); color: var(--cream); box-shadow: inset 0 0 0 2px rgba(255,255,255,.25); }
.btn.danger { background: var(--danger); color: white; box-shadow: 0 4px 0 #a33a31; }
.btn.small { padding: 7px 13px; font-size: .9rem; }
.btn.big { padding: 15px 26px; font-size: 1.15rem; width: 100%; }
.btn.on { background: #ffe08a; box-shadow: 0 0 0 3px #fff, 0 4px 0 var(--gold-dark); }
.iconbtn { background: rgba(255,255,255,.12); border: 0; color: var(--cream); width: 38px; height: 38px; border-radius: 50%; font-size: 1.05rem; }

/* ---------- Accueil ---------- */
.home { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 18px; text-align: center; }
.logo { font-size: 4.2rem; margin: 0; color: var(--gold); text-shadow: 0 4px 0 rgba(0,0,0,.25); line-height: 1; }
.logo-cards { display: flex; justify-content: center; gap: 0; height: 110px; margin-bottom: 4px; }
.logo-cards .card { --w: 70px; margin: 0 -14px; }
.logo-cards .card:nth-child(1) { transform: rotate(-14deg) translateY(10px); }
.logo-cards .card:nth-child(3) { transform: rotate(14deg) translateY(10px); }
.tagline { color: var(--muted); margin: 0 0 8px; }
.panel {
  background: rgba(0,0,0,.22);
  border-radius: 20px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
input[type=text] {
  font: inherit; font-weight: 700; font-size: 1.1rem;
  padding: 13px 16px; border-radius: 12px; border: 2px solid transparent;
  background: var(--cream); color: var(--ink); width: 100%; text-align: center;
}
input[type=text]:focus { outline: none; border-color: var(--gold); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.sep { color: var(--muted); font-size: .9rem; }

/* ---------- En-tête ---------- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.topbar .title { font-family: 'Fredoka'; font-weight: 700; font-size: 1.35rem; color: var(--gold); }
.topbar .room { font-size: .8rem; color: var(--muted); background: rgba(0,0,0,.2); padding: 3px 9px; border-radius: 99px; }
.topbar .spacer { flex: 1; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.conn.off { background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- Lobby ---------- */
.lobby { display: flex; flex-direction: column; gap: 14px; flex: 1; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li { background: rgba(0,0,0,.2); padding: 11px 14px; border-radius: 12px; display: flex; align-items: center; gap: 10px; font-weight: 700; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-family: 'Fredoka'; font-weight: 700; color: #222; flex: none; }
.tag { font-size: .72rem; background: var(--gold); color: #3a2a00; padding: 2px 8px; border-radius: 99px; font-weight: 800; }
.invite { display: flex; gap: 8px; align-items: center; background: rgba(0,0,0,.2); border-radius: 12px; padding: 8px 8px 8px 14px; }
.invite code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; color: var(--muted); }

/* ---------- Cartes ---------- */
.card {
  --w: 64px;
  width: var(--w);
  height: calc(var(--w) * 1.4);
  border-radius: calc(var(--w) * .11);
  background: var(--cream);
  color: var(--ink);
  position: relative;
  box-shadow: 0 2px 0 rgba(0,0,0,.18), 0 4px 10px rgba(0,0,0,.25);
  flex: none;
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card.red { color: var(--red); }
.card .c1, .card .c2 { position: absolute; line-height: .9; text-align: center; font-size: calc(var(--w) * .22); }
.card .c1 { top: 6%; left: 8%; }
.card .c2 { bottom: 6%; right: 8%; transform: rotate(180deg); }
.card .c1 small, .card .c2 small { display: block; font-size: .85em; }
.card .mid { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--w) * .46); }
.card .mid.face { font-size: calc(var(--w) * .5); }
.card .mid.face span {
  width: 58%; height: 52%; border-radius: 8%;
  display: grid; place-items: center;
  background: linear-gradient(160deg, rgba(242,193,78,.35), rgba(242,193,78,.08));
  box-shadow: inset 0 0 0 1.5px currentColor;
}
.card .zero {
  position: absolute; top: 4%; right: 6%;
  font-size: calc(var(--w) * .15); background: var(--red); color: white;
  border-radius: 99px; padding: 0 .35em; font-family: 'Nunito'; font-weight: 800;
}
.card.back {
  background:
    radial-gradient(circle at 50% 50%, rgba(242,193,78,.55) 0 14%, transparent 15%),
    repeating-linear-gradient(45deg, #24366e 0 6px, #1b2a58 6px 12px);
  box-shadow: inset 0 0 0 calc(var(--w)*.05) var(--cream), 0 2px 0 rgba(0,0,0,.2), 0 4px 10px rgba(0,0,0,.25);
}
.card.empty {
  background: transparent;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18);
  border: 0;
}
.card.selectable { cursor: pointer; }
.card.selectable:hover { transform: translateY(-3px); }
.card.target { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(242,193,78,.8); animation: pulse 1.2s ease-in-out infinite; }
.card.picked { box-shadow: 0 0 0 4px #fff, 0 0 22px rgba(255,255,255,.9); transform: translateY(-6px); }
.card.hl { animation: hl 1.4s ease; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px var(--gold), 0 0 6px rgba(242,193,78,.3); } }
@keyframes hl { 0%, 60% { box-shadow: 0 0 0 4px #7fe7ff, 0 0 24px #7fe7ff; } }
.card.flip { animation: flip .35s ease; }
@keyframes flip { from { transform: rotateY(90deg); } to { transform: rotateY(0); } }
.card.pop { animation: pop .3s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.6) rotate(-12deg); opacity: .3; } }

/* ---------- Table ---------- */
.table { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.opps { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.opp {
  background: rgba(0,0,0,.22);
  border-radius: 14px;
  padding: 7px 9px 9px;
  min-width: 96px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow .2s;
  position: relative;
}
.opp.turn { box-shadow: inset 0 0 0 2px var(--gold), 0 0 16px rgba(242,193,78,.35); }
.opp.out { opacity: .4; }
.opp .who { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: .85rem; max-width: 130px; }
.opp .who .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp .pts { font-size: .75rem; color: var(--muted); font-weight: 700; }
.opp .badge { position: absolute; top: -8px; right: -6px; font-size: .9rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: var(--danger); }

.hand { display: grid; gap: 6px; justify-content: center; }
.opp .hand .card { --w: 34px; }
.opp .hand { gap: 4px; }

.center {
  display: flex; justify-content: center; align-items: center; gap: 18px;
  padding: 12px 0 6px;
  position: relative;
}
.pile { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: .78rem; color: var(--muted); font-weight: 700; }
.pile .card { --w: min(19vw, 82px); }
.pile .stack { position: relative; }
.pile .stack.deck .card:nth-child(1) { position: absolute; top: 4px; left: 3px; }
.pile .stack.deck .card:nth-child(2) { position: absolute; top: 2px; left: 1.5px; }
.pile .stack.deck .card:nth-child(3) { position: relative; }
.drawn { position: relative; }
.drawn .card { --w: min(22vw, 92px); transform: rotate(4deg); box-shadow: 0 0 0 3px var(--gold), 0 10px 26px rgba(0,0,0,.45); }
.drawn .lbl { color: var(--gold); }

.status {
  text-align: center;
  font-weight: 700;
  min-height: 2.6em;
  display: flex; align-items: center; justify-content: center;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(0,0,0,.18);
  font-size: .95rem;
  line-height: 1.3;
}
.status > span { display: block; }
.status.mine { background: rgba(242,193,78,.18); box-shadow: inset 0 0 0 1.5px rgba(242,193,78,.5); }
.status.fast { background: rgba(127,231,255,.15); box-shadow: inset 0 0 0 1.5px rgba(127,231,255,.6); }
.dutchbar {
  text-align: center; font-family: 'Fredoka'; font-weight: 700;
  background: var(--red); color: white; padding: 6px 10px; border-radius: 12px;
  animation: dutchIn .5s cubic-bezier(.2,1.6,.4,1);
}
@keyframes dutchIn { from { transform: scale(.7); opacity: 0; } }

.me { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: auto; padding-top: 6px; }
.me .hand .card { --w: min(21vw, 88px); }
.me .hand { gap: 9px; }
.me .who { font-weight: 800; color: var(--muted); font-size: .9rem; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; min-height: 48px; align-items: center; }

.log { font-size: .78rem; color: var(--muted); max-height: 0; overflow: hidden; transition: max-height .25s; }
.log.open { max-height: 260px; overflow-y: auto; }
.log div { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.logtoggle { background: none; border: 0; color: var(--muted); font-size: .8rem; font-weight: 700; padding: 4px; align-self: center; }

/* ---------- Modale ---------- */
#modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(5, 25, 18, .78);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 16px;
  overflow-y: auto;
}
.sheet {
  background: linear-gradient(180deg, #1a6a4f, #0f4734);
  border-radius: 22px;
  padding: 20px 18px;
  width: 100%; max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5), inset 0 0 0 1px rgba(255,255,255,.1);
  animation: dutchIn .35s cubic-bezier(.2,1.4,.4,1);
}
.sheet h2 { margin: 0 0 4px; color: var(--gold); text-align: center; font-size: 1.6rem; }
.sheet .sub { text-align: center; color: var(--muted); margin: 0 0 14px; font-weight: 700; }
.res { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.res .r { background: rgba(0,0,0,.2); border-radius: 12px; padding: 9px 11px; }
.res .r.best { box-shadow: inset 0 0 0 2px var(--gold); }
.res .top { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.res .top .nm { flex: 1; }
.res .cards { display: flex; gap: 4px; margin-top: 7px; flex-wrap: wrap; }
.res .cards .card { --w: 34px; }
.res .num { font-family: 'Fredoka'; font-size: 1.05rem; }
.res .plus { color: #ffb4a8; }
.res .plus.zero { color: var(--ok); }
.bar { height: 6px; border-radius: 9px; background: rgba(255,255,255,.12); margin-top: 7px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), var(--gold), var(--danger)); }
.rules h3 { color: var(--gold); margin: 14px 0 4px; font-size: 1.05rem; }
.rules p, .rules li { color: var(--cream); line-height: 1.45; margin: 4px 0; font-size: .95rem; }
.rules ul { padding-left: 20px; margin: 4px 0; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; top: max(10px, env(safe-area-inset-top)); left: 0; right: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  background: rgba(10, 30, 22, .94); color: var(--cream);
  padding: 9px 16px; border-radius: 99px; font-weight: 800; font-size: .92rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  animation: toastIn .3s cubic-bezier(.2,1.4,.4,1);
  display: flex; align-items: center; gap: 8px; max-width: 92vw;
}
.toast.bad { background: #8f2a22; }
.toast.ok { background: #1f7a52; }
.toast.dutch { background: var(--red); font-family: 'Fredoka'; font-size: 1.15rem; }
.toast .card { --w: 24px; }
.toast .card .c1 { font-size: 7px; }
@keyframes toastIn { from { transform: translateY(-20px); opacity: 0; } }

/* ---------- Confettis ---------- */
.confetti { position: fixed; top: -12px; width: 9px; height: 14px; z-index: 50; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (min-width: 480px) {
  .opp .hand .card { --w: 40px; }
}
