:root {
  --felt: #12573f;
  --felt-dark: #0b3326;
  --felt-deep: #061f17;
  --cream: #fbf4e4;
  --ink: #1c1c1e;
  --red: #d42a33;
  --gold: #f5c451;
  --gold-ink: #3a2a00;
  --muted: rgba(251, 244, 228, .64);
  --line: rgba(251, 244, 228, .13);
  --glass: rgba(0, 0, 0, .22);
  --ok: #4ade80;
  --warn: #fbbf24;
  --ko: #e5383b;
  --serif: Georgia, "Times New Roman", serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--felt-deep); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--cream);
  background: var(--felt-deep);
  isolation: isolate; /* le feutre (body::before) se peint par-dessus ce fond, sous le contenu */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
/* Tapis de jeu : feutre vert avec un léger grain. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .14 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(120% 75% at 50% 32%, var(--felt) 0%, var(--felt-dark) 55%, var(--felt-deep) 100%);
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
.btn {
  display: block;
  width: 100%;
  padding: 14px 18px;
  border-radius: 14px;
  font-weight: 700;
  text-align: center;
  background: var(--glass);
  border: 1px solid var(--line);
  transition: transform .1s;
}
.btn:active:not(:disabled), .icon:active:not(:disabled), .chip:active { transform: scale(.96); }
.btn.primary { background: var(--gold); color: var(--gold-ink); border-color: transparent; box-shadow: 0 6px 20px rgba(245, 196, 81, .22); }
.btn.danger { background: var(--ko); color: #fff; border-color: transparent; }
.btn.small { width: auto; padding: 8px 12px; font-size: 14px; border-radius: 10px; flex: none; }
.icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 18px;
  background: var(--glass);
  border: 1px solid var(--line);
}
.dim { color: var(--muted); }

input, textarea, select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* en dessous, l'iPhone zoome sur le champ */
  color: var(--cream);
  background: rgba(0, 0, 0, .28);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  -webkit-user-select: text;
  user-select: text;
}
input::placeholder, textarea::placeholder { color: rgba(251, 244, 228, .4); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
textarea { resize: none; min-height: 76px; text-align: left; }

.palm { display: block; }

/* ---------- Accueil / joueurs ---------- */

.setup { max-width: 480px; margin: 0 auto; padding: 20px 0 32px; display: grid; gap: 16px; }
.brand { text-align: center; padding-top: 8px; }
.brand .palm { width: 88px; height: 88px; margin: 0 auto; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .4)); }
.brand h1 { margin: 4px 0; font: 800 42px/1 var(--serif); letter-spacing: -.5px; }
.brand p { margin: 0; color: var(--muted); }
.brand.small .palm { width: 64px; height: 64px; }

.panel { background: var(--glass); border: 1px solid var(--line); border-radius: 20px; padding: 16px; }
.panel h2, .table-wrap h2 {
  display: flex;
  justify-content: space-between;
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--gold);
}
.add { display: flex; gap: 8px; }
.add .btn { width: auto; flex: none; }
.players { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.players li { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 10px; background: rgba(255, 255, 255, .04); border-radius: 12px; }
.players .icon { width: 34px; height: 34px; font-size: 15px; }
.num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--gold);
  color: var(--gold-ink);
  font-weight: 800;
  font-size: 13px;
}
.pname { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { margin: 10px 2px 0; color: var(--muted); font-size: 14px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field + .field { margin-top: 14px; }
.field span { display: grid; font-weight: 600; }
.field small { color: var(--muted); font-weight: 400; font-size: 13px; }
.field select {
  width: auto;
  max-width: 55%;
  -webkit-appearance: none;
  appearance: none;
  padding-right: 34px;
  background: rgba(0, 0, 0, .28) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23fbf4e4' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 12px center;
}
.actions { display: grid; gap: 10px; }
.share { display: grid; gap: 10px; }
.share h2 { margin: 0; }
.share-row { display: flex; gap: 8px; }
.share-row input { flex: 1; min-width: 0; color: var(--gold); font-weight: 600; }
.share-row .btn { width: auto; flex: none; }

/* ---------- Partie ---------- */

.game { display: flex; flex-direction: column; padding-bottom: 16px; }
.bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 10px 0 4px; }
.bar-end { justify-self: end; display: flex; gap: 8px; }
.bar h1 { margin: 0; display: flex; align-items: center; gap: 6px; font: 800 22px/1 var(--serif); white-space: nowrap; }
.bar .palm { width: 30px; height: 30px; }
.board { display: grid; gap: 16px; }
.play { display: grid; justify-items: center; gap: 4px; }

/* Au-dessus du cercle : à qui le tour, remplacé par la jauge de douceur pendant qu'on tire. */
.status { width: 100%; min-height: 92px; display: grid; place-items: center; text-align: center; }
.info, .meter { grid-area: 1 / 1; transition: opacity .2s; }
.meter { width: min(80%, 300px); opacity: 0; pointer-events: none; }
.play.dragging .info { opacity: 0; pointer-events: none; }
.play.dragging .meter { opacity: 1; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .14em; color: var(--gold); }
.turn { display: flex; align-items: center; justify-content: center; gap: 2px; margin: 2px 0; }
.turn strong { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 800 clamp(26px, 8vw, 40px)/1.15 var(--serif); }
.arrow { width: 40px; height: 44px; font-size: 30px; line-height: 1; color: var(--muted); }
.sub { color: var(--muted); font-size: 14px; }
.gauge { height: 12px; border-radius: 6px; overflow: hidden; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); }
.gauge i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--ok); transition: width .08s linear, background-color .15s; }
.gauge i[data-lvl="warn"] { background: var(--warn); }
.meter span { display: block; margin-top: 8px; font-weight: 700; }
.play > .hint { margin: 2px 0 0; text-align: center; font-size: 13px; }
.play > .hint b { color: var(--cream); }

