@font-face {
  font-family: Inter;
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(fonts/inter-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: Inter;
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(fonts/inter-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url(fonts/space-grotesk-latin.woff2) format("woff2");
}

:root {
  --bg: #0e0f13;
  --surface: #171920;
  --surface-2: #1f222b;
  --border: #2a2e39;
  --text: #eceef3;
  --muted: #8d93a3;
  --accent: #f4b740;
  --accent-ink: #1b1403;
  --good: #3ecf7a;
  --bad: #ef5a5a;
  --skip: #4a4f5c;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: radial-gradient(1200px 600px at 50% -200px, #1d1a12 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

button { font: inherit; color: inherit; }

/* ---------- En-tête ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand b { color: var(--accent); font-weight: 700; }
.brand-eye { width: 38px; height: 24px; color: var(--text); }

.actions { display: flex; gap: 4px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.lang-btn {
  display: grid;
  place-items: center;
  height: 32px;
  min-width: 40px;
  margin: 4px 0 4px 4px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
}
.lang-btn:hover { border-color: var(--accent); }

.intro {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 0;
  text-align: center;
}
.intro h1 {
  margin: 0;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: clamp(1.15rem, 4.5vw, 1.5rem);
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.intro p { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.intro p:empty { display: none; }

main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

/* Contenu éditorial (règles, FAQ, réponse des énigmes passées) */
.seo {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  color: var(--muted);
  font-size: 0.95rem;
}
.seo h2 {
  margin: 28px 0 10px;
  color: var(--text);
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 1.15rem;
}
.seo b, .seo strong { color: var(--text); }
.seo details {
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.seo summary { cursor: pointer; color: var(--text); font-weight: 600; }
.seo details p { margin: 10px 0 0; }
.seo .spoiler { border-color: var(--accent); }

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 18px 16px 28px;
  border-top: 1px solid var(--border);
}
.footer p { margin: 6px 0; }
.footer a { color: var(--muted); }

/* ---------- Jeu ---------- */

.puzzle-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.puzzle-head h2 {
  margin: 0;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 1.25rem;
}
.puzzle-head .date { color: var(--muted); font-size: 0.9rem; }

.stage {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 0 1px var(--border), 0 20px 50px -20px rgba(244, 183, 64, 0.25);
}
.stage canvas { display: block; width: 100%; height: 100%; }

.stage .overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  background: var(--surface);
}

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.steps {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 18px;
}
.step {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.step:disabled { cursor: default; opacity: 0.45; }
.step.wrong { background: color-mix(in srgb, var(--bad) 22%, var(--surface)); border-color: var(--bad); color: var(--text); }
.step.skipped { background: var(--surface-2); border-color: var(--skip); color: var(--text); }
.step.right { background: color-mix(in srgb, var(--good) 25%, var(--surface)); border-color: var(--good); color: var(--text); }
.step.active { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Saisie */

.guess-form { position: relative; display: flex; gap: 8px; }

.guess-input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.guess-input:focus { outline: none; border-color: var(--accent); }

.btn {
  height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.wide { width: 100%; }

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 5;
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
}
.suggestions li {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.suggestions li.sel, .suggestions li:hover { background: var(--surface-2); }
.suggestions .desc { display: block; color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggestions mark { background: none; color: var(--accent); font-weight: 600; }

.guesses { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 6px; }
.guesses li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.guesses li.wrong { border-color: color-mix(in srgb, var(--bad) 55%, var(--border)); }
.guesses li.right { border-color: var(--good); }
.guesses li.skipped { color: var(--muted); }
.guesses .n { color: var(--muted); font-variant-numeric: tabular-nums; width: 1.2em; }

/* Résultat */

.result {
  margin-top: 18px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}
.result h2 { margin: 0 0 4px; font-family: "Space Grotesk", Inter, sans-serif; }
.result .who { font-size: 1.5rem; font-weight: 700; color: var(--accent); margin: 6px 0 2px; }
.result .desc { color: var(--muted); margin: 0 0 12px; }
.result .emoji { font-size: 1.4rem; letter-spacing: 2px; margin: 10px 0 16px; }
.result .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.result .links { margin-top: 14px; font-size: 0.85rem; color: var(--muted); }
.result.compact { padding: 16px; }
.result.compact .who { font-size: 1.25rem; }
.result.compact .emoji { margin: 6px 0 12px; font-size: 1.15rem; }

/* Popup de résultat */
.modal.result-modal {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  overflow-y: auto;
}
.modal.result-modal .close {
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}
.result-modal[open] { animation: pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
.result-photo {
  margin: 0;
  background: #000;
  display: grid;
  place-items: center;
}
.result-photo img {
  display: block;
  width: 100%;
  max-height: min(48dvh, 440px);
  object-fit: contain;
}
.result-modal.won .result-photo { box-shadow: inset 0 -3px 0 var(--good); }
.result-modal:not(.won) .result-photo { box-shadow: inset 0 -3px 0 var(--bad); }
.result-modal .result {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.countdown { margin-top: 16px; color: var(--muted); font-size: 0.9rem; }
.countdown b { color: var(--text); font-variant-numeric: tabular-nums; font-size: 1.1rem; }

.error {
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--bad);
  background: color-mix(in srgb, var(--bad) 10%, var(--surface));
  text-align: center;
}

/* ---------- Archives ---------- */

.archive h1 { font-family: "Space Grotesk", Inter, sans-serif; font-size: 1.3rem; margin: 0 0 14px; }
.archive-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.archive-list a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.archive-list a:hover { border-color: var(--accent); }
.archive-list .num { font-weight: 700; min-width: 3.2em; }
.archive-list .meta { flex: 1; min-width: 0; }
.archive-list .meta small { display: block; color: var(--muted); }
.archive-list .badge { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.archive-list .badge.won { color: var(--good); }
.archive-list .badge.lost { color: var(--bad); }
.archive-list .badge.playing { color: var(--accent); }

/* ---------- Modales ---------- */

.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(3px); }
.modal h2 { margin: 0 0 12px; font-family: "Space Grotesk", Inter, sans-serif; }
.modal .close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: 0;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.modal form:first-child { margin: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }

.rules { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 10px; }
.rules li { display: flex; gap: 10px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-bottom: 18px; }
.stat-grid b { display: block; font-size: 1.6rem; font-family: "Space Grotesk", Inter, sans-serif; }
.stat-grid span { color: var(--muted); font-size: 0.75rem; }

.dist { display: grid; gap: 5px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.dist-row .k { width: 1.2em; color: var(--muted); }
.dist-row .bar {
  min-width: 26px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  text-align: right;
  font-weight: 600;
}
.dist-row .bar.hl { background: var(--good); color: #062812; }

#toast {
  position: fixed;
  left: 50%;
  top: 76px;
  transform: translate(-50%, -12px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .brand { font-size: 1.15rem; }
  .step { width: 34px; height: 34px; }
  .btn { padding: 0 14px; }
  .stat-grid b { font-size: 1.3rem; }
}

@media (max-width: 480px) {
  .result-photo img { max-height: 38dvh; }
  .result-modal .result { padding: 16px; }
}

/* Photo filtrée dans la popup de résultat */
.result-photo canvas { display: block; max-width: 100%; }

/* Calque plein écran des confettis / de la pluie (popover, au-dessus de la popup) */
.fx-layer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
  overflow: visible;
}

/* Défaite : la popup tremble */
.result-modal.shake { animation: pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2), shake 0.6s 0.35s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-10px) rotate(-1deg); }
  30% { transform: translateX(9px) rotate(1deg); }
  45% { transform: translateX(-7px); }
  60% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}
