:root {
  color-scheme: dark;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: #111318;
  color: #f3f6fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 10%, rgba(80, 180, 255, 0.16), transparent 30%),
    linear-gradient(135deg, #111318 0%, #171d26 54%, #101219 100%);
}

button {
  border: 0;
  border-radius: 8px;
  background: #242b36;
  color: #f8fbff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

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

.app {
  width: min(100%, 920px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(240px, 1fr);
  gap: 18px;
  align-content: center;
}

.hud {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.hud > div {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(20, 25, 33, 0.84);
}

.label {
  display: block;
  margin-bottom: 6px;
  color: #91a0b4;
  font-size: 12px;
}

.hud strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
}

.stage-wrap {
  position: relative;
  width: min(100%, 420px);
  aspect-ratio: 3 / 4;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  overflow: hidden;
  background: #080a0f;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: rgba(8, 10, 15, 0.82);
}

.overlay.active {
  display: grid;
}

.overlay-title {
  margin-bottom: 10px;
  font-size: clamp(26px, 8vw, 48px);
  font-weight: 900;
  line-height: 1;
}

.overlay p {
  max-width: 28rem;
  margin: 0 0 18px;
  color: #c8d0dc;
  line-height: 1.7;
}

.primary {
  background: #39a7ff;
  color: #07111d;
}

.overlay button,
.modal-actions button {
  padding: 12px 18px;
}

.controls {
  align-self: center;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.controls button {
  width: min(30vw, 86px);
  height: min(18vw, 72px);
  min-width: 64px;
  min-height: 56px;
  font-size: 18px;
}

.middle-row {
  display: flex;
  gap: 10px;
}

.rules {
  grid-column: 1 / -1;
  color: #aeb8c7;
  font-size: 14px;
  line-height: 1.65;
}

.rules p {
  margin: 4px 0;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(3, 5, 8, 0.74);
}

.modal.active {
  display: grid;
}

.modal-panel {
  width: min(100%, 420px);
  padding: 24px;
  border-radius: 8px;
  background: #171d26;
  box-shadow: 0 18px 80px rgba(0, 0, 0, 0.45);
}

.modal-panel h1 {
  margin: 0 0 12px;
}

.modal-panel p {
  color: #c8d0dc;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    align-content: start;
  }

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

  .stage-wrap {
    justify-self: center;
  }
}
