/* =====================================================================
   KIT DES JEUX (packages/ui/kit.css)
   Composants partagés par les jeux : feuilles, boutons, champs, chrono, scores, chat…
   Look d'origine (ardoise + papier + marqueur). Chaque jeu le restyle à sa sauce
   dans son propre style.css (classes préfixées), ou s'en passe complètement.
   ===================================================================== */
/* ---------- Polices (auto-hébergées, licence SIL OFL) ---------- */
@font-face { font-family: 'Shantell Sans'; src: url('/fonts/shantell-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Shantell Sans'; src: url('/fonts/shantell-sans-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Shantell Sans'; src: url('/fonts/shantell-sans-latin-800-normal.woff2') format('woff2'); font-weight: 800; font-display: swap; }

/* ---------- Jetons de design ---------- */
:root {
  /* Ardoise */
  --slate-900: #18211E;
  --slate-800: #1F2A27;
  --slate-700: #2A3833;
  --slate-600: #3A4A44;
  --chalk: #EDEBE4;
  --chalk-dim: #A9B3AE;
  /* Papier & encre */
  --paper: #FBFAF6;
  --paper-2: #F1EFE8;
  --paper-line: #E2DFD6;
  --ink: #1C1F1E;
  --ink-2: #59605C;
  /* Marqueurs */
  --yellow: #F5C431;
  --yellow-d: #DDA912;
  --coral: #F2665A;
  --blue: #4C8DF6;
  --green: #3DBE7A;
  --violet: #8E6CF0;
  --red: #E5484D;

  /* Typo : échelle 1,25 */
  --font: 'Shantell Sans', 'Segoe Print', 'Comic Sans MS', system-ui, sans-serif;
  --fs-xs: .75rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5625rem;
  --fs-2xl: 1.953rem;
  --fs-3xl: 2.441rem;

  /* Espacements : base 4 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;

  /* Formes */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --sheet-shadow: 0 1px 0 rgba(0, 0, 0, .25), 0 22px 44px -18px rgba(0, 0, 0, .7);

  /* Mouvement */
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --t-fast: 120ms;
  --t-med: 260ms;
  --t-slow: 520ms;

  color-scheme: dark;
}


/* ---------- Zone de jeu ---------- */
.game-root { font-family: var(--font); color: var(--chalk); line-height: 1.5; }
.game-root h1, .game-root h2, .game-root h3, .game-root p { margin: 0; }
.game-root .icon, .qg-kit .icon { width: 1.25em; height: 1.25em; flex: none; display: block; }
.game-root [data-icon] { display: inline-flex; }
.game-root button, .game-root input, .game-root select, .game-root textarea { font: inherit; }

/* ---------- Feuilles de papier ---------- */
.sheet {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--r-lg);
  box-shadow: var(--sheet-shadow);
  padding: var(--s5);
}
.sheet-title {
  font-size: var(--fs-lg);
  font-weight: 800;
  display: flex; align-items: center; gap: var(--s2);
  margin-bottom: var(--s4);
  position: relative;
  width: fit-content;
}
.sheet-title .icon { color: var(--ink-2); }
/* souligné griffonné qui se trace */
.sheet-title::after, .chalk-title::after {
  content: '';
  position: absolute; left: -2px; right: -6px; bottom: -6px; height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 10' preserveAspectRatio='none'%3E%3Cpath d='M2 6 C40 2 80 8 120 5 S180 3 198 6' fill='none' stroke='%23F5C431' stroke-width='3.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
  animation: reveal-x var(--t-slow) var(--ease-out) .25s both;
}
@keyframes reveal-x { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.count { font-weight: 400; color: var(--ink-2); font-size: var(--fs-md); }

/* ---------- Boutons ---------- */
.game-root button { color: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s4);
  border: none;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: var(--fs-md);
  line-height: 1;
  background: var(--paper-2);
  color: var(--ink);
  transition: transform var(--t-fast) var(--ease-out), background var(--t-fast), box-shadow var(--t-med) var(--ease-out);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--yellow); color: var(--ink); box-shadow: inset 0 -3px 0 var(--yellow-d); }
