:root {
  --bg: #0b0f14;
  --panel: #161d26;
  --panel-2: #1f2833;
  --panel-3: #2a3542;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef2f7;
  --muted: #8a97a8;
  --sign: #1f5bd6;
  --sign-2: #1546ad;
  --green-sign: #0f8a4c;
  --amber: #ffc531;
  --amber-2: #ff9f2e;
  --ok: #2fd47a;
  --ko: #ff4d5e;
  --warn: #ff9f2e;
  --asphalt: #262b33;
  --cw: 100px;
  --road-h: 70px;
  --post-h: 26px;
  --ease-out: cubic-bezier(0.22, 0.9, 0.24, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Overpass', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  background:
    radial-gradient(120% 55% at 50% -12%, #1d3360 0%, rgba(29, 51, 96, 0) 62%),
    radial-gradient(60% 40% at 100% 100%, rgba(255, 159, 46, 0.08), transparent 70%),
    linear-gradient(#0d131b, #090c11);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
}

/* ---------- Barre du haut ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 50px;
  flex: none;
}

.top-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  transition: transform 0.15s, background 0.2s;
}
.icon-btn:active {
  transform: scale(0.9);
  background: var(--panel-2);
}
.icon-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn svg .fill {
  fill: currentColor;
}

.logo {
  display: flex;
  align-items: center;
  gap: 1px;
  font-weight: 900;
  font-size: 19px;
  letter-spacing: 0.02em;
}
.logo-sign {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--sign);
  box-shadow: inset 0 0 0 2px var(--sign), inset 0 0 0 4px #fff;
  font-size: 18px;
  padding-top: 3px;
  margin-right: 2px;
}
.logo-text {
  padding-top: 3px;
}

/* ---------- HUD ---------- */

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 42px;
  flex: none;
}

.phase-sign {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 4px;
  border-radius: 9px;
  background: var(--sign);
  box-shadow: inset 0 0 0 2px var(--sign), inset 0 0 0 4px #fff, 0 6px 18px rgba(31, 91, 214, 0.35);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.12em;
  transition: background 0.4s, box-shadow 0.4s;
}
.phase-sign.back {
  background: var(--green-sign);
  box-shadow: inset 0 0 0 2px var(--green-sign), inset 0 0 0 4px #fff, 0 6px 18px rgba(15, 138, 76, 0.35);
}
.phase-sign.won {
  background: var(--amber-2);
  box-shadow: inset 0 0 0 2px var(--amber-2), inset 0 0 0 4px #fff, 0 6px 18px rgba(255, 159, 46, 0.4);
}
.phase-arrow {
  display: inline-block;
  transition: transform 0.5s var(--ease-spring);
}
.phase-sign.back .phase-arrow {
  transform: scaleX(-1);
}
.phase-sign.flip {
  animation: signFlip 0.7s var(--ease-out);
}

.chips {
  display: flex;
  gap: 6px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px 4px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 15px;
  min-width: 52px;
  justify-content: center;
}
.chip b {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.chip-ico {
  color: var(--amber);
  font-size: 13px;
  margin-top: -2px;
}
.chip-ko .chip-ico {
  color: var(--ko);
}
.chip.bump {
  animation: bump 0.45s var(--ease-spring);
}
.chip-ko.bump {
  animation: bumpKo 0.5s var(--ease-out);
}

/* ---------- Mini-carte ---------- */

.minimap {
  position: relative;
  height: 30px;
  flex: none;
  margin-top: 2px;
  cursor: pointer;
}
.mm-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.mm-seg {
  position: relative;
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: var(--panel-3);
  transition: background 0.35s, box-shadow 0.35s, transform 0.35s;
}
.mm-seg.hidden {
  background: repeating-linear-gradient(-45deg, #3a4554 0 4px, #232c37 4px 8px);
}
.mm-seg.done {
  background: var(--ok);
  box-shadow: 0 0 10px rgba(47, 212, 122, 0.5);
}
.mm-seg.current {
  background: var(--amber);
  box-shadow: 0 0 12px rgba(255, 197, 49, 0.7);
  transform: scaleY(1.4);
}
.mm-seg.view {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.mm-seg.flag::after {
  content: '';
  position: absolute;
  top: -15px;
  width: 12px;
  height: 11px;
  background: conic-gradient(#fff 0 25%, #111 0 50%, #fff 0 75%, #111 0) 0 0 / 6px 5.5px;
  border-left: 2px solid #cfd6df;
}
.mm-seg.flag.end::after {
  right: -2px;
}
.mm-seg.flag.start::after {
  left: -2px;
}
.mm-seg.flag.cp::after {
  background: var(--ok);
}
.mm-car {
  position: absolute;
  top: 0;
  width: 22px;
  height: 14px;
  transform: translateX(-50%);
  transition: left 0.55s var(--ease-out);
  background: center / contain no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 54'%3E%3Cpath d='M8 38c0-6 3-10 9-11l16-3 12-11c3-3 6-4 10-4h22c4 0 7 1 10 4l12 12 10 2c5 1 7 5 7 10v3c0 2-1 3-3 3H11c-2 0-3-1-3-3z' fill='%23ff5a4a'/%3E%3Ccircle cx='32' cy='42' r='9' fill='%23111'/%3E%3Ccircle cx='90' cy='42' r='9' fill='%23111'/%3E%3C/svg%3E");
}
.mm-car.back {
  transform: translateX(-50%) scaleX(-1);
}

/* ---------- Scène ---------- */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  margin: 0 -16px;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 9%, #000 91%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 9%, #000 91%, transparent);
  touch-action: none;
}

.road {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--ground, 0px);
  height: var(--road-h);
  background:
    linear-gradient(rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.85)) 0 5px / 100% 3px no-repeat,
    linear-gradient(rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.85)) 0 calc(100% - 5px) / 100% 3px no-repeat,
    linear-gradient(#2d333c, #20252c);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
}
.road::before {
  /* Bas-côté herbeux */
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -5px;
  height: 5px;
  background: linear-gradient(#173a28, #12301f);
}
.road::after {
  /* Accotement sous la route */
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: var(--ground, 0px);
  background: linear-gradient(#12301f, rgba(11, 26, 18, 0.6) 30%, transparent);
}
.lane {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.9) 0 30px, transparent 30px 62px);
  transition: background-position 0.6s var(--ease-out);
}

.track {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  transition: transform 0.6s var(--ease-out);
  will-change: transform;
}
.stage[data-mode='rewind'] .track,
.stage[data-mode='rewind'] .lane {
  transition-duration: 1s;
  transition-timing-function: cubic-bezier(0.65, 0, 0.25, 1);
}
.stage.no-anim .track,
.stage.no-anim .lane,
.stage.no-anim .slot,
.stage.no-anim .car,
.stage.dragging .track,
.stage.dragging .lane,
.stage.dragging .car {
  transition: none !important;
}
.stage.dragging {
  cursor: grabbing;
}

.recenter {
  position: absolute;
  top: 8px;
  left: 50%;
  z-index: 4;
  padding: 7px 14px 5px;
  border: 0;
  border-radius: 99px;
  background: rgba(31, 91, 214, 0.92);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.85), 0 6px 16px rgba(0, 0, 0, 0.4);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px) scale(0.9);
  transition: opacity 0.25s, transform 0.3s var(--ease-spring);
}
.stage.panned .recenter {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.slot {
  position: absolute;
  bottom: calc(var(--ground, 0px) + var(--road-h) - 4px);
  width: var(--cw);
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: 50% 100%;
  transform: scale(0.8);
  opacity: 0.6;
  transition: transform 0.5s var(--ease-out), opacity 0.5s, left 0.3s;
}
.slot.current {
  transform: scale(1.18);
  opacity: 1;
  z-index: 2;
}
.slot.done {
  opacity: 0.8;
}
.slot.focus {
  transform: scale(1.05);
  opacity: 1;
  z-index: 2;
}
.slot.deal-in {
  animation: dealIn 0.55s var(--ease-spring) backwards;
}

.pile {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
}
.pile .card {
  position: absolute;
  inset: 0;
}
.slot.current .pile::before {
  content: '';
  position: absolute;
  inset: -22%;
  background: radial-gradient(closest-side, rgba(255, 197, 49, 0.32), transparent);
  animation: halo 2.2s ease-in-out infinite;
  z-index: -1;
}
.under {
  position: absolute;
  inset: 0;
  border-radius: 7% / 5%;
  background: #ece4d3;
  border: 1px solid #c9bfa8;
  display: none;
}
.under:nth-child(1) {
  transform: translate(-3px, 3px) rotate(-1.5deg);
}
.under:nth-child(2) {
  transform: translate(-6px, 5px) rotate(-3deg);
}
.under:nth-child(3) {
  transform: translate(3px, 6px) rotate(2deg);
}
.pile[data-depth='2'] .under:nth-child(1),
.pile[data-depth='3'] .under:nth-child(-n + 2),
.pile[data-depth='4'] .under {
  display: block;
}

.card {
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45));
}
.card-svg {
  display: block;
  width: 100%;
  height: 100%;
}
.card.pop {
  animation: cardPop 0.4s var(--ease-spring);
}

