:root {
  --bg: #f6f1e7;
  --bg-2: #efe7d7;
  --surface: #fffdf8;
  --ink: #1f2a22;
  --ink-soft: #5d6a5f;
  --line: #ddd3bf;
  --leaf: #3f8f4f;
  --leaf-deep: #2b6a39;
  --leaf-soft: #d8ebd6;
  --tomato: #e0543c;
  --tomato-soft: #fbe0d9;
  --corn: #f2b631;
  --corn-soft: #fcefc7;
  --tile: #fffaf0;
  --tile-edge: #e4d8bf;
  --tile-ink: #1f2a22;
  --shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 3px 0 var(--tile-edge), 0 8px 18px rgba(60, 45, 20, .10);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16201a;
    --bg-2: #1c2821;
    --surface: #1f2c24;
    --ink: #eef3ea;
    --ink-soft: #a3b3a6;
    --line: #34463a;
    --leaf: #6cc27b;
    --leaf-deep: #8fd89b;
    --leaf-soft: #264331;
    --tomato: #ff7a62;
    --tomato-soft: #4a2821;
    --corn: #f5c451;
    --corn-soft: #4a3d19;
    --tile: #26352c;
    --tile-edge: #121a15;
    --tile-ink: #f2f6ee;
    --shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 3px 0 var(--tile-edge), 0 8px 18px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100svh;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% -10%, var(--leaf-soft), transparent 40%),
    radial-gradient(circle at 110% 30%, var(--corn-soft), transparent 35%),
    var(--bg);
  background-attachment: fixed;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; }

/* ---------- barre du haut ---------- */
.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  max-width: 1040px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px 6px;
}
.brand {
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.35rem, 5vw, 1.8rem);
  letter-spacing: -.02em;
}
.brand em { font-style: italic; font-weight: 600; color: var(--leaf); padding-right: .08em; }
.brand-bowl { display: inline-block; transform: translateY(-1px); }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-btn:hover { border-color: var(--leaf); }

/* ---------- mise en page ---------- */
.layout {
  max-width: 1040px;
  margin: 0 auto;
  padding: 4px 16px 32px;
  display: grid;
  gap: 18px;
}
@media (min-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; gap: 36px; padding-top: 18px; }
  .words { position: sticky; top: 16px; }
}

.play { display: flex; flex-direction: column; align-items: center; }
.meta { text-align: center; }
.meta-line {
  margin: 0;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.theme {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.6rem, 6.5vw, 2.3rem);
  letter-spacing: -.02em;
  line-height: 1.1;
}

