/* Layout : une machine à sous en bois et laiton, posée dans une forêt de nuit autour d'un feu de camp. Look sombre assumé (veillée). */
:root {
  --night: #0c1613;
  --night-2: #142420;
  --pine: #1d3a2d;
  --wood: #7a4a2a;
  --wood-dark: #4a2b17;
  --wood-light: #a5703f;
  --brass: #d9a94c;
  --brass-dark: #8c6522;
  --steel: #c9c4b8;
  --steel-dark: #6f6a60;
  --paper: #f4ead4;
  --ink: #24180f;
  --fire: #f0782a;
  --ember: #ffcf5a;
  --text: #f4ead4;
  --muted: #b8b19c;
  --ok: #7bd389;
  --shade: rgba(20, 12, 6, 0.55);

  --font-display: "Rye", "Georgia", serif;
  --font-body: "Karla", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;

  --cell: clamp(64px, 20vw, 124px);
  color-scheme: dark;
}

[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 40px;
  overflow-x: hidden;
}

#sky, #confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#sky { z-index: 0; }
#confetti { z-index: 30; }

.stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* ---------- Machine ---------- */
.machine {
  position: relative;
  width: min(100%, 520px);
  padding: 18px 18px 22px;
  border-radius: 30px 30px 18px 18px;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.07) 0 2px, transparent 2px 9px, rgba(255,255,255,0.03) 9px 10px, transparent 10px 23px),
    linear-gradient(180deg, var(--wood-light), var(--wood) 35%, var(--wood-dark));
  border: 5px solid var(--brass-dark);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,0.18),
    0 0 0 2px var(--brass),
    0 30px 60px rgba(0,0,0,0.55),
    0 0 120px rgba(240,120,42,0.12);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.marquee {
  position: relative;
  text-align: center;
  padding: 14px 12px 12px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--night-2), var(--night));
  border: 3px solid var(--brass);
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.bulbs { display: flex; justify-content: space-between; padding: 0 6px 10px; }
.bulb {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 8px var(--ember), 0 0 2px var(--fire);
  animation: blink 1.2s steps(1) infinite;
}
.bulb:nth-child(even) { animation-delay: 0.6s; }
.machine.won .bulb { animation-duration: 0.24s; }
@keyframes blink { 50% { opacity: 0.25; box-shadow: none; } }

.marquee h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(26px, 7vw, 40px);
  line-height: 1.05;
  color: var(--ember);
  text-shadow: 0 2px 0 var(--fire), 0 0 22px rgba(255,207,90,0.35);
  text-wrap: balance;
}
.marquee p {
  margin: 6px 0 0;
  white-space: pre-line;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.04em;
}

.frame {
  padding: 10px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--brass), var(--brass-dark));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 4px 10px rgba(0,0,0,0.35);
}
.reels {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: var(--ink);
}
.reel {
  position: relative;
  flex: 0 0 var(--cell);
  width: var(--cell);
  height: calc(var(--cell) * 1.7);
  overflow: hidden;
  border-radius: 10px;
  background: var(--paper);
  transition: box-shadow 0.25s;
}
.reel::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, var(--shade), transparent 30%, transparent 70%, var(--shade));
}
.strip { will-change: transform; }
.cell {
  height: var(--cell);
  display: grid;
  place-items: center;
  font-family: var(--font-emoji);
  font-size: calc(var(--cell) * 0.56);
  line-height: 1;
}
.reel.spinning .cell { filter: blur(1.5px); }
.machine.tension .reel:nth-child(3) { box-shadow: 0 0 0 3px var(--fire), 0 0 26px var(--fire); }
.reel.winner { animation: glow 0.6s ease-in-out infinite alternate; }
@keyframes glow {
  from { box-shadow: 0 0 0 3px var(--ember), 0 0 10px var(--fire); }
  to   { box-shadow: 0 0 0 3px var(--ember), 0 0 32px var(--fire); }
}

.payline {
  position: absolute; left: 2px; right: 2px; top: 50%;
  height: 2px; transform: translateY(-50%);
  background: var(--fire); opacity: 0.75; pointer-events: none;
}
.payline::before, .payline::after {
  content: ""; position: absolute; top: 50%; transform: translateY(-50%);
  border: 7px solid transparent;
}
.payline::before { left: -2px; border-left-color: var(--fire); }
.payline::after { right: -2px; border-right-color: var(--fire); }

.result {
  min-height: 1.5em;
  margin: 0;
  text-align: center;
  font-weight: 700;
  font-size: 18px;
  color: var(--paper);
  text-shadow: 0 1px 0 rgba(0,0,0,0.5);
}

