:root {
  --gold: #e8b54d;
  --blood: #b3322e;
  --bone: #e8e2d4;
  --ink: #07070c;
  --panel: rgba(10, 10, 18, 0.78);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  font-family: 'IBM Plex Mono', monospace;
  color: var(--bone);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#game-root, #game-root canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hidden { display: none !important; }

/* ---------- damage flash ---------- */
#damage-flash {
  position: fixed; inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(179, 30, 30, 0.55) 100%);
  opacity: 0;
  transition: opacity 0.35s ease-out;
  z-index: 5;
}
#damage-flash.active { opacity: 1; transition: opacity 0.05s; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#hud-top-left {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 6px;
}

#hp-bar {
  width: min(280px, 38vw); height: 22px;
  background: rgba(0,0,0,0.65);
  border: 1px solid rgba(232, 181, 77, 0.45);
  border-radius: 4px;
  position: relative; overflow: hidden;
}
#hp-fill {
  height: 100%; width: 100%;
  background: linear-gradient(180deg, #d8453f, #8e211d);
  transition: width 0.15s ease-out;
}
#hp-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; text-shadow: 0 1px 2px #000;
}

#dash-bar {
  width: min(170px, 26vw); height: 10px;
  background: rgba(0,0,0,0.65);
  border: 1px solid rgba(120, 180, 255, 0.35);
  border-radius: 3px;
  position: relative; overflow: hidden;
}
#dash-fill { height: 100%; width: 100%; background: #5fa8ff; }
.dash-label {
  position: absolute; inset: 0;
  font-size: 7px; letter-spacing: 2px;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.8);
}

#stats-row { display: flex; gap: 14px; font-size: 14px; }
#coin-counter { color: var(--gold); }
#kill-counter { color: #c9c2b2; }

#hud-top-right {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
#minimap {
  width: min(220px, 30vw); height: min(220px, 30vw);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(232, 181, 77, 0.3);
  border-radius: 6px;
}
#code-badge {
  background: var(--panel);
  border: 1px solid rgba(232, 181, 77, 0.4);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px; letter-spacing: 1px;
}
#code-badge b { color: var(--gold); letter-spacing: 3px; }

#boss-bar-wrap {
  position: absolute;
  bottom: max(26px, env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  width: min(520px, 70vw);
  text-align: center;
}
.boss-name {
  font-family: 'Cinzel', serif;
  font-size: 15px; letter-spacing: 6px;
  color: #ff6b5e; text-shadow: 0 0 12px rgba(255, 60, 40, 0.6);
  margin-bottom: 5px;
}
#boss-bar {
  height: 14px;
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255, 90, 70, 0.5);
  border-radius: 3px; overflow: hidden;
}
#boss-fill {
  height: 100%; width: 100%;
  background: linear-gradient(180deg, #ff5240, #861410);
  transition: width 0.2s ease-out;
}

#respawn-msg {
  position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%);
  font-family: 'Cinzel', serif; font-size: clamp(18px, 4vw, 30px);
  color: #ff8c80; text-shadow: 0 2px 14px #000;
  text-align: center;
}

#toasts {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.toast {
  background: var(--panel);
  border: 1px solid rgba(232, 181, 77, 0.35);
  border-radius: 4px;
  padding: 6px 16px;
  font-size: 13px;
  animation: toast-in 0.25s ease-out, toast-out 0.4s ease-in 2.6s forwards;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

/* ---------- menu ---------- */
#menu {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(70, 30, 16, 0.45), transparent 60%),
    radial-gradient(ellipse at 50% 110%, rgba(120, 30, 20, 0.3), transparent 55%),
    var(--ink);
}
.menu-inner { text-align: center; padding: 24px; max-width: 560px; }

