/* Mélimot — une table de jeu en feutre, des tuiles en relief, un hamster. */
:root {
  --felt: #0e5a52;
  --felt-deep: #0a4640;
  --felt-light: #14706a;
  --ivory: #fff4d8;
  --ivory-edge: #e2cb92;
  --ink: #23233b;
  --ink-soft: #5d5c78;
  --sun: #ffc83d;
  --sun-edge: #d29b14;
  --tomato: #f0525e;
  --tomato-edge: #b6323d;
  --mint: #55d6a8;
  --mint-edge: #2c9d76;
  --sky: #5cc8f5;
  --radius: 18px;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  color: var(--ivory);
  background-color: var(--felt);
  background-image: radial-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1.4px);
  background-size: 7px 7px;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.9rem; line-height: 1.1; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; line-height: 1.2; font-weight: 600; }
h3 { font-size: 1.05rem; font-weight: 600; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }

#app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100dvh;
}
#app.in-game { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

/* ---------- cartes et boutons : tout est une tuile en relief ---------- */
.card {
  background: var(--ivory);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 6px 0 var(--ivory-edge);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card.flat { background: rgba(0, 0, 0, 0.18); color: var(--ivory); box-shadow: none; }
.muted { color: var(--ink-soft); }
.on-felt-muted { color: rgba(255, 244, 216, 0.72); }
.small { font-size: 0.88rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  padding: 14px 18px;
  min-height: 52px;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--sun);
  box-shadow: 0 5px 0 var(--sun-edge);
  transition: transform 0.06s, box-shadow 0.06s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--sun-edge); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.alt { background: var(--ivory); box-shadow: 0 5px 0 var(--ivory-edge); }
.btn.alt:active:not(:disabled) { box-shadow: 0 1px 0 var(--ivory-edge); }
.btn.good { background: var(--mint); box-shadow: 0 5px 0 var(--mint-edge); }
.btn.good:active:not(:disabled) { box-shadow: 0 1px 0 var(--mint-edge); }
.btn.danger { background: var(--tomato); color: #fff; box-shadow: 0 5px 0 var(--tomato-edge); }
.btn.danger:active:not(:disabled) { box-shadow: 0 1px 0 var(--tomato-edge); }
.btn.ghost { background: transparent; color: var(--ivory); box-shadow: inset 0 0 0 2px rgba(255, 244, 216, 0.5); }
.btn.ghost:active:not(:disabled) { transform: none; background: rgba(255, 255, 255, 0.1); box-shadow: inset 0 0 0 2px rgba(255, 244, 216, 0.5); }
.btn.small { min-height: 42px; padding: 8px 14px; font-size: 0.95rem; border-radius: 13px; }
.btn.tiny { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; border-radius: 11px; }

.input {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  border: 3px solid var(--ivory-edge);
  background: #fff;
  color: var(--ink);
  padding: 10px 14px;
  font-size: 1.1rem;
  box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.06);
}
.input:focus { border-color: var(--sky); outline: none; }
.input.code { text-align: center; letter-spacing: 0.35em; text-transform: uppercase; font-weight: 700; font-size: 1.4rem; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 500; }
.error { color: var(--tomato-edge); font-weight: 500; }
.card.flat .error, .on-felt .error { color: #ffb4ba; }

/* ---------- mascotte ---------- */
.mascot { display: flex; align-items: center; gap: 10px; }
.mascot .hamster { flex: none; }
.bubble {
  position: relative;
  background: var(--ivory);
  color: var(--ink);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: 0 4px 0 var(--ivory-edge);
  min-width: 0;
}
.bubble::before {
  content: '';
  position: absolute;
  left: -9px;
  top: 50%;
  margin-top: -9px;
  border: 9px solid transparent;
  border-left: 0;
  border-right-color: var(--ivory);
}
.sheet .bubble::before { border-right-color: var(--ivory); }
.bubble strong { font-weight: 600; }
.hero { align-items: center; text-align: center; gap: 6px; padding-top: 8px; }
.hero .wordmark { font-size: 2.6rem; font-weight: 700; display: flex; gap: 4px; justify-content: center; }

/* ---------- tuiles de lettres ---------- */
.tile {
  --h: 52px;
  flex: 1 1 0;
  max-width: 44px;
  min-width: 0;
  height: var(--h);
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--ivory);
  color: var(--ink);
  font-weight: 700;
  font-size: 1.7rem;
  text-transform: uppercase;
  box-shadow: 0 4px 0 var(--ivory-edge);
  border: 0;
  padding: 0;
  user-select: none;
}
.tile.slot { background: rgba(0, 0, 0, 0.22); box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.18); color: transparent; }
.tile.found { background: var(--mint); box-shadow: 0 4px 0 var(--mint-edge); }
.tile.sun { background: var(--sun); box-shadow: 0 4px 0 var(--sun-edge); }
.tile.big { --h: 60px; font-size: 1.9rem; }
.tile.pop { animation: pop 0.28s ease-out; }
button.tile { cursor: pointer; transition: transform 0.06s, box-shadow 0.06s; }
button.tile:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ivory-edge); }
button.tile:disabled { opacity: 0.35; box-shadow: none; transform: translateY(3px); cursor: default; }
.tiles { display: flex; gap: 5px; justify-content: center; width: 100%; }
.tiles.fit { flex-wrap: wrap; row-gap: 8px; }
.tiles.fit .tile { flex: 0 0 calc((100% - (var(--per-row) - 1) * 5px) / var(--per-row)); max-width: 44px; }
.tiles.fit .tile.big { max-width: 48px; }
.tiles.shake { animation: shake 0.35s; }
.letter-code { --h: 64px; max-width: 58px; font-size: 2.2rem; }
.tile.mark { flex: none; width: 38px; max-width: none; --h: 46px; font-size: 1.45rem; }