.spin {
  align-self: center;
  min-width: min(100%, 260px);
  padding: 14px 28px 12px;
  border: 0;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: linear-gradient(180deg, var(--ember), var(--fire));
  box-shadow: 0 6px 0 var(--wood-dark), 0 10px 24px rgba(240,120,42,0.35);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.2s;
}
.spin:hover:not(:disabled) { filter: brightness(1.06); }
.spin:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 var(--wood-dark), 0 4px 10px rgba(240,120,42,0.3); }
.spin:disabled { filter: grayscale(0.5) brightness(0.8); cursor: wait; }
.spin:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid var(--ember); outline-offset: 3px;
}

.counters {
  display: flex; justify-content: center; gap: 18px;
  margin: 0;
  color: var(--paper);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.counters b { font-size: 18px; color: var(--ember); }

/* Levier */
.lever {
  position: absolute;
  right: -62px; top: 150px;
  width: 56px; height: 200px;
  padding: 0; border: 0; background: none;
  cursor: pointer;
}
.lever .base {
  position: absolute; left: 0; bottom: 40px;
  width: 26px; height: 52px;
  border-radius: 4px 14px 14px 4px;
  background: linear-gradient(90deg, var(--brass-dark), var(--brass), var(--brass-dark));
}
.lever .arm {
  position: absolute; left: 14px; bottom: 66px;
  width: 10px; height: 110px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--steel-dark), var(--steel), var(--steel-dark));
  transform-origin: 50% 100%;
  transition: transform 0.35s cubic-bezier(.3,1.4,.5,1);
}
.lever .knob {
  position: absolute; top: -28px; left: 50%;
  width: 36px; height: 36px; margin-left: -18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--ember), var(--fire) 55%, var(--wood-dark));
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
.lever.pulled .arm { transform: scaleY(-1); transition-duration: 0.16s; transition-timing-function: ease-in; }
.lever:disabled { cursor: wait; }
@media (max-width: 680px) { .lever { display: none; } }

/* ---------- Légende ---------- */
.legend { width: min(100%, 520px); text-align: center; }
.legend h2 {
  margin: 0 0 10px;
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 0; padding: 0; list-style: none; }
.chips li {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  background: var(--night-2);
  border: 1px solid var(--pine);
  font-size: 14px;
}
.chips span { font-family: var(--font-emoji); font-size: 20px; line-height: 1; }
/* Symbole dessiné (le foulard) : à la taille d'un emoji, quel que soit l'endroit. */
.sym-img { display: inline-block; width: 1.2em; height: 1.2em; vertical-align: -0.2em; }
.win-emoji .sym-img { margin: 0 0.05em; }

/* Mention du compteur anonyme, sous la légende. */
.privacy { width: min(100%, 520px); margin: 0; font-size: 12px; line-height: 1.5; text-align: center; color: var(--muted); }

/* ---------- Réglages : bouton menu et panneau glissant ---------- */
.menu-btn {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 15;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2px solid var(--brass-dark);
  background: var(--night-2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
.menu-btn:hover { border-color: var(--brass); }
.menu-bars { display: flex; flex-direction: column; gap: 4px; }
.menu-bars i { display: block; width: 20px; height: 2px; border-radius: 1px; background: var(--paper); }
/* Point vert discret : le prochain lancer est armé pour gagner. */
.armed {
  position: absolute; right: 5px; bottom: 5px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  opacity: 0; transition: opacity 0.2s;
}
.armed.on { opacity: 1; box-shadow: 0 0 6px var(--ok); }

.drawer { position: fixed; inset: 0; z-index: 25; visibility: hidden; transition: visibility 0s 0.3s; }
.drawer.open { visibility: visible; transition: none; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(8, 14, 12, 0.6); opacity: 0; transition: opacity 0.3s; }
.drawer.open .drawer-backdrop { opacity: 1; }

.panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(380px, 100%);
  overflow-y: auto;
  padding: calc(20px + env(safe-area-inset-top, 0px)) calc(22px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) 22px;
  background: var(--night-2);
  border-left: 3px solid var(--brass-dark);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; gap: 18px;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(.2, .8, .2, 1);
}
.drawer.open .panel { transform: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 22px; color: var(--ember); }
.close-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--pine); background: var(--night); color: var(--text);
  font: inherit; font-size: 24px; line-height: 1;
  cursor: pointer;
}
.close-btn:hover { border-color: var(--brass); }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.row label { font-weight: 600; }
.panel select {
  padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--pine); background: var(--night); color: var(--text);
  font: inherit;
}
.panel input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--fire); }
.actions { display: flex; flex-direction: column; gap: 8px; }
.btn {
  padding: 9px 14px; border-radius: 8px;
  border: 1px solid var(--brass-dark); background: var(--night);
  color: var(--text); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer;
}
.btn:hover { border-color: var(--brass); }
.hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; max-width: 65ch; }
.hint kbd {
  padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--pine); background: var(--night);
  font-family: var(--font-body); font-weight: 700; color: var(--text);
}

