/* =========================================================================
   Le Mot — Wordle français. Thème « Améthyste » (violet / abricot / prune).
   Mécanique identique à lemot.fr, identité visuelle distincte.
   ========================================================================= */

:root {
  /* Thème sombre (par défaut) */
  --bg: #1d1525;
  --surface: #2a1f38;
  --header-bg: #241a30;
  --fg: #f3e9ff;
  --fg-muted: #b9a9cf;
  --line: #4a3a5e;

  --tile-border: #4a3a5e;
  --tile-fg: #f3e9ff;

  --correct: #9b5de5;
  --correct-deep: #6f3cc4;
  --correct-fg: #ffffff;

  --wrong-place: #f4a261;
  --wrong-place-deep: #c97d3a;
  --wrong-place-fg: #2a1500;

  --wrong: #3a2f49;
  --wrong-deep: #2a2138;
  --wrong-fg: #d8cce8;

  --key: #5a4a72;
  --key-border: #3f3454;
  --key-fg: #f3e9ff;

  --accent: #c77dff;
  --accent-fg: #1d1525;

  --tile-size: clamp(2.1rem, min(13vw, 7svh), 4rem);
  --tile-gap: clamp(0.25rem, min(1.3vw, 0.8svh), 0.5rem);
  --tile-font: clamp(1.1rem, min(6vw, 3.2svh), 2.1rem);
  --radius: 0.3rem;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.light {
  --bg: #faf5ff;
  --surface: #ffffff;
  --header-bg: #ffffff;
  --fg: #2a1f38;
  --fg-muted: #6b5b80;
  --line: #d8c8ec;

  --tile-border: #cdb9e6;
  --tile-fg: #2a1f38;

  --correct: #9b5de5;
  --correct-deep: #7b3fd0;
  --correct-fg: #ffffff;

  --wrong-place: #f4a261;
  --wrong-place-deep: #d4823f;
  --wrong-place-fg: #3a1c00;

  --wrong: #cbb8de;
  --wrong-deep: #b29ccb;
  --wrong-fg: #2a1f38;

  --key: #e4d7f4;
  --key-border: #cdb9e6;
  --key-fg: #2a1f38;

  --accent: #7b3fd0;
  --accent-fg: #ffffff;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
}

button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---------------------------------------------------------------- Layout */

.app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.app-header {
  background: var(--header-bg);
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
  position: sticky;
  top: 0;
  z-index: 20;
}
body.light .app-header { border-bottom-color: #ece0f7; }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: min(100%, 36rem);
  margin: 0 auto;
  min-height: 3.75rem;
  padding: 0.6rem 0.75rem;
}

.side { display: flex; align-items: center; gap: 0.4rem; flex: 1; }
.side.right { justify-content: flex-end; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font-size: 1.2rem;
  line-height: 1;
}
.icon-btn:hover { background: rgb(255 255 255 / 0.08); }
body.light .icon-btn:hover { background: rgb(0 0 0 / 0.05); }

.logo {
  display: inline-flex;
  gap: 0.18rem;
  text-decoration: none;
}
.logo-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 0.2rem;
  background: var(--wrong);
  color: var(--wrong-fg);
  font-weight: 800;
  font-size: 0.95rem;
  text-transform: uppercase;
}
.logo-tile.correct { background: var(--correct); color: var(--correct-fg); }
.logo-tile.wrongPlace { background: var(--wrong-place); color: var(--wrong-place-fg); }
.logo-gap { width: 0.4rem; }

/* --------------------------------------------------------------- Controls */

.game {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  align-items: center;
  padding: 0.5rem 0.75rem;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 30rem;
}

.length-tabs { display: flex; gap: 0.4rem; }
.pill {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg-muted);
  font-weight: 800;
  font-size: 0.95rem;
}
.pill.active { background: var(--accent); color: var(--accent-fg); }

.mode-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }
.mode {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--fg-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
}
.mode.active { background: var(--surface); color: var(--fg); border-color: var(--accent); }

/* ------------------------------------------------------------------ Board */

.board-wrap {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 100%;
  min-height: 0;
}

.board {
  display: grid;
  gap: var(--tile-gap);
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  justify-content: center;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tile-size);
  height: var(--tile-size);
  border: 2px solid var(--tile-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--tile-fg);
  font-size: var(--tile-font);
  font-weight: 800;
  text-transform: uppercase;
  line-height: 1;
  user-select: none;
}
.tile.filled { border-color: var(--fg-muted); animation: pop 0.1s ease; }
.tile.checked { border-radius: 999px; }
.tile.correct { background: var(--correct); border-color: var(--correct); color: var(--correct-fg); }
.tile.wrongPlace { background: var(--wrong-place); border-color: var(--wrong-place); color: var(--wrong-place-fg); }
.tile.wrong { background: var(--wrong); border-color: var(--wrong); color: var(--wrong-fg); }

