* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #7ec8ff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }

#hud {
  position: fixed; left: 0; right: 0;
  top: env(safe-area-inset-top);
  padding: 8px calc(8px + env(safe-area-inset-right)) 0 calc(8px + env(safe-area-inset-left));
  display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none;
}
#hud[hidden] { display: none; }
.box {
  pointer-events: auto; background: rgba(0,0,0,.55); color: #fff; border: 0;
  border-radius: 10px; padding: 6px 10px; font-size: 15px; line-height: 1.2;
}
.box b { font-size: 18px; margin-left: 4px; }
button.box { font-family: inherit; cursor: pointer; }
#reload {
  position: fixed; z-index: 5;
  right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 84px; height: 84px; border-radius: 50%; border: 4px solid #fff;
  background: #d9822b; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0; box-shadow: 0 4px 14px rgba(0,0,0,.45); cursor: pointer; font-family: inherit; touch-action: manipulation;
}
#reload[hidden] { display: none; }
#reload span { font-size: 12px; font-weight: 700; margin-top: -2px; opacity: .85; }
#reload:active { transform: scale(.93); }
#reload.empty { background: #d62828; animation: pulse .6s ease-in-out infinite alternate; }
#reload.busy { opacity: .5; }
#reload.busy svg { animation: spin .8s linear infinite; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.12); } }
@keyframes spin { to { transform: rotate(360deg); } }
#mag {
  position: fixed; z-index: 5; display: flex; gap: 4px; align-items: flex-end; pointer-events: none;
  right: calc(18px + 84px + 14px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  padding: 8px 10px; background: rgba(0,0,0,.45); border-radius: 12px;
}
#mag[hidden] { display: none; }
.shell {
  width: 13px; height: 44px; border-radius: 7px 7px 2px 2px; transition: opacity .15s, filter .15s, transform .15s;
  background: linear-gradient(to bottom, #c9743a 0 28%, #6b3a14 28% 30%, #f6c84c 30% 90%, #a8780f 90% 100%);
  box-shadow: inset -3px 0 0 rgba(0,0,0,.18), inset 2px 0 0 rgba(255,255,255,.35);
}
.shell.spent { opacity: .22; filter: grayscale(1); transform: translateY(4px); }
#ammoBox.low b { color: #ff7b7b; }

#overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(10,30,50,.55); padding: 16px;
}
#overlay[hidden] { display: none; }
.namefield { display: block; margin: 12px 0 4px; font-size: 14px; color: #555; font-weight: 600; }
#name {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font-size: 18px; text-align: center;
  border: 2px solid #d9c59a; border-radius: 10px; background: #fff; color: #222; font-family: inherit;
  -webkit-user-select: text; user-select: text;
}
#name:focus { outline: none; border-color: #e0572b; }
#name.err { border-color: #d62828; animation: shk .3s; }
@keyframes shk { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
#board { margin-top: 16px; text-align: left; }
#board h2 { margin: 0 0 6px; font-size: 18px; text-align: center; }
#boardList { margin: 0; padding: 0; list-style: none; counter-reset: r; }
#boardList li {
  counter-increment: r; display: flex; gap: 8px; padding: 5px 8px; border-radius: 8px; font-size: 15px; color: #333;
}
#boardList li:nth-child(odd) { background: rgba(0,0,0,.05); }
#boardList li::before { content: counter(r) "."; width: 24px; text-align: right; color: #999; font-variant-numeric: tabular-nums; }
#boardList li:nth-child(1)::before { content: "🥇"; } #boardList li:nth-child(2)::before { content: "🥈"; } #boardList li:nth-child(3)::before { content: "🥉"; }
#boardList .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#boardList .s { font-weight: 700; font-variant-numeric: tabular-nums; }
#boardList li { flex-wrap: wrap; }
.stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; font-size: 14px; color: #444; }
#boardList .stats { width: 100%; justify-content: flex-start; padding-left: 32px; font-size: 13px; }
.stats span { white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats .c1 { font-size: 1.35em; } .stats .c2 { font-size: 1em; } .stats .c3 { font-size: .7em; }
#runStats { margin: 6px 0 4px; font-size: 16px; }
#boardList li.me { background: #ffe9a8; outline: 2px solid #e0a800; }
#boardList li.empty::before { content: ""; width: 0; }
#rankNote { margin: 6px 0 0; text-align: center; font-weight: 600; }
.card {
  background: #fff8e6; border-radius: 18px; padding: 22px 24px; max-width: 420px; width: 100%;
  text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.4);
  max-height: calc(100vh - 32px); overflow-y: auto; touch-action: pan-y;
}
.card h1 { margin: 0 0 10px; font-size: 30px; }
.card p { margin: 8px 0; color: #444; line-height: 1.4; }
#final { font-size: 22px; font-weight: 700; color: #222; }
#start {
  margin-top: 10px; font-size: 20px; font-weight: 700; padding: 12px 28px; border: 0;
  border-radius: 12px; background: #e0572b; color: #fff; cursor: pointer;
}
#start:active { transform: scale(.97); }
