:root {
  color-scheme: light;
  --bg: #edf1f4;
  --ink: #1f2630;
  --muted: #66707c;
  --panel: #fffdf8;
  --line: rgba(31, 38, 48, 0.12);
  --accent: #d2a24c;
  --accent-dark: #a77a2d;
  --blue: #27374d;
  --danger: #c64c3e;
  --good: #2f7f73;
  --lightning: #f5c542;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(39, 55, 77, 0.2), transparent 34%),
    linear-gradient(315deg, rgba(210, 162, 76, 0.18), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #171b21;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

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

button:hover:not(:disabled) {
  background: var(--accent-dark);
  color: #fff;
}

.game-shell {
  width: min(100%, 1080px);
  position: relative;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin-bottom: 12px;
  color: var(--blue);
  font-weight: 900;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.game-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(40px, 8vw, 66px);
  line-height: 1;
  letter-spacing: 0;
}

.game-header p {
  margin-top: 10px;
  color: var(--muted);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, 1fr));
  gap: 10px;
}

.status-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  line-height: 1;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 16px;
  align-items: stretch;
}

.arena {
  min-height: 540px;
  position: relative;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #dbe3e8;
  box-shadow: 0 18px 42px rgba(31, 38, 48, 0.12);
}

.room {
  position: relative;
  margin: 18px;
  border: 8px solid #7f8a96;
  border-right: 0;
  border-radius: 8px 0 0 8px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.35) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,0.35) 1px, transparent 1px),
    #f6f0df;
  background-size: 42px 42px;
}

.bed,
.game-machine,
.player {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  text-align: center;
  box-shadow: inset 0 0 0 10px rgba(255,255,255,0.18);
}

.bed {
  left: 8%;
  top: 10%;
  width: 150px;
  height: 96px;
  background: #6e8bb7;
}

.bed-icon {
  font-size: 34px;
  font-weight: 900;
}

.game-machine {
  left: 8%;
  bottom: 12%;
  width: 150px;
  height: 96px;
  background: #3a4664;
}

.game-machine span {
  font-size: 24px;
  font-weight: 900;
}

.game-machine small,
.bed small,
.player small {
  color: rgba(255,255,255,0.88);
}

.player {
  left: 42%;
  top: 42%;
  width: 96px;
  height: 88px;
  background: #2f7f73;
}

.player span {
  font-size: 30px;
  font-weight: 900;
}

.door {
  position: absolute;
  right: -24px;
  top: 38%;
  width: 44px;
  height: 130px;
  display: grid;
  align-items: end;
  overflow: hidden;
  border: 4px solid #5d4530;
  border-radius: 8px;
  background: #9d6b3c;
  color: #fff;
  text-align: center;
  font-size: 12px;
  font-weight: 900;
}

.door-health {
  position: absolute;
  inset: auto 0 0;
  height: 100%;
  background: rgba(47, 127, 115, 0.65);
  transition: height 160ms ease, background 160ms ease;
}

.door span {
  position: relative;
  z-index: 1;
  padding: 8px 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.45);
}

.turret-slot {
  position: absolute;
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(39, 55, 77, 0.35);
  border-radius: 8px;
  background: rgba(255,255,255,0.45);
}

.turret-slot::before {
  content: "空";
  color: rgba(39, 55, 77, 0.45);
  font-weight: 900;
}

.turret-slot.built {
  border-style: solid;
  border-color: #27374d;
  background: #314762;
  color: #fff;
}

.turret-slot.built::before {
  content: "炮 Lv." attr(data-level);
  color: #fff;
}

.turret-slot.firing {
  box-shadow: 0 0 0 5px rgba(210, 162, 76, 0.32);
}

.slot-a { left: 42%; top: 12%; }
.slot-b { left: 38%; bottom: 14%; }
.slot-c { right: 10%; bottom: 16%; }

.corridor {
  position: relative;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.08) 0 18px, transparent 18px 36px),
    #303946;
}

.hunter {
  position: absolute;
  left: 120px;
  top: 42%;
  width: 74px;
  height: 96px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-weight: 900;
  transition: left 220ms linear;
}

.hunter.inside {
  background: #8b2635;
}

.hunter span {
  font-size: 32px;
}

.hunter b {
  font-size: 13px;
}

.hunter small {
  font-size: 12px;
}

.projectiles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bullet {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffd166;
  box-shadow: 0 0 12px rgba(255, 209, 102, 0.8);
  animation: bullet 240ms linear forwards;
}

.shop {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.shop-group {
  display: grid;
  gap: 8px;
}

.shop h2 {
  font-size: 20px;
}

.shop button {
  min-height: 64px;
  display: grid;
  gap: 4px;
  align-content: center;
  padding: 10px 12px;
  text-align: left;
}

.shop button small {
  color: rgba(23, 27, 33, 0.72);
  font-weight: 700;
}

.shop button:hover:not(:disabled) small {
  color: rgba(255,255,255,0.82);
}

.shop .secondary {
  min-height: 44px;
  background: #66707c;
  color: #fff;
  text-align: center;
}

.mine.copper {
  background: #bf7c4b;
}

.mine.gold {
  background: #f0c64a;
}

.mine.diamond {
  background: #78d8f6;
}

.mystery {
  background: #8a63d2;
  color: #fff;
}

.log-panel {
  min-height: 48px;
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(31, 38, 48, 0.45);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(100%, 320px);
  padding: 24px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 56px rgba(31, 38, 48, 0.24);
  text-align: center;
}

.panel p {
  margin: 10px 0 18px;
  color: var(--muted);
}

.panel button {
  width: 100%;
  height: 44px;
}

@keyframes bullet {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(240px);
    opacity: 0;
  }
}

@media (max-width: 900px) {
  body {
    align-items: start;
    padding: 16px;
  }

  .game-header,
  .play-layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .arena {
    grid-template-columns: minmax(220px, 1fr) 150px;
    min-height: 430px;
  }

  .status-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .bed,
  .game-machine,
  .player {
    width: 118px;
    height: 76px;
  }

  .player {
    width: 72px;
  }

  .turret-slot {
    width: 64px;
    height: 64px;
    font-size: 12px;
  }

  .hunter {
    left: 78px;
  }
}

@media (max-width: 560px) {
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .arena {
    grid-template-columns: minmax(180px, 1fr) 112px;
  }

  .shop {
    padding: 12px;
  }
}
