:root {
  color-scheme: dark;
  --ink: #edf1d0;
  --muted: #9ca58d;
  --panel: rgba(15, 20, 22, 0.92);
  --panel-edge: #59634d;
  --accent: #dfb94a;
  --danger: #d64d4d;
  --health: #5acb68;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0a0e10;
  color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
  image-rendering: pixelated;
}

button, input { font: inherit; }

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  background: #17221b;
  cursor: crosshair;
  image-rendering: pixelated;
  touch-action: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at 50% 42%, rgba(70, 95, 66, 0.22), transparent 38%),
    rgba(5, 8, 10, 0.72);
  backdrop-filter: blur(5px);
}

.pixel-panel {
  border: 3px solid #2b322c;
  outline: 2px solid rgba(183, 196, 152, 0.3);
  background: var(--panel);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.4), inset 0 0 0 2px #0a0d0c;
}

.login-card {
  width: min(520px, 100%);
  padding: 34px 38px 30px;
  text-align: center;
}

.rune {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 38px;
  line-height: 1;
  text-shadow: 0 0 20px rgba(223, 185, 74, 0.55);
}

.eyebrow {
  margin: 0 0 8px;
  color: #a6ae92;
  font-size: 11px;
  letter-spacing: 0.2em;
}

h1 {
  margin: 0;
  color: #f0ce60;
  font-size: clamp(48px, 11vw, 78px);
  line-height: 1;
  letter-spacing: -0.08em;
  text-shadow: 4px 4px 0 #763f28, 7px 7px 0 #080a09;
}

.subtitle {
  max-width: 420px;
  margin: 20px auto 25px;
  color: #c4cbb4;
  line-height: 1.55;
}

#login-form { display: grid; gap: 10px; }

#login-form label {
  text-align: left;
  color: #d8dfc0;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#nickname {
  width: 100%;
  border: 3px solid #606a54;
  border-radius: 0;
  outline: none;
  background: #080c0d;
  color: #fff5c2;
  padding: 15px 16px;
  font-size: 18px;
  box-shadow: inset 4px 4px 0 rgba(0, 0, 0, 0.45);
}

#nickname:focus { border-color: var(--accent); }

button {
  border: 0;
  border-bottom: 5px solid #76532d;
  background: #d7ad42;
  color: #18150e;
  padding: 16px 14px 13px;
  font-weight: 900;
  letter-spacing: 0.07em;
  cursor: pointer;
  box-shadow: inset 0 0 0 3px #f0d476;
}

button:hover { filter: brightness(1.08); transform: translateY(-1px); }
button:active { transform: translateY(3px); border-bottom-width: 2px; }
button:disabled { opacity: 0.55; cursor: wait; }

.controls-preview {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  margin-top: 24px;
  color: var(--muted);
  font-size: 11px;
}

kbd {
  border: 1px solid #616b58;
  background: #1c241d;
  color: #e4e9cf;
  padding: 3px 5px;
  box-shadow: 2px 2px 0 #060806;
}

