:root {
  --paper: #f4efe2;
  --ink: #1d1a17;
  --red: #ef4b3c;
  --yellow: #ffd25a;
  --blue: #3d7be0;
  --green: #4cc26a;
  --pad-size: min(15vh, 82px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font-family: "Gochi Hand", "Comic Sans MS", cursive;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

button {
  font: inherit; color: var(--ink); cursor: pointer;
  background: #fff; border: 3px solid var(--ink);
  border-radius: 14px 18px 12px 20px / 18px 12px 20px 14px;
  padding: .35em 1.1em; font-size: 1.35rem;
  box-shadow: 3px 4px 0 var(--ink);
  transition: transform .08s;
}
button:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--ink); }
button.ghost { background: transparent; box-shadow: none; }
button small { display: block; font-size: .65em; color: #4a443d; line-height: 1; }

/* ---------- écrans ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vh;
  padding: 3vh calc(16px + var(--safe-r)) 3vh calc(16px + var(--safe-l));
  background:
    repeating-linear-gradient(transparent 0 calc(4vh - 1px), rgba(61, 123, 224, .22) calc(4vh - 1px) 4vh),
    var(--paper);
}
.screen.arming button { pointer-events: none; } /* délai de garde contre le martelage (main.js show) */
.screen::before { /* marge rouge du cahier */
  content: ""; position: absolute; top: 0; bottom: 0; left: calc(9vw + var(--safe-l));
  width: 2px; background: rgba(239, 75, 60, .5);
}
#pause, #result { background: rgba(244, 239, 226, .88); }
#loading { font-size: 1.6rem; }

.title {
  font-family: "Bangers", cursive; font-weight: 400; margin: 0;
  font-size: min(16vh, 11vw); line-height: .85; text-align: center;
  transform: rotate(-3deg); letter-spacing: .03em;
  color: var(--yellow); -webkit-text-stroke: 3px var(--ink);
  text-shadow: 5px 6px 0 var(--ink);
}
.title span { color: var(--red); }
h2 { font-family: "Bangers", cursive; font-weight: 400; font-size: min(9vh, 7vw); margin: 0; letter-spacing: .03em; }
.menu-buttons { display: flex; gap: 2.5vw; flex-wrap: wrap; justify-content: center; }
.menu-buttons button:nth-child(1) { transform: rotate(-2deg); background: var(--yellow); }
.menu-buttons button:nth-child(2) { transform: rotate(1.5deg); }
.menu-buttons button:nth-child(3) { transform: rotate(-1deg); }
.help { max-width: 40em; text-align: center; font-size: 1.05rem; margin: 0; color: var(--ink); }

/* ---------- sélection ---------- */
#select { justify-content: space-between; background: transparent; pointer-events: none; }
#select::before { display: none; }
#select > * { pointer-events: auto; }
#select h2 {
  background: var(--paper); padding: 0 .5em; border: 3px solid var(--ink); border-radius: 12px;
  font-size: min(6.5vh, 5vw); transform: rotate(-1deg);
}
/* grille de vignettes au centre (comme Smash Bros) */
.roster {
  /* --cols est réglé par main.js : toujours 2 rangées, autant de colonnes qu'il faut */
  display: grid; grid-template-columns: repeat(var(--cols, 5), 1fr); gap: 1.8vh;
  /* grandit avec l'écran : limité par la largeur (côtés pour les persos 3D) et la hauteur */
  width: min(64vw, calc(var(--cols, 5) * 22vh)); margin: auto 0;
  padding: 1.8vh; background: rgba(255, 255, 255, .9);
  border: 3px solid var(--ink); border-radius: 18px 14px 20px 12px; box-shadow: 4px 5px 0 var(--ink);
}
.roster .card {
  position: relative; padding: 2px 2px 0; border-width: 2px; border-radius: 10px 12px 9px 13px;
  background: var(--paper); box-shadow: 2px 3px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; min-width: 0;
}
.roster .card img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; pointer-events: none; }
.roster .card span {
  font-family: "Bangers", cursive; font-size: max(.75rem, 3vh); letter-spacing: .03em; line-height: 1.3;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.roster .card:hover { transform: rotate(-2deg) scale(1.06); }
.roster .card.on1 { background: #ffe1dc; border-color: var(--red); box-shadow: 0 0 0 3px var(--red), 2px 3px 0 var(--ink); }
.roster .card.on2 { background: #dce8ff; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue), 2px 3px 0 var(--ink); }
.roster .card.on1.on2 { background: linear-gradient(90deg, #ffe1dc 50%, #dce8ff 50%); box-shadow: -2px 0 0 3px var(--red), 2px 0 0 3px var(--blue); }
.roster .m {
  position: absolute; top: -1.6vh; font-style: normal; font-family: "Bangers", cursive; font-size: max(.75rem, 2.6vh);
  color: #fff; padding: 0 .4em; border: 2px solid var(--ink); border-radius: 8px; line-height: 1.2;
  white-space: nowrap; pointer-events: none;
}
.roster .card.lock1 .m1, .roster .card.lock2 .m2 { transform: scale(1.25); }
.roster .card.lock1 .m1::after, .roster .card.lock2 .m2::after { content: " ✓"; }
.roster .m1 { left: -6px; background: var(--red); transform: rotate(-8deg); }
.roster .m2 { right: -6px; background: var(--blue); transform: rotate(8deg); }

/* bas de l'écran : carte de chaque joueur + boutons */
.select-bottom { display: flex; width: 100%; justify-content: space-between; align-items: flex-end; gap: 2vw; }
.picker {
  position: relative;
  background: rgba(255, 255, 255, .94); border: 3px solid var(--ink); border-radius: 16px 12px 18px 10px;
  padding: .6vh 10px; display: flex; flex-direction: column; align-items: center; gap: .3vh;
  width: min(30vw, 58vh); box-shadow: 3px 4px 0 var(--ink);
}
.picker.p1 { border-color: var(--red); }
.picker.p2 { border-color: var(--blue); }
.picker.active.p1 { box-shadow: 0 0 0 4px var(--red), 3px 4px 0 var(--ink); }
.picker.active.p2 { box-shadow: 0 0 0 4px var(--blue), 3px 4px 0 var(--ink); }
.picker.off { opacity: .85; }
.picker .who { font-family: "Bangers", cursive; font-size: max(1.1rem, 4.2vh); letter-spacing: .04em; white-space: nowrap; }
.picker .tag { color: #fff; font-weight: 400; padding: 0 .35em; border: 2px solid var(--ink); border-radius: 7px; font-size: .9em; }
.picker.p1 .tag { background: var(--red); }
.picker.p2 .tag { background: var(--blue); }
.picker .ready { font-weight: 400; color: #1f6e3a; font-size: .8em; }
.picker .special { font-size: max(.85rem, 2.8vh); color: #1f4f9e; white-space: nowrap; }
.picker .mixbtn { font-size: max(.85rem, 2.6vh); padding: .05em .7em; border-width: 2px; box-shadow: 2px 2px 0 var(--ink); }
.picker .mix {
  display: none; position: absolute; bottom: calc(100% + 6px); left: -3px; right: -3px;
  background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 8px;
  flex-direction: column; gap: 4px; box-shadow: 3px 4px 0 var(--ink);
}
.picker.mixing .mix { display: flex; }
.picker .row { display: grid; grid-template-columns: 2em 1fr 2em; align-items: center; font-size: max(.9rem, 2.8vh); }
.picker .row button { padding: 0; font-size: 1rem; height: 1.6em; box-shadow: none; border-width: 2px; }
.picker .row span { text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.select-actions { display: flex; gap: 2vw; }
.select-actions button { background: var(--paper); font-size: max(1.1rem, 4.4vh); }
#selectGo { background: var(--red); color: #fff; }

/* ---------- en ligne ---------- */
.online-box { display: flex; flex-direction: column; align-items: center; gap: 1.5vh; }
.join { display: flex; gap: 10px; }
#joinCode {
  font: inherit; font-size: 1.6rem; width: 5em; text-align: center; text-transform: uppercase;
  border: 3px solid var(--ink); border-radius: 12px; background: #fff; padding: .1em .3em;
}
#netStatus { min-height: 1.4em; font-size: 1.25rem; margin: 0; text-align: center; }
#netStatus b { font-family: "Bangers", cursive; font-size: 2.2rem; letter-spacing: .15em; color: var(--red); }
.or { color: #4a443d; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10; pointer-events: none;
  display: flex; align-items: flex-start; gap: 2vw;
  padding: max(1.2vh, env(safe-area-inset-top, 0px)) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
}
#hud .side { flex: 1; display: flex; flex-direction: column; gap: .5vh; }
#hud .p2 { align-items: flex-end; }
#hud .name { font-family: "Bangers", cursive; font-size: min(5vh, 1.5rem); letter-spacing: .04em; line-height: 1; }
.bar { position: relative; width: 100%; border: 3px solid var(--ink); background: #fff; overflow: hidden; }
.bar.hp { height: min(4.6vh, 22px); border-radius: 8px 12px 6px 10px; transform: rotate(-.6deg); }
.p2 .bar.hp { transform: rotate(.6deg) scaleX(-1); }
.bar.sp { height: min(2.6vh, 12px); width: 70%; border-width: 2px; border-radius: 6px; }
.p2 .bar.sp { transform: scaleX(-1); }
.bar i, .bar b { position: absolute; top: 0; bottom: 0; left: 0; width: 100%; transform-origin: left; }
.bar.hp i { background: repeating-linear-gradient(-55deg, var(--green) 0 7px, #69d684 7px 11px); z-index: 2; }
.bar.hp b { background: var(--red); z-index: 1; }
.bar.sp i { background: repeating-linear-gradient(-55deg, var(--blue) 0 6px, #6c9ff0 6px 10px); }
.bar.sp.full i { background: repeating-linear-gradient(-55deg, var(--yellow) 0 6px, #fff1a8 6px 10px); animation: blink .35s steps(2) infinite; }
@keyframes blink { 50% { filter: brightness(1.3); } }
.wins { display: flex; gap: 4px; height: 12px; }
.wins i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.wins i.on { background: var(--yellow); }
#timer {
  font-family: "Bangers", cursive; font-size: min(9vh, 2.6rem); line-height: 1; min-width: 2.2em; text-align: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 50% 45% 50% 40%; padding: .15em .2em 0;
}
#pauseBtn {
  pointer-events: auto; position: absolute; top: calc(max(1.2vh, env(safe-area-inset-top, 0px)) + min(9vh, 2.6rem) + 1.5vh);
  left: 50%; transform: translateX(-50%); font-size: .9rem; padding: .1em .6em; box-shadow: none; border-width: 2px;
}

#banner {
  position: fixed; left: 0; right: 0; top: 34%; z-index: 11; text-align: center; pointer-events: none;
  font-family: "Bangers", cursive; font-size: min(18vh, 12vw); letter-spacing: .03em;
  color: var(--yellow); -webkit-text-stroke: 3px var(--ink); text-shadow: 5px 6px 0 var(--ink);
  animation: pop .35s cubic-bezier(.2, 1.6, .4, 1);
}
#banner small { display: block; font-size: .4em; color: #fff; }
@keyframes pop { from { transform: scale(.3) rotate(-10deg); opacity: 0; } }

/* ---------- contrôles tactiles ---------- */
#controls { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
.pad {
  position: absolute; bottom: max(3vh, env(safe-area-inset-bottom, 0px));
  display: flex; align-items: flex-end; gap: 2vw; pointer-events: none;
}
.pad.left { left: calc(14px + var(--safe-l)); }
.pad.right { right: calc(14px + var(--safe-r)); }
.dpad {
  pointer-events: auto; position: relative; width: calc(var(--pad-size) * 2.3); height: calc(var(--pad-size) * 1.15);
  display: flex; touch-action: none;
}
.dpad span {
  flex: 1; display: grid; place-items: center; font-size: calc(var(--pad-size) * .45);
  background: rgba(255, 255, 255, .72); border: 3px solid var(--ink);
}
.dpad span:first-child { border-radius: 40% 10% 10% 45%; }
.dpad span:last-child { border-radius: 10% 45% 40% 10%; border-left: 0; }
.dpad span.dn { flex: .8; border-left: 0; border-radius: 0 0 35% 35%; font-size: calc(var(--pad-size) * .38); }
.dpad span.on { background: var(--yellow); }
.btns { display: grid; grid-template-columns: repeat(2, var(--pad-size)); grid-template-rows: repeat(2, var(--pad-size)); gap: 1.6vh; pointer-events: none; }
.btn {
  pointer-events: auto; touch-action: none;
  display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 50%;
  font-family: "Bangers", cursive; font-size: calc(var(--pad-size) * .25); letter-spacing: .03em;
  background: rgba(255, 255, 255, .75); box-shadow: 2px 3px 0 var(--ink);
}
.btn.on { transform: translate(2px, 3px); box-shadow: none; filter: brightness(.9); }
.btn.punch { background: rgba(255, 210, 90, .9); grid-column: 1; grid-row: 2; }
.btn.kick { background: rgba(239, 75, 60, .85); color: #fff; grid-column: 2; grid-row: 2; }
.btn.jump { background: rgba(76, 194, 106, .85); grid-column: 2; grid-row: 1; }
.btn.special { grid-column: 1; grid-row: 1; background: rgba(61, 123, 224, .9); color: #fff; visibility: hidden; font-size: calc(var(--pad-size) * .2); }
.btn.special.ready { visibility: visible; animation: wobble .5s ease-in-out infinite alternate; }
@keyframes wobble { from { transform: rotate(-8deg) scale(1); } to { transform: rotate(8deg) scale(1.08); } }
/* 2 joueurs : boutons plus petits, chacun dans sa moitié */
#controls.duo { --pad-size: min(12vh, 64px); }
#controls.duo .pad { gap: 1vw; }
#controls.duo .dpad { width: calc(var(--pad-size) * 1.9); }
.pad.p2side { flex-direction: row-reverse; }

#rotate {
  display: none; position: fixed; inset: 0; z-index: 50; background: var(--paper);
  flex-direction: column; align-items: center; justify-content: center; text-align: center; font-size: 1.6rem;
}
#rotate div { font-size: 4rem; animation: spin 1.6s ease-in-out infinite; }
@keyframes spin { 50% { transform: rotate(90deg); } }
@media (orientation: portrait) and (max-width: 820px) { #rotate { display: flex; } }

@media (max-height: 420px) {
  button { font-size: 1.1rem; }
  .picker .who { font-size: 1.1rem; }
  .picker .row button { height: 1.4em; }
  .help { font-size: .9rem; }
}

/* le menu laisse voir le ring derrière */
#menu, #online {
  background:
    repeating-linear-gradient(transparent 0 calc(4vh - 1px), rgba(61, 123, 224, .18) calc(4vh - 1px) 4vh),
    rgba(244, 239, 226, .8);
}

/* ---------- manette ---------- */
button.pad-focus, input.pad-focus {
  outline: 4px dashed #1f4f9e; outline-offset: 4px;
  transform: rotate(-1.5deg) scale(1.06);
}
#padToast {
  position: fixed; left: 50%; top: 10px; transform: translateX(-50%) rotate(-1deg);
  background: #fff; border: 3px solid var(--ink); border-radius: 14px 18px 12px 20px;
  box-shadow: 3px 4px 0 var(--ink); padding: .3em 1em; font-size: 1.1rem; z-index: 50;
  pointer-events: none;
}
.pad-status { font-size: .95rem; margin: .2em 0 0; color: #4a443d; text-align: center; }
.pad-status.ok { color: #1f6e3a; }
.pad-status.warn { color: #b3261e; background: #fff; border: 2px solid currentColor; border-radius: 10px; padding: .2em .6em; }