@keyframes pop { 0% { transform: scale(0.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes dots { 0%, 20% { opacity: 0.2; } 50% { opacity: 1; } 100% { opacity: 0.2; } }

.waiting-dots span { animation: dots 1.2s infinite; }
.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ---------- clavier ---------- */
.keyboard { display: flex; flex-direction: column; gap: 7px; align-items: center; width: 100%; }
.krow { display: flex; gap: 5px; width: 100%; justify-content: center; }
.key {
  flex: 1 1 0;
  max-width: 40px;
  height: 50px;
  border-radius: 10px;
  border: 0;
  background: var(--ivory);
  color: var(--ink);
  font-weight: 600;
  font-size: 1.1rem;
  text-transform: uppercase;
  box-shadow: 0 4px 0 var(--ivory-edge);
  padding: 0;
  transition: transform 0.06s, box-shadow 0.06s;
}
.key:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ivory-edge); }
.key.ok { background: var(--mint); box-shadow: 0 4px 0 var(--mint-edge); }
.key.ko { background: var(--tomato); color: #fff; box-shadow: 0 4px 0 var(--tomato-edge); }
.key:disabled { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2); cursor: default; }
.key:disabled:not(.ok):not(.ko) { opacity: 0.4; }

/* ---------- bandeau de partie ---------- */
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.scoreboard { display: flex; align-items: center; gap: 10px; background: rgba(0, 0, 0, 0.2); border-radius: 16px; padding: 6px 14px; font-weight: 700; font-size: 1.5rem; }
.scoreboard .sep { opacity: 0.5; }
.pill { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; background: rgba(0, 0, 0, 0.2); border-radius: 999px; padding: 4px 12px; font-weight: 500; font-size: 0.92rem; }
.names { display: flex; justify-content: space-between; gap: 10px; font-weight: 500; font-size: 0.95rem; margin-top: -6px; }
.names .me { color: var(--sun); }
.names span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }

