:root {
  --bg: #3a1878;
  --panel: rgba(30, 10, 70, 0.38);
  --panel-border: rgba(255, 255, 255, 0.18);
  --text: #fdf8ff;
  --muted: #dccdf7;
  --accent: #ffd23f;
  --accent-text: #1d2b30;
  --danger: #ff6b5e;

  --c-neg: #4b4fd1;
  --c-zero: #48b8e8;
  --c-low: #5cb83c;
  --c-mid: #f2c624;
  --c-high: #e2453a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Fond : dégradé festif, taches de couleur qui dérivent, petites cartes qui flottent ---------- */
body::before {
  content: "";
  position: fixed;
  inset: -25%;
  z-index: -2;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 92, 170, 0.75), transparent 32%),
    radial-gradient(circle at 82% 18%, rgba(255, 196, 64, 0.65), transparent 30%),
    radial-gradient(circle at 78% 80%, rgba(56, 210, 255, 0.6), transparent 34%),
    radial-gradient(circle at 20% 82%, rgba(110, 230, 120, 0.45), transparent 30%),
    linear-gradient(135deg, #4a1d9e 0%, #8a2bb8 45%, #e2477f 100%);
  animation: drift 26s ease-in-out infinite alternate;
}
@keyframes drift {
  0% { transform: translate(0, 0) rotate(0deg) scale(1); }
  50% { transform: translate(4%, -3%) rotate(8deg) scale(1.08); }
  100% { transform: translate(-4%, 3%) rotate(-6deg) scale(1.04); }
}
.bg-deco { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-deco span {
  position: absolute;
  bottom: -90px;
  width: 38px; height: 54px;
  border-radius: 7px;
  border: 3px solid rgba(255, 255, 255, 0.75);
  display: grid; place-items: center;
  color: #fff; font-weight: 900; font-size: 18px;
  opacity: 0.22;
  animation: float 22s linear infinite;
}
.bg-deco span:nth-child(1) { left: 6%;  background: var(--c-neg);  animation-duration: 24s; }
.bg-deco span:nth-child(2) { left: 22%; background: var(--c-mid);  animation-duration: 19s; animation-delay: -8s; color: #3a3000; }
.bg-deco span:nth-child(3) { left: 38%; background: var(--c-high); animation-duration: 27s; animation-delay: -15s; }
.bg-deco span:nth-child(4) { left: 55%; background: var(--c-zero); animation-duration: 21s; animation-delay: -4s; }
.bg-deco span:nth-child(5) { left: 71%; background: var(--c-low);  animation-duration: 25s; animation-delay: -12s; }
.bg-deco span:nth-child(6) { left: 86%; background: var(--c-high); animation-duration: 20s; animation-delay: -18s; }
.bg-deco span:nth-child(7) { left: 94%; background: var(--c-neg);  animation-duration: 28s; animation-delay: -2s; }
.bg-deco span:nth-child(8) { left: 47%; background: var(--c-mid);  animation-duration: 23s; animation-delay: -20s; color: #3a3000; }
@keyframes float {
  from { transform: translateY(0) rotate(-15deg); }
  to { transform: translateY(calc(-100vh - 140px)) rotate(200deg); }
}
@media (prefers-reduced-motion: reduce) {
  body::before, .bg-deco span { animation: none; }
  .bg-deco { display: none; }
}
button, input { font: inherit; }
.hidden { display: none !important; }

.screen {
  max-width: 1100px;
  margin: 0 auto;
  /* une fois installée, l'app passe sous la barre d'état et l'encoche du téléphone */
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(40px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}
.btn.install { margin-bottom: 16px; background: rgba(255, 255, 255, 0.16); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.install-steps { padding-left: 22px; line-height: 1.6; }
.install-steps li { margin: 8px 0; }
.share-glyph {
  display: inline-grid; place-items: center; width: 26px; height: 26px; vertical-align: middle;
  border-radius: 7px; background: rgba(255, 255, 255, 0.15); font-size: 15px;
}
#home, #lobby { max-width: 460px; text-align: center; }

/* ---------- Accueil ---------- */
.logo {
  font-size: clamp(56px, 16vw, 84px);
  margin: 28px 0 0;
  letter-spacing: 4px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 0 #2a0b5c, 0 10px 30px rgba(255, 80, 170, 0.55);
}
.logo span { color: var(--accent); }
.tagline { color: var(--muted); margin: 6px 0 24px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 18px;
  text-align: left;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(30, 0, 60, 0.25);
  margin-bottom: 16px;
}
.panel h3 { margin: 0 0 12px; font-size: 17px; }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field input, .share input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.block { margin-top: 14px; }
.sep { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 18px 0 4px; font-size: 13px; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: var(--panel-border); }
.error { color: var(--danger); min-height: 1.2em; margin: 12px 0 0; font-weight: 600; }
.hint { color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s, background .15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.2); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { background: #ffdc66; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { width: auto; padding: 7px 12px; font-size: 14px; border-radius: 10px; white-space: nowrap; flex: none; }
.btn.ghost { background: transparent; }

.rules { text-align: left; color: var(--muted); font-size: 14px; background: var(--panel); border-radius: 14px; padding: 12px 16px; }
.rules summary { cursor: pointer; font-weight: 700; color: var(--text); }
.rules li { margin: 6px 0; }

/* ---------- Salle d'attente ---------- */
.kicker { text-transform: uppercase; letter-spacing: 2px; color: var(--muted); font-size: 12px; margin: 28px 0 0; }
.room-name { font-size: 34px; margin: 4px 0 14px; word-break: break-word; }
.share { display: flex; gap: 8px; }
.share input { font-size: 14px; padding: 8px 12px; }
.player-list { list-style: none; padding: 0; margin: 0 0 14px; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: rgba(0, 0, 0, 0.18); margin-bottom: 6px;
}
.player-list .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; color: #fff;
}
.tag { font-size: 12px; color: var(--muted); }
.off { opacity: .5; }
.bot-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 14px; border-radius: 12px; border: 1px dashed var(--panel-border);
}
.bot-label { font-size: 14px; font-weight: 700; color: var(--muted); }
.bot-btns { display: flex; gap: 8px; }
.bot-btns .btn:disabled { opacity: .4; cursor: not-allowed; }
.tag.bot-hard { color: #ffb3c7; }
.kick {
  border: none; background: none; color: var(--danger); cursor: pointer; font-size: 18px; padding: 2px 6px;
}

/* ---------- Cartes ---------- */
.card {
  --w: var(--cw, 60px);
  width: var(--w);
  height: calc(var(--w) * 1.4);
  border-radius: calc(var(--w) * 0.14);
  position: relative;
  display: grid; place-items: center;
  border: calc(var(--w) * 0.05) solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  color: #fff;
  font-weight: 900;
  user-select: none;
  padding: 0;
  font-family: inherit;
}
.card .val { font-size: calc(var(--w) * 0.46); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.card .corner { position: absolute; font-size: calc(var(--w) * 0.18); line-height: 1; }
.card .tl { top: 6%; left: 9%; }
.card .br { bottom: 6%; right: 9%; transform: rotate(180deg); }
.card.v-neg { background: linear-gradient(145deg, #6a6ef0, var(--c-neg)); }
.card.v-zero { background: linear-gradient(145deg, #7fd3f5, var(--c-zero)); }
.card.v-low { background: linear-gradient(145deg, #86d466, var(--c-low)); }
.card.v-mid { background: linear-gradient(145deg, #ffe066, var(--c-mid)); color: #3a3000; }
.card.v-mid .val { text-shadow: none; }
.card.v-high { background: linear-gradient(145deg, #f2786e, var(--c-high)); }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.06) 0 6px, transparent 6px 12px),
    linear-gradient(145deg, #4f46d8, #2a1a80);
}
.card.back .logo-mini {
  font-size: calc(var(--w) * 0.2); letter-spacing: 1px; transform: rotate(-60deg); opacity: .8;
}
.card.removed { background: none; border: 2px dashed rgba(255, 255, 255, 0.15); box-shadow: none; }
.card.empty { background: rgba(0, 0, 0, 0.2); border: 2px dashed rgba(255, 255, 255, 0.25); box-shadow: none; }
.card.clickable { cursor: pointer; outline: 3px solid var(--accent); outline-offset: 2px; animation: pulse 1.4s infinite; }
.card.clickable:hover { transform: translateY(-3px); }
.card.fresh { animation: pop .45s ease-out; }
@keyframes pulse { 50% { outline-color: rgba(255, 210, 63, 0.35); } }
@keyframes pop { 0% { transform: scale(.6) rotateY(90deg); } 100% { transform: none; } }

.grid {
  display: grid;
  grid-template-columns: repeat(4, var(--cw));
  gap: calc(var(--cw) * 0.12);
  justify-content: center;
}

/* ---------- Jeu ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.topbar .title b { font-size: 18px; margin-right: 8px; }
.topbar .title span { color: var(--muted); font-size: 14px; }
.tools { display: flex; gap: 4px; }

.banner {
  margin: 12px 0;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--panel-border);
  text-align: center;
  font-weight: 600;
}
.banner.me { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.banner.last { box-shadow: 0 0 0 2px var(--danger) inset; }
.banner .btn { margin-top: 10px; }

.opponents {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
}
.board {
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 8px 10px 10px;
  transition: box-shadow .2s;
}
.board.small { --cw: 26px; }
.board.turn { box-shadow: 0 0 0 3px var(--accent); }
.board.off { opacity: .55; }
.board-head {
  display: flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 6px; max-width: 100%;
}
.board-head .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.board-head .pts { margin-left: auto; color: var(--muted); white-space: nowrap; }
.board-head .avatar { width: 20px; height: 20px; font-size: 11px; }

.table {
  display: flex; justify-content: center; align-items: flex-end; gap: clamp(14px, 5vw, 36px);
  margin: 18px 0; --cw: clamp(54px, 15vw, 70px);
}
.pile { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pile-label { font-size: 13px; color: var(--muted); }
.pile.hand .card:not(.empty) { transform: rotate(4deg); }

.my-area .board { --cw: clamp(54px, min(19vw, 9.5vh), 82px); max-width: 520px; margin: 0 auto; padding: 12px; }
.my-area .board-head { font-size: 15px; }
.my-area .board-head .name { max-width: none; }

.log { list-style: none; padding: 0; margin: 18px auto 0; max-width: 520px; font-size: 13px; color: var(--muted); }
.log li { padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.log li:last-child { color: var(--text); }

/* ---------- Fenêtres ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(25, 5, 50, 0.7); display: grid; place-items: center; padding: 16px; z-index: 10;
}
.modal-box {
  background: #34146e; border: 1px solid var(--panel-border); border-radius: 18px; padding: 20px;
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
}
.modal-box h2 { margin: 0 0 4px; }
.modal-box .sub { color: var(--muted); margin: 0 0 14px; }
.modal-box .actions { display: flex; gap: 8px; margin-top: 16px; }
.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
.scores th, .scores td { padding: 8px 6px; text-align: center; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores .total { font-weight: 800; }
.scores tr.best td { color: var(--accent); }
.scores .dbl { color: var(--danger); font-size: 12px; }
.table-wrap { overflow-x: auto; }
.winner { font-size: 22px; margin: 6px 0 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(100px);
  background: #fff; color: #10303a; padding: 10px 16px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3); transition: transform .25s; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (min-width: 800px) {
  .board.small { --cw: 34px; }
}

/* ---------- Réactions ---------- */
.me-react {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  background: rgba(255, 255, 255, 0.1); border: 1px solid var(--panel-border); color: inherit;
  border-radius: 999px; padding: 3px 10px 3px 3px; cursor: pointer; font: inherit;
  transition: background .15s, transform .08s;
}
.me-react:hover { background: rgba(255, 255, 255, 0.2); }
.me-react:active { transform: scale(0.96); }
.react-hint { font-size: 15px; animation: wiggle 2.8s ease-in-out infinite; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-18deg); } 90% { transform: rotate(16deg); } 95% { transform: rotate(-8deg); } }

.react-picker {
  position: fixed; z-index: 35; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  width: min(440px, calc(100% - 24px)); transform: translateX(-50%);
  background: #34146e; border: 1px solid var(--panel-border); border-radius: 22px; padding: 12px;
  box-shadow: 0 18px 50px rgba(20, 0, 50, 0.55);
  animation: sheetIn .22s ease-out;
}
@keyframes sheetIn { from { transform: translate(-50%, 30px); opacity: 0; } }
.react-title { margin: 2px 4px 10px; font-size: 13px; color: var(--muted); font-weight: 700; text-align: center; }
.react-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.react-option {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px;
  border: none; border-radius: 14px; background: rgba(255, 255, 255, 0.07); color: var(--text);
  font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; transition: transform .1s, background .15s;
}
.react-option:hover { background: rgba(255, 255, 255, 0.16); transform: translateY(-2px); }
.react-option:active { transform: scale(0.92); }
.react-slot { width: 46px; height: 46px; display: grid; place-items: center; font-size: 36px; line-height: 1; }

.react-layer { position: fixed; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.react-pop {
  position: absolute; top: 42%; left: 50%;
  display: flex; flex-direction: column; align-items: center;
  transform: translate(calc(-50% + var(--dx, 0px)), -50%);
  animation: reactPop 3.2s cubic-bezier(.2, .9, .3, 1.2) forwards;
}
@keyframes reactPop {
  0% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), -40%) scale(.2) rotate(-12deg); }
  12% { opacity: 1; transform: translate(calc(-50% + var(--dx, 0px)), -50%) scale(1.15) rotate(4deg); }
  22% { transform: translate(calc(-50% + var(--dx, 0px)), -50%) scale(1) rotate(0); }
  78% { opacity: 1; transform: translate(calc(-50% + var(--dx, 0px)), -62%) scale(1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), -95%) scale(.85); }
}
.react-anim {
  width: clamp(110px, 32vw, 170px); height: clamp(110px, 32vw, 170px);
  display: grid; place-items: center; font-size: clamp(80px, 24vw, 130px); line-height: 1;
  filter: drop-shadow(0 10px 18px rgba(30, 0, 60, 0.45));
}
.react-label {
  margin-top: -4px; font-size: clamp(26px, 8vw, 38px); font-weight: 900; color: #fff; white-space: nowrap;
  -webkit-text-stroke: 6px #3a0f7a; paint-order: stroke fill; text-shadow: 0 6px 16px rgba(30, 0, 60, 0.5);
}
.react-who {
  margin-top: 6px; padding: 3px 12px; border-radius: 999px; font-size: 14px; font-weight: 800;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 12px rgba(30, 0, 60, 0.35);
}
.react-non .react-label, .react-grr .react-label, .react-quoi .react-label { animation: shake .35s ease-in-out 4; }
.react-zzz .react-label { animation: doze 1.6s ease-in-out infinite; }
@keyframes shake { 25% { transform: translateX(-6px) rotate(-3deg); } 75% { transform: translateX(6px) rotate(3deg); } }
@keyframes doze { 50% { transform: translateY(-6px) rotate(-4deg); opacity: .8; } }
@media (prefers-reduced-motion: reduce) {
  .react-pop { animation-duration: .01s; animation-fill-mode: none; }
}
.credits { font-size: 12px; opacity: .8; margin: 10px 0 0; }
.credits a { color: inherit; }