.ring {
  position: relative;
  width: min(100%, calc(100vh - 340px), 620px);
  width: min(100%, calc(100dvh - 340px), 620px);
  min-width: 280px;
  aspect-ratio: 1;
}
.ring.shake { animation: shake .6s; }
/* Le palmier au milieu, qui rapetisse avec le cercle. */
.glass {
  position: absolute;
  left: 50%;
  top: 50%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(0, 0, 0, .3), transparent 70%);
}
.glass .palm { width: 78%; height: 78%; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .35)); }

.card {
  position: absolute;
  width: 7.6%;
  height: 11%;
  border-radius: 3px;
  transform: translate(-50%, -50%) translate(var(--dx, 0px), var(--dy, 0px)) rotate(var(--rot)) scale(var(--s, 1));
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .16) 0 2px, transparent 2px 5px),
    linear-gradient(160deg, #ef6b4f, #b5311e);
  border: 1.5px solid var(--cream);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .5);
  touch-action: none;
  cursor: grab;
  transition: transform .45s cubic-bezier(.2, .9, .3, 1.15), box-shadow .2s;
}
.card.dragging { --s: 1.18; z-index: 60; transition: none; cursor: grabbing; box-shadow: 0 14px 26px rgba(0, 0, 0, .55); }
@media (hover: hover) { .card:hover { filter: brightness(1.15); } }