.timer { display: flex; flex-direction: column; gap: 6px; }
.timer .num { font-weight: 700; font-size: 2.6rem; line-height: 1; text-align: center; font-variant-numeric: tabular-nums; }
.timer .track { height: 14px; border-radius: 999px; background: rgba(0, 0, 0, 0.28); overflow: hidden; }
.timer .fill { height: 100%; border-radius: 999px; background: var(--sky); width: 100%; }
.timer.urgent .fill { background: var(--tomato); }
.timer.urgent .num { color: #ffb4ba; animation: bob 0.5s infinite; }
.timer.slim .num { font-size: 1.2rem; }
.timer.slim .track { height: 8px; }

.attempts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: 36px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-weight: 600; text-transform: uppercase; font-size: 0.95rem; }
.chip.ok { background: var(--mint); color: var(--ink); }
.chip.ko { background: var(--tomato); color: #fff; }
.status-line { text-align: center; font-weight: 500; }
.penalty { color: #ffb4ba; font-weight: 600; }

.answer-zone { background: rgba(0, 0, 0, 0.18); border-radius: 18px; padding: 14px 10px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- navigation basse ---------- */
.nav {
  position: fixed;
  inset: auto 0 0 0;
  background: var(--felt-deep);
  border-top: 3px solid rgba(0, 0, 0, 0.25);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 5;
}
.nav-inner { max-width: 480px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.nav button {
  background: transparent;
  border: 0;
  border-radius: 14px;
  padding: 6px 0 4px;
  color: rgba(255, 244, 216, 0.72);
  font-weight: 500;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}
.nav button svg { width: 26px; height: 26px; }
.nav button[aria-current='page'] { background: var(--ivory); color: var(--ink); box-shadow: 0 3px 0 var(--ivory-edge); }
.badge { position: absolute; top: 0; right: 18%; background: var(--tomato); color: #fff; border-radius: 999px; min-width: 20px; height: 20px; font-size: 0.75rem; font-weight: 700; display: grid; place-items: center; padding: 0 5px; }

/* ---------- listes ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 14px; padding: 8px 10px; box-shadow: 0 3px 0 var(--ivory-edge); }
.item.me { background: #fff0b8; }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; color: var(--ink); flex: none; position: relative; text-transform: uppercase; }
.dot { position: absolute; right: -3px; bottom: -3px; width: 14px; height: 14px; border-radius: 50%; border: 3px solid #fff; background: #b9b7c8; }
.dot.on { background: var(--mint-edge); }
.dot.busy { background: var(--sun-edge); }
.rank { width: 28px; text-align: center; font-weight: 700; color: var(--ink-soft); flex: none; }
.points { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: #fff; border-radius: 14px; padding: 10px 6px; text-align: center; box-shadow: 0 3px 0 var(--ivory-edge); }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.big-points { font-size: 3.2rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: rgba(0, 0, 0, 0.2); padding: 5px; border-radius: 16px; }
.tabs button { border: 0; background: transparent; border-radius: 12px; padding: 10px; font-weight: 600; color: rgba(255, 244, 216, 0.8); }
.tabs button[aria-selected='true'] { background: var(--ivory); color: var(--ink); box-shadow: 0 3px 0 var(--ivory-edge); }

/* ---------- feuilles (règles, défi) et messages ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5, 30, 27, 0.72); display: flex; align-items: flex-end; justify-content: center; z-index: 20; padding: 0; }
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--felt);
  border-radius: 26px 26px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 -4px 0 var(--felt-light);
}
.sheet.enter { animation: rise 0.22s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.steps { display: flex; gap: 6px; justify-content: center; }
.steps i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 244, 216, 0.3); }
.steps i.on { background: var(--sun); width: 24px; border-radius: 9px; }
.demo { display: flex; flex-direction: column; gap: 8px; align-items: center; background: rgba(0, 0, 0, 0.18); border-radius: 14px; padding: 12px 8px; }
.demo .tiles { gap: 4px; }
.demo .tile { --h: 40px; font-size: 1.25rem; max-width: 34px; }
.demo .tiny-note { font-size: 0.85rem; opacity: 0.85; text-align: center; }

#toasts { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 40; pointer-events: none; padding: 0 16px; }
.toast { background: var(--ivory); color: var(--ink); border-radius: 14px; padding: 10px 16px; box-shadow: 0 4px 0 var(--ivory-edge); font-weight: 500; max-width: 440px; animation: rise 0.2s ease-out; }
.toast.error { background: var(--tomato); color: #fff; box-shadow: 0 4px 0 var(--tomato-edge); }
.toast.good { background: var(--mint); box-shadow: 0 4px 0 var(--mint-edge); }
.banner { background: var(--sun); color: var(--ink); border-radius: 12px; padding: 8px 12px; font-weight: 500; text-align: center; }

.result-word { margin: 4px 0; }
.delta { font-weight: 700; font-size: 1.6rem; }
.delta.up { color: var(--mint-edge); }
.delta.down { color: var(--tomato-edge); }
.celebrate .hamster { animation: bob 0.9s infinite; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 4px solid rgba(255, 244, 216, 0.3); border-top-color: var(--sun); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
@media (min-width: 700px) {
  #app { padding-top: 32px; }
  .nav { background: transparent; border: 0; }
  .nav-inner { background: var(--felt-deep); border-radius: 20px; padding: 6px; margin-bottom: 8px; }
}

/* Bulles posées sur une carte ivoire : fond blanc pour qu'elles ressortent */
.card .bubble { background: #fff; }
.card .bubble::before { border-right-color: #fff; }
