:root {
  font-family: "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
  background: #111;
  color: #f5f5f5;
}

body {
  margin: 0;
  overflow: hidden;
}

canvas#game {
  display: block;
  width: 100vw;
  height: 100vh;
}

.hud {
  position: fixed;
  top: 1rem;
  left: 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  background: rgba(0, 0, 0, 0.6);
  color: #f0f0f0;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.35;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
}

.hud.hidden {
  opacity: 0;
  pointer-events: none;
}

.hud--top-right {
  left: auto;
  right: 1rem;
  text-align: right;
  min-width: auto;
}

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: rgba(0, 0, 0, 0.75);
  opacity: 1;
  pointer-events: auto;
  transition: opacity 200ms ease;
  z-index: 12;
}

.loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading__panel {
  width: min(22rem, 90vw);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem 1.75rem;
  border-radius: 0.9rem;
  background: rgba(12, 16, 24, 0.9);
  box-shadow: 0 25px 55px rgba(0, 0, 0, 0.35);
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #e8f1ff;
}

.loading__label {
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}

.loading__bar {
  position: relative;
  height: 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.loading__bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, #58c4ff, #8df7b5);
  transition: width 0.12s ease-out;
}

.loading__percent {
  font-size: 0.85rem;
  text-align: right;
  color: rgba(222, 235, 255, 0.88);
}

.crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 9;
}

.crosshair.hidden {
  opacity: 0;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 1px;
}

.crosshair::before {
  top: 0;
  left: 50%;
  width: 2px;
  height: 18px;
  transform: translateX(-50%);
}

.crosshair::after {
  top: 50%;
  left: 0;
  width: 18px;
  height: 2px;
  transform: translateY(-50%);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(0, 0, 0, 0.75);
  text-align: center;
  cursor: pointer;
  transition: opacity 200ms ease;
}

.overlay.hidden {
  pointer-events: none;
  opacity: 0;
}

.overlay h1 {
  font-size: clamp(2rem, 4vw, 3.25rem);
  margin: 0;
}

.overlay p {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.25rem);
}

.inventory {
  position: fixed;
  left: 50%;
  bottom: 1.75rem;
  transform: translate(-50%, 0);
  display: flex;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: rgba(10, 14, 20, 0.65);
  border-radius: 0.9rem;
  backdrop-filter: blur(6px);
  pointer-events: none;
  z-index: 11;
  transition: opacity 160ms ease, transform 160ms ease;
}

.inventory.hidden {
  opacity: 0;
  transform: translate(-50%, 8px);
}

.inventory__slot {
  position: relative;
  width: 4.5rem;
  height: 3.2rem;
  border-radius: 0.55rem;
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  transition: border-color 120ms ease, transform 120ms ease;
  overflow: hidden;
}

.touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  opacity: 1;
  transition: opacity 180ms ease;
}

.touch-controls.hidden {
  opacity: 0;
}

.touch-controls__movement,
.touch-controls__actions {
  position: absolute;
  pointer-events: auto;
}

.touch-controls.hidden .touch-controls__movement,
.touch-controls.hidden .touch-controls__actions {
  pointer-events: none;
}

.touch-controls__movement {
  left: 1.5rem;
  top: 50%;
  transform: translateY(-40%);
}

.touch-controls__actions {
  right: 1.5rem;
  top: 50%;
  transform: translateY(-40%);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.move-pad {
  position: relative;
  width: min(33vw, 9rem);
  height: min(33vw, 9rem);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(180, 220, 255, 0.25), rgba(40, 62, 90, 0.65));
  border: 2px solid rgba(130, 190, 255, 0.35);
  box-shadow: 0 20px 35px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(5px);
  touch-action: none;
}

.move-pad__knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.85), rgba(120, 180, 255, 0.75));
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 12px 18px rgba(0, 0, 0, 0.25);
  transform: translate(calc(-50% + var(--knob-x, 0px)), calc(-50% + var(--knob-y, 0px)));
  transition: transform 60ms ease;
  pointer-events: none;
}

.touch-button {
  min-width: min(28vw, 6.2rem);
  min-height: min(12vw, 3.2rem);
  padding: 0.6rem 1.2rem;
  border-radius: 1.5rem;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #0b1320;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(4px);
  touch-action: manipulation;
}

.touch-button:active {
  transform: scale(0.95);
}

.touch-button--jump {
  background: linear-gradient(140deg, #9ffcf8, #70b7ff);
}

.touch-button--attack {
  background: linear-gradient(140deg, #ffaf9f, #ff7e79);
}

.touch-button--place {
  background: linear-gradient(140deg, #d0fcb1, #63e0b8);
}

.touch-button--sprint {
  background: linear-gradient(140deg, #f3ff99, #aef46b);
}

.touch-button--crouch {
  background: linear-gradient(140deg, #c9daff, #7ab6ff);
}

.touch-button--active {
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.35);
  transform: translateY(-2px);
}

.inventory__slot--active {
  border-color: rgba(255, 210, 102, 0.9);
  box-shadow: 0 0 12px rgba(255, 210, 102, 0.6);
  transform: translateY(-2px);
}

.inventory__slot--empty {
  opacity: 0.25;
}

.inventory__item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  color: #0b0d11;
  padding: 0.35rem 0.4rem;
  border-radius: 0.45rem;
  text-align: center;
  text-transform: uppercase;
  line-height: 1.1;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.inventory__count {
  position: absolute;
  bottom: 0.3rem;
  right: 0.45rem;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: #f8f8f8;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.inventory__key {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.health {
  position: fixed;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.6rem;
  background: rgba(10, 14, 20, 0.55);
  backdrop-filter: blur(6px);
  pointer-events: none;
  z-index: 11;
  transition: opacity 160ms ease, transform 160ms ease;
}

.health.hidden {
  opacity: 0;
  transform: translate(-50%, -8px);
}

.health__heart {
  position: relative;
  width: 1.4rem;
  height: 1.4rem;
  font-size: 1.35rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.25);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.health__heart::before {
  content: '\2661';
  display: block;
}

.health__heart::after {
  content: '\2665';
  position: absolute;
  inset: 0;
  display: block;
  color: #ff4d6d;
  text-shadow: 0 2px 6px rgba(255, 77, 109, 0.35);
  clip-path: inset(0 100% 0 0);
  transition: clip-path 120ms ease;
}

.health__heart--half::after {
  clip-path: inset(0 50% 0 0);
}

.health__heart--full::after {
  clip-path: inset(0 0 0 0);
}