.slot-badge {
  position: absolute;
  left: 50%;
  bottom: 9%;
  transform: translateX(-50%);
  padding: 3px 7px 1px;
  border-radius: 6px;
  background: rgba(10, 14, 20, 0.85);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: #c9d6ff;
  white-space: nowrap;
  display: none;
}
.slot.hidden-slot .slot-badge {
  display: block;
}
.slot-check {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ok);
  color: #06210f;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 3px 10px rgba(47, 212, 122, 0.5);
  transform: scale(0);
  transition: transform 0.35s var(--ease-spring);
}
.slot.done .slot-check {
  transform: scale(1);
}
.slot.burning .pile {
  animation: burnGlow 0.8s ease-out;
}

.post {
  position: relative;
  width: 5px;
  height: var(--post-h);
  background: linear-gradient(90deg, #8b939e, #c9d0d9 50%, #6f7782);
  border-radius: 0 0 2px 2px;
}
.plate {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 22px;
  height: 17px;
  padding: 2px 5px 0;
  border-radius: 4px;
  background: var(--sign);
  box-shadow: inset 0 0 0 1.5px #fff;
  font-size: 11px;
  font-weight: 900;
  line-height: 16px;
  text-align: center;
}
.slot.hidden-slot .plate {
  background: #3b4553;
}
.slot.current .plate {
  background: var(--amber);
  color: #241a00;
}

/* Voiture */
.car {
  position: absolute;
  left: 50%;
  bottom: calc(var(--ground, 0px) + var(--road-h) * 0.08);
  width: calc(var(--road-h) * 0.95);
  transform: translateX(-50%);
  translate: var(--pan, 0px) 0;
  transition: transform 0.55s var(--ease-spring), translate 0.6s var(--ease-out);
  z-index: 3;
  pointer-events: none;
}
.car.back {
  transform: translateX(-50%) scaleX(-1);
}
.car svg {
  display: block;
  width: 100%;
  overflow: visible;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.5));
}
.car .wheel {
  transform-box: fill-box;
  transform-origin: center;
}
.car.drive .car-body {
  animation: carBounce 0.3s ease-in-out 2;
}
.car.drive .wheel,
.car.rewind .wheel {
  animation: spin 0.25s linear infinite;
}
.car.rewind .wheel {
  animation-direction: reverse;
}
.car.rewind .car-body {
  animation: carShake 0.12s linear infinite;
}
.car.uturn .car-body {
  animation: carHop 0.6s var(--ease-out);
}
.beam {
  opacity: 0.7;
}

.speedlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: repeating-linear-gradient(
      180deg,
      transparent 0 23px,
      rgba(255, 255, 255, 0.12) 23px 25px,
      transparent 25px 61px
    ),
    linear-gradient(90deg, transparent, rgba(255, 77, 94, 0.08), transparent);
  transition: opacity 0.3s;
  -webkit-mask-image: repeating-linear-gradient(90deg, #000 0 80px, transparent 80px 170px);
  mask-image: repeating-linear-gradient(90deg, #000 0 80px, transparent 80px 170px);
}
.stage[data-mode='rewind'] .speedlines {
  opacity: 1;
  animation: speed 0.25s linear infinite;
}

.verdict {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px 6px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 17px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}
.verdict.ok {
  background: var(--ok);
  color: #052611;
}
.verdict.ko {
  background: var(--ko);
  color: #fff;
}
.verdict.warn {
  background: var(--warn);
  color: #2a1500;
}
.verdict.show {
  animation: verdictIn 1.3s var(--ease-out) forwards;
}

/* ---------- Texte d'invite ---------- */

.prompt {
  flex: none;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  color: #dbe3ee;
  padding: 6px 0 2px;
}
.prompt .muted {
  color: var(--muted);
}
.prompt.swap {
  animation: promptIn 0.35s var(--ease-out);
}
.card-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px 2px 9px;
  border-radius: 8px;
  background: #fbf7ee;
  color: #1b2330;
  font-weight: 900;
  font-size: 17px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}
