/* Jeu de mèmes — feuille de style unique.
   Mobile d'abord (on joue au téléphone, l'écran du salon sert de vitrine). */

/* Anton (la police « Impact » des mèmes), auto-hébergée, en deux sous-ensembles :
   latin de base puis latin étendu — sans ça, les accents retombent sur une
   police système et le mème perd sa tête. */
@font-face {
  font-family: 'Anton';
  src: url('/fonts/anton-latin.woff2') format('woff2');
  font-weight: 400; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Anton';
  src: url('/fonts/anton-latin-ext.woff2') format('woff2');
  font-weight: 400; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Roboto Flex';
  src: url('/fonts/roboto-flex.woff2') format('woff2-variations');
  font-weight: 100 1000; font-display: swap;
}

:root {
  --bg: #100e1b;
  --bg-2: #17142a;
  --surface: #1e1a35;
  --surface-2: #272242;
  --line: #362f57;
  --text: #f4f1ff;
  --muted: #a79fca;
  --accent: #ffd23f;        /* jaune : action principale */
  --violet: #7c5cff;
  --pink: #ff4f9a;
  --green: #3ddc84;
  --red: #ff5c5c;
  --radius: 18px;
  --radius-s: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --ease: cubic-bezier(.2,.9,.25,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Roboto Flex', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background:
    radial-gradient(1000px 600px at 15% -10%, #2a1f57 0%, transparent 60%),
    radial-gradient(900px 500px at 95% 0%, #4a1a52 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ------------------------------------------------------------ écrans */
.screen { display: none; min-height: 100dvh; padding: 18px 16px 40px; }
.screen.on { display: block; animation: pop .35s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(10px); } }
.wrap { max-width: 980px; margin: 0 auto; }
.wrap.narrow { max-width: 520px; }

/* ------------------------------------------------------------ titres */
.logo {
  font-family: Anton, Impact, sans-serif; letter-spacing: .5px;
  text-transform: uppercase; line-height: .92; text-align: center;
  font-size: clamp(42px, 13vw, 86px); margin: 6vh 0 4px;
  background: linear-gradient(180deg, #fff 20%, var(--accent) 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,.35));
}
.logo span { color: transparent; background: linear-gradient(180deg,#fff,var(--pink));
  -webkit-background-clip: text; background-clip: text; }
.tagline { text-align: center; color: var(--muted); margin: 0 0 26px; font-size: 15px; }
h2 { font-family: Anton, Impact, sans-serif; text-transform: uppercase;
  letter-spacing: .6px; font-weight: 400; margin: 0 0 12px; font-size: 22px; }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: 11px;
  color: var(--muted); font-weight: 700; }

/* ------------------------------------------------------------ blocs */
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-it { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ------------------------------------------------------------ contrôles */
input[type=text], input[type=number], select, textarea {
  width: 100%; background: #0e0c1a; border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: 13px 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--violet); box-shadow: 0 0 0 3px rgba(124,92,255,.25);
}
.btn {
  border: 0; border-radius: 999px; padding: 14px 22px; font-weight: 700;
  background: var(--surface-2); color: var(--text); cursor: pointer;
  transition: transform .12s var(--ease), filter .15s, background .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(180deg, #ffe071, var(--accent)); color: #241c00;
  box-shadow: 0 6px 0 #b98d00; }
.btn.primary:active { box-shadow: 0 2px 0 #b98d00; transform: translateY(3px) scale(.99); }
.btn.violet { background: linear-gradient(180deg, #9a80ff, var(--violet)); color: #fff;
  box-shadow: 0 6px 0 #4a2ec0; }
.btn.violet:active { box-shadow: 0 2px 0 #4a2ec0; transform: translateY(3px) scale(.99); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: #3a1620; color: #ffb3c4; border: 1px solid #6d2338; }
.btn.big { width: 100%; padding: 18px; font-size: 18px; }
.btn.small { padding: 8px 14px; font-size: 13px; }
.icon-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer;
  padding: 6px; border-radius: 10px; }
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,.06); }

/* ------------------------------------------------------------ avatar */
.avatar {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; flex: none; box-shadow: inset 0 0 0 2px rgba(0,0,0,.25);
}
.avatar.lg { width: 64px; height: 64px; font-size: 32px; }
.avatar.sm { width: 30px; height: 30px; font-size: 16px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px,1fr));
  gap: 6px; max-height: 190px; overflow: auto; margin-top: 10px; }
.emoji-grid button { font-size: 24px; background: var(--surface-2); border: 1px solid transparent;
  border-radius: 12px; padding: 6px; cursor: pointer; }
.emoji-grid button[aria-pressed=true] { border-color: var(--accent); background: #3a3160; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; }
.swatches button[aria-pressed=true] { border-color: #fff; transform: scale(1.12); }

/* ------------------------------------------------------------ salon */
.code-badge {
  font-family: Anton, Impact, sans-serif; font-size: clamp(38px, 12vw, 64px);
  letter-spacing: .18em; text-align: center; color: var(--accent);
  text-shadow: 0 4px 0 rgba(0,0,0,.4); user-select: all;
}
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px; }
.player {
  display: flex; gap: 10px; align-items: center; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 14px; padding: 9px 11px; position: relative;
  transition: border-color .2s, opacity .2s;
}
.player.offline { opacity: .45; }
.player.done { border-color: var(--green); }
.player .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.player .sc { font-size: 12px; color: var(--muted); }
.player .crown { position: absolute; top: -8px; left: -4px; font-size: 15px; }
.player .tick { margin-left: auto; color: var(--green); font-weight: 800; }

/* réglages */
.settings { display: grid; gap: 14px; }
.setting { display: grid; gap: 6px; }
.setting .lbl { display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 700; font-size: 14px; }
.setting .val { font-family: Anton, sans-serif; color: var(--accent); font-size: 18px; }
.setting .hint { font-size: 12px; color: var(--muted); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px;
  background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 999px;
  background: linear-gradient(90deg, var(--violet) var(--p,50%), #2c2647 var(--p,50%)); }
input[type=range]::-moz-range-track { height: 8px; border-radius: 999px; background: #2c2647; }
input[type=range]::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--violet); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; margin-top: -7px; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%;
  background: #fff; }
input[type=range]:disabled { opacity: .5; }
.seg { display: flex; background: #0e0c1a; border: 1px solid var(--line);
  border-radius: 999px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 9px 6px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: 13px; }
.seg button[aria-pressed=true] { background: var(--violet); color: #fff; }
.switch { display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px dashed var(--line); }
.switch:last-child { border-bottom: 0; }
.switch .t { font-weight: 700; font-size: 14px; }
.switch .h { font-size: 12px; color: var(--muted); }
.toggle { width: 52px; height: 30px; border-radius: 999px; background: #2c2647;
  border: 0; position: relative; cursor: pointer; flex: none; transition: background .2s; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform .2s var(--ease); }
.toggle[aria-pressed=true] { background: var(--green); }
.toggle[aria-pressed=true]::after { transform: translateX(22px); }

/* ------------------------------------------------------------ le mème */
.meme {
  position: relative; display: block; margin: 0 auto; max-width: 100%;
  border-radius: 14px; overflow: hidden; background: #000; line-height: 0;
  box-shadow: var(--shadow);
}
.meme img { display: block; width: 100%; height: auto; }
.mbox {
  position: absolute; display: flex; align-items: center; justify-content: center;
  text-align: center; line-height: 1.02; padding: 0 1%;
  font-family: Anton, Impact, 'Arial Black', sans-serif;
  text-transform: uppercase;
  /* On ne coupe PAS les mots : c'est la taille de police qui s'adapte
     (voir fit() dans meme.js). La coupure ne sert que de dernier recours. */
  word-break: normal; overflow-wrap: normal; hyphens: none;
}
.mbox.squeeze .mline { overflow-wrap: anywhere; word-break: break-word; }
/* le bloc qui porte réellement le texte (voir fillBox) */
.mbox .mline { width: 100%; min-width: 0; }
.mbox.white { color: #fff; -webkit-text-stroke: .06em #000;
  paint-order: stroke fill;
  text-shadow: 0 .04em .05em rgba(0,0,0,.55); }
.mbox.black { color: #000; text-transform: none; font-family: 'Roboto Flex', sans-serif;
  font-weight: 700; }
.mbox .mline .blank {
  outline: none; display: inline; min-width: 1.4em; padding: 0 .1em;
  border-bottom: .07em dashed currentColor; background: rgba(124,92,255,.28);
  border-radius: .1em;
}
.mbox .blank:focus { background: rgba(255,210,63,.4); }
/* toute la case est à écrire : ni surlignage ni soulignement, on tape sur l'image */
.mbox .mline .blank.solo { background: none; border-bottom: 0; padding: 0; }
.mbox .mline .blank.solo:focus { background: rgba(255,210,63,.22); }
.mbox .blank:empty::before { content: '…'; opacity: .55; }
.meme.editing .mbox { cursor: text; }
/* inset:0 et pas -2px : un pseudo-élément qui dépasse gonfle scrollWidth/Height
   de la case, et la mise à l'échelle du texte croit déborder en permanence. */
.meme.editing .mbox::after {
  content: ''; position: absolute; inset: 0; border: 2px dashed rgba(255,255,255,.25);
  border-radius: 8px; pointer-events: none;
}

/* ------------------------------------------------------------ jeu */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.pill { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-weight: 700; font-size: 13px; white-space: nowrap; }
.timer {
  font-family: Anton, sans-serif; font-size: 26px; min-width: 62px; text-align: center;
  padding: 4px 12px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line);
}
.timer.warn { color: #241c00; background: var(--accent); border-color: var(--accent); }
.timer.hot { color: #fff; background: var(--red); border-color: var(--red);
  animation: beat .8s infinite; }
@keyframes beat { 50% { transform: scale(1.08); } }
.bar { height: 6px; border-radius: 999px; background: #2c2647; overflow: hidden; margin: 10px 0; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg,var(--violet),var(--pink));
  transition: width .4s linear; }

.stage { max-width: 620px; margin: 0 auto; }
.prompt-line { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.actions { display: flex; gap: 10px; margin-top: 14px; }
.actions .btn { flex: 1; white-space: nowrap; font-size: 15px; padding: 14px 12px; }

.reactions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.react {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 16px;
  padding: 10px 12px; cursor: pointer; display: grid; gap: 2px; justify-items: center;
  min-width: 72px; transition: transform .12s var(--ease), border-color .15s, background .15s;
}
.react:hover { transform: translateY(-4px); border-color: var(--violet); }
.react[aria-pressed=true] { background: var(--violet); border-color: #fff; transform: translateY(-4px); }
.react .e { font-size: 30px; line-height: 1; }
.react .p { font-size: 11px; color: var(--muted); font-weight: 700; }
.react[aria-pressed=true] .p { color: #fff; }
.react:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.gain {
  font-family: Anton, sans-serif; font-size: clamp(34px,10vw,60px); text-align: center;
  color: var(--green); animation: rise .6s var(--ease); margin-top: 8px;
}
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.8); } }
.tally { display: flex; gap: 10px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
.tally span { background: var(--surface-2); border-radius: 999px; padding: 5px 11px;
  font-size: 14px; border: 1px solid var(--line); }

/* tableau des scores */
.board { display: grid; gap: 8px; }
.board .rowb { display: flex; align-items: center; gap: 12px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; }
.board .rk { font-family: Anton, sans-serif; font-size: 20px; width: 28px; color: var(--muted); }
.board .rowb:nth-child(1) .rk { color: var(--accent); }
.board .pts { margin-left: auto; font-family: Anton, sans-serif; font-size: 20px; }
.board .plus { color: var(--green); font-size: 13px; font-weight: 700; margin-left: 8px; }

.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; gap: 10px;
  margin: 20px 0 24px; }
.podium .stand { background: linear-gradient(180deg,var(--surface-2),var(--surface));
  border: 1px solid var(--line); border-radius: 14px 14px 0 0; padding: 12px 6px;
  text-align: center; }
.podium .p1 .stand { height: 150px; border-color: var(--accent); box-shadow: 0 0 30px rgba(255,210,63,.25); }
.podium .p2 .stand { height: 112px; }
.podium .p3 .stand { height: 90px; }
.podium .who { display: grid; justify-items: center; gap: 4px; margin-bottom: 6px; }
.podium .sc { font-family: Anton, sans-serif; font-size: 20px; color: var(--accent); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px,1fr)); gap: 12px; }
.gallery figure { margin: 0; }
.gallery figcaption { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: center; }

/* ------------------------------------------------------------ modale */
.modal-back {
  position: fixed; inset: 0; background: rgba(6,4,14,.72); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 14px; z-index: 60; animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px;
  width: min(760px, 100%); max-height: 92dvh; overflow: auto; box-shadow: var(--shadow);
  animation: slideup .3s var(--ease);
}
@keyframes slideup { from { transform: translateY(24px); opacity: 0; } }
.modal header { position: sticky; top: 0; background: var(--bg-2); padding: 16px 18px;
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; z-index: 2; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 18px; }
.modal footer { position: sticky; bottom: 0; background: var(--bg-2); padding: 14px 18px;
  border-top: 1px solid var(--line); display: flex; gap: 10px; }

/* éditeur de mème */
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px;
  text-align: center; color: var(--muted); cursor: pointer; transition: border-color .2s, background .2s;
}
.drop.hot { border-color: var(--accent); background: rgba(255,210,63,.08); color: var(--text); }
.editor-stage { position: relative; margin: 0 auto; max-width: 100%; line-height: 0;
  border-radius: 12px; overflow: hidden; background: #000; touch-action: none; }
.editor-stage img { width: 100%; display: block; }
.ebox { position: absolute; border: 2px solid var(--accent); border-radius: 6px;
  background: rgba(255,210,63,.12); cursor: grab; display: flex; align-items: center;
  justify-content: center; overflow: hidden; }
.ebox.sel { border-color: #fff; background: rgba(255,255,255,.16); box-shadow: 0 0 0 3px rgba(124,92,255,.5); }
.ebox .tag { font: 700 11px/1 'Roboto Flex',sans-serif; color: #241c00; background: var(--accent);
  padding: 3px 6px; border-radius: 5px; position: absolute; top: 2px; left: 2px; }
.ebox .hnd { position: absolute; right: -1px; bottom: -1px; width: 22px; height: 22px;
  background: var(--accent); border-radius: 6px 0 6px 0; cursor: nwse-resize; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px,1fr)); gap: 10px; }
.tpl-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface-2);
  cursor: pointer; position: relative; }
.tpl-card img { width: 100%; height: 92px; object-fit: cover; display: block; }
.tpl-card .n { font-size: 11px; padding: 6px; color: var(--muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.tpl-card .del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.65);
  border: 0; color: #ffb3c4; border-radius: 8px; padding: 3px 7px; cursor: pointer; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 12px; }

/* chat */
.chat { max-height: 160px; overflow: auto; display: grid; gap: 5px; font-size: 13px;
  margin-bottom: 8px; }
.chat b { color: var(--accent); }

/* toasts */
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: grid; gap: 8px; z-index: 99; pointer-events: none; }
.toast { background: #2a2447; border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow);
  animation: toast .3s var(--ease); font-size: 14px; }
.toast.err { background: #47202c; border-color: #7a2e42; }
@keyframes toast { from { opacity: 0; transform: translateY(14px); } }

.waiting-dots::after { content: ''; animation: dots 1.4s steps(4,end) infinite; }
@keyframes dots { 0% {content:''} 25%{content:'.'} 50%{content:'..'} 75%{content:'...'} }

@media (min-width: 760px) {
  .screen { padding: 26px 22px 60px; }
  .cols { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; align-items: start; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
