:root {
  --bg: #f9f8f6;
  --surface: #ffffff;
  --line: #e7e5e0;
  --line-strong: #d6d3cc;
  --ink: #1d1c19;
  --muted: #8b8984;
  --accent: #2d5bff;
  --danger: #e5484d;
  --radius: 10px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.instant, .instant * { transition: none !important; }

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Tableau ---------- */

#board {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.9s ease, visibility 0s linear 0.9s;
}

#board.grabbing { cursor: grabbing; }

.on-board #board {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.9s ease;
}

.board-ui {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease 0.4s, visibility 0s linear 0.9s;
}

.on-board .board-ui {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s ease 0.4s;
}

/* ---------- Saisie ---------- */

.composer {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: min(440px, calc(100vw - 32px));
  margin: 0;
  transform: translate(-50%, -50%);
  transition: top 0.8s var(--ease);
}

.on-board .composer { top: calc(100% - 52px - env(safe-area-inset-bottom)); }

.composer input {
  width: 100%;
  height: 48px;
  padding: 0 64px 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: 400 15px/1 var(--font);
  outline: none;
  box-shadow: 0 1px 2px rgba(29, 28, 25, 0.04);
  transition: border-color 0.15s, box-shadow 0.3s;
}

.composer input::placeholder { color: var(--muted); opacity: 1; }

.composer input:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 4px rgba(45, 91, 255, 0.08), 0 1px 2px rgba(29, 28, 25, 0.04);
}

.on-board .composer input { box-shadow: 0 10px 30px rgba(29, 28, 25, 0.08), 0 1px 2px rgba(29, 28, 25, 0.06); }

.on-board .composer input:focus {
  box-shadow: 0 0 0 4px rgba(45, 91, 255, 0.08), 0 10px 30px rgba(29, 28, 25, 0.08);
}

.composer.busy input { color: var(--muted); }

.composer input.shake { animation: shake 0.4s var(--ease); }

@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.counter {
  position: absolute;
  top: 24px;
  right: 16px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.composer.has-text .counter { opacity: 1; }
.counter.full { color: var(--danger); }

.lede,
.msg {
  position: absolute;
  top: calc(100% + 14px);
  left: 0;
  right: 0;
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s var(--ease);
}

.lede { color: var(--muted); }

.composer:has(.msg.show) .lede,
.on-board .lede { opacity: 0; }

.msg {
  opacity: 0;
  transform: translateY(-4px);
}

.msg.show { opacity: 1; transform: none; }
.msg.ok { color: var(--accent); }
.msg.error { color: var(--danger); }

.on-board .msg {
  top: auto;
  bottom: calc(100% + 12px);
  transform: translateY(4px);
}

.on-board .msg.show { transform: none; }

.on-board .msg span {
  display: inline-block;
  max-width: 100%;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(29, 28, 25, 0.06);
}

/* ---------- Interface du tableau ---------- */

.hud {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.chip {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: border-color 0.15s, opacity 0.5s ease 0.4s, visibility 0s linear 0.9s;
}

.on-board .chip { transition: border-color 0.15s, opacity 0.5s ease 0.4s; }

.chip:hover { border-color: var(--line-strong); }
.chip strong { font-weight: 600; }
.chip span { color: var(--muted); }
.score strong { color: var(--accent); }

.score.bump { animation: bump 0.6s cubic-bezier(0.3, 1.8, 0.5, 1); }

@keyframes bump {
  40% { transform: scale(1.12); }
}

.zoom {
  position: fixed;
  right: 16px;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(29, 28, 25, 0.06);
  overflow: hidden;
}

.zoom button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.zoom button + button { border-top: 1px solid var(--line); }
.zoom button:hover { background: #f4f3f0; }
.zoom button:focus-visible { outline-offset: -2px; }

.hint {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  z-index: 1;
  height: 36px;
  margin: 0;
  padding: 0 14px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -4px);
  transition: opacity 0.4s, transform 0.4s var(--ease);
}

.hint.show { opacity: 1; transform: translate(-50%, 0); transition-delay: 1s; }

.tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 3;
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}

.tip.show { opacity: 1; }

@media (max-width: 640px) {
  .composer input { font-size: 16px; }
  .zoom { display: none; }
  .hint {
    top: calc(62px + env(safe-area-inset-top));
    width: max-content;
    max-width: calc(100vw - 32px);
    height: auto;
    min-height: 36px;
    padding: 8px 14px;
    white-space: normal;
    text-align: center;
  }
}

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