.card-chip.red {
  color: #d3263a;
}
.suit-ico {
  width: 0.85em;
  height: 0.85em;
  fill: currentColor;
  margin-top: -3px;
}

/* ---------- Commandes ---------- */

.controls {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
  position: relative;
}

.guess {
  position: relative;
  height: clamp(76px, 12.5vh, 108px);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-weight: 900;
  letter-spacing: 0.08em;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.2s, opacity 0.3s;
  overflow: hidden;
}
.guess::after {
  /* Reflet */
  content: '';
  position: absolute;
  inset: 0 0 55% 0;
  background: linear-gradient(rgba(255, 255, 255, 0.25), transparent);
  border-radius: inherit;
  pointer-events: none;
}
.guess.up {
  background: linear-gradient(160deg, #ffd34d, #ff9f2e);
  color: #2b1a00;
  box-shadow: 0 7px 0 #b8650d, 0 14px 28px rgba(255, 159, 46, 0.35);
}
.guess.down {
  background: linear-gradient(160deg, #4f8bff, #1f5bd6);
  color: #fff;
  box-shadow: 0 7px 0 #0f3a91, 0 14px 28px rgba(31, 91, 214, 0.35);
}
.guess:active,
.guess.pressed {
  transform: translateY(6px);
}
.guess.up:active,
.guess.up.pressed {
  box-shadow: 0 1px 0 #b8650d, 0 6px 14px rgba(255, 159, 46, 0.3);
}
.guess.down:active,
.guess.down.pressed {
  box-shadow: 0 1px 0 #0f3a91, 0 6px 14px rgba(31, 91, 214, 0.3);
}
.guess:disabled {
  filter: saturate(0.35) brightness(0.7);
  cursor: default;
}
.g-ico {
  font-size: 22px;
  line-height: 1;
}
.g-lbl {
  font-size: 19px;
  line-height: 1.2;
  padding-top: 2px;
}
.g-odds {
  font-size: 12px;
  font-weight: 800;
  opacity: 0.85;
  min-height: 0;
  letter-spacing: 0.02em;
}
.g-odds:empty {
  display: none;
}
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: scale(0);
  animation: ripple 0.55s ease-out forwards;
  pointer-events: none;
}

.deck {
  position: relative;
  width: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.deck-pile {
  position: relative;
  width: 58px;
  aspect-ratio: 5 / 7;
  border-radius: 6px;
}
.deck-pile .card {
  position: absolute;
  inset: 0;
  filter: none;
}
.deck-pile .card:nth-child(1) {
  transform: translate(-3px, 4px);
  filter: brightness(0.7);
}
.deck-pile .card:nth-child(2) {
  transform: translate(-1.5px, 2px);
  filter: brightness(0.85);
}
.deck-pile .card:nth-child(3) {
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}
.deck[data-level='1'] .deck-pile .card:nth-child(1),
.deck[data-level='1'] .deck-pile .card:nth-child(2) {
  display: none;
}
.deck[data-level='2'] .deck-pile .card:nth-child(1) {
  display: none;
}
.deck.shuffle .deck-pile {
  animation: deckShuffle 0.8s var(--ease-out);
}
.deck.shuffle .deck-pile .card:nth-child(1) {
  animation: riffleL 0.8s var(--ease-out);
}
.deck.shuffle .deck-pile .card:nth-child(3) {
  animation: riffleR 0.8s var(--ease-out);
}
.deck-count {
  position: absolute;
  top: -8px;
  right: -6px;
  min-width: 26px;
  height: 22px;
  padding: 3px 6px 0;
  border-radius: 99px;
  background: #fff;
  color: #111;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  font-variant-numeric: tabular-nums;
}
.deck-count.low {
  background: var(--warn);
}
.deck-num {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

.replay {
  display: none;
  grid-column: 1 / -1;
  height: 76px;
  border-radius: 24px;
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.05em;
  background: linear-gradient(160deg, #3ce38c, #14a659);
  color: #052611;
  box-shadow: 0 7px 0 #0b6b38, 0 14px 28px rgba(47, 212, 122, 0.35);
  animation: pulse 1.6s ease-in-out infinite;
}
.replay:active {
  transform: translateY(6px);
  box-shadow: 0 1px 0 #0b6b38;
}
.controls.won .guess,
.controls.won .deck {
  display: none;
}
.controls.won .replay {
  display: block;
}

/* ---------- Carte volante ---------- */

.flyer {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 40;
  perspective: 900px;
  pointer-events: none;
  will-change: transform;
}
.flyer-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: rotateY(180deg);
}
.flyer .face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 7% / 5%;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.25s;
}
.flyer .face.back {
  transform: rotateY(180deg);
}
.flyer.ok .face.front {
  box-shadow: 0 0 0 4px var(--ok), 0 0 34px 6px rgba(47, 212, 122, 0.7);
}
.flyer.ko .face.front {
  box-shadow: 0 0 0 4px var(--ko), 0 0 34px 6px rgba(255, 77, 94, 0.7);
}
.flyer.warn .face.front {
  box-shadow: 0 0 0 4px var(--warn), 0 0 34px 6px rgba(255, 159, 46, 0.7);
}

/* ---------- Superpositions ---------- */

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  opacity: 0;
}
#flash.ko {
  background: radial-gradient(ellipse at center, transparent 35%, rgba(255, 40, 60, 0.55));
  animation: flash 0.6s ease-out;
}
#flash.ok {
  background: radial-gradient(ellipse at center, transparent 45%, rgba(47, 212, 122, 0.35));
  animation: flash 0.5s ease-out;
}
#flash.gold {
  background: radial-gradient(ellipse at center, rgba(255, 197, 49, 0.25), rgba(255, 197, 49, 0.45));
  animation: flash 0.9s ease-out;
}

