* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #f2f5f8;
  color: #2b3a55;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, .95);
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(90, 130, 180, .1);
}
.hud-group { display: flex; align-items: center; gap: 10px; }
.hud-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .02em;
  color: #ff8a2e;
  margin-right: 6px;
}
.hud-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #8aa3c0;
}
.hud-group b { font-size: 17px; color: #2b3a55; min-width: 34px; }
#hudErrors.warn { color: #e5484d; }
.hud-btn {
  background: #fff;
  color: #4a6286;
  border: 1px solid #bcd4ea;
  border-radius: 8px;
  padding: 6px 13px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.hud-btn:hover { background: #eef6ff; }
.hud-btn:active { transform: scale(.96); }

#stage { position: relative; margin: 10px; }
canvas#game {
  display: block;
  width: min(96vw, 132vh);
  aspect-ratio: 3 / 2;
  border-radius: 22px;
  box-shadow: 0 10px 34px rgba(40, 70, 110, .22);
  touch-action: none;
  background: #ffffff;
}
#stage.flash { animation: flash .35s; }
@keyframes flash {
  0% { filter: none; }
  25% { filter: drop-shadow(0 0 18px rgba(229, 72, 77, .9)); }
  100% { filter: none; }
}

#countdown {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 120px;
  font-weight: 900;
  color: #2e9cff;
  -webkit-text-stroke: 3px #ffffff;
  text-shadow: 0 6px 24px rgba(46, 156, 255, .45);
  pointer-events: none;
}
#countdown.show { display: flex; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(43, 58, 85, .35);
  backdrop-filter: blur(5px);
  padding: 16px;
}
.overlay.hidden { display: none; }
.card {
  background: #ffffff;
  border: 1px solid #e3eefb;
  border-radius: 20px;
  padding: 28px 32px;
  max-width: 620px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 24px 70px rgba(43, 58, 85, .35);
}
.card h1 {
  margin: 0 0 6px;
  font-size: 32px;
  color: #2b3a55;
  letter-spacing: .01em;
}
.card h1 .accent { color: #ff8a2e; }
.card .sub { color: #5a7396; margin: 0 0 14px; }
.rules {
  text-align: left;
  color: #4a6286;
  font-size: 15px;
  line-height: 1.55;
  padding-left: 20px;
  margin: 0 0 18px;
}
.rules li { margin-bottom: 6px; }
.btn {
  display: block;
  width: 100%;
  max-width: 340px;
  margin: 12px auto 0;
  padding: 14px 24px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #3fa2ff, #2e8ce8);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(46, 140, 232, .35);
  transition: filter .15s, transform .1s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.98); }
.btn.ghost {
  background: #fff;
  border: 1px solid #bcd4ea;
  color: #4a6286;
  font-weight: 600;
  box-shadow: none;
}
#resBody { color: #4a6286; font-size: 16px; line-height: 1.7; margin-bottom: 6px; }
#resBody .big { font-size: 26px; font-weight: 800; color: #ff8a2e; }
#bestLine { color: #7d97b8; font-size: 14px; margin: 10px 0 0; }
#credit { color: #7d97b8; font-size: 12px; margin: 0 0 14px; text-align: center; }

@media (max-width: 560px) {
  .card h1 { font-size: 24px; }
  #countdown { font-size: 84px; }
  .hud-group { gap: 6px; }
  #hud { padding: 8px 10px; }
}
