* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #071018;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #eaf6ff;
}

.hidden {
  display: none !important;
}

#back-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 30;
  background: rgba(6, 14, 22, 0.65);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  color: #eaf6ff;
  text-decoration: none;
}

#back-link:hover {
  background: rgba(6, 14, 22, 0.85);
}

#game-canvas {
  display: block;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: #0d1622;
  touch-action: none;
}

#menu, #leaderboard-overlay, #gameover-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(30, 40, 50, 0.6), rgba(4, 8, 16, 0.92));
}

.panel {
  background: rgba(8, 18, 28, 0.75);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 2rem 2.5rem;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  text-align: center;
  max-width: 440px;
  width: min(90vw, 440px);
  max-height: 90vh;
  overflow-y: auto;
}

.panel h1 {
  margin: 0 0 0.25rem;
  background: linear-gradient(90deg, #ff8a3d, #3bb0ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.panel h2 {
  margin: 0 0 1rem;
}

.tagline {
  margin: 0 0 1.25rem;
  color: #a7bdd1;
  font-size: 0.9rem;
}

.controls-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.25rem;
  text-align: left;
  font-size: 0.85rem;
  color: #cdd8e3;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

#leaderboard-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.9rem;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.primary {
  background: linear-gradient(135deg, #34e89e, #3b9dff);
  color: #04121c;
  border: none;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
}

.primary:hover {
  filter: brightness(1.08);
}

/* --- HUD --- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#hud-top {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#streak-label {
  margin-right: auto;
  font-weight: 700;
  font-size: 1.1rem;
  background: rgba(6, 14, 22, 0.55);
  backdrop-filter: blur(8px);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
}

#best-label {
  color: #a7bdd1;
  font-size: 0.8rem;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: inherit;
  font-size: 1.1rem;
  min-width: 44px;
  min-height: 44px;
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

#hp-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.hp-block {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.hp-name {
  font-size: 0.75rem;
  color: #a7bdd1;
}

.hp-block:last-child {
  align-items: flex-end;
}

.hp-bar {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: rgba(6, 14, 22, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 100%;
  transition: width 0.15s ease;
}

.hp-fill.player {
  background: linear-gradient(90deg, #3bb0ff, #34e89e);
}

.hp-fill.opponent {
  background: linear-gradient(90deg, #ff8a3d, #ff5a5a);
}

#vs-label {
  font-size: 0.75rem;
  color: #6b8199;
  font-weight: 700;
  flex: 0 0 auto;
}

/* --- Touch controls --- */
#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 12;
  pointer-events: none;
}

#touch-controls.hidden {
  display: none;
}

#touch-joystick {
  position: absolute;
  left: 24px;
  bottom: 28px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.2);
  pointer-events: auto;
  touch-action: none;
}

#touch-joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  border: 2px solid rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

.touch-btn {
  position: absolute;
  border-radius: 50%;
  color: #eaf6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  padding: 0;
  pointer-events: auto;
  border: 2px solid rgba(255, 255, 255, 0.5);
  font-size: 1.5rem;
}

#touch-punch {
  right: 108px;
  bottom: 78px;
  width: 68px;
  height: 68px;
  background: rgba(255, 224, 102, 0.28);
  border-color: rgba(255, 224, 102, 0.55);
}

#touch-kick {
  right: 24px;
  bottom: 28px;
  width: 76px;
  height: 76px;
  background: rgba(255, 90, 90, 0.28);
  border-color: rgba(255, 90, 90, 0.55);
}

#touch-block {
  right: 96px;
  bottom: 168px;
  width: 60px;
  height: 60px;
  background: rgba(120, 200, 255, 0.25);
  border-color: rgba(120, 200, 255, 0.55);
}

.touch-btn:active {
  filter: brightness(1.3);
}
