:root {
  --felt: #123D30;
  --felt-deep: #0C2E24;
  --rim: #1C4D3E;
  --ink: #E8F0EA;
  --muted: #8DB3A5;
  --orange: #F26B1D;
  --orange-hi: #FF8A3D;
  --face: #FAFAF7;
  --red: #C8102E;
  --black: #1C1C1C;
  --good: #7BD88F;
  --bad: #FF6B5B;
  --cw: clamp(40px, min(17vw, calc((100dvh - 230px) / 7.4)), 96px);
  --ch: calc(var(--cw) * 1.4);
  --r: calc(var(--cw) * 0.08);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--felt) radial-gradient(ellipse at 50% 45%, #17493A 0%, var(--felt) 55%, var(--felt-deep) 100%) fixed;
  color: var(--ink);
  font-family: 'Fraunces', Georgia, serif;
  font-variation-settings: 'SOFT' 50, 'opsz' 14;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--orange-hi); outline-offset: 3px; }

/* ---------- écrans d'accueil ---------- */
.screen {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px; padding: 24px 16px;
}
.logo {
  font-weight: 900; letter-spacing: -0.02em; line-height: 0.9;
  font-size: clamp(64px, 18vw, 140px);
  font-variation-settings: 'SOFT' 100, 'opsz' 144;
}
.logo-small { font-weight: 900; letter-spacing: -0.01em; font-size: 24px; font-variation-settings: 'SOFT' 100, 'opsz' 72; }
form.login { display: grid; gap: 12px; width: min(320px, 100%); }
.field {
  background: var(--felt-deep); border: 1px solid var(--rim); border-radius: 12px;
  padding: 14px 16px; color: var(--ink); font: inherit; font-size: 17px; width: 100%;
}
.field::placeholder { color: var(--muted); }
.field:focus { outline: none; border-color: var(--orange); }
.err { color: var(--bad); font-size: 14px; min-height: 1.2em; margin: 0; }
.big {
  background: var(--orange); color: #fff; border: none; border-radius: 999px;
  padding: 16px 44px; font-weight: 800; font-size: 20px; cursor: pointer;
  transition: transform .12s, background .12s;
}
.big:hover { background: var(--orange-hi); }
.big:active { transform: scale(.96); }
.ghost {
  background: none; border: 1px solid var(--rim); border-radius: 999px;
  padding: 10px 20px; color: var(--muted); cursor: pointer;
}
.ghost:hover { color: var(--ink); border-color: var(--muted); }
.hint { color: var(--muted); margin: 0; text-align: center; max-width: 32ch; line-height: 1.5; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: 1px; }
.dot.on { background: var(--good); }
.waiting-stack { position: relative; width: var(--cw); height: var(--ch); }
.waiting-stack .card { position: absolute; inset: 0; animation: breathe 1.6s ease-in-out infinite; }
.waiting-stack .card:nth-child(2) { animation-delay: .2s; }
.waiting-stack .card:nth-child(3) { animation-delay: .4s; }
@keyframes breathe { 50% { transform: translateY(-8px) rotate(var(--rot, 0deg)); } }

/* ---------- cartes ---------- */
.card {
  width: var(--cw); height: var(--ch); border-radius: var(--r);
  position: relative; flex: none;
  box-shadow: 0 1px 0 rgba(0,0,0,.25), 0 6px 14px -6px rgba(0,0,0,.5);
}
.back {
  background-color: var(--orange);
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.2) 0 1.5px, transparent 1.5px 7px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.2) 0 1.5px, transparent 1.5px 7px);
  border: calc(var(--cw) * 0.05) solid #fff;
}
.back::after {
  content: ''; position: absolute; inset: calc(var(--cw) * 0.04);
  border: 1.5px solid rgba(255,255,255,.75); border-radius: calc(var(--r) * 0.5);
}
.face {
  background: var(--face); color: var(--black);
  font-family: Georgia, 'Times New Roman', serif; font-weight: 700;
}
.face.red { color: var(--red); }
.face .corner {
  position: absolute; display: flex; flex-direction: column; align-items: center;
  line-height: 0.95; font-size: calc(var(--cw) * 0.22);
}
.face .corner small { font-size: calc(var(--cw) * 0.18); }
.face .tl { top: 5%; left: 7%; }
.face .br { bottom: 5%; right: 7%; transform: rotate(180deg); }
.face .pip {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: calc(var(--cw) * 0.48);
}
.face .pip.court { font-size: calc(var(--cw) * 0.34); font-weight: 800; letter-spacing: -0.02em; }
.face.joker .pip { font-size: calc(var(--cw) * 0.17); letter-spacing: .02em; flex-direction: column; }
.flip-in { animation: flipIn .28s ease-out; }
@keyframes flipIn { from { transform: rotateY(90deg); } to { transform: none; } }

