:root {
  --bg-deep: #070510;
  --bg-card: rgba(18, 14, 35, 0.72);
  --fg: #f4f2ff;
  --muted: #9b94b8;
  --neon: #39ff9c;
  --neon-dim: rgba(57, 255, 156, 0.35);
  --hot: #ff2d8b;
  --hot-dim: rgba(255, 45, 139, 0.4);
  --pitch: #0d2818;
  --pitch-mid: #143d28;
  --pitch-line: rgba(255, 255, 255, 0.2);
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --radius: 14px;
  --font: "Outfit", system-ui, sans-serif;
  --font-display: "Unbounded", system-ui, sans-serif;
  --page-gap: clamp(0.55rem, 2.2vw, 0.85rem);
  --block-gap: 0.5rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
  height: -webkit-fill-available;
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--fg);
  line-height: 1.4;
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(57, 255, 156, 0.12);
  touch-action: manipulation;
  overscroll-behavior-y: contain;
}

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

button:focus-visible {
  outline-offset: 3px;
}

.bg-aurora {
  position: fixed;
  inset: -20% -10%;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(255, 45, 139, 0.32), transparent 55%),
    radial-gradient(ellipse 70% 45% at 90% 10%, rgba(57, 255, 156, 0.2), transparent 50%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(120, 80, 255, 0.18), transparent 45%),
    linear-gradient(180deg, #0a0618 0%, #070510 100%);
  pointer-events: none;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding:
    max(0.65rem, env(safe-area-inset-top))
    max(0.85rem, env(safe-area-inset-right))
    max(0.85rem, env(safe-area-inset-bottom))
    max(0.85rem, env(safe-area-inset-left));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  gap: var(--page-gap);
  align-items: stretch;
  width: 100%;
}

/* ——— En-tête ——— */
.header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  text-align: left;
  flex-shrink: 0;
}

.header__top {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  min-width: 0;
}

.header__title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem 0.65rem;
  min-width: 0;
  flex: 1 1 auto;
  overflow: visible;
}

.title-cluster {
  --title-size: clamp(1.85rem, 8vw, 2.65rem);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  flex: 1 1 auto;
}

.title__emoji {
  flex-shrink: 0;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  font-size: var(--title-size);
  line-height: 1;
  user-select: none;
}

.lang-dd {
  position: relative;
  flex-shrink: 0;
  align-self: flex-start;
  margin: 0.1rem 0 0;
  z-index: 40;
}

.lang-dd__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: 2.1rem;
  padding: 0.15rem 0.4rem;
  font: inherit;
  line-height: 1;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  cursor: pointer;
  background-color: rgba(255, 255, 255, 0.1);
  transition: border-color 0.15s, background-color 0.15s;
}

.lang-dd__btn:hover {
  border-color: rgba(255, 255, 255, 0.25);
  background-color: rgba(255, 255, 255, 0.14);
}

.lang-dd__btn:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: 2px;
}

.lang-dd__emoji {
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  font-size: 1.35rem;
  line-height: 1;
  user-select: none;
}

.lang-dd__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  min-width: 2.75rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(18, 14, 35, 0.96);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.lang-dd__item {
  cursor: pointer;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  font-size: 1.35rem;
  line-height: 1;
  text-align: center;
  user-select: none;
}

.lang-dd__item:hover {
  background: rgba(57, 255, 156, 0.12);
}

.lang-dd__item:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: -2px;
}

.lang-dd__item.is-active {
  background: rgba(57, 255, 156, 0.18);
  box-shadow: inset 0 0 0 1px var(--neon-dim);
}

.title {
  font-family: var(--font-display);
  font-size: var(--title-size);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.2;
  margin: 0;
  padding-bottom: 0.08em;
  min-width: 0;
  flex: 1 1 auto;
  overflow: visible;
  overflow-wrap: anywhere;
  word-break: break-word;
  background: linear-gradient(135deg, #fff 0%, #c8ffd9 45%, #ff9ecf 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* pas de filter ici : avec background-clip:text ça rogne les descendantes (ex. queue du G) */
  text-shadow: 0 2px 28px rgba(57, 255, 156, 0.22);
}

.header__badge {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(57, 255, 156, 0.2), rgba(255, 45, 139, 0.15));
  border: 1px solid var(--neon-dim);
  color: var(--neon);
  animation: badge-in 0.45s ease-out;
}

@keyframes badge-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ——— Blocs (formation, banc) ——— */
.block {
  display: flex;
  flex-direction: column;
  gap: var(--block-gap);
  width: 100%;
  min-width: 0;
  flex-shrink: 0;
}

