/* Superpositions de jeu : popover de tour, bannière de phase, ambiance Overdrive / Mort subite, écran de résultat. */

/* ---------- ambiance de phase (halo sur le bord du terrain) ---------- */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 10px;
  transition: box-shadow 0.6s;
}
.stage[data-phase="assault"]::after { box-shadow: inset 0 0 26px 2px rgba(255, 160, 40, 0.28); }
.stage[data-phase="finale"]::after { animation: danger 1.1s ease-in-out infinite; }
@keyframes danger {
  0%, 100% { box-shadow: inset 0 0 22px 2px rgba(255, 50, 50, 0.22); }
  50% { box-shadow: inset 0 0 44px 8px rgba(255, 50, 50, 0.5); }
}

/* ---------- multijoueur : voile réseau (attente, départ) et hall ---------- */
.net-veil {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 20px;
  background: rgba(6, 10, 7, 0.62);
  backdrop-filter: blur(2px);
  text-align: center;
  color: var(--text);
}
.net-veil[hidden] { display: none; }
.net-veil b { font-size: 22px; letter-spacing: 0.04em; }
.net-veil span { color: var(--muted); font-size: 14px; max-width: 280px; }
.net-veil.count b { font-size: 64px; color: var(--gold); }
.lobby-body { display: grid; gap: 10px; }
.lobby-body .btn { min-height: 46px; }
.lobby-me { margin: 0; text-align: center; color: var(--muted); }
.lobby-me b { color: var(--gold); }
.lobby-note { margin: 0; color: var(--muted); font-size: 13px; text-align: center; line-height: 1.4; }
.lobby-wait { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0; color: var(--text); }
.lobby-wait b { font-variant-numeric: tabular-nums; color: var(--gold); }
.lobby-code { margin: 0; text-align: center; font-size: 46px; font-weight: 900; letter-spacing: 0.25em; color: var(--gold); text-indent: 0.25em; }
.lobby-join { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.lobby-join input { min-width: 0; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-size: 20px; font-weight: 800; letter-spacing: 0.3em; text-transform: uppercase; text-align: center; }
.lobby-msg { margin: 0; min-height: 2.6em; color: var(--muted); font-size: 12.5px; text-align: center; }
.lobby-msg.warn { color: var(--gold); }
.lobby-msg.ok { color: #7fe39a; }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- bannière de phase ---------- */
.banner {
  position: absolute;
  left: 50%;
  top: 22%;
  display: grid;
  gap: 4px;
  justify-items: center;
  max-width: calc(100% - 28px);
  padding: 12px 22px;
  border-radius: 14px;
  background: rgba(10, 14, 10, 0.86);
  border: 2px solid var(--bn, #ffb347);
  color: var(--bn, #ffb347);
  text-align: center;
  pointer-events: none;
  transform: translate(-50%, 0);
  animation: banner-in 2.6s ease-out forwards;
  box-shadow: 0 0 30px -4px var(--bn, #ffb347);
}
.banner[hidden] { display: none; }
.banner b { font-size: 24px; letter-spacing: 0.12em; text-transform: uppercase; }
.banner span { font-size: 12.5px; color: var(--text); }
.banner.finale { --bn: #ff5a5a; }
.banner.skirmish { --bn: #9ad7ff; }
@keyframes banner-in {
  0% { opacity: 0; transform: translate(-50%, -14px) scale(0.8); }
  10% { opacity: 1; transform: translate(-50%, 0) scale(1.06); }
  16% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, 8px) scale(1); }
}

/* ---------- popover d'une tour posée ---------- */
.popover {
  position: absolute;
  z-index: 5;
  width: 224px;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* sans ça, les boutons élargissent le popover */
  gap: 7px;
  padding: 9px 10px 10px;
  border-radius: 14px;
  background: rgba(14, 22, 17, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  animation: pop-in 0.14s ease-out;
}
.popover[hidden] { display: none; }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(0.96); } }
.pop-head { display: flex; align-items: center; gap: 6px; }
.pop-name { font-size: 14px; }
.pop-stars { flex: 1; color: #ffd25e; font-size: 12px; letter-spacing: 1px; }
.pop-stars i { color: rgba(255, 255, 255, 0.22); font-style: normal; }
.pop-x { width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.pop-x:hover { color: var(--text); }
.pop-role { color: var(--muted); font-size: 11px; }
.pop-stats { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12px; font-variant-numeric: tabular-nums; }
.pop-stats dt { color: var(--muted); }
.pop-stats dd { margin: 0; text-align: right; font-weight: 700; }
.pop-stats .up { color: #7fe39a; }
.pop-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pop-actions .btn { min-height: 48px; min-width: 0; padding: 3px 4px; gap: 1px; font-size: 12.5px; line-height: 1.15; flex-direction: column; }
.pop-actions .btn .l1, .pop-actions .btn .l2 { display: inline-flex; align-items: center; gap: 4px; }
.pop-actions .btn .l2 { font-size: 12px; color: #ffe08a; font-variant-numeric: tabular-nums; }
.pop-actions svg { width: 14px; height: 14px; }
.pop-up { background: linear-gradient(#3fae5f, #2c8a49); }
.pop-up.maxed { background: var(--panel-2); color: var(--muted); }
.pop-sell { background: linear-gradient(#9b4a2c, #7a3720); }
.pop-actions .btn:disabled { opacity: 0.45; cursor: not-allowed; }
.pop-actions .poor { opacity: 0.55; }
.pop-up.locked { background: var(--panel-2); color: var(--muted); }
.pop-evolve { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.pop-evolve[hidden] { display: none; }
.pop-evolve .evo { display: grid; justify-items: center; gap: 1px; padding: 4px 2px 5px; min-width: 0; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; cursor: pointer; }
.pop-evolve .evo img { height: 34px; width: 100%; object-fit: contain; pointer-events: none; }
.pop-evolve .e-name { font-size: 10px; font-weight: 800; color: var(--muted); }
.pop-evolve .e-cost { display: inline-flex; align-items: center; gap: 2px; font-size: 11.5px; font-weight: 800; color: var(--gold); }
.pop-evolve .e-cost svg { width: 10px; height: 10px; }
.pop-evolve .e-cost.lock { color: var(--muted); }
.pop-evolve .evo:active { transform: scale(0.95); border-color: #ffd25e; }
.pop-evolve .evo.poor { opacity: 0.55; }
.pop-evolve .evo.locked { opacity: 0.5; cursor: not-allowed; }
.popover.is-wall .pop-actions { grid-template-columns: 1fr; }
.popover.foreign .pop-actions { display: none; }

/* ---------- écran de résultat ---------- */
.overlay { overflow: hidden; z-index: 8; }
.overlay.victory { background: radial-gradient(circle at 50% 35%, rgba(70, 60, 10, 0.55), rgba(5, 10, 5, 0.86)); }
.overlay.defeat { background: radial-gradient(circle at 50% 35%, rgba(90, 10, 10, 0.55), rgba(5, 5, 5, 0.9)); }
.overlay.draw { background: radial-gradient(circle at 50% 35%, rgba(40, 50, 70, 0.55), rgba(5, 8, 10, 0.88)); }
.overlay:not([hidden]) { animation: fade-in 0.4s ease-out; }
@keyframes fade-in { from { opacity: 0; } }

.result-card {
  position: relative;
  display: grid;
  gap: 8px;
  width: min(92%, 340px);
  max-height: calc(100% - 12px);
  overflow-y: auto;
  padding: 16px 14px 14px;
  border-radius: 18px;
  background: rgba(14, 22, 17, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.14);
  text-align: center;
  animation: card-in 0.55s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(30px) scale(0.7); } }
.result-title {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0.08em;
  font-weight: 900;
  text-transform: uppercase;
  animation: title-pop 0.7s 0.15s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.victory .result-title { color: #ffd25e; text-shadow: 0 0 22px rgba(255, 200, 60, 0.8), 0 2px 0 #7a5400; }
.defeat .result-title { color: #ff6b6b; text-shadow: 0 0 22px rgba(255, 60, 60, 0.7), 0 2px 0 #5a0d0d; animation: title-pop 0.7s 0.15s both, shake 0.5s 0.3s; }
.draw .result-title { color: #cfe0ff; }
@keyframes title-pop { from { opacity: 0; transform: scale(2.4); } }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
.result-reason { margin: 0; color: var(--muted); font-size: 13px; }

.result-stats { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.result-stats th { padding: 4px 0; font-size: 12px; letter-spacing: 0.06em; }
.result-stats th.c0 { color: var(--p0); }
.result-stats th.c1 { color: var(--p1); }
.result-stats td { padding: 4px 6px; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.result-stats td:first-child { text-align: left; color: var(--muted); }
.result-stats td.v { text-align: center; font-weight: 700; }
.result-stats td.best { color: #7fe39a; }
.result-stats tbody tr { animation: row-in 0.35s both; }
@keyframes row-in { from { opacity: 0; transform: translateX(-14px); } }
.result-stats .win-col { background: rgba(255, 255, 255, 0.05); }
.result-btn { width: 100%; font-size: 15px; animation: row-in 0.4s 1.1s both; }
.result-actions { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; margin-top: 4px; }
.result-kump { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); animation: row-in 0.4s 1s both; }
.result-kump.ok { color: var(--accent); }
.result-kump.warn { color: var(--gold); }

.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -14px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation: confetti-fall linear infinite;
}
@keyframes confetti-fall {
  to { transform: translate3d(var(--dx, 0), 110vh, 0) rotate(var(--rot, 720deg)); }
}

@media (max-height: 720px) {
  .result-title { font-size: 28px; }
  .result-stats { font-size: 12px; }
  .result-stats td { padding: 1px 6px; }
  .result-card { gap: 4px; padding: 10px 12px 10px; }
  .result-reason { font-size: 12px; }
}

/* ---------------------------------------------------------------- menu d'accueil */
.menu {
  position: absolute;
  inset: 0;
  z-index: 20; /* au-dessus du HUD, du dock et de l'écran « Chargement… » */
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  overflow-y: auto;
  background:
    radial-gradient(90% 55% at 50% 8%, rgba(94, 208, 122, 0.16), transparent 70%),
    radial-gradient(120% 80% at 50% 0%, #17301c 0%, var(--bg) 62%);
}
.menu[hidden] { display: none; } /* sinon `display: grid` l’emporte sur l’attribut hidden */
.menu:not([hidden]) { animation: fade-in 0.3s ease-out; }
.menu-card { display: grid; gap: 18px; width: min(100%, 380px); }
.menu-brand { display: grid; justify-items: center; gap: 4px; text-align: center; }
.menu-brand h1 {
  margin: 8px 0 0;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(255, 200, 60, 0.35), 0 2px 0 #7a5400;
}
.menu-brand p { margin: 0; color: var(--muted); font-size: 13px; }

.mode-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(var(--panel-2), var(--panel));
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.15s, filter 0.15s;
}
.mode-btn:hover { border-color: rgba(255, 255, 255, 0.22); filter: brightness(1.08); }
.mode-btn:active { transform: scale(0.98); }
.mode-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mode-btn svg { flex: none; width: 34px; height: 34px; padding: 6px; border-radius: 10px; background: rgba(0, 0, 0, 0.28); }
.mode-btn[data-play="ai"] svg { color: var(--accent); }
.mode-btn[data-play="local"] svg { color: var(--gold); }
.mode-btn[data-play="online"] svg { color: var(--p0); }
.mode-btn b { display: block; font-size: 16px; }
.mode-btn small { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.mode-btn.soon { opacity: 0.62; }
.mode-btn .badge {
  position: absolute;
  top: 8px;
  right: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(79, 141, 255, 0.18);
  color: #a9c6ff;
  font-size: 10.5px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

@media (max-height: 640px) { /* hall multijoueur sur petit écran */
  .menu-card { gap: 12px; }
  .menu-brand h1 { font-size: 26px; margin-top: 4px; }
  .mode-btn { min-height: 58px; padding: 9px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .stage[data-phase="finale"]::after, .banner, .result-card, .result-title, .result-stats tbody tr, .confetti i, .menu { animation-duration: 0.01s; animation-iteration-count: 1; }
  .confetti { display: none; }
}
.popover.foreign .pop-evolve { display: none; } /* le mur de l'adversaire se regarde, il ne s'évolue pas */

/* ---- PAUSE (touche le chrono) : voile + carte au centre ; au-dessus du HUD et des boutons du bas, sous les fenêtres (confirmation, amis) */
.pause-veil {
  position: absolute; inset: 0; z-index: 9; display: grid; place-items: center; padding: 20px; background: rgba(3, 6, 16, 0.6); animation: pv-fade 0.2s ease-out;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.pause-veil[hidden] { display: none; }
@keyframes pv-fade { from { opacity: 0; } }
.pv-card {
  display: grid; justify-items: center; gap: calc(var(--gu, 1px) * 8); width: min(calc(var(--gu, 1px) * 250), 100%); padding: calc(var(--gu, 1px) * 22) calc(var(--gu, 1px) * 20) calc(var(--gu, 1px) * 20);
  border: 1.5px solid rgba(201, 164, 90, 0.8); border-radius: calc(var(--gu, 1px) * 22); color: #fff4d6; text-align: center;
  background: radial-gradient(90% 60% at 50% 0%, rgba(96, 150, 255, 0.2), transparent 70%), linear-gradient(#0d1527, #060a15); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.65);
  animation: pv-in 0.26s cubic-bezier(0.3, 1.4, 0.5, 1);
}
@keyframes pv-in { from { opacity: 0; transform: scale(0.9); } }
.pv-ic { width: calc(var(--gu, 1px) * 38); height: calc(var(--gu, 1px) * 38); color: #ffd25e; filter: drop-shadow(0 2px 0 #4a3000); }
.pv-card b { font: 800 calc(var(--gu, 1px) * 22) / 1.1 var(--pn-serif, Georgia, serif); color: #ffd25e; text-shadow: 0 2px 0 #4a3000; letter-spacing: 0.03em; }
.pv-secs { display: inline-flex; align-items: baseline; gap: 3px; font-variant-numeric: tabular-nums; }
.pv-secs i { font: 900 calc(var(--gu, 1px) * 56) / 1 var(--pn-serif, Georgia, serif); font-style: normal; color: #fff4d6; text-shadow: 0 3px 0 #2b1707; }
.pv-secs small { font: 800 calc(var(--gu, 1px) * 18) / 1 var(--pn-serif, Georgia, serif); color: #d8ccaa; }
.pv-track { width: 100%; height: calc(var(--gu, 1px) * 7); overflow: hidden; border-radius: 99px; background: rgba(255, 255, 255, 0.1); }
.pv-track i { display: block; width: 100%; height: 100%; border-radius: 99px; background: linear-gradient(#ffe08a, #e0a52f); transform-origin: left center; transition: transform 0.2s linear; }
.pv-card em { font-style: normal; font-size: calc(var(--gu, 1px) * 12); font-weight: 600; color: #d8ccaa; }
.pv-resume {
  min-width: calc(var(--gu, 1px) * 150); height: calc(var(--gu, 1px) * 44); margin-top: calc(var(--gu, 1px) * 4); padding: 0 calc(var(--gu, 1px) * 24); cursor: pointer; touch-action: manipulation; color: #fff;
  border: 1px solid rgba(160, 255, 170, 0.45); border-radius: 99px; background: linear-gradient(#4cc950, #1f8a2a); font: 800 calc(var(--gu, 1px) * 15) / 1 var(--pn-serif, Georgia, serif);
  text-shadow: 0 1px 2px rgba(0, 40, 10, 0.7); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 6px rgba(0, 0, 0, 0.4);
}
.pv-resume[hidden] { display: none; }
.pv-resume:active { transform: scale(0.95); }
.clock .phase-tag.warn { white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .pause-veil, .pv-card { animation: none; } .pv-track i { transition: none; } }