#banner {
  position: fixed;
  left: 50%;
  top: 42%;
  z-index: 55;
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-align: center;
  width: 92%;
  max-width: 480px;
  opacity: 0;
}
#banner.show {
  animation: bannerIn 1.6s var(--ease-out) forwards;
}
#banner .b-main {
  display: inline-block;
  padding: 14px 24px 9px;
  border-radius: 16px;
  font-weight: 900;
  font-size: clamp(24px, 7.5vw, 36px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}
#banner .b-sub {
  margin-top: 10px;
  font-weight: 800;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}
#banner.ko .b-main {
  background: var(--ko);
  color: #fff;
}
#banner.cp .b-main {
  background: var(--green-sign);
  color: #fff;
  box-shadow: inset 0 0 0 3px var(--green-sign), inset 0 0 0 6px #fff, 0 18px 40px rgba(0, 0, 0, 0.5);
}
#banner.win .b-main {
  background: linear-gradient(160deg, #ffd34d, #ff9f2e);
  color: #2b1a00;
}

#toasts {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 60px);
  transform: translateX(-50%);
  z-index: 58;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: 92%;
  max-width: 420px;
}
.toast {
  padding: 11px 16px 8px;
  border-radius: 14px;
  background: rgba(24, 31, 41, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  font-weight: 800;
  font-size: 14px;
  animation: toastIn 2.8s var(--ease-out) forwards;
  text-align: center;
}
.toast.amber {
  background: linear-gradient(160deg, #ffd34d, #ff9f2e);
  color: #2b1a00;
  border: 0;
}

/* ---------- Feuilles (bottom sheets) ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(3, 6, 10, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 80;
  width: min(560px, 100%);
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: #121921;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, 105%);
  transition: transform 0.42s var(--ease-out);
  visibility: hidden;
}
.sheet.open {
  transform: translate(-50%, 0);
  visibility: visible;
}
.sheet.dragging {
  transition: none;
}
.sheet-grip {
  padding: 10px 0 2px;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
}
.sheet-grip span {
  width: 42px;
  height: 5px;
  border-radius: 9px;
  background: #3a4553;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 18px 6px 20px;
  touch-action: none;
}
.sheet-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
}
.sheet-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--panel-2);
  font-size: 15px;
}
.sheet-body {
  overflow-y: auto;
  padding: 6px 18px calc(env(safe-area-inset-bottom, 0px) + 20px);
  overscroll-behavior: contain;
  -webkit-user-select: none;
}

.group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 4px 14px;
  margin-bottom: 14px;
}
.group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 0 4px;
}
.pending {
  display: none;
  padding: 3px 8px 1px;
  border-radius: 99px;
  background: rgba(255, 197, 49, 0.15);
  color: var(--amber);
  letter-spacing: 0.04em;
  font-size: 11px;
  text-transform: none;
}
.pending.show {
  display: inline-block;
  animation: bump 0.4s var(--ease-spring);
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.group-title + .row {
  border-top: 0;
}
.row.column {
  flex-direction: column;
  align-items: stretch;
}
.row-label {
  font-weight: 800;
  font-size: 15px;
}
.row-label small {
  display: block;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  min-height: 15px;
}

.stepper {
  display: flex;
  align-items: center;
  background: var(--panel-2);
  border-radius: 14px;
  padding: 3px;
}
.stepper button {
  width: 42px;
  height: 40px;
  border-radius: 11px;
  font-size: 22px;
  font-weight: 800;
}
.stepper button:active {
  background: var(--panel-3);
}
.stepper output {
  min-width: 34px;
  text-align: center;
  font-weight: 900;
  font-size: 19px;
  padding-top: 3px;
}

.seg {
  display: flex;
  background: var(--panel-2);
  border-radius: 13px;
  padding: 3px;
  gap: 3px;
}
.seg.wide {
  width: 100%;
}
.seg button {
  flex: 1;
  min-width: 62px;
  height: 38px;
  padding: 3px 12px 0;
  border-radius: 10px;
  font-weight: 800;
  font-size: 14px;
  color: var(--muted);
  transition: background 0.25s, color 0.25s, transform 0.15s;
}
.seg button.active {
  background: var(--sign);
  color: #fff;
  box-shadow: 0 4px 12px rgba(31, 91, 214, 0.4);
}
.seg button:active {
  transform: scale(0.95);
}

.layout-preview {
  display: flex;
  gap: 5px;
  justify-content: center;
  padding: 4px 0;
}
.mini {
  position: relative;
  width: min(34px, calc((100% - 45px) / 10));
  aspect-ratio: 5 / 7;
  border-radius: 5px;
  background: #fbf7ee;
  color: #1b2330;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 14px;
  padding-top: 2px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.35s var(--ease-spring), background 0.25s;
}
.mini.hidden {
  background: repeating-linear-gradient(45deg, #1a4aad 0 4px, #2257c2 4px 8px);
  color: #fff;
  transform: rotateY(180deg);
  box-shadow: inset 0 0 0 2px #fff, 0 3px 8px rgba(0, 0, 0, 0.4);
}
.mini.hidden span {
  transform: rotateY(180deg);
}
.mini.nope {
  animation: nope 0.4s;
}
.presets {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.presets button {
  padding: 8px 12px 6px;
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 13px;
  font-weight: 800;
}
.presets button:active {
  transform: scale(0.95);
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 52px;
  height: 32px;
  border-radius: 99px;
  background: var(--panel-3);
  transition: background 0.25s;
  flex: none;
  margin: 0;
  cursor: pointer;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s var(--ease-spring);
}
.switch:checked {
  background: var(--ok);
}
.switch:checked::after {
  transform: translateX(20px);
}
.switch-row {
  cursor: pointer;
}

.btn {
  height: 52px;
  padding: 4px 20px 0;
  border-radius: 16px;
  font-weight: 900;
  font-size: 16px;
  transition: transform 0.12s;
}
.btn:active {
  transform: scale(0.97);
}
.btn.block {
  display: block;
  width: 100%;
  margin-top: 6px;
}
.btn.primary {
  background: linear-gradient(160deg, #4f8bff, #1f5bd6);
  color: #fff;
  box-shadow: 0 8px 20px rgba(31, 91, 214, 0.4);
}
.btn.primary.attention {
  background: linear-gradient(160deg, #ffd34d, #ff9f2e);
  color: #2b1a00;
  box-shadow: 0 8px 20px rgba(255, 159, 46, 0.4);
}
.btn.ghost {
  background: var(--panel-2);
  color: var(--text);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 8px 9px;
  text-align: center;
}
.stat b {
  display: block;
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.stat span {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.stat-grid.compact {
  grid-template-columns: repeat(2, 1fr);
  margin: 16px 0 6px;
}

.rules {
  font-size: 15px;
  line-height: 1.5;
}
.rule-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: s;
}
.rule-steps li {
  position: relative;
  padding: 10px 0 10px 44px;
  border-bottom: 1px solid var(--line);
  color: #cdd6e2;
}
.rule-steps li::before {
  counter-increment: s;
  content: counter(s);
  position: absolute;
  left: 0;
  top: 10px;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--sign);
  box-shadow: inset 0 0 0 2px var(--sign), inset 0 0 0 3.5px #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
  padding-top: 3px;
  color: #fff;
}
.rule-steps b {
  color: #fff;
}
.rule-tip {
  margin: 14px 0 10px;
  padding: 12px 14px 10px;
  border-radius: 14px;
  background: rgba(255, 197, 49, 0.1);
  color: #ffe08a;
  font-size: 14px;
}

/* ---------- Dialogues ---------- */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 6, 10, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.dialog.open {
  opacity: 1;
  pointer-events: auto;
}
.dialog-card {
  width: min(380px, 100%);
  background: #141b24;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 22px 18px 18px;
  text-align: center;
  transform: scale(0.85) translateY(20px);
  transition: transform 0.4s var(--ease-spring);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
}
.dialog.open .dialog-card {
  transform: none;
}
.dialog-title {
  font-size: 21px;
  font-weight: 900;
}
.dialog-card p {
  color: var(--muted);
  margin: 8px 0 18px;
}
.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.trophy {
  font-size: 60px;
  line-height: 1;
  animation: trophy 1.2s var(--ease-spring);
}
.win-title {
  margin-top: 8px;
  font-size: 25px;
  font-weight: 900;
}
.win-record {
  display: none;
  margin: 8px auto 0;
  width: max-content;
  padding: 5px 12px 3px;
  border-radius: 99px;
  background: linear-gradient(160deg, #ffd34d, #ff9f2e);
  color: #2b1a00;
  font-weight: 900;
  font-size: 13px;
  animation: pulse 1.4s ease-in-out infinite;
}
.win-record.show {
  display: block;
}

/* ---------- Animations ---------- */

@keyframes halo {
  0%, 100% { opacity: 0.55; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1.05); }
}
@keyframes dealIn {
  from { transform: translateY(-60px) rotate(-12deg) scale(0.5); opacity: 0; }
}
@keyframes cardPop {
  0% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
@keyframes bumpKo {
  0%, 100% { transform: none; }
  20% { transform: translateX(-5px) scale(1.15); background: rgba(255, 77, 94, 0.3); }
  40% { transform: translateX(5px) scale(1.15); }
  60% { transform: translateX(-3px); }
}
@keyframes signFlip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
@keyframes carBounce {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-3px) rotate(-1.5deg); }
}
@keyframes carShake {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(1px, -1px); }
}
@keyframes carHop {
  0% { transform: translateY(0); }
  40% { transform: translateY(-16px) rotate(-6deg); }
  100% { transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes speed {
  from { background-position: 0 0; }
  to { background-position: 0 61px; }
}
@keyframes verdictIn {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  25% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(0.95); }
}
@keyframes promptIn {
  from { opacity: 0; transform: translateY(6px); }
}
@keyframes ripple {
  to { transform: scale(2.6); opacity: 0; }
}
@keyframes deckShuffle {
  0%, 100% { transform: none; }
  20% { transform: rotate(-8deg) scale(1.08); }
  50% { transform: rotate(6deg) scale(1.08); }
  75% { transform: rotate(-3deg); }
}
@keyframes riffleL {
  30% { transform: translate(-26px, -6px) rotate(-18deg); }
}
@keyframes riffleR {
  30% { transform: translate(26px, -6px) rotate(18deg); }
}
@keyframes flash {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(1deg); }
  24% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); }
}
@keyframes toastIn {
  0% { opacity: 0; transform: translateY(-16px) scale(0.9); }
  10% { opacity: 1; transform: translateY(0) scale(1); }
  85% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}
@keyframes burnGlow {
  0% { filter: none; }
  30% { filter: drop-shadow(0 0 18px rgba(255, 120, 30, 0.9)) brightness(1.2); }
  100% { filter: none; }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
@keyframes nope {
  0%, 100% { transform: rotateY(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@keyframes trophy {
  0% { transform: scale(0) rotate(-30deg); }
  100% { transform: scale(1) rotate(0); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.15s !important;
  }
}

/* Petits écrans en hauteur */
@media (max-height: 640px) {
  .topbar { height: 44px; }
  .hud { height: 36px; }
  .prompt { min-height: 40px; font-size: 15px; }
  .guess { height: 70px; }
}