.block__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.35rem 0.75rem;
  min-height: 1.1em;
}

.block__label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.formations-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  padding: 0.1rem 0 0.35rem;
  width: 100%;
  min-width: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--neon-dim) transparent;
}

.formations {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.4rem;
  width: max-content;
  min-width: 100%;
}

@media (min-width: 560px) {
  .formations {
    flex-wrap: wrap;
    justify-content: center;
    width: auto;
    min-width: 0;
  }

  .formations-scroll {
    overflow: visible;
  }
}

.formation-btn {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.42rem 0.85rem;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: var(--glass);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.formation-btn:hover {
  color: var(--fg);
  border-color: rgba(255, 255, 255, 0.22);
}

.formation-btn.is-active {
  color: var(--bg-deep);
  background: linear-gradient(135deg, var(--neon) 0%, #7dffb8 100%);
  border-color: transparent;
  box-shadow: 0 4px 20px rgba(57, 255, 156, 0.3);
}

.formation-btn:active:not(:disabled) {
  transform: scale(0.97);
}

/* ——— Terrain ——— */
.pitch-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
  margin: 0;
}

.pitch {
  position: relative;
  width: 100%;
  max-width: 100%;
  contain: paint;
  aspect-ratio: 68 / 105;
  max-height: min(78dvh, 560px);
  background: linear-gradient(165deg, var(--pitch-mid) 0%, var(--pitch) 55%, #081a10 100%);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(57, 255, 156, 0.2);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 18px 44px -14px rgba(0, 0, 0, 0.55),
    0 0 36px -10px rgba(57, 255, 156, 0.1);
}

.pitch-texture {
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  mix-blend-mode: overlay;
}

.pitch-line--center {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--pitch-line);
  transform: translateY(-50%);
}

.pitch-circle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22%;
  padding-bottom: 22%;
  border: 1px solid var(--pitch-line);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.pitch-box {
  position: absolute;
  width: 44%;
  height: 18%;
  border: 1px solid var(--pitch-line);
}

.pitch-box--left {
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.pitch-box--right {
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.slots {
  position: absolute;
  inset: 3.5% 4%;
  z-index: 1;
}

.pitch__url {
  position: absolute;
  right: max(0.45rem, 2.5%);
  bottom: max(0.4rem, 2.2%);
  z-index: 0;
  font-size: clamp(0.68rem, 2vw, 0.9rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.44);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  user-select: none;
}

.slot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: min(36%, 124px);
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  padding: 0.26rem 0.26rem 0.3rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition:
    border-color 0.12s ease-out,
    box-shadow 0.12s ease-out,
    opacity 0.12s ease-out,
    filter 0.12s ease-out;
}

.slot.is-drop-target {
  border-color: var(--neon);
  box-shadow: 0 0 0 2px var(--neon-dim), 0 4px 20px rgba(57, 255, 156, 0.15);
  z-index: 4;
}

.slot.is-drag-source {
  opacity: 0.42;
  filter: brightness(0.88) saturate(0.9);
}

.slot.is-selected {
  border-color: var(--hot);
  box-shadow: 0 0 0 2px var(--hot-dim);
}

.slot input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: clamp(0.65rem, 2.2vw, 0.78rem);
  font-weight: 600;
  text-align: center;
  padding: 0.35rem 0.22rem;
  min-height: 2.2rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  outline: none;
}

.slot input:focus {
  border-color: rgba(57, 255, 156, 0.55);
  background: rgba(255, 255, 255, 0.1);
}

.slot-label {
  display: block;
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  color: rgba(255, 255, 255, 0.55);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  padding: 0.15rem 0.2rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

.slot-label:hover {
  color: rgba(255, 255, 255, 0.85);
  background: rgba(57, 255, 156, 0.12);
}

.slot-label:active {
  cursor: grabbing;
}

.bench {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 0.5rem;
}

.bench .slot {
  position: relative;
  transform: none;
  width: 100%;
  left: auto !important;
  top: auto !important;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
}

.bench .slot input {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--fg);
}

.bench .slot input:focus {
  border-color: rgba(255, 45, 139, 0.45);
}

.bench .slot-label {
  color: var(--muted);
}

.bench .slot-label:hover {
  color: var(--fg);
  background: rgba(255, 45, 139, 0.12);
}

/* ——— Pied ——— */
.footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
  width: 100%;
  min-width: 0;
}

.footer__stats {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.65rem;
  flex-wrap: wrap;
  min-height: 1.35em;
}

