/* Central palette: surfaces, players, interface. */
:root {
  --page: #181b20;
  --panel: #25292f;
  --ink: #f6f7f8;
  --muted: #aeb5bf;
  --line: #49515d;
  --ground: #dddfe1;
  --grass: #8bb897;
  --ice: #b4dfea;
  --tar: #545763;
  --lava: #e66b65;
  --start: #eceef0;
  --goal: #ffd700;
  --p1: #ef617a;
  --p2: #51c8ed;
  --p3: #f5d663;
  --p4: #8bd68b;
  --shadow: #00000055;
  --veil: #11151ad9;
  --white: #ffffff;
  --success: #237a45;
  --success-ink: #ffffff;
  --silver: #c7d1dc;
  --bronze: #cb9161;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--page);
  letter-spacing: 0;
  color-scheme: dark;
}
* {
  box-sizing: border-box;
}
html,
body,
#game {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
#game {
  height: 100dvh;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#terrain,
#board {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#lobby {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  width: 140px;
  text-align: center;
}
#lobby[hidden] {
  display: none;
}
#lobby #launch {
  width: 100%;
  height: 40px;
  margin: 0;
}
#lobby-options {
  position: absolute;
  right: calc(100% + 8px);
  top: 0;
}
.in-lobby #scores {
  display: none;
}
.in-lobby #settings,
.in-lobby #new,
.in-lobby #pause {
  display: none;
}
button:disabled {
  opacity: 0.35;
  cursor: default;
}
.stick.waiting {
  opacity: 0.4;
}
.stick.tracking {
  opacity: 1;
}
header {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 64px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--page);
}
.brand {
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
}
.brand small {
  color: var(--muted);
  font-size: 10px;
  margin-left: 4px;
}
#scores {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex: 1;
}
.score {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 20px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}
.dot {
  width: 12px;
  height: 12px;
  display: inline-block;
  border-radius: 50%;
  background: var(--player);
}
.score small {
  font-size: 11px;
  color: var(--muted);
}
nav {
  display: flex;
  gap: 4px;
}
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
button:hover {
  border-color: var(--ink);
}
button:focus-visible,
.stick:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}
button svg {
  width: 19px;
  height: 19px;
  pointer-events: none;
}
.primary {
  width: 100%;
  height: 44px;
  margin-top: 20px;
  background: var(--ink);
  color: var(--page);
  border: 0;
  font-size: 15px;
  font-weight: bold;
}
#announcement {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: 64px;
  font-weight: 800;
  text-align: center;
  text-shadow: 0 2px 8px var(--shadow);
}
#round-label {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.stick {
  --player: var(--p1);
  width: 112px;
  height: 112px;
  position: absolute;
  border: 2px solid var(--player);
  background: var(--veil);
  border-radius: 50%;
  touch-action: none;
  cursor: grab;
}
.stick[data-player='1'] {
  --player: var(--p2);
}
.stick[data-player='2'] {
  --player: var(--p3);
}
.stick[data-player='3'] {
  --player: var(--p4);
}
.stick.top {
  top: calc(76px + env(safe-area-inset-top));
}
.stick.bottom {
  bottom: calc(28px + env(safe-area-inset-bottom));
}
.stick.left {
  left: calc(16px + env(safe-area-inset-left));
}
.stick.right {
  right: calc(16px + env(safe-area-inset-right));
}
.knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--player);
  position: absolute;
  top: 30px;
  left: 30px;
  pointer-events: none;
  opacity: 0.9;
}
.stick.armed::before {
  content: '';
  position: absolute;
  inset: -5px;
  border: 3px solid var(--player);
  border-radius: 50%;
  box-shadow:
    0 0 14px 5px var(--player),
    inset 0 0 10px var(--player);
  pointer-events: none;
  animation: power-aura 1.1s ease-in-out infinite alternate;
}
.stick.charging {
  box-shadow: 0 0 calc(4px + var(--charge) * 18px) var(--player);
}
.stick.charging .knob {
  filter: brightness(calc(1 + var(--charge) * 0.5));
}
.stick.recharging:not(.armed) {
  border-style: dashed;
}
@keyframes power-aura {
  from {
    transform: scale(1);
    opacity: 0.9;
  }
  to {
    transform: scale(1.06);
    opacity: 0.35;
  }
}
@media (prefers-reduced-motion: reduce) {
  .stick.armed::before {
    animation: none;
  }
}
.power-label {
  position: absolute;
  top: 116px;
  left: -16px;
  width: 140px;
  text-align: center;
  color: var(--player);
  font-size: 11px;
  pointer-events: none;
}
.stick.top .power-label {
  transform: rotate(180deg);
}
.stick.fired {
  box-shadow: 0 0 0 7px var(--player);
}
.stick {
  --stick-size: min(112px, calc(100vw / 3 - 16px), calc(100dvh / 3 - 70px));
  width: var(--stick-size);
  height: var(--stick-size);
}
.stick .knob {
  width: 43%;
  height: 43%;
  top: 28.5%;
  left: 28.5%;
}
.stick .power-label {
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
}
.stick.top .power-label {
  transform: translateX(-50%) rotate(180deg);
}
button[hidden] {
  display: none;
}
.stick.inactive {
  opacity: 0.3;
}
.swal2-container {
  background: var(--veil);
  touch-action: pan-y;
}
.swal2-popup.warp-popup {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 20px;
  width: min(410px, calc(100% - 24px));
}
.warp-popup .swal2-title {
  padding: 0 28px 12px 0;
  color: var(--ink);
  font-size: 22px;
  text-align: left;
}
.warp-popup .swal2-html-container {
  margin: 0;
  padding: 6px;
  color: var(--ink);
  font-size: 14px;
  text-align: left;
}
.warp-popup .swal2-actions {
  gap: 8px;
  margin: 20px 0 0;
}
.warp-popup .swal2-close {
  color: var(--muted);
}
.warp-confirm,
.warp-cancel {
  width: auto;
  min-width: 120px;
  padding: 0 14px;
  font-size: 14px;
}
.warp-confirm {
  background: var(--success);
  color: var(--success-ink);
}
.warp-popup .swal2-validation-message {
  background: var(--page);
  color: var(--ink);
}
h1 {
  font-size: 22px;
  margin: 0 0 20px;
}
label {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(0, 170px);
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  font-size: 14px;
}
input,
select {
  min-width: 0;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--page);
  color: var(--ink);
  font: inherit;
}
input[type='checkbox'] {
  width: 20px;
  height: 20px;
  justify-self: end;
  accent-color: var(--grass);
}
input[type='range'] {
  accent-color: var(--p2);
}
.seed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.seed-control input {
  flex: 1;
  width: 0;
}
.seed-control button {
  flex: 0 0 32px;
  height: 34px;
}
.standing {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.standing strong {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}
.standing small {
  color: var(--muted);
}
@media (max-width: 720px) {
  header {
    height: 52px;
    gap: 8px;
    padding: 6px 8px;
  }
  .brand {
    font-size: 12px;
  }
  .brand small {
    display: none;
  }
  #media-controls {
    position: absolute;
    top: 58px;
    left: 50%;
    transform: translateX(-50%);
  }
  #lobby {
    top: 9px;
    width: 104px;
  }
  #lobby #launch {
    height: 34px;
    font-size: 13px;
  }
  #lobby-options {
    right: calc(100% + 6px);
  }
  #scores {
    gap: 8px;
  }
  .score {
    gap: 4px;
    font-size: 16px;
  }
  .score small {
    display: none;
  }
  button {
    width: 32px;
    height: 34px;
  }
  .stick {
    --stick-size: min(88px, calc(100vw / 3 - 16px), calc(100dvh / 3 - 70px));
  }
  .stick.top {
    top: calc(62px + env(safe-area-inset-top));
  }
  .stick.bottom {
    bottom: calc(22px + env(safe-area-inset-bottom));
  }
  .stick.left {
    left: calc(8px + env(safe-area-inset-left));
  }
  .stick.right {
    right: calc(8px + env(safe-area-inset-right));
  }
  .power-label {
    width: 124px;
    font-size: 10px;
  }
  #announcement {
    font-size: 44px;
  }
}
@media (max-height: 450px) {
  .stick.top {
    top: 58px;
  }
  .stick.bottom {
    bottom: 22px;
  }
  header {
    height: 50px;
  }
}
@media (max-width: 360px) {
  header {
    gap: 4px;
  }
  .brand {
    width: 44px;
    white-space: normal;
    font-size: 10px;
    line-height: 12px;
  }
  #scores {
    gap: 4px;
  }
  .score {
    font-size: 14px;
  }
  .score .dot {
    width: 8px;
    height: 8px;
  }
  nav {
    gap: 2px;
  }
  button {
    width: 28px;
  }
}