.btn-primary:hover:not(:disabled) { box-shadow: inset 0 -3px 0 var(--yellow-d), 0 10px 22px -10px rgba(245, 196, 49, .8); }
.btn-dark { background: var(--ink); color: var(--paper); }
.btn-dark:hover:not(:disabled) { background: #2d3230; }
.btn-soft { background: var(--paper-2); }
.btn-soft:hover:not(:disabled) { background: var(--paper-line); }
.btn-ghost { background: transparent; color: var(--chalk); box-shadow: inset 0 0 0 1.5px var(--slate-600); }
.btn-ghost:hover:not(:disabled) { background: var(--slate-700); }
.btn-lg { min-height: 54px; font-size: var(--fs-lg); width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: var(--fs-sm); }
.full { width: 100%; }
.link-btn {
  display: inline-flex; align-items: center; gap: var(--s1);
  border: none; background: none; padding: 0;
  color: var(--ink-2); font-weight: 600; font-size: var(--fs-sm);
  text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px;
  width: fit-content;
}
.link-btn:hover { color: var(--ink); }

/* ---------- Champs ---------- */
.game-root input, .game-root select, .game-root textarea {
  font: inherit; color: var(--ink);
  background: var(--paper-2);
  border: 1.5px solid transparent;
  border-radius: var(--r-md);
  padding: 10px 12px;
  width: 100%;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.game-root input:hover, .game-root select:hover, .game-root textarea:hover { border-color: var(--paper-line); }
.game-root input:focus, .game-root select:focus, .game-root textarea:focus { outline: none; border-color: var(--ink); background: #fff; }
.game-root input::placeholder, .game-root textarea::placeholder { color: #A3A69F; }
.game-root textarea { resize: vertical; }
.game-root select:disabled, .game-root input:disabled, .game-root textarea:disabled { opacity: .6; cursor: default; }
.field { display: flex; flex-direction: column; gap: var(--s1); font-weight: 600; font-size: var(--fs-sm); }
.field-title { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); margin-bottom: var(--s2); display: block; }
.switch { display: flex; align-items: center; gap: var(--s3); font-weight: 600; font-size: var(--fs-sm); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 40px; height: 24px; flex: none; border-radius: 99px;
  background: var(--paper-line); position: relative; transition: background var(--t-med);
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform var(--t-med) var(--ease-spring);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--blue); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }
.error { color: var(--red); min-height: 1.4em; font-weight: 600; font-size: var(--fs-sm); }
.note { color: var(--ink-2); font-size: var(--fs-sm); margin-top: var(--s3); }

/* ---------- Persos ---------- */
.avatar { width: 44px; height: 44px; flex: none; display: block; }
.avatar svg { display: block; width: 100%; height: 100%; overflow: visible; }
.avatar.tiny { width: 24px; height: 24px; }
.avatar.mid { width: 64px; height: 64px; }
.avatar.big { width: 96px; height: 96px; }

.skin { display: grid; grid-template-columns: 140px 1fr; gap: var(--s5); align-items: center; }
.skin-preview {
  width: 140px; height: 140px; border-radius: var(--r-lg);
  background: var(--paper-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Ccircle cx='2' cy='2' r='1' fill='%23D8D4C9'/%3E%3C/svg%3E");
  padding: var(--s2);
}
.skin-preview svg { width: 100%; height: 100%; display: block; }
.skin-preview.wiggle svg { animation: wiggle .45s var(--ease-spring); }
@keyframes wiggle { 30% { transform: rotate(7deg) scale(1.06); } 65% { transform: rotate(-6deg); } }
.skin-controls { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.skin-row { display: grid; grid-template-columns: 32px 1fr 32px; align-items: center; gap: var(--s2); }
.arrow {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--paper-2); display: grid; place-items: center; padding: 0;
  transition: background var(--t-fast), transform var(--t-fast);
}
.arrow .icon { width: 16px; height: 16px; }
.arrow:hover { background: var(--yellow); }
.arrow:active { transform: scale(.9); }
.part { text-align: center; line-height: 1.15; }
.part-label { display: block; font-size: var(--fs-xs); color: var(--ink-2); }
.part-name { font-weight: 600; }
.skin-swatches { display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: var(--s2); }
.skin-swatches .part-label { font-size: var(--fs-xs); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%; padding: 0;
  border: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
  transition: transform var(--t-fast) var(--ease-spring);
}
.swatch:hover { transform: scale(1.15); }
.swatch[aria-checked="true"] { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15), 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.dice { justify-self: start; align-self: flex-start; margin-top: var(--s1); }


.side { display: flex; flex-direction: column; gap: var(--s6); padding-top: var(--s3); }
.chalk-block { animation: fade-up var(--t-slow) var(--ease-out) both; }
.chalk-block:nth-child(1) { animation-delay: .7s; }
.chalk-block:nth-child(2) { animation-delay: .85s; }
.chalk-title { font-size: var(--fs-lg); font-weight: 800; color: var(--chalk); display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s4); position: relative; width: fit-content; }
.chalk-title::after { animation-delay: 1.1s; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s4); }
.steps li { display: grid; grid-template-columns: 36px 1fr; gap: var(--s3); align-items: start; color: var(--chalk-dim); }
.step-n {
  width: 36px; height: 36px; display: grid; place-items: center;
  font-weight: 800; color: var(--chalk);
  border: 2px solid var(--chalk-dim); border-radius: 46% 54% 50% 50% / 55% 45% 55% 45%;
}
.steps p { padding-top: 5px; }
.hof { display: flex; flex-direction: column; }
.hof-row { display: grid; grid-template-columns: 28px 1fr auto; gap: var(--s3); align-items: center; padding: var(--s2) 0; border-bottom: 1px dashed var(--slate-600); }
.hof-row .rank { font-weight: 800; color: var(--chalk-dim); text-align: center; }
.hof-row:first-child .rank { color: var(--yellow); }
.hof-row .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hof-row .w { color: var(--chalk-dim); font-size: var(--fs-sm); }
.hof .muted { color: var(--chalk-dim); font-size: var(--fs-sm); margin-top: var(--s2); }
.foot { display: flex; justify-content: center; gap: var(--s3); color: var(--chalk-dim); font-size: var(--fs-sm); margin-top: var(--s7); }
.foot a { color: var(--chalk); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }


/* ---------- Chat ---------- */
.chat-slot { display: flex; flex-direction: column; padding: var(--s3); min-height: 0; }
.chat-panel { display: flex; flex-direction: column; gap: var(--s2); height: 100%; min-height: 0; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; padding: var(--s1); scrollbar-width: thin; }
.msg { padding: 5px var(--s2); border-radius: var(--r-sm); line-height: 1.35; overflow-wrap: anywhere; font-size: var(--fs-sm); display: flex; gap: var(--s2); align-items: flex-start; animation: msg-in var(--t-med) var(--ease-out) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.msg .icon { width: 16px; height: 16px; margin-top: 1px; }
.msg .who { font-weight: 800; white-space: nowrap; }
.msg .txt { min-width: 0; }
.msg.system, .msg.turn, .msg.leave { color: var(--ink-2); }
.msg.join { color: #1d7a4a; }
.msg.round { justify-content: center; font-weight: 800; color: var(--ink); margin: var(--s2) 0; }
.msg.round::before, .msg.round::after { content: ''; flex: 1; height: 1.5px; background: var(--paper-line); align-self: center; }
.msg.success, .msg.success-me { background: rgba(61, 190, 122, .16); color: #1d7a4a; font-weight: 600; }
.msg.close { background: rgba(242, 102, 90, .14); color: #b8382c; font-weight: 600; }
.msg.reveal { background: rgba(245, 196, 49, .22); font-weight: 600; }
.msg.secret { background: rgba(142, 108, 240, .12); }
.msg.secret .icon { color: var(--violet); }
.msg.win { background: var(--yellow); font-weight: 800; justify-content: center; }
.msg.error { color: var(--red); font-weight: 600; }
.chat-form { position: relative; }
.chat-form.secret input { padding-left: 38px; background: rgba(142, 108, 240, .1); }
.chat-lock { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--violet); }



/* ---------- Utilitaires ---------- */
.muted { color: var(--chalk-dim); font-size: var(--fs-sm); }
.sheet .muted { color: var(--ink-2); }
.icon-btn:hover { background: var(--slate-600); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.dark { background: var(--paper-2); color: var(--ink); }
.icon-btn.dark:hover { background: var(--paper-line); }
.badge-18 { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 6px; background: var(--red); color: #fff; font-size: var(--fs-xs); font-weight: 800; vertical-align: middle; line-height: 1.4; }
.waiting { display: flex; align-items: center; gap: var(--s3); color: var(--ink-2); font-weight: 600; padding: var(--s3) 0; }
.waiting.center { justify-content: center; color: var(--chalk-dim); }
.dots { display: inline-flex; gap: 4px; }
.dots::before, .dots::after, .dots { --c: currentColor; }
.dots::before, .dots::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: dot 1s infinite ease-in-out; }
.dots::after { animation-delay: .2s; }
@keyframes dot { 50% { transform: translateY(-5px); opacity: .5; } }
.chip-toggle { border: 1.5px solid var(--paper-line); background: #fff; border-radius: 99px; padding: 5px 12px; font-size: var(--fs-sm); font-weight: 600; transition: background var(--t-fast), border-color var(--t-fast); }
.chip-toggle.on { background: var(--yellow); border-color: var(--yellow-d); }
.chip-toggle:disabled { cursor: default; }

/* ---------- Kit pour les jeux ---------- */
.timer { position: relative; width: 56px; height: 56px; flex: none; display: grid; place-items: center; }
.timer-ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.timer-ring circle { fill: none; stroke-width: 4; }
.timer-ring .bg { stroke: var(--slate-600); }
.timer-ring .fg { stroke: var(--yellow); stroke-dasharray: 100; stroke-linecap: round; transition: stroke-dashoffset .2s linear; }
.timer-num { font-weight: 800; font-size: var(--fs-lg); position: relative; }
.timer.urgent .fg { stroke: var(--coral); }
.timer.urgent .timer-num { color: var(--coral); animation: pulse .5s infinite alternate; }
.sheet .timer-ring .bg { stroke: var(--paper-line); }
@keyframes pulse { to { transform: scale(1.15); } }
.clock-badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; }

.pchip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; border-radius: 99px; background: var(--paper-2); color: var(--ink); font-weight: 600; font-size: var(--fs-sm); max-width: 100%; }
.pchip .pchip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip .pchip-extra { color: var(--ink-2); font-weight: 400; }
.pchip.me { background: var(--yellow); }
.pchip.off { opacity: .5; }

.scoreboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.scoreboard li { display: grid; grid-template-columns: 20px auto 1fr auto auto auto; align-items: center; gap: var(--s2); padding: 5px var(--s2); border-radius: var(--r-sm); }
.scoreboard li.me { background: var(--paper-2); }
.scoreboard li.active { box-shadow: inset 3px 0 0 var(--yellow); background: rgba(245, 196, 49, .14); }
.scoreboard li.off { opacity: .45; }
.sb-rank { font-weight: 800; color: var(--ink-2); font-size: var(--fs-sm); text-align: center; }
.sb-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sb-you { color: var(--ink-2); font-weight: 400; font-size: var(--fs-sm); }
.sb-badge { font-size: var(--fs-xs); padding: 1px 6px; border-radius: 6px; background: var(--paper-line); }
.sb-done { color: var(--green); display: inline-flex; }
.sb-score { font-weight: 800; }

.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: var(--s3); }
.pick { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s3) var(--s2); border: none; border-radius: var(--r-md); background: var(--paper-2); color: var(--ink); font-weight: 600; transition: transform var(--t-fast) var(--ease-spring), background var(--t-fast), box-shadow var(--t-fast); }
.pick:not(:disabled):hover { transform: translateY(-3px) rotate(-1deg); background: #fff; }
.pick.sel { background: var(--yellow); box-shadow: inset 0 0 0 2.5px var(--ink); transform: scale(1.03); }
.pick:disabled { opacity: .4; cursor: not-allowed; }
.pick-name { text-align: center; line-height: 1.2; overflow-wrap: anywhere; }
.pick-label { font-size: var(--fs-xs); color: var(--ink-2); }

.progress-line { display: flex; align-items: center; gap: var(--s3); font-size: var(--fs-sm); color: var(--ink-2); font-weight: 600; }
.progress-bar { flex: 1; height: 8px; background: var(--paper-line); border-radius: 99px; overflow: hidden; }
.progress-bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width var(--t-med) var(--ease-out); }

.big-title { font-size: var(--fs-3xl); font-weight: 800; line-height: 1.15; text-align: center; }
.stage-title { font-size: var(--fs-2xl); font-weight: 800; line-height: 1.2; }
.pop-in { animation: pop-in .45s var(--ease-spring) both; }
@keyframes pop-in { from { opacity: 0; transform: scale(.85); } }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.confetti { position: fixed; z-index: 60; pointer-events: none; width: 0; height: 0; }
.confetti i { position: absolute; width: 10px; height: 10px; border-radius: 3px; animation: burst .9s var(--ease-out) forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: var(--s5); z-index: 70;
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--paper); color: var(--ink);
  padding: var(--s3) var(--s4); border-radius: var(--r-md);
  font-weight: 600; box-shadow: var(--sheet-shadow);
  max-width: calc(100% - 32px);
  transition: transform var(--t-med) var(--ease-spring), opacity var(--t-med);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: var(--red); color: #fff; }
.toast.success { background: var(--green); color: #fff; }
body.offline::after { content: 'Connexion perdue… on se reconnecte'; position: fixed; top: 0; left: 0; right: 0; z-index: 80; background: var(--coral); color: #fff; text-align: center; font-weight: 700; padding: 6px; }


@media (prefers-reduced-motion: reduce) {
  .game-root *, .game-root *::before, .game-root *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}