.tile.flip { animation: flip 0.5s ease forwards; }

@keyframes pop {
  0% { transform: scale(0.9); }
  100% { transform: scale(1); }
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

.row.invalid { animation: shake 0.5s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.tile.bounce { animation: bounce 0.6s ease; }
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-12px); }
  70% { transform: translateY(-5px); }
}

.replay {
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.7rem 1.4rem;
  text-transform: uppercase;
}

/* --------------------------------------------------------------- Keyboard */

.keyboard-wrap {
  width: min(100%, 36rem);
  margin: 0 auto;
  padding: 0 0.5rem calc(0.6rem + env(safe-area-inset-bottom));
}

.keyboard { display: flex; flex-direction: column; gap: 0.4rem; }
.keyboard-row { display: flex; gap: 0.3rem; justify-content: center; }

.key {
  flex: 1;
  min-width: 0;
  height: clamp(2.8rem, 7svh, 3.6rem);
  border: none;
  border-bottom: 2px solid var(--key-border);
  border-radius: var(--radius);
  background: var(--key);
  color: var(--key-fg);
  font-weight: 700;
  font-size: 1.05rem;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
}
.key.correct { background: var(--correct); border-bottom-color: var(--correct-deep); color: var(--correct-fg); }
.key.wrongPlace { background: var(--wrong-place); border-bottom-color: var(--wrong-place-deep); color: var(--wrong-place-fg); }
.key.wrong { background: var(--wrong); border-bottom-color: var(--wrong-deep); color: var(--wrong-fg); }
.key.action { flex: 1.5; font-size: 0.8rem; }

/* ------------------------------------------------------------------ Toast */

.toast {
  position: fixed;
  top: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.6rem 1rem;
  border-radius: 0.4rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; }

/* ----------------------------------------------------------------- Modals */

.overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}
.overlay.open { display: flex; }

.modal {
  background: var(--surface);
  color: var(--fg);
  border-radius: 0.8rem;
  width: min(100%, 26rem);
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.4rem;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.4);
}
.modal h2 { margin: 0 0 0.8rem; font-size: 1.2rem; text-transform: uppercase; letter-spacing: 0.03em; }
.modal p { color: var(--fg-muted); line-height: 1.5; font-size: 0.92rem; }
.modal .close {
  float: right;
  border: none;
  background: transparent;
  color: var(--fg-muted);
  font-size: 1.5rem;
  line-height: 1;
  margin: -0.4rem -0.4rem 0 0;
}

.legend { display: flex; flex-direction: column; gap: 0.6rem; margin: 1rem 0; }
.legend-row { display: flex; align-items: center; gap: 0.6rem; }
.legend-tile {
  width: 2rem; height: 2rem; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; flex: 0 0 auto;
}
.legend-tile.correct { background: var(--correct); color: var(--correct-fg); }
.legend-tile.wrongPlace { background: var(--wrong-place); color: var(--wrong-place-fg); }
.legend-tile.wrong { background: var(--wrong); color: var(--wrong-fg); }

/* Stats */
.stats-grid { display: flex; justify-content: space-around; text-align: center; margin: 1rem 0; }
.stat-num { font-size: 1.8rem; font-weight: 800; }
.stat-lbl { font-size: 0.72rem; color: var(--fg-muted); text-transform: uppercase; }

.dist { display: flex; flex-direction: column; gap: 0.3rem; margin: 1rem 0; }
.dist-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.dist-bar {
  background: var(--correct);
  color: var(--correct-fg);
  border-radius: 0.2rem;
  padding: 0.1rem 0.4rem;
  text-align: right;
  font-weight: 700;
  min-width: 1.4rem;
}
.dist-bar.zero { background: var(--wrong); color: var(--wrong-fg); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  border: none;
  border-radius: 0.5rem;
  background: var(--correct);
  color: var(--correct-fg);
  font-weight: 800;
  font-size: 1rem;
  padding: 0.8rem;
  text-transform: uppercase;
  margin-top: 0.6rem;
}

.field { width: 100%; margin: 0.6rem 0; }
.field input {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.7rem;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.2em;
}
.field input:focus { outline: none; border-color: var(--accent); }
.share-link {
  width: 100%;
  border: 2px dashed var(--line);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg-muted);
  font-size: 0.8rem;
  padding: 0.6rem;
  word-break: break-all;
  margin-top: 0.6rem;
}

@media (min-width: 480px) {
  :root { --tile-size: clamp(2.4rem, 4rem, 4rem); }
}
