:root {
  color-scheme: dark;
  --bg: #10100f;
  --panel: #1b1a17;
  --panel-2: #23211d;
  --line: #3b372d;
  --text: #f1eadc;
  --muted: #a99f8e;
  --accent: #f0b43c;
  --danger: #d34e3d;
  --green: #5e8c4f;
  --steel: #7e8584;
  --shadow: rgba(0, 0, 0, 0.45);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--text);
  overflow-x: hidden;
}

button {
  border: 1px solid #5d5546;
  border-radius: 6px;
  background: #2c2820;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 130ms ease,
    border-color 130ms ease,
    background 130ms ease,
    color 130ms ease;
}

button:hover {
  border-color: var(--accent);
  color: #fff5d7;
}

button:active {
  transform: translateY(1px) scale(0.98);
}

.shell {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 624px) minmax(220px, 280px);
  grid-template-rows: 1fr auto;
  gap: 18px;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
}

.stage {
  position: relative;
  width: min(100%, 624px);
  aspect-ratio: 1;
  background: #070707;
  border: 2px solid #5a5140;
  border-radius: 8px;
  box-shadow:
    0 22px 60px var(--shadow),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05), transparent 12%),
    radial-gradient(circle at center, transparent 52%, rgba(0, 0, 0, 0.28));
  mix-blend-mode: screen;
  z-index: 1;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #070707;
}

.hud {
  min-height: min(624px, calc(100svh - 48px));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 22px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent 26%),
    var(--panel);
  box-shadow: 0 18px 48px var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: inline-block;
  border: 2px solid var(--accent);
  border-radius: 4px;
  background:
    linear-gradient(90deg, transparent 40%, #111 40% 60%, transparent 60%),
    linear-gradient(0deg, transparent 40%, #111 40% 60%, transparent 60%),
    #76663b;
  box-shadow: 0 0 0 3px rgba(240, 180, 60, 0.13);
}

h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 40px);
  line-height: 0.95;
  letter-spacing: 0;
}

.stats {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stats div {
  min-height: 78px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

.stats dt {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.stats dd {
  margin: 0;
  font-family:
    "Cascadia Mono", "Consolas", ui-monospace, SFMono-Regular, Menlo,
    monospace;
  font-size: clamp(18px, 3vw, 30px);
  font-weight: 800;
  line-height: 1.15;
  color: var(--text);
  overflow-wrap: anywhere;
}

#status {
  color: var(--accent);
}

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

.actions button:first-child {
  grid-column: 1 / -1;
  min-height: 48px;
  background: var(--accent);
  border-color: #ffd37a;
  color: #16120b;
}

.actions button {
  min-height: 44px;
}

.actions button[aria-pressed="true"] {
  background: #54412f;
  border-color: var(--danger);
  color: #ffd4cf;
}

.mini-map {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  opacity: 0.7;
}

.mini-map span {
  aspect-ratio: 1;
  border-radius: 3px;
  background: #574f40;
}

.mini-map span:nth-child(2),
.mini-map span:nth-child(4),
.mini-map span:nth-child(6),
.mini-map span:nth-child(8) {
  background: var(--steel);
}

.mini-map span:nth-child(5) {
  background: var(--danger);
}

.touch-controls {
  grid-column: 1 / -1;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.dpad {
  width: 154px;
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
}

.dpad button,
.fire {
  min-width: 46px;
  min-height: 46px;
  touch-action: none;
  user-select: none;
}

.dpad [data-touch-dir="up"] {
  grid-column: 2;
  grid-row: 1;
}

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

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

.dpad [data-touch-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}

.fire {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: var(--danger);
  border-color: #f39b8f;
  color: #fff5f2;
  font-size: 24px;
}

@media (max-width: 900px) {
  .shell {
    width: min(100vw - 20px, 680px);
    grid-template-columns: 1fr;
    align-content: start;
    padding: 12px 0 18px;
  }

  .stage {
    width: min(100%, calc(100svh - 310px));
    min-width: min(100%, 320px);
    justify-self: center;
  }

  .hud {
    min-height: 0;
    padding: 14px;
    gap: 14px;
  }

  .brand {
    justify-content: space-between;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats div {
    min-height: 58px;
    padding: 9px 10px;
  }

  .stats dt {
    font-size: 11px;
    margin-bottom: 5px;
  }

  .mini-map {
    display: none;
  }

  .touch-controls {
    display: flex;
  }
}

@media (max-width: 520px) {
  .shell {
    gap: 10px;
  }

  .stage {
    width: 100%;
  }

  h1 {
    font-size: 26px;
  }

  .stats {
    gap: 6px;
  }

  .actions {
    gap: 6px;
  }
}
