:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111615;
  color: #fff8e8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(207, 76, 47, 0.24), transparent 18rem),
    radial-gradient(circle at 82% 28%, rgba(57, 151, 115, 0.2), transparent 20rem),
    linear-gradient(135deg, #121816, #1b1715 58%, #0d1012);
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  color: #161310;
  background: #ffd166;
  box-shadow: 0 6px 0 #966a1e;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease, opacity 120ms ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.05);
  transform: translateY(1px);
  box-shadow: 0 5px 0 #966a1e;
}

button:active:not(:disabled) {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #966a1e;
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.game-shell {
  width: min(1180px, 100vw);
  padding: clamp(10px, 1.6vw, 18px);
}

.stage {
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  min-height: min(760px, calc(100vh - 20px));
  background: #17211d;
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.48);
}

canvas {
  display: block;
  width: 100%;
  height: min(74vh, 680px);
  min-height: 520px;
  background: #182922;
  cursor: crosshair;
}

.hud {
  position: absolute;
  z-index: 4;
  top: 12px;
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  pointer-events: none;
}

.hud > div,
.shop,
.message,
.banner {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 18, 17, 0.72);
  backdrop-filter: blur(9px);
}

.hud > div {
  min-width: 0;
  border-radius: 8px;
  padding: 9px 11px;
}

#inventoryHud,
#pauseHud {
  pointer-events: auto;
}

#inventoryHudButton,
#pauseButton {
  width: 100%;
  min-height: 30px;
  margin-top: 3px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 0.74rem;
  box-shadow: 0 4px 0 #966a1e;
}

.label {
  display: block;
  color: #c4d0bd;
  font-size: 0.68rem;
  font-weight: 750;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(0.92rem, 1.7vw, 1.22rem);
}

.health-track {
  height: 7px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.48);
}

#healthFill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8fd5c6, #ffd166, #f2644b);
  transition: width 160ms ease;
}

.message {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 96px;
  width: min(620px, calc(100% - 28px));
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 11px 14px;
  color: #f8f1df;
  font-weight: 750;
  text-align: center;
  pointer-events: none;
}

.banner {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 16px;
  padding: 28px;
  text-align: center;
  background:
    linear-gradient(rgba(12, 17, 16, 0.46), rgba(12, 17, 16, 0.82)),
    radial-gradient(circle at 52% 26%, rgba(239, 90, 58, 0.28), transparent 22rem);
}

.banner.hidden {
  display: none;
}

.banner h1 {
  margin: 0;
  font-size: clamp(2.8rem, 9vw, 6.8rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow: 0 8px 22px rgba(0, 0, 0, 0.55);
}

.banner p {
  margin: 0 auto;
  max-width: 650px;
  color: #efe7d2;
  font-size: clamp(1rem, 2vw, 1.24rem);
  font-weight: 680;
  line-height: 1.42;
}

.end-popup {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: 50%;
  width: min(480px, calc(100% - 28px));
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 20px;
  background: rgba(11, 14, 13, 0.9);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(10px);
  text-align: center;
}

.end-popup.hidden {
  display: none;
}

.end-popup h2 {
  margin: 0 0 10px;
  font-size: clamp(1.6rem, 4vw, 2.5rem);
}

.end-popup p {
  margin: 0;
  color: #efe7d2;
  font-weight: 750;
  line-height: 1.5;
  white-space: pre-line;
}

.end-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

#startButton {
  justify-self: center;
  min-width: 190px;
}

.shop {
  position: absolute;
  z-index: 6;
  top: 112px;
  right: 12px;
  width: 236px;
  max-height: calc(100% - 190px);
  overflow: auto;
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.shop.hidden {
  display: none;
}

.shop-title {
  color: #efe7d2;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.shop button {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 8px;
  padding: 0 10px;
  background: #8fd5c6;
  box-shadow: 0 5px 0 #326e65;
  text-align: left;
}

.shop button strong {
  flex: 0 0 auto;
}

#medkitButton {
  background: #f59d87;
  box-shadow: 0 5px 0 #914435;
}

.lobby-panel {
  position: absolute;
  z-index: 7;
  top: 104px;
  left: 50%;
  width: min(540px, calc(100% - 28px));
  max-height: min(420px, calc(100% - 150px));
  transform: translateX(-50%);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 12px;
  background: rgba(12, 16, 15, 0.9);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(10px);
}

.lobby-panel.hidden {
  display: none;
}

.lobby-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.lobby-panel-header strong {
  color: #fff8e8;
  font-size: 1rem;
  font-weight: 900;
}

.lobby-panel-header button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 0.78rem;
}

.lobby-panel-items {
  display: grid;
  gap: 8px;
}

.lobby-shop-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.06);
}

.lobby-shop-item h3 {
  margin: 0 0 3px;
  color: #fff8e8;
  font-size: 0.9rem;
}

.lobby-shop-item p {
  margin: 0;
  color: #cdd5cb;
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.32;
}

.lobby-shop-item button {
  min-width: 92px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.76rem;
}

.help-chat {
  display: grid;
  gap: 10px;
}

.help-chat p {
  margin: 0;
  color: #efe7d2;
  font-weight: 750;
  line-height: 1.4;
}

.help-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.help-input-row input {
  min-width: 0;
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 0 10px;
  color: #fff8e8;
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
  font-weight: 700;
}

.help-input-row button {
  min-height: 38px;
}

.touch-controls {
  position: absolute;
  z-index: 7;
  left: 14px;
  bottom: 66px;
  display: none;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(2, 46px);
  gap: 8px;
}

.touch-controls button {
  min-height: 46px;
  padding: 0;
  background: rgba(255, 209, 102, 0.9);
}

.touch-controls [data-move="up"] {
  grid-column: 2;
}

.touch-controls [data-move="left"] {
  grid-column: 1;
  grid-row: 2;
}

.touch-controls [data-move="down"] {
  grid-column: 2;
  grid-row: 2;
}

.touch-controls [data-move="right"] {
  grid-column: 3;
  grid-row: 2;
}

.touch-controls [data-action="attack"] {
  position: fixed;
  right: 18px;
  bottom: 72px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #f2644b;
  box-shadow: 0 6px 0 #8e3729;
  color: #fff8e8;
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .game-shell {
    padding: 0;
  }

  .stage {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  canvas {
    height: 100vh;
    min-height: 640px;
  }

  .hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 6px;
  }

  .hud > div {
    padding: 7px 8px;
  }

  .shop {
    top: 160px;
    right: 8px;
    width: min(216px, 54vw);
  }

  .shop button {
    font-size: 0.82rem;
  }

  .lobby-panel {
    top: 144px;
  }

  .message {
    top: 142px;
    font-size: 0.88rem;
  }

  .touch-controls {
    display: grid;
  }
}