.footer__count {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.footer__count--pulse {
  animation: count-pop 0.65s ease;
}

@keyframes count-pop {
  0% {
    transform: scale(1);
    color: var(--muted);
  }
  40% {
    transform: scale(1.08);
    color: var(--neon);
  }
  100% {
    transform: scale(1);
    color: var(--muted);
  }
}

.footer__saved {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--neon);
}

.footer__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.footer__legal {
  margin: 0;
  text-align: center;
}

.footer__legal-link {
  display: inline;
  padding: 0;
  margin: 0;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border: none;
  border-bottom: 1px solid rgba(155, 148, 184, 0.35);
  background: transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.footer__legal-link:hover {
  color: var(--fg);
  border-bottom-color: var(--muted);
}

.legal-dialog {
  max-width: min(92vw, 400px);
  width: 100%;
  margin: auto;
  padding: 0;
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  background: rgba(18, 14, 35, 0.98);
  color: var(--fg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.legal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.legal-dialog__inner {
  position: relative;
  padding: 1.1rem 1.15rem 1.15rem;
}

.legal-dialog__close {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.legal-dialog__close:hover {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.06);
}

.legal-dialog__close:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: 2px;
}

.legal__title {
  font-family: inherit;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.4rem;
  padding-right: 2.25rem;
}

.legal__text {
  font-size: 0.68rem;
  line-height: 1.45;
  color: rgba(200, 196, 218, 0.88);
}

.legal__text p {
  margin: 0 0 0.45rem;
}

.legal__text p:last-child {
  margin-bottom: 0;
}

.btn {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.45rem 0.95rem;
  min-height: 2.5rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.btn--share {
  border-color: rgba(255, 45, 139, 0.35);
  background: rgba(255, 45, 139, 0.1);
  color: #ffb8dc;
}

.btn--share:hover {
  border-color: rgba(255, 45, 139, 0.5);
  background: rgba(255, 45, 139, 0.16);
}

.toast-host {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  max-width: min(92vw, 360px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 0.65rem 1rem;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
  border-radius: 12px;
  background: rgba(18, 14, 35, 0.94);
  border: 1px solid var(--glass-border);
  color: var(--fg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  cursor: pointer;
}

.toast--show {
  opacity: 1;
  transform: translateY(0);
}

.toast--success {
  border-color: rgba(57, 255, 156, 0.35);
}

.toast--error {
  border-color: rgba(255, 80, 100, 0.45);
  color: #ffc8d0;
}

@media (max-width: 640px) {
  .page {
    gap: clamp(0.45rem, 2.5vw, 0.65rem);
  }

  .title-cluster {
    --title-size: clamp(0.88rem, 4vw, 1.35rem);
    align-items: center;
  }

  .title__emoji {
    font-size: clamp(0.82rem, 3.8vw, 1.25rem);
  }

  .lang-dd__btn {
    min-height: 2.5rem;
    min-width: 2.75rem;
  }

  .formation-btn {
    min-height: 2.45rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.72rem;
  }

  .formations-scroll {
    padding-bottom: 0.45rem;
  }

  .pitch {
    max-height: min(78dvh, 520px);
  }

  .slots {
    inset: 5% 3.25%;
  }

  .pitch .slot {
    width: min(17%, 70px);
    padding: 0.14rem 0.1rem 0.16rem;
    gap: 0.08rem;
    border-radius: 8px;
  }

  .pitch .slot input {
    font-size: clamp(0.56rem, 2.4vw, 0.72rem);
    min-height: 1.72rem;
    padding: 0.24rem 0.14rem;
    border-radius: 5px;
  }

  .pitch .slot .slot-label {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: auto;
    font-size: 0.44rem;
    padding: 0.14rem 0.08rem;
    letter-spacing: 0.07em;
  }

  .pitch__url {
    font-size: clamp(0.52rem, 1.65vw, 0.68rem);
  }

  .bench {
    grid-template-columns: 1fr;
  }

  .bench .slot input {
    font-size: 1rem;
    min-height: 2.65rem;
  }

  .btn {
    font-size: 0.72rem;
    padding: 0.5rem 0.4rem;
    min-height: 2.75rem;
  }
}

@media (max-width: 380px) {
  .title-cluster {
    --title-size: clamp(0.82rem, 3.8vw, 1.2rem);
  }

  .title__emoji {
    font-size: clamp(0.75rem, 3.5vw, 1.1rem);
  }

  .pitch .slot {
    width: min(16%, 64px);
  }

  .pitch .slot input {
    min-height: 1.58rem;
    font-size: clamp(0.52rem, 2.2vw, 0.66rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .formation-btn,
  .btn,
  .toast,
  .header__badge {
    transition: none;
    animation: none;
  }

  .footer__count--pulse {
    animation: none;
  }
}