.title {
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: clamp(38px, 9vw, 76px);
  letter-spacing: 4px;
  margin: 0 0 4px;
  color: var(--bone);
  text-shadow: 0 0 30px rgba(216, 69, 63, 0.45), 0 4px 2px #000;
}
.title span {
  display: block;
  font-size: 0.32em; letter-spacing: 14px;
  color: var(--blood);
  margin: 2px 0;
}
.subtitle { color: #9b9484; font-size: 13px; margin: 0 0 34px; }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }

.menu-btn {
  font-family: 'Cinzel', serif;
  font-size: 17px; font-weight: 600; letter-spacing: 2px;
  color: var(--bone);
  background: linear-gradient(180deg, #2a1c14, #190f0b);
  border: 1px solid rgba(232, 181, 77, 0.5);
  border-radius: 5px;
  padding: 13px 38px;
  min-width: 250px;
  cursor: pointer;
  transition: all 0.15s;
}
.menu-btn:hover {
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(232, 181, 77, 0.25);
  transform: translateY(-1px);
}
.menu-btn.slim { min-width: 0; padding: 13px 22px; font-size: 14px; }

#join-row { display: flex; gap: 8px; }
#join-code {
  width: 130px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 20px; letter-spacing: 8px; text-align: center;
  text-transform: uppercase;
  color: var(--gold);
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(232, 181, 77, 0.4);
  border-radius: 5px;
  outline: none;
}
#join-code:focus { border-color: var(--gold); }

.menu-error { color: #ff7b6e; font-size: 13px; min-height: 18px; margin: 14px 0 0; }
.controls-hint { color: #6e685c; font-size: 11px; margin-top: 26px; line-height: 1.7; }

.music-btn {
  margin-top: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; letter-spacing: 1px;
  color: #9b9484;
  background: none;
  border: 1px solid rgba(232, 181, 77, 0.3);
  border-radius: 4px;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.music-btn:hover { color: var(--gold); border-color: var(--gold); }

.credits { color: #57524a; font-size: 10.5px; margin: 18px 0 0; line-height: 1.8; }
.credits a { color: #8a7340; text-decoration: none; }
.credits a:hover { color: var(--gold); text-decoration: underline; }

/* ---------- leaderboard ---------- */
#leaderboard {
  margin: 18px auto 0;
  width: min(340px, 80vw);
  background: var(--panel);
  border: 1px solid rgba(232, 181, 77, 0.3);
  border-radius: 6px;
  padding: 12px 18px 14px;
}
.lb-title {
  font-family: 'Cinzel', serif;
  font-size: 13px; letter-spacing: 3px;
  color: var(--gold);
  margin-bottom: 8px;
}
#lb-list {
  list-style: none;
  margin: 0; padding: 0;
  counter-reset: lb;
  font-size: 12px;
  max-height: 168px; overflow-y: auto;
}
#lb-list li {
  counter-increment: lb;
  display: flex; justify-content: space-between; gap: 12px;
  padding: 2.5px 0;
}
#lb-list li::before {
  content: counter(lb) '.';
  color: #6e685c; width: 20px; text-align: right; margin-right: 8px;
}
#lb-list li:first-child .lb-name, #lb-list li:first-child .lb-time { color: var(--gold); }
.lb-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-time { color: #9b9484; }
.lb-empty { color: #6e685c; justify-content: center !important; }
.lb-empty::before { content: '' !important; width: 0 !important; margin: 0 !important; }

/* victory name submission */
#score-submit { display: flex; gap: 8px; justify-content: center; margin-bottom: 24px; }
#score-name {
  width: 200px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 15px; letter-spacing: 2px; text-align: center;
  text-transform: uppercase;
  color: var(--gold);
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(232, 181, 77, 0.4);
  border-radius: 5px;
  outline: none;
}
#score-name:focus { border-color: var(--gold); }

/* ---------- overlay ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 15;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 3, 6, 0.82);
  backdrop-filter: blur(3px);
}
.overlay-inner { text-align: center; padding: 24px; }
#overlay-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(34px, 8vw, 64px);
  letter-spacing: 6px; margin: 0 0 10px;
}
#overlay-title.victory { color: var(--gold); text-shadow: 0 0 34px rgba(232, 181, 77, 0.5); }
#overlay-title.death { color: var(--blood); text-shadow: 0 0 34px rgba(179, 50, 46, 0.6); }
#overlay-stats { color: #a89f8d; font-size: 14px; margin-bottom: 30px; line-height: 1.9; }
.overlay-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- touch controls ---------- */
#touch-ui { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#joystick {
  position: absolute;
  bottom: max(34px, env(safe-area-inset-bottom));
  left: max(30px, env(safe-area-inset-left));
  width: 124px; height: 124px;
  border: 2px solid rgba(232, 226, 212, 0.25);
  border-radius: 50%;
  background: rgba(0,0,0,0.25);
  pointer-events: auto;
}
#joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(232, 226, 212, 0.35);
}
#touch-buttons {
  position: absolute;
  bottom: max(34px, env(safe-area-inset-bottom));
  right: max(26px, env(safe-area-inset-right));
  display: flex; align-items: flex-end; gap: 14px;
  pointer-events: auto;
}
.touch-btn {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(232, 181, 77, 0.5);
  background: rgba(20, 12, 8, 0.6);
  color: var(--bone);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
}
.touch-btn.big { width: 86px; height: 86px; font-size: 30px; }
.touch-btn:active { background: rgba(232, 181, 77, 0.35); }
