*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0 }

body {
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: linear-gradient(135deg, #1a3a1a 0%, #0d2b0d 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Lobby ─────────────────────────────────────────────────────────────────── */
#lobby {
  width: 100%;
  max-width: 700px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.logo-wrap { text-align: center }
.logo-title {
  font-size: 2.2rem;
  font-weight: 900;
  text-shadow: 0 0 30px rgba(100,255,100,0.5);
  background: linear-gradient(90deg, #a8ff78, #78ffd6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 2px;
}
.logo-sub { color: rgba(255,255,255,0.6); font-size: 0.85rem; margin-top: 6px }

.lobby-form {
  width: 100%;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.form-row label {
  width: 52px;
  text-align: right;
  color: rgba(255,255,255,0.7);
  font-size: 0.88rem;
  flex-shrink: 0;
}
.form-row input {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  padding: 8px 14px;
  outline: none;
  transition: border-color 0.2s;
}
.form-row input:focus { border-color: #78ffd6 }
.form-row input::placeholder { color: rgba(255,255,255,0.3) }

.char-select-label { color: rgba(255,255,255,0.7); font-size: 0.88rem }
.char-cards {
  display: flex;
  gap: 14px;
  justify-content: center;
}
.char-card {
  flex: 1;
  max-width: 220px;
  background: rgba(255,255,255,0.06);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.char-card:hover { border-color: rgba(120,255,214,0.5); background: rgba(120,255,214,0.08) }
.char-card.selected {
  border-color: #78ffd6;
  background: rgba(120,255,214,0.15);
  box-shadow: 0 0 20px rgba(120,255,214,0.3);
}
.char-card canvas { border-radius: 8px; background: rgba(0,0,0,0.2) }
.char-card-name { font-size: 1.05rem; font-weight: 700; color: #fff }
.char-card-stats { display: flex; gap: 8px; font-size: 0.8rem }
.stat { padding: 2px 8px; border-radius: 99px; font-size: 0.75rem }
.stat.hp { background: rgba(255,80,80,0.25); color: #ff8080 }
.stat.spd { background: rgba(100,200,255,0.25); color: #80d4ff }
.stat.dmg { background: rgba(255,165,0,0.25); color: #ffa840 }
.char-card-skills { font-size: 0.72rem; color: rgba(255,255,255,0.55); line-height: 1.6; text-align: left }

.btn-join {
  background: linear-gradient(90deg, #a8ff78, #78ffd6);
  color: #0a2a0a;
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 12px 0;
  cursor: pointer;
  width: 100%;
  transition: opacity 0.2s, transform 0.1s;
  letter-spacing: 1px;
}
.btn-join:hover { opacity: 0.9 }
.btn-join:active { transform: scale(0.98) }

.lobby-msg { font-size: 0.85rem; color: #ff7070; min-height: 18px; text-align: center }

.controls-hint {
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.55);
  text-align: center;
  line-height: 1.8;
}

.btn-history {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.5);
  border-radius: 8px;
  padding: 7px 18px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.2s;
}
.btn-history:hover { color: #fff; border-color: rgba(255,255,255,0.5) }

/* ── Waiting ────────────────────────────────────────────────────────────────── */
#waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100vw;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
}
.waiting-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 1.2rem;
  color: #fff;
}
.waiting-anim { font-size: 3rem; animation: spin 2s linear infinite }
@keyframes spin { to { transform: rotate(360deg) } }
.waiting-room { font-size: 0.85rem; color: rgba(255,255,255,0.5) }

/* ── Game Screen ────────────────────────────────────────────────────────────── */
#game-screen {
  width: 100vw;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: fixed;
  inset: 0;
  background: #0d1f0d;
}

/* HUD */
.hud {
  display: flex;
  align-items: center;
  width: 800px;
  max-width: 100%;
  gap: 10px;
  padding: 6px 10px;
  background: rgba(0,0,0,0.5);
  border-radius: 10px 10px 0 0;
}
.hud-player {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.hud-p1 { align-items: flex-start }
.hud-p2 { align-items: flex-end }
.hud-name { font-size: 0.78rem; font-weight: 700; color: rgba(255,255,255,0.8) }
.hud-bar-wrap {
  width: 100%;
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 5px;
  overflow: hidden;
}
.hud-bar {
  height: 100%;
  border-radius: 5px;
  transition: width 0.12s;
}
.p1-bar { background: linear-gradient(90deg, #4CAF50, #81C784); }
.p2-bar { background: linear-gradient(90deg, #f44336, #e57373); float: right }
.hud-hp-text { font-size: 0.68rem; color: rgba(255,255,255,0.55) }
.hud-lives { font-size: 0.9rem; color: #ff6b6b; letter-spacing: 3px }
.hud-center {
  flex-shrink: 0;
  text-align: center;
}
.round-info { font-size: 0.82rem; color: rgba(255,255,255,0.7); white-space: nowrap }

canvas#canvas {
  display: block;
  border: 2px solid rgba(255,255,255,0.1);
  border-top: none;
  border-bottom: none;
  image-rendering: pixelated;
  max-width: 100%;
}

/* Cooldowns */
.cooldowns {
  display: flex;
  gap: 12px;
  width: 800px;
  max-width: 100%;
  padding: 6px 10px;
  background: rgba(0,0,0,0.5);
  border-radius: 0 0 10px 10px;
}
.cd-item {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}
.cd-key {
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  padding: 2px 6px;
  min-width: 20px;
  text-align: center;
}
.cd-bar-wrap {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}
.cd-bar {
  height: 100%;
  border-radius: 3px;
  background: #78ffd6;
  width: 100%;
  transition: width 0.05s;
}
.cd-name { font-size: 0.68rem; color: rgba(255,255,255,0.5); white-space: nowrap }

/* ── Overlay ────────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(0,0,0,0.65);
  z-index: 100;
}
.overlay-text {
  font-size: 3.5rem;
  font-weight: 900;
  text-shadow: 0 0 30px rgba(100,255,150,0.6);
  text-align: center;
  line-height: 1.2;
}
#overlay-btn { max-width: 200px }

/* ── History Modal ──────────────────────────────────────────────────────────── */
.history-modal {
  position: fixed;
  inset: 0;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.8);
  z-index: 200;
}
.history-box {
  background: #0d2a0d;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  padding: 24px;
  width: 560px;
  max-width: 95vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.history-title { font-size: 1.2rem; font-weight: 700; text-align: center }
.history-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
}
.history-winner { color: #a8ff78; font-weight: 700 }
.history-loser  { color: rgba(255,255,255,0.5) }
.history-vs     { color: rgba(255,255,255,0.3); font-size: 0.72rem }
.history-time   { margin-left: auto; color: rgba(255,255,255,0.3); font-size: 0.72rem }
.btn-close {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
  border-radius: 8px;
  padding: 8px 0;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.btn-close:hover { background: rgba(255,255,255,0.15); color: #fff }

/* ── Animations ─────────────────────────────────────────────────────────────── */
@keyframes flash {
  0%,100% { opacity: 1 }
  50%      { opacity: 0.3 }
}
.flash { animation: flash 0.2s 3 }
