:root {
  --green: #7dc500;
  --green-hot: #b6ff2a;
  --bg: #070807;
  --panel: #111111;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: #fff;
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#layout,
#wrap,
#game {
  touch-action: none;
}

#layout {
  height: 100%;
  height: 100dvh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 18px;
  padding: 12px 16px;
}

#wrap {
  position: relative;
  width: min(100%, calc((100vh - 24px) * 480 / 720));
  height: min(calc(100vh - 24px), calc(100vw * 720 / 480));
  max-height: calc(100vh - 24px);
  flex: 0 0 auto;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #070807;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  flex-wrap: wrap;
  padding: 14px 18px 0;
  font-variant-numeric: tabular-nums;
}

.hud-top .label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8a8a8a;
}

.hud-top strong {
  font-size: 20px;
  line-height: 1.1;
  color: var(--green);
  white-space: nowrap;
}

#weapon {
  font-size: 15px;
  color: var(--green-hot);
}

.mute-btn {
  pointer-events: auto;
  align-self: flex-start;
  margin-top: 2px;
  border: 1px solid #2a2a2a;
  background: rgba(17, 17, 17, 0.85);
  color: var(--green);
  font: 600 12px "Segoe UI", system-ui, sans-serif;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.mute-btn:hover {
  border-color: var(--green);
  color: var(--green-hot);
}
.mute-btn[aria-pressed="true"] {
  color: #8a8a8a;
}

#board {
  width: 240px;
  flex: 0 0 240px;
  background: var(--panel);
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 16px 14px;
  align-self: center;
  max-height: calc(100vh - 24px);
  overflow: auto;
}

#board h2 {
  color: var(--green);
  font-size: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

#board-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#board-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: #0c0c0c;
  border: 1px solid #222;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

#board-list .rank {
  color: #8a8a8a;
  font-weight: 700;
  font-size: 13px;
}

#board-list .name {
  color: #fff;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#board-list .pts {
  color: var(--green);
  font-weight: 800;
}

#board-list li.top1 {
  border-color: var(--green);
}

.board-empty {
  color: #8a8a8a;
  font-size: 13px;
  line-height: 1.4;
}

.board-empty[hidden],
#board-list:not(:empty) + .board-empty,
#board-list-inline:not(:empty) + .board-empty {
  display: none;
}

.board-inline {
  display: none;
}

.pad {
  display: none;
  position: absolute;
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 2px solid rgba(125, 197, 0, 0.28);
  background: rgba(10, 12, 10, 0.35);
  pointer-events: none;
  z-index: 3;
}
.pad::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(125, 197, 0, 0.35);
  border: 1px solid rgba(182, 255, 42, 0.45);
  transform: translate(var(--dx, 0px), var(--dy, 0px));
}
.pad-move { left: max(18px, env(safe-area-inset-left)); }
.pad-aim { right: max(18px, env(safe-area-inset-right)); }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 8, 7, 0.78);
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  z-index: 5;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid #2a2a2a;
  border-radius: 14px;
  padding: 28px 22px 22px;
  text-align: center;
  max-height: min(92dvh, 100%);
  overflow: auto;
}

.brand {
  color: var(--green);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  margin-bottom: 10px;
}

.panel h1 {
  font-size: 42px;
  line-height: 1;
  color: var(--green-hot);
  margin-bottom: 8px;
}

.tag {
  color: #cfcfcf;
  margin-bottom: 14px;
}

.hint {
  color: #8a8a8a;
  font-size: 14px;
  line-height: 1.45;
  margin-bottom: 18px;
}

.hint strong {
  color: var(--green);
}

.save-box {
  margin: 0 0 14px;
  text-align: left;
}

.save-box label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a8a8a;
  margin-bottom: 6px;
}

.save-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #333;
  border-radius: 8px;
  background: #0c0c0c;
  color: #fff;
  font-size: 16px;
  outline: none;
}

.save-box input:focus {
  border-color: var(--green);
}

#save {
  margin-top: 8px;
  width: 100%;
  cursor: pointer;
  background: #1f1f1f;
  color: var(--green);
  border: 1px solid var(--green);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 14px;
  border-radius: 8px;
}

#save:disabled {
  opacity: 0.5;
  cursor: default;
}

.save-msg {
  margin-top: 8px;
  color: var(--green);
  font-size: 13px;
}

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

button {
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  font: 700 16px "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}

#play {
  background: var(--green);
  color: #0a0a0a;
}
#play:hover {
  background: var(--green-hot);
}
#play:disabled {
  opacity: 0.45;
  cursor: default;
}

.best-line {
  margin-top: 14px;
  color: #8a8a8a;
  font-size: 13px;
}

@media (max-width: 900px), (pointer: coarse) {
  html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  #layout {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    height: 100dvh;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }

  #wrap {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
  }

  .hud-top {
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }

  .pad { display: block; }
  .hud-top strong { font-size: 18px; }
  #weapon { font-size: 13px; }

  /* Pas de Top 10 flottant qui recouvre le bouton Jouer */
  #board {
    display: none !important;
  }

  .board-inline {
    display: block;
    margin-top: 16px;
    text-align: left;
    border-top: 1px solid #2a2a2a;
    padding-top: 14px;
    max-height: min(28vh, 220px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .board-inline h2 {
    color: var(--green);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin-bottom: 10px;
  }

  #board-list-inline {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  #board-list-inline li {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 7px 9px;
    background: #0c0c0c;
    border: 1px solid #222;
    border-radius: 8px;
    font-variant-numeric: tabular-nums;
  }

  #board-list-inline .rank {
    color: #8a8a8a;
    font-weight: 700;
    font-size: 12px;
  }

  #board-list-inline .name {
    color: #fff;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  #board-list-inline .pts {
    color: var(--green);
    font-weight: 800;
    font-size: 13px;
  }

  #board-list-inline li.top1 {
    border-color: var(--green);
  }

  .overlay .panel {
    max-height: min(88dvh, 100%);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .panel h1 {
    font-size: 34px;
  }

  .hint {
    font-size: 13px;
    margin-bottom: 12px;
  }
}
