:root {
  color-scheme: light;
  --ink: #20304a;
  --muted: #60718b;
  --paper: #fffaf0;
  --panel: rgba(255, 255, 255, 0.92);
  --green: #37bf6e;
  --yellow: #ffd348;
  --red: #f25f5c;
  --blue: #3b82f6;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at 15% 12%, rgba(255, 211, 72, 0.36), transparent 24rem),
    linear-gradient(135deg, #dff7ff 0%, #effadd 48%, #fff1c7 100%);
}

button {
  font: inherit;
}

.game-shell {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 16px;
}

.game-stage {
  position: relative;
  width: min(100%, 1280px);
  aspect-ratio: 1280 / 760;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  border: 6px solid #ffffff;
  border-radius: 14px;
  background: #bcefa7;
  box-shadow: 0 24px 60px rgba(42, 61, 86, 0.22);
  cursor: crosshair;
  user-select: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  z-index: 3;
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.hud-top {
  top: 14px;
  left: 14px;
  align-items: center;
  flex-wrap: wrap;
  max-width: calc(100% - 250px);
}

.stat {
  display: flex;
  align-items: center;
  min-height: 40px;
  gap: 8px;
  padding: 8px 10px;
  border: 2px solid rgba(32, 48, 74, 0.08);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(42, 61, 86, 0.1);
  white-space: nowrap;
}

.stat-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.health-shell {
  width: clamp(86px, 14vw, 160px);
  height: 16px;
  overflow: hidden;
  border: 2px solid rgba(32, 48, 74, 0.14);
  border-radius: 99px;
  background: #eef2f6;
}

.health-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #38bdf8, var(--green));
  transition:
    width 160ms ease,
    background 160ms ease;
}

.vault {
  position: absolute;
  z-index: 3;
  top: 14px;
  right: 14px;
  width: min(214px, calc(100% - 28px));
  min-height: 98px;
  padding: 10px;
  border: 2px solid rgba(32, 48, 74, 0.08);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(42, 61, 86, 0.1);
  pointer-events: none;
}

.vault-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.vault-items {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.vault-item {
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid rgba(32, 48, 74, 0.08);
  border-radius: 8px;
  background: #fff7d6;
  color: var(--ink);
  font-size: clamp(13px, 1.6vw, 18px);
  font-weight: 900;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(37, 53, 82, 0.45);
  backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

#endScreen {
  background: rgba(37, 53, 82, 0.28);
  backdrop-filter: none;
}

.celebration-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.spark {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--spark-color);
  box-shadow: 0 0 14px var(--spark-color);
  animation: spark-burst 1200ms ease-out forwards;
  animation-delay: var(--spark-delay);
}

@keyframes spark-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.35);
  }

  18% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--spark-x)), calc(-50% + var(--spark-y))) scale(1);
  }
}

.dialog {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  padding: clamp(22px, 4vw, 34px);
  border: 3px solid #ffffff;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 22px 60px rgba(25, 40, 65, 0.28);
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: #24745d;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  color: #15253e;
  line-height: 1.1;
}

h1 {
  font-size: clamp(32px, 5vw, 54px);
}

h2 {
  font-size: clamp(28px, 4.4vw, 46px);
}

.lead {
  max-width: 470px;
  margin: 14px auto 22px;
  color: var(--muted);
  font-size: clamp(15px, 2vw, 18px);
  line-height: 1.7;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 22px;
}

.difficulty-card {
  min-height: 92px;
  padding: 13px 8px;
  border: 2px solid rgba(32, 48, 74, 0.12);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.difficulty-card:hover {
  transform: translateY(-2px);
}

.difficulty-card.selected {
  border-color: #20a36b;
  box-shadow: 0 0 0 4px rgba(32, 163, 107, 0.16);
}

.difficulty-card span,
.difficulty-card small {
  display: block;
}

.difficulty-card span {
  margin-bottom: 7px;
  font-size: 18px;
  font-weight: 900;
}

.difficulty-card small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.primary-button {
  min-width: 180px;
  min-height: 50px;
  padding: 12px 22px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffe36d, var(--yellow));
  color: #513c00;
  box-shadow: 0 7px 0 #d89d18;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #d89d18;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 22px 0;
}

.result-grid div {
  padding: 14px;
  border: 2px solid rgba(32, 48, 74, 0.08);
  border-radius: 8px;
  background: #ffffff;
}

.result-grid span,
.result-grid strong {
  display: block;
}

.result-grid span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.result-grid strong {
  margin-top: 5px;
  font-size: 28px;
}

@media (max-width: 760px) {
  .game-shell {
    padding: 8px;
  }

  .game-stage {
    border-width: 3px;
    border-radius: 10px;
    max-height: calc(100vh - 16px);
  }

  .hud-top {
    top: 8px;
    left: 8px;
    max-width: calc(100% - 16px);
  }

  .stat {
    min-height: 32px;
    padding: 5px 7px;
    gap: 5px;
  }

  .stat-label {
    font-size: 12px;
  }

  .vault {
    top: auto;
    right: 8px;
    bottom: 8px;
    width: min(184px, calc(100% - 16px));
    min-height: 72px;
    padding: 8px;
  }

  .vault-items {
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
  }

  .difficulty-grid,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .difficulty-card {
    min-height: 70px;
  }
}