/* HUD de course : un ilot central, sans panneau qui intercepte les coins tactiles. */
header {
  height: 96px;
  background: transparent;
  pointer-events: none;
}
header nav {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  pointer-events: auto;
}
header #scores {
  position: absolute;
  left: 50%;
  top: 56px;
  transform: translateX(-50%);
  flex: none;
  white-space: nowrap;
}
.brand {
  display: none;
}
.in-lobby .brand {
  display: block;
}
.in-lobby nav {
  display: none;
}

/* Les boutons audio sont des interrupteurs : aria-pressed est leur source d'etat. */
.option-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}
.option-tools button {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  height: auto;
  padding: 10px;
  font-size: 13px;
  transition:
    transform 0.12s,
    background 0.18s,
    border-color 0.18s;
}
.option-tools button:active {
  transform: scale(0.95);
}
.option-tools button[aria-pressed='true'] {
  background: var(--success);
  border-color: var(--grass);
  color: var(--success-ink);
}
.toggle-light {
  flex: 0 0 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
[aria-pressed='true'] .toggle-light {
  background: var(--white);
  box-shadow: 0 0 6px var(--white);
}
#install-help {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
@media (max-width: 720px) {
  header #scores {
    top: 48px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .option-tools button {
    transition: none;
  }
}

/* Le bouton d'aide reste a droite de Lancer, hors des zones tactiles. */
#power-help {
  position: absolute;
  left: calc(100% + 8px);
  top: 0;
}
.power-guide {
  display: grid;
  gap: 0;
}
.power-guide-row {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.power-symbol {
  flex: 0 0 42px;
  text-align: center;
  font-size: 30px;
  color: var(--goal);
}
.power-guide-row strong {
  font-size: 14px;
}
.power-guide-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

/* Recapitulatif : chiffres stables et lignes reordonnees avec FLIP. */
.standing {
  min-height: 68px;
  gap: 10px;
  padding: 12px 0;
}
.standing-rank {
  flex: 0 0 16px;
  font-size: 12px;
  color: var(--muted);
}
.standing .dot {
  flex-shrink: 0;
  box-shadow: 0 0 10px var(--player);
}
.standing-details {
  display: grid;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.standing-details > span {
  font-weight: 700;
  overflow-wrap: anywhere;
}
.standing-details small {
  font-size: 11px;
}
.standing .standing-score {
  margin-left: 0;
  min-width: 36px;
  /* Le zoom reste dans le panneau au lieu de depasser son bord droit. */
  transform-origin: right center;
  text-align: right;
  font-size: 28px;
}
.score-delta {
  min-width: 28px;
  text-align: center;
  font-weight: 800;
  font-size: 16px;
}
.score-delta.positive {
  color: var(--grass);
}
.score-delta.negative {
  color: var(--lava);
}
.score-delta.neutral {
  color: var(--muted);
}
.warp-popup .swal2-title svg {
  display: inline-block;
  width: 28px;
  height: 28px;
  vertical-align: middle;
  color: var(--goal);
  margin-right: 10px;
}
.celebration-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1070;
  pointer-events: none;
}

/* Trois places, meme geometrie sur mobile ; l'or est au centre. */
.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 10px;
  min-height: 200px;
  margin: 10px 0 20px;
}
.podium-place {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.podium-1 {
  order: 2;
}
.podium-2 {
  order: 1;
}
.podium-3 {
  order: 3;
}
.medal {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 2px solid currentColor;
  border-radius: 50%;
}
.medal svg {
  width: 26px;
  height: 26px;
}
.medal-1 {
  color: var(--goal);
}
.medal-2 {
  color: var(--silver);
}
.medal-3 {
  color: var(--bronze);
}
.podium-name {
  font-size: 12px;
  text-align: center;
  overflow-wrap: anywhere;
  color: var(--player);
}
.podium-step {
  display: grid;
  place-items: center;
  width: 100%;
  height: 64px;
  border-top: 3px solid var(--player);
  background: var(--page);
  font-size: 30px;
  font-weight: 800;
}
.podium-1 .podium-step {
  height: 100px;
}
.podium-3 .podium-step {
  height: 44px;
}