.connection-state { margin: 18px 0 0; color: #97a08c; font-size: 12px; }

.hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.hidden { display: none !important; }

.top-left { position: absolute; top: 18px; left: 18px; width: min(360px, calc(100vw - 36px)); }
.player-card { padding: 13px 15px; }
.player-line, .stats-line { display: flex; justify-content: space-between; gap: 12px; }
.player-line { align-items: baseline; margin-bottom: 9px; }
.player-line strong { color: #fff4bd; font-size: 15px; text-shadow: 2px 2px #000; }
.player-line span { color: var(--accent); font-size: 12px; }
.stats-line { margin-top: 7px; color: #bfc7ae; font-size: 11px; }

.bar-shell {
  height: 17px;
  border: 3px solid #090c09;
  outline: 1px solid #69705c;
  background: #3b2020;
  overflow: hidden;
}

.health-bar {
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(90deg, #4dad58 0 14px, #60cc69 14px 16px);
  transition: width 100ms linear;
}

.messages { margin-top: 12px; display: grid; gap: 5px; }
.message {
  width: fit-content;
  max-width: 100%;
  background: rgba(4, 7, 6, 0.72);
  color: #c5ccb8;
  padding: 6px 8px;
  font-size: 11px;
  text-shadow: 1px 1px #000;
  animation: message-in 180ms ease-out;
}
@keyframes message-in { from { opacity: 0; transform: translateX(-8px); } }

.leaderboard {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 230px;
  padding: 12px 14px;
}

.leaderboard h2 { margin: 0 0 10px; color: var(--accent); font-size: 12px; letter-spacing: 0.14em; }
.leaderboard ol { margin: 0; padding: 0; list-style: none; counter-reset: rank; }
.leaderboard li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 6px;
  padding: 5px 0;
  border-top: 1px solid rgba(170, 183, 143, 0.15);
  color: #c8ceba;
  font-size: 11px;
}
.leaderboard li::before { content: counter(rank) "."; color: #77806d; }
.leaderboard li.me { color: #ffe279; }
.leaderboard .rank-score { color: #e0b94d; }

.bottom-help {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 13px;
  color: #aeb7a1;
  font-size: 10px;
  white-space: nowrap;
}
.separator { color: #596251; padding: 0 6px; }

.respawn {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  background: rgba(45, 8, 8, 0.28);
  text-shadow: 3px 3px #000;
}
.respawn strong { color: #ff7565; font-size: clamp(28px, 5vw, 58px); }
.respawn .taunt { color: #ffd479; font-size: clamp(14px, 2.4vw, 20px); font-style: italic; }
.respawn button {
  justify-self: center;
  margin-top: 6px;
  background: #e2574c;
  border-bottom-color: #7a231c;
  color: #2a0906;
  box-shadow: inset 0 0 0 3px #ffb3ac;
  font-size: 15px;
  pointer-events: auto;
}
.respawn button:hover { filter: brightness(1.12); }

.latency {
  position: absolute;
  right: 18px;
  bottom: 18px;
  color: #72c978;
  font-size: 10px;
  text-shadow: 1px 1px #000;
}

@media (max-width: 720px) {
  .login-card { padding: 26px 22px; }
  .leaderboard { top: auto; right: 12px; bottom: 52px; width: 190px; opacity: 0.88; }
  .top-left { top: 12px; left: 12px; width: calc(100vw - 24px); }
  .bottom-help { display: none; }
  .latency { right: 12px; bottom: 12px; }
}

.touch-controls { display: none; }
.touch-help { display: none; }

@media (hover: none) and (pointer: coarse) {
  .bottom-help { display: none; }
  .touch-controls { display: block; }

  .top-left { width: min(300px, 54vw); }
  .leaderboard {
    top: 18px;
    right: 12px;
    bottom: auto;
    width: min(190px, 42vw);
    padding: 10px 12px;
    opacity: 0.85;
  }
  .leaderboard h2 { font-size: 10px; }
  .leaderboard li { font-size: 11px; }

  .touch-help {
    display: flex;
    position: absolute;
    bottom: 150px;
    left: 50%;
    transform: translateX(-50%);
    padding: 7px 11px;
    gap: 6px;
    color: #aeb7a1;
    font-size: 9px;
    white-space: nowrap;
    pointer-events: none;
  }

  .joystick {
    position: absolute;
    bottom: 22px;
    width: 118px;
    height: 118px;
    touch-action: none;
    pointer-events: auto;
  }
  .joystick-move { left: 22px; }
  .joystick-aim { right: 22px; }

  .joystick-base {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(15, 20, 22, 0.55);
    border: 2px solid rgba(223, 185, 74, 0.35);
    box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.4);
  }
  .joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    margin: -25px 0 0 -25px;
    border-radius: 50%;
    background: rgba(255, 244, 189, 0.9);
    border: 2px solid rgba(0, 0, 0, 0.4);
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
  }
  .joystick-aim .joystick-knob { background: rgba(255, 117, 101, 0.9); }
}

@media (hover: none) and (pointer: coarse) and (max-width: 400px) {
  .touch-help { bottom: 140px; font-size: 8px; }
  .joystick { width: 100px; height: 100px; }
}