/* ---------- table ---------- */
.table {
  height: 100dvh; display: grid;
  grid-template-rows: auto 1fr auto 1fr auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
}
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 40px; }
.who { color: var(--muted); font-size: 15px; display: flex; align-items: center; gap: 8px; }
.who b { color: var(--ink); font-weight: 600; }
.who.active b { color: var(--orange-hi); }
.zone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.hand { display: grid; grid-template-rows: repeat(2, var(--ch)); grid-auto-flow: column; grid-auto-columns: var(--cw); gap: 10px; }
.slot {
  width: var(--cw); height: var(--ch); padding: 0; border: none; background: none;
  border-radius: var(--r); cursor: pointer; position: relative; display: block;
}
.slot.empty { border: 1.5px dashed rgba(232,240,234,.14); cursor: default; }
.slot.target .card { outline: 2px solid var(--orange-hi); outline-offset: 3px; }
.slot.picked .card { outline: 3px solid #fff; outline-offset: 3px; transform: translateY(-4px); }
.slot:not(.empty):hover .card { transform: translateY(-3px); }
.slot .card { transition: transform .12s; }
.slot.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.center { display: flex; align-items: center; justify-content: center; gap: clamp(20px, 7vw, 48px); padding: 8px 0; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pile-label { font-size: 13px; color: var(--muted); }
.stack { isolation: isolate; position: relative; width: var(--cw); height: var(--ch); background: none; border: none; padding: 0; border-radius: var(--r); cursor: pointer; }
.stack .card { position: absolute; inset: 0; }
.stack.under-1::before, .stack.under-2::after {
  content: ''; position: absolute; inset: 0; border-radius: var(--r);
  background: #E35F12; border: calc(var(--cw) * 0.05) solid #f3f3f3; z-index: -1;
}
.stack.under-1::before { transform: translate(2px, 2px); }
.stack.under-2::after { transform: translate(4px, 4px); }
.stack.target .card:last-child { outline: 2px solid var(--orange-hi); outline-offset: 3px; }
.fosse-empty { width: var(--cw); height: var(--ch); border-radius: var(--r); border: 1.5px dashed rgba(232,240,234,.22); }
.drawn-wrap { width: var(--cw); height: var(--ch); position: relative; }
.drawn-wrap .card { position: absolute; inset: 0; transform: translateY(-6px) rotate(-3deg); }

.bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.status { font-size: 15px; line-height: 1.35; color: var(--ink); max-width: 30ch; }
.status .sub { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.mimamo-btn {
  background: var(--orange); color: #fff; border: none; border-radius: 999px;
  padding: 14px 26px; font-weight: 800; font-size: 18px; letter-spacing: -0.01em;
  cursor: pointer; flex: none; transition: transform .1s, background .12s, opacity .12s;
}
.mimamo-btn:active { transform: scale(.94); }
.mimamo-btn.idle { background: transparent; box-shadow: inset 0 0 0 1.5px var(--orange); color: var(--orange-hi); }
.mimamo-btn.shake { animation: shake .35s; }

.timer { height: 3px; background: rgba(232,240,234,.12); border-radius: 2px; overflow: hidden; width: 100%; margin-top: 6px; }
.timer i { display: block; height: 100%; background: var(--orange); transform-origin: left; animation: drain linear forwards; }
@keyframes drain { to { transform: scaleX(0); } }

.actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.chip { background: var(--felt-deep); border: 1px solid var(--rim); color: var(--ink); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: 14px; }
.chip:hover { border-color: var(--muted); }

/* pierre feuille ciseaux */
.rps { display: flex; gap: 12px; }
.rps button {
  width: 92px; height: 92px; border-radius: 50%; background: var(--felt-deep);
  border: 1.5px solid var(--rim); font-size: 15px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.rps button span { font-size: 30px; }
.rps button:hover { border-color: var(--orange); }
.rps button.chosen { background: var(--orange); border-color: var(--orange); }

/* fin de partie */
.score { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; }
.score.win { color: var(--orange-hi); }

/* messages flash */
#toast {
  font-variation-settings: 'SOFT' 100, 'opsz' 144;
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.9);
  pointer-events: none; opacity: 0; text-align: center;
  font-weight: 800; letter-spacing: -0.03em; font-size: clamp(30px, 9vw, 56px);
  text-shadow: 0 4px 24px rgba(0,0,0,.45); transition: opacity .18s, transform .18s; z-index: 10;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#toast.good { color: var(--good); }
#toast.bad { color: var(--bad); }
#toast.orange { color: var(--orange-hi); font-size: clamp(48px, 16vw, 110px); }
#toast small { display: block; font-size: 16px; font-weight: 600; letter-spacing: 0; color: var(--ink); margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.tag { background: var(--orange); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }
.fosse-empty.target { border-color: var(--orange-hi); border-style: solid; cursor: pointer; }
.face .photo {
  position: absolute; left: 16%; right: 16%; top: 20%; bottom: 20%;
  width: 68%; height: 60%; object-fit: cover; border-radius: calc(var(--r) * 0.6);
  pointer-events: none;
}

/* ---------- classement ---------- */
.scoreboard { display: grid; gap: 14px; }
.sb-title { font-size: 13px; color: var(--muted); }
.sb-row { display: grid; gap: 4px; }
.sb-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.sb-name { font-weight: 700; font-size: 17px; }
.sb-row.me .sb-name { color: var(--orange-hi); }
.sb-wins {
  font-weight: 800; font-size: 13px; color: var(--felt); background: var(--ink);
  border-radius: 999px; padding: 2px 9px; font-variant-numeric: tabular-nums;
}
.sb-pts { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }
.sb-pts b { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.sb-pts span { color: var(--muted); font-size: 13px; }
.sb-bar { position: relative; height: 4px; border-radius: 2px; background: rgba(232,240,234,.12); overflow: hidden; }
.sb-bar.thick i, .sb-bar i { position: absolute; inset: 0 auto 0 0; border-radius: 2px; background: var(--ink); transition: width .6s cubic-bezier(.2,.8,.2,1); }
.sb-bar i.hot { background: var(--bad); }
.sb-bar.thick { height: 6px; }
.sb-bar i.before { background: rgba(232,240,234,.35); }

.scoreboard.side {
  display: none; position: fixed; left: 28px; top: 50%; transform: translateY(-50%);
  width: 190px; padding: 18px; border-radius: 16px;
  background: rgba(12,46,36,.55); border: 1px solid var(--rim);
}
@media (min-width: 1100px) { .scoreboard.side { display: grid; } }

.scoreboard.strip { display: flex; gap: 14px; }
.scoreboard.strip .sb-title, .scoreboard.strip .sb-bar, .scoreboard.strip .sb-pts span { display: none; }
.scoreboard.strip .sb-row { display: flex; align-items: center; gap: 6px; }
.scoreboard.strip .sb-head { order: 0; gap: 6px; }
.scoreboard.strip .sb-name { font-size: 14px; }
.scoreboard.strip .sb-pts b { font-size: 15px; }
.scoreboard.strip .sb-wins { font-size: 11px; padding: 1px 6px; }
@media (min-width: 1100px) { .scoreboard.strip { display: none; } }
@media (max-width: 1099px) { .table .logo-small { display: none; } }

.scoreboard.lobby { width: min(300px, 100%); margin-top: 8px; padding: 18px; border-radius: 16px; border: 1px solid var(--rim); background: rgba(12,46,36,.45); }

/* ---------- tableau de fin de manche ---------- */
.result-veil {
  position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 16px;
  background: rgba(10,38,30,.72); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.result-veil.anim { animation: fadeIn .25s ease-out; }
@keyframes fadeIn { from { opacity: 0; } }
.result {
  width: min(460px, 100%); display: grid; gap: 18px; padding: 26px 24px;
  border-radius: 20px; background: var(--felt); border: 1px solid var(--rim);
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.6);
}
.anim .result { animation: rise .35s cubic-bezier(.2,.9,.25,1); }
@keyframes rise { from { transform: translateY(16px) scale(.98); opacity: 0; } }
.rs-title { font-size: 34px; font-weight: 900; letter-spacing: -0.02em; line-height: 1.05; font-variation-settings: 'SOFT' 100, 'opsz' 144; }
.rs-title.win { color: var(--orange-hi); }
.result.match .rs-title { color: var(--orange-hi); font-size: 40px; }
.rs-rows { display: grid; gap: 16px; }
.rs-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; }
.rs-name { font-weight: 700; font-size: 19px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rs-row.me .rs-name { color: var(--orange-hi); }
.rs-detail { grid-column: 1; color: var(--muted); font-size: 14px; }
.rs-gain { grid-column: 2; grid-row: 1 / span 2; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; align-self: center; }
.rs-pen { color: var(--bad); font-weight: 700; }
.rs-total { grid-column: 1 / -1; display: grid; gap: 6px; margin-top: 4px; }
.rs-total span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rs-total b { color: var(--ink); font-size: 15px; }
.rs-w {
  background: var(--orange); color: #fff; font-size: 14px; font-weight: 800; padding: 2px 10px; border-radius: 999px;
}
.anim .rs-w { animation: pop .5s .4s cubic-bezier(.2,1.6,.4,1) backwards; }
@keyframes pop { from { transform: scale(0); } }
.rs-ready { font-size: 12px; font-weight: 600; color: var(--good); }
.rs-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.rs-actions .big { padding: 13px 28px; font-size: 17px; }
.result .hint { text-align: left; margin: 0; }
.scoreboard.strip .sb-head { display: contents; }
.scoreboard.strip .sb-name { order: 0; }
.scoreboard.strip .sb-pts { order: 1; }
.scoreboard.strip .sb-wins { order: 2; }
