:root {
  --bg: #0f1418;
  --panel: #182027;
  --panel-2: #232e3c;
  --accent: #d4a72c;
  --accent-fg: #14100a;
  --danger: #e6533c;
  --text: #eef2f6;
  --text-dim: #93a1b0;
  --border: #33414c;
  --card: #182027;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.screen { display: none; width: 100%; padding: 12px; }
.screen.active { display: block; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

h1, h2, h3 { margin-top: 0; font-family: Cinzel, Georgia, serif; font-weight: 800; }
h1 .lite { color: var(--accent); }
h1 { font-size: clamp(26px,6vw,42px); color: var(--accent); }

/* HOME / LOBBY */
.home-panel, .lobby-panel { max-width: 420px; margin: 0 auto; text-align: center; }
input {
  width: 100%; padding: 10px 12px; margin: 8px 0;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 15px;
}
.home-actions { margin-top: 16px; }
.join-row { display: flex; gap: 8px; margin-top: 10px; }
.join-row input { flex: 1; }

.btn {
  cursor: pointer; border: none; border-radius: 8px;
  padding: 10px 16px; font-size: 15px; font-weight: 700;
  transition: transform 0.08s ease, opacity 0.15s ease;
  color: var(--accent-fg);
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); width: 100%; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }

.error-msg { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
.hint { color: var(--text-dim); font-size: 13px; }

.leaderboard-box { margin-top: 24px; text-align: left; }
.leaderboard-list { max-height: 220px; overflow-y: auto; }
.lb-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.lb-rank { color: var(--accent); font-weight: 700; width: 24px; display: inline-block; }

#lobby-code-display { color: var(--accent); letter-spacing: 3px; }
.lobby-players { margin: 16px 0; text-align: left; }
.lobby-player-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel-2); padding: 8px 12px; border-radius: 8px; margin-bottom: 6px;
}
.tag-host { color: var(--accent); font-size: 11px; margin-left: 6px; }
.tag-ready { color: #4fd18b; font-size: 12px; }
.lobby-actions { display: flex; gap: 10px; }

/* BATTLE CANVAS */
.stage {
  position: relative;
  width: min(97vw, 97vh);
  aspect-ratio: 1;
  margin: 0 auto;
}
#screen-game {
  display: none;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
#screen-game.active {
  display: flex;
}
canvas {
  width: 100%; height: 100%; display: block; border-radius: 10px; touch-action: none;
  background: #3f6b33; box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.hud { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.hud button {
  font: 600 clamp(11px,1.7vw,14px)/1 system-ui,sans-serif; color: #f3ead0; background: rgba(20,16,10,.75);
  border: 1px solid rgba(255,255,255,.25); border-radius: 8px; padding: 8px 11px; cursor: pointer;
}
.hud button:hover { background: rgba(20,16,10,.95); }

/* MODAL */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-overlay.active { display: flex; }
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; width: 340px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.gameover-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }