:root {
  --ally: #4ea3ff;
  --enemy: #ff5a4e;
  --you: #ffd23f;
  --bg: #14160f;
  --panel: rgba(18, 22, 14, 0.94);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0a0b07;
  color: #e8e8df;
  font-family: -apple-system, "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#app { position: fixed; inset: 0; }

#stage-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0b07;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #2b3a1e;
  image-rendering: auto;
  touch-action: none;
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.hud-top {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(0, 0, 0, 0.4);
  padding: 5px 14px;
  border-radius: 10px;
  backdrop-filter: blur(2px);
}
.score { display: flex; align-items: center; gap: 6px; font-weight: 800; }
.score .num { font-size: 22px; }
.score.ally .num { color: var(--ally); }
.score.enemy .num { color: var(--enemy); }
.score .tag { font-size: 11px; opacity: 0.85; font-weight: 600; }
.objective { font-size: 13px; opacity: 0.92; }
.objective b { color: var(--you); }

.hud-bottom {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(0, 0, 0, 0.42);
  padding: 8px 12px;
  border-radius: 10px;
  min-width: 230px;
}
.hp-row, .xp-row { display: flex; align-items: center; gap: 8px; }
.hp-bar, .xp-bar {
  position: relative;
  height: 12px;
  flex: 1;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  overflow: hidden;
}
.xp-bar { height: 6px; }
.hp-bar .fill { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, #46d36a, #8cf06a); transition: width 0.12s linear; }
.xp-bar .fill { position: absolute; inset: 0; width: 0%; background: linear-gradient(90deg, #ffd23f, #ffa53f); transition: width 0.18s ease; }
.hp-text { font-size: 13px; font-weight: 800; min-width: 30px; }
.xp-row .lv { font-size: 12px; opacity: 0.92; min-width: 44px; }
.xp-row .lv b { color: var(--you); }

.weapon {
  position: absolute;
  right: 12px;
  bottom: 12px;
  text-align: right;
  background: rgba(0, 0, 0, 0.42);
  padding: 8px 12px;
  border-radius: 10px;
}
.wname { display: block; font-size: 13px; opacity: 0.92; }
.ammo { display: block; font-size: 26px; font-weight: 800; letter-spacing: 0.02em; }
.ammo.low { color: var(--enemy); }

#minimap {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 160px;
  height: 106px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

#killfeed {
  position: absolute;
  top: 120px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  pointer-events: none;
  font-size: 12px;
}
.kf-item {
  background: rgba(0, 0, 0, 0.5);
  padding: 3px 8px;
  border-radius: 5px;
  animation: kf-in 0.2s ease;
}
.kf-item .kf-killer { font-weight: 800; }
.kf-item .kf-victim { opacity: 0.85; }
@keyframes kf-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

#topbtns {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 6px;
}
.ui-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
}
.ui-btn:active { transform: scale(0.94); }

#levelup {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(255, 165, 63, 0.95), rgba(255, 210, 63, 0.95));
  color: #221a00;
  font-weight: 900;
  font-size: 22px;
  padding: 10px 26px;
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(255, 180, 40, 0.5);
  pointer-events: none;
  animation: lvl 1.4s ease forwards;
}
#levelup.hidden { display: none; }
@keyframes lvl {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  18% { opacity: 1; transform: translateX(-50%) scale(1.08); }
  30% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-26px) scale(1); }
}

/* ===== タッチ操作 ===== */
#touch { position: absolute; inset: 0; pointer-events: none; }
#touch.hidden { display: none; }
.stick {
  position: absolute;
  bottom: 22px;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.18);
  pointer-events: auto;
}
#stick-move { left: 18px; }
#stick-aim { right: 18px; }
.stick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.5);
}
#touch-btns {
  position: absolute;
  right: 162px;
  bottom: 30px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}
.tbtn {
  width: 76px;
  height: 44px;
  border-radius: 10px;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.tbtn:active { background: rgba(255, 255, 255, 0.25); }

/* ===== オーバーレイ (メニュー / ヘルプ / 結果) ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, rgba(40, 50, 24, 0.6), rgba(5, 6, 3, 0.92));
  z-index: 20;
  padding: 16px;
  overflow: auto;
}
.overlay.hidden { display: none; }
.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 22px 24px 26px;
  width: min(440px, 94vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  text-align: center;
}
.panel h1 {
  margin: 4px 0 4px;
  font-size: 38px;
  letter-spacing: 0.06em;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 0 #6b8e3b;
}
.panel h1 .sub { display: block; font-size: 15px; letter-spacing: 0.3em; color: #b7c08a; margin-top: 2px; }
.panel h2 { margin: 0 0 12px; font-size: 26px; }
.panel h3 { margin: 0 0 6px; font-size: 15px; color: var(--you); }
.lead { font-size: 13px; opacity: 0.86; margin: 0 0 16px; line-height: 1.5; }
.lead.small { font-size: 12px; }

.field { display: block; text-align: left; margin: 0 0 14px; }
.field span { display: block; font-size: 12px; opacity: 0.8; margin-bottom: 4px; }
.field input, .join-row input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 16px;
}

.big-btn {
  display: block;
  width: 100%;
  padding: 13px;
  margin: 8px 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.06s, background 0.15s;
}
.big-btn:active { transform: scale(0.98); }
.big-btn.primary {
  background: linear-gradient(180deg, #7bb33f, #4f7d28);
  border-color: #8fce4f;
}
.big-btn.primary:hover { background: linear-gradient(180deg, #8cc84a, #5a8c2e); }
.link-btn {
  background: none;
  border: none;
  color: #b7c08a;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
}

.diff-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 13px;
  opacity: 0.9;
}
.seg { display: flex; border-radius: 9px; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.16); }
.seg button {
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: #ddd;
  padding: 7px 11px;
  font-size: 12px;
  cursor: pointer;
}
.seg button.on { background: var(--you); color: #221a00; font-weight: 800; }

.join-row { display: flex; gap: 8px; align-items: stretch; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.15em; }
.join-row .big-btn { width: auto; margin: 0; padding: 11px 18px; }
.net-status { font-size: 12px; min-height: 18px; margin: 10px 0 0; color: #b7c08a; white-space: pre-line; }
.net-status.err { color: var(--enemy); }
.net-status.ok { color: #8cf06a; }

.help-cols { display: flex; gap: 18px; text-align: left; margin-bottom: 12px; }
.help-cols > div { flex: 1; }
.help-cols ul { margin: 0; padding-left: 16px; font-size: 12.5px; line-height: 1.7; }
.help-cols b { color: var(--you); }
.help-rpg { font-size: 12.5px; opacity: 0.88; line-height: 1.6; text-align: left; margin: 4px 0 16px; }

.result-stats { font-size: 14px; line-height: 1.9; margin-bottom: 16px; }
.result-stats .row { display: flex; justify-content: space-between; padding: 0 6px; }
.result-stats .row b { color: var(--you); }

.hint { font-size: 11px; opacity: 0.55; margin: 14px 0 0; min-height: 14px; }

@media (max-width: 560px) {
  .panel h1 { font-size: 30px; }
  .hud-bottom { min-width: 180px; }
  #minimap { width: 116px; height: 77px; }
}