/* La table : cartes qui restent à côté du cercle */
.table { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.slot { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 8px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); }
.slot.wide { grid-column: 1 / -1; }
.slot-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left; }
.minis { display: flex; flex: none; }
.minis .mini + .mini { margin-left: -20px; }
.slot-text { display: grid; min-width: 0; }
.t { font-weight: 700; font-size: 14px; }
.h { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.h em { color: var(--gold); }
.empty { margin: 0; padding: 14px; text-align: center; color: var(--muted); font-size: 14px; border: 1.5px dashed var(--line); border-radius: 14px; }

.mini {
  flex: none;
  width: 30px;
  height: 42px;
  border-radius: 5px;
  display: grid;
  place-content: center;
  justify-items: center;
  font: 700 14px/1 var(--serif);
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.mini i { font-style: normal; font-size: 13px; margin-top: 2px; }
.mini.red { color: var(--red); }
.mini.boom { background: var(--ko); font-size: 18px; }

/* ---------- Pop-ups ---------- */

#modal:empty { display: none; }
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid; /* centré par les marges auto de .sheet : un pop-up plus haut que l'écran reste lisible en entier */
  overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(3, 18, 12, .72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade .2s ease-out;
}
.sheet {
  width: 100%;
  max-width: 420px;
  margin: auto;
  display: grid;
  gap: 12px;
  padding: 20px;
  text-align: center;
  border-radius: 24px;
  background: linear-gradient(180deg, #1a5a43, #0e3a2c);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
  animation: pop .3s cubic-bezier(.2, .9, .3, 1.25);
}
.sheet h2 { margin: 0; font: 800 26px/1.15 var(--serif); }
.sheet p { margin: 0; }
.rule { font-size: 17px; line-height: 1.45; }
.drawn-by { color: var(--muted); }
.drawn-by b { color: var(--cream); }

.face {
  position: relative;
  width: 116px;
  height: 164px;
  margin: 0 auto;
  border-radius: 12px;
  font-family: var(--serif);
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5), inset 0 0 0 5px var(--cream), inset 0 0 0 6px rgba(0, 0, 0, .12);
  animation: flip .55s cubic-bezier(.2, .9, .3, 1.1);
}
.face.red { color: var(--red); }
.corner { position: absolute; font-weight: 700; font-size: 17px; line-height: 1.05; text-align: center; }
.tl { top: 9px; left: 10px; }
.br { bottom: 9px; right: 10px; transform: rotate(180deg); }
.mid { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; line-height: 1; }
.mid b { font-size: 54px; }
.mid i { font-style: normal; font-size: 30px; }
.mid .pip { font-size: 76px; }

.broken {
  display: grid;
  gap: 2px;
  padding: 10px;
  border-radius: 14px;
  background: var(--ko);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  animation: shake .5s;
}
.broken span { font-size: 15px; font-weight: 600; }
.partner-note { padding: 8px; border-radius: 12px; background: rgba(245, 196, 81, .14); color: var(--gold); font-weight: 600; }
.crowns { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 26px; }
.crowns b { font-weight: normal; }
.crowns i { width: 24px; height: 24px; border-radius: 50%; border: 2px dashed var(--muted); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip { padding: 10px 16px; border-radius: 999px; font-weight: 600; background: var(--glass); border: 1px solid var(--line); }
.chip.on { background: var(--gold); color: var(--gold-ink); border-color: transparent; }
.already { display: grid; gap: 4px; text-align: left; font-size: 14px; color: var(--muted); }
.already b { color: var(--gold); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }

.menu { display: grid; gap: 8px; }
.menu .btn { text-align: left; }
.rules-list { display: grid; gap: 12px; max-height: 62vh; max-height: 62dvh; overflow-y: auto; text-align: left; padding-right: 4px; }
.rule-row { display: flex; align-items: flex-start; gap: 12px; }
.rule-row p { margin-top: 2px; color: var(--muted); font-size: 14px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; color: var(--gold-ink); background: var(--gold); vertical-align: 2px; }
.tag.ko { color: #fff; background: var(--ko); }
.history { list-style: none; margin: 0; padding: 0 4px 0 0; }
.history li { display: flex; align-items: center; gap: 10px; }
.history .n { width: 22px; flex: none; text-align: right; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.history p { margin-top: 2px; color: var(--muted); font-size: 14px; }

/* Le tas des cartes tirées, dans le coin du plateau. */
.pile { position: absolute; right: 1%; bottom: 2%; width: 12.5%; aspect-ratio: .7; z-index: 5; }
.pile-card {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  border-radius: 6px;
  font: 700 clamp(12px, 3.8vw, 22px)/1 var(--serif);
  background: var(--cream);
  color: var(--ink);
  border: 1px solid rgba(0, 0, 0, .18);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45);
  transform: rotate(var(--tilt));
}
.pile-card.red { color: var(--red); }
.pile-card i { font-style: normal; font-size: .85em; }
.pile-label {
  position: absolute;
  right: -4px;
  bottom: -9px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--gold-ink);
  background: var(--gold);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.stats { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; text-align: left; }
.stats li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 12px; background: var(--glass); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 80;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  color: var(--cream);
  background: rgba(0, 0, 0, .82);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(24px) scale(.96); } }
@keyframes flip {
  0% { opacity: 0; transform: perspective(700px) rotateY(180deg) scale(.5); }
  60% { opacity: 1; }
}
@keyframes shake {
  10%, 90% { transform: translate(-2px, 1px) rotate(-.5deg); }
  20%, 80% { transform: translate(4px, -2px) rotate(1deg); }
  30%, 50%, 70% { transform: translate(-7px, 2px) rotate(-1.5deg); }
  40%, 60% { transform: translate(7px, -1px) rotate(1.5deg); }
}

/* Écran large (tablette à l'horizontale, ordinateur) : la table passe à droite du cercle. */
@media (min-width: 860px) {
  .board { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .ring { width: min(100%, calc(100vh - 210px), 760px); width: min(100%, calc(100dvh - 210px), 760px); }
  .table { grid-template-columns: 1fr; }
}

/* Très petits écrans (320 px) : le titre perd son palmier pour laisser la place aux boutons. */
@media (max-width: 350px) {
  .bar .palm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
