:root {
  color-scheme: dark;
  --panel: rgba(10, 14, 18, 0.74);
  --panel-strong: rgba(10, 14, 18, 0.9);
  --line: rgba(205, 221, 230, 0.2);
  --text: #f4f7f8;
  --muted: #9ca8ad;
  --cyan: #66e0ff;
  --amber: #ffb84a;
  --red: #ff4f5f;
  --green: #73f7a5;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #06080a;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  color: inherit;
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #070a0d;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none; /* taps aim+shoot; never scroll/zoom the page */
}

/* Touch devices: no text selection / tap highlight / callout getting in the way. */
body.is-touch {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.hud {
  position: absolute;
  z-index: 3;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.hud__cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.hud__cluster--right {
  justify-content: flex-end;
}

.stat,
.icon-button,
.message,
.menu__panel,
.touch-actions button {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}

.stat {
  min-width: 90px;
  border-radius: 8px;
  padding: 9px 12px;
}

.stat--ammo {
  min-width: 154px;
}

.stat--sigma {
  min-width: 102px;
}

.stat--sigma strong {
  color: var(--cyan);
}

.stat--sigma.is-active strong {
  color: var(--amber);
}

.stat--sigma.is-cooling strong {
  color: var(--muted);
}

.stat--health strong {
  color: var(--green);
}

.stat--health.is-danger strong {
  color: var(--red);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  white-space: nowrap;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  line-height: 1;
}

.icon-button {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  pointer-events: auto;
  cursor: pointer;
}

.icon-button:focus-visible,
.primary-action:focus-visible,
.touch-actions button:focus-visible,
.player-form input:focus-visible,
.player-form select:focus-visible {
  outline: 3px solid rgba(102, 224, 255, 0.9);
  outline-offset: 3px;
}

.message {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 22%;
  min-width: 160px;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%) translateY(16px);
  border-radius: 8px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  opacity: 0;
  text-align: center;
  text-transform: uppercase;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.message.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.menu {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(rgba(5, 7, 9, 0.32), rgba(5, 7, 9, 0.58));
  overflow: auto;
}

.menu.is-hidden {
  display: none;
}

.menu__panel {
  width: min(480px, calc(100vw - 32px));
  border-radius: 8px;
  margin: auto 0;
  padding: 28px;
  text-align: center;
}

.kicker {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 62px);
  line-height: 0.95;
  letter-spacing: 0;
}

.game-over-card {
  display: none;
  margin-top: 20px;
}

.game-over-card.is-visible {
  display: block;
}

.game-over-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: min(42vh, 360px);
  border: 1px solid rgba(205, 221, 230, 0.22);
  border-radius: 8px;
  object-fit: cover; /* trim portrait photos to fill the box, no stretch */
  object-position: 30% 15%; /* lost.jpg: bias to the face (upper area) */
}

.game-over-card.is-won img {
  object-position: center; /* won.jpg is landscape, face centered */
}

.game-over-card__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-top: 10px;
}

.game-over-card__text h2,
.game-over-card__text p {
  margin: 0;
}

.game-over-card__text h2 {
  color: var(--red);
  font-size: clamp(34px, 6vw, 54px);
  line-height: 1.02;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 900;
}

.game-over-card.is-won .game-over-card__text h2 {
  color: #73f7a5;
  text-transform: none;
  letter-spacing: 0;
}

.game-over-card__text p {
  color: var(--text);
  font-weight: 900;
}

.player-form {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.player-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-align: left;
  text-transform: uppercase;
}

.player-form input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  background: rgba(255, 255, 255, 0.075);
  color: var(--text);
  font: inherit;
  font-weight: 800;
}

.player-form select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.075);
  color: var(--text);
  font: inherit;
  font-weight: 800;
}

.player-form input::placeholder {
  color: rgba(244, 247, 248, 0.42);
}

.options-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 4px;
}

.options-panel label {
  min-width: 0;
}

.options-panel input[type="range"] {
  min-height: 40px;
  padding: 0;
  accent-color: var(--cyan);
}

.option-toggle {
  display: flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.055);
}

.option-toggle input {
  width: 18px;
  min-height: 18px;
  margin: 0 9px 0 0;
  accent-color: var(--cyan);
}

.primary-action {
  width: 100%;
  border: 0;
  border-radius: 8px;
  margin-top: 4px;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--amber), #ff6b4a);
  color: #160b05;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 14px 36px rgba(255, 118, 62, 0.3);
}

.leaderboard {
  margin-top: 22px;
  text-align: left;
}

.leaderboard h2 {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.leaderboard ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  border-top: 1px solid rgba(205, 221, 230, 0.16);
  padding-top: 8px;
}

.leaderboard li > span:nth-child(2) {
  display: grid;
  min-width: 0;
}

.leaderboard__rank,
.leaderboard__score {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.leaderboard__name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard__meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.stat--player {
  max-width: 160px;
}

.stat--player strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.touch-actions {
  position: absolute;
  z-index: 4;
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

.touch-actions button {
  min-width: 78px;
  min-height: 54px;
  border-radius: 8px;
  pointer-events: auto;
  cursor: pointer;
  font-weight: 900;
  text-transform: uppercase;
  touch-action: manipulation;
}

/* Touch build: tap the screen to aim+shoot, so only Reload remains as a button. */
body.is-touch .touch-actions {
  display: flex;
  justify-content: flex-end;
}

body.is-touch #touchFire {
  display: none;
}

body.is-touch #touchReload {
  min-width: 96px;
  min-height: 68px;
  font-size: 20px;
}

@media (max-width: 760px) {
  .hud {
    align-items: flex-start;
  }

  .stat {
    min-width: 76px;
    padding: 8px 10px;
  }

  .stat--ammo {
    min-width: 130px;
  }

  .stat--sigma {
    min-width: 92px;
  }

  .stat--player {
    max-width: 118px;
  }

  .stat strong {
    font-size: 18px;
  }

  .icon-button {
    display: none;
  }

  .touch-actions {
    display: flex;
  }

  .menu__panel {
    padding: 24px 18px;
  }

  .options-panel {
    grid-template-columns: 1fr;
  }
}