/* ---------- mot en cours ---------- */
.current {
  position: relative;
  height: 52px;
  width: 100%;
  display: grid;
  place-items: center;
  margin: 6px 0 4px;
}
.current-word {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 2rem);
  letter-spacing: .12em;
  color: var(--ink);
  min-height: 1.2em;
}
.current-word.bad { color: var(--tomato); animation: shake .35s; }
.current-word.good { color: var(--leaf); }
.current-word.near::after {
  content: "Presque !";
  margin-left: .6em;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--corn);
  color: #2a2006;
  font-family: var(--font-ui);
  font-size: .8rem;
  letter-spacing: 0;
  vertical-align: middle;
  animation: pop .25s ease-out;
}
.toast {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
}
.toast.show { opacity: 1; }
.toast span {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 800;
  font-size: .95rem;
  animation: pop .25s ease-out;
}
.toast.good span { background: var(--leaf); color: #fff; }
.toast.bad span { background: var(--tomato); color: #fff; }
.toast.near span { background: var(--corn); color: #2a2006; }

/* ---------- grille ---------- */
.board-wrap {
  --size: min(calc(100vw - 32px), 420px, 56svh);
  width: var(--size);
  padding: calc(var(--size) * .035);
  border-radius: calc(var(--radius) + 6px);
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: calc(var(--size) * .03);
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.tile {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--tile);
  box-shadow: var(--shadow);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: calc(var(--size) * .12);
  color: var(--tile-ink);
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, color .15s ease;
}
.tile.sel {
  background: var(--corn);
  color: #2a2006;
  transform: translateY(1px) scale(.96);
}
.tile.sel.first { background: #e9a514; }
/* Lettre qui ne sert plus à aucun mot restant : elle s'efface après l'animation de réussite. */
.tile.gone {
  opacity: 0;
  transform: scale(.6);
  pointer-events: none;
  transition: opacity .4s ease .5s, transform .4s ease .5s;
}
.tile.flash-good { animation: flashGood .6s ease; }
.tile.flash-bad { animation: flashBad .4s ease; }
.tile.flash-near { animation: flashNear .6s ease; }
/* Sélection en cours à une lettre d'un mot restant : les lettres choisies frétillent. */
.board.near .tile.sel {
  box-shadow: 0 0 0 3px var(--corn-soft), var(--shadow);
  animation: nearWiggle .45s ease-in-out infinite alternate;
}
.tile.hint { animation: hintPulse 1.2s ease 2; }
.trail {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  overflow: visible;
}
.trail polyline {
  fill: none;
  stroke: var(--tomato);
  stroke-opacity: .55;
  stroke-width: calc(var(--size) * .045);
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- boutons ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  min-height: 46px;
}
.btn {
  min-height: 46px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 800;
  cursor: pointer;
  transition: transform .1s ease, background .15s ease;
}
.btn:hover { border-color: var(--leaf); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn.primary:hover { background: var(--leaf-deep); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f1a12; } }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn[hidden] { display: none; }

/* ---------- liste de mots ---------- */
.words {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 18px 18px 14px;
}
.words-head { display: flex; align-items: baseline; justify-content: space-between; }
.words-head h3 { margin: 0; font-family: var(--font-display); font-size: 1.2rem; }
.count { font-weight: 800; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.progress {
  height: 8px;
  margin: 10px 0 14px;
  border-radius: 99px;
  background: var(--bg-2);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--leaf), var(--corn));
  border-radius: inherit;
  transition: width .4s ease;
}
.word-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
}
.word {
  display: flex;
  gap: 3px;
  padding: 4px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px dashed transparent;
}
.word:hover:not(.found) { border-color: var(--line); }
.word .l {
  width: 24px; height: 28px;
  display: grid; place-items: center;
  border-radius: 6px;
  background: var(--bg-2);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 800;
  font-size: .9rem;
  color: var(--ink-soft);
}
.word .l.hinted { background: var(--corn-soft); color: var(--ink); }
.word.found {
  cursor: default;
  padding: 4px 12px;
  align-items: center;
  height: 36px;
  background: var(--leaf-soft);
  color: var(--leaf-deep);
  font-weight: 800;
  border-radius: 999px;
}
.word.found.helped { background: var(--corn-soft); color: var(--ink); }
.word.found.revealed { background: var(--bg-2); color: var(--ink-soft); font-style: italic; }
.word.new { animation: pop .4s ease-out; }
.words-tip { margin: 14px 0 0; font-size: .82rem; color: var(--ink-soft); }

/* ---------- dialogues ---------- */
.sheet {
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100svh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0,0,0,.3);
}
.sheet::backdrop { background: rgba(20, 28, 22, .45); backdrop-filter: blur(3px); }
.sheet[open] { animation: rise .25s ease-out; }
.sheet-inner { position: relative; padding: 26px 22px 22px; }
.sheet-inner.center { text-align: center; }
.sheet h2 { margin: 0 0 10px; font-family: var(--font-display); font-size: 1.6rem; }
.close {
  position: absolute; top: 12px; right: 12px;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: var(--bg-2);
  cursor: pointer;
}
.rules { padding-left: 20px; line-height: 1.5; }
.rules li { margin-bottom: 6px; }
.muted { color: var(--ink-soft); }

.archive-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.archive-list button {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  cursor: pointer;
}
.archive-list button:hover { border-color: var(--leaf); }
.archive-list .cur { border-color: var(--leaf); box-shadow: 0 0 0 2px var(--leaf-soft); }
.archive-list .e { font-size: 1.4rem; text-align: center; }
.archive-list .t { font-weight: 800; }
.archive-list .n { display: block; font-size: .75rem; color: var(--ink-soft); font-weight: 700; }
.archive-list .s { font-size: .85rem; font-weight: 800; color: var(--ink-soft); }
.archive-list .s.done { color: var(--leaf); }

.win-emoji { font-size: 3.4rem; animation: pop .5s ease-out; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.stats div { background: var(--bg-2); border-radius: 14px; padding: 10px 4px; }
.stats strong { display: block; font-family: var(--font-display); font-size: 1.5rem; }
.stats span { font-size: .8rem; color: var(--ink-soft); font-weight: 700; }
.share-text {
  margin: 0 0 16px;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg);
  font-family: var(--font-ui);
  font-size: .9rem;
  white-space: pre-wrap;
  line-height: 1.5;
}
.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- animations ---------- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes flashGood { 30% { background: var(--leaf); color: #fff; transform: scale(1.06); } }
@keyframes flashBad { 30% { background: var(--tomato-soft); } }
@keyframes nearWiggle {
  from { transform: translateY(1px) scale(.96) rotate(-3deg); }
  to { transform: translateY(1px) scale(.96) rotate(3deg); }
}
@keyframes flashNear {
  15%, 55% { background: var(--corn); color: #2a2006; transform: rotate(-6deg) scale(1.05); }
  35%, 75% { background: var(--corn); color: #2a2006; transform: rotate(6deg) scale(1.05); }
}
@keyframes hintPulse { 50% { box-shadow: 0 0 0 4px var(--corn), var(--shadow); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 380px) {
  .word .l { width: 20px; height: 24px; font-size: .8rem; }
}