/* ---------- Victoire ---------- */
.win {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
  background: rgba(8, 14, 12, 0.72);
  cursor: pointer;
}
.win-card {
  text-align: center;
  padding: 28px 32px 30px;
  border-radius: 24px;
  background: linear-gradient(180deg, var(--wood-light), var(--wood-dark));
  border: 4px solid var(--brass);
  box-shadow: 0 0 80px rgba(240,120,42,0.45);
  animation: pop 0.45s cubic-bezier(.2,1.6,.4,1);
  max-width: 100%;
}
.win-emoji { font-family: var(--font-emoji); font-size: clamp(44px, 14vw, 72px); line-height: 1.1; letter-spacing: 0.1em; }
.win-title {
  /* Marge du bas large : la jambe du « g » de la police Rye descend loin sous la ligne. */
  margin: 6px 0 22px;
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(48px, 15vw, 88px); line-height: 1.1;
  color: var(--ember);
  text-shadow: 0 3px 0 var(--fire), 0 0 30px rgba(255,207,90,0.5);
}
.win-sub { margin: 0 0 18px; font-size: 20px; font-weight: 700; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .bulb, .reel.winner, .win-card { animation: none; }
  .reel.spinning .cell { filter: none; }
}

/* ---------- Ambiance fête foraine ---------- */
/* Chapiteau rayé rouge et crème, machine laquée rouge, guirlande d'ampoules en chenillard. */
:root {
  --stripe-a: #b81f2d;
  --stripe-b: #f3e3c3;
  --veil: rgba(42, 9, 16, 0.6);
  --veil-deep: rgba(42, 9, 16, 0.9);
}
:root[data-ambiance="foire"] {
  --night: #2a0910;
  --night-2: #3a0e17;
  --pine: #6e1f2c;
  --wood-light: #d8423f;
  --wood: #a81e2a;
  --wood-dark: #5e0f18;
}
[data-ambiance="foire"] #sky { display: none; }
[data-ambiance="foire"] body {
  position: relative;
  padding-block-start: 60px;
  background:
    linear-gradient(180deg, var(--veil), var(--veil-deep)),
    repeating-linear-gradient(90deg, var(--stripe-a) 0 56px, var(--stripe-b) 56px 112px);
  background-attachment: fixed;
}
/* Lambrequin festonné en haut du chapiteau. */
[data-ambiance="foire"] body::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 34px;
  z-index: 2;
  background:
    radial-gradient(circle at 28px 0, var(--stripe-a) 0 26px, var(--brass) 27px 29px, transparent 30px) 0 0 / 56px 34px repeat-x;
}

.lights { position: absolute; inset: -9px; pointer-events: none; display: none; }
[data-ambiance="foire"] .lights { display: block; }
.lights i {
  position: absolute;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 10px var(--ember);
  animation: chase 0.6s steps(1) infinite;
}
.lights i:nth-child(3n + 2) { animation-delay: -0.2s; }
.lights i:nth-child(3n + 3) { animation-delay: -0.4s; }
[data-ambiance="foire"] .bulb { animation-name: chase; animation-duration: 0.6s; }
[data-ambiance="foire"] .bulb:nth-child(3n + 2) { animation-delay: -0.2s; }
[data-ambiance="foire"] .bulb:nth-child(3n + 3) { animation-delay: -0.4s; }
.machine.won .lights i, [data-ambiance="foire"] .machine.won .bulb { animation-duration: 0.24s; }
@keyframes chase { 0% { opacity: 1; } 33% { opacity: 0.2; box-shadow: none; } }
.lever { z-index: 1; }

/* Rayons qui tournent derrière l'écran de victoire. */
.win { overflow: hidden; }
.win::before {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 160vmax; height: 160vmax;
  margin: -80vmax 0 0 -80vmax;
  background: repeating-conic-gradient(rgba(255, 207, 90, 0.16) 0 10deg, transparent 10deg 20deg);
  animation: rays 14s linear infinite;
  pointer-events: none;
}
.win-card { position: relative; }
@keyframes rays { to { transform: rotate(1turn); } }

@media (prefers-reduced-motion: reduce) {
  .lights i, .win::before { animation: none; }
  .panel, .drawer-backdrop { transition: none; }
}
