:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --ink: #392a34;
  --cream: #fffaf0;
  --yellow: #ffc62f;
  --coral: #ff6f76;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #69c9f3;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 420px;
  overflow: hidden;
  isolation: isolate;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: max(16px, env(safe-area-inset-top)) 14px 0;
  pointer-events: none;
}

.score-card, .best-card {
  display: flex;
  flex-direction: column;
  width: fit-content;
  min-width: 58px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.best-card { min-width: 44px; text-align: right; }

.hud-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 9px;
}

.hud-label {
  color: rgba(57, 42, 52, 0.58);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: .11em;
  line-height: 1;
}

.score-card strong, .best-card strong {
  margin-top: 0;
  color: var(--ink);
  font-size: clamp(1.8rem, 7.5vw, 2.25rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.brand {
  align-self: start;
  margin-top: 1px;
  padding: 7px 12px 8px;
  border: 2px solid rgba(57, 42, 52, .1);
  border-radius: 16px 16px 20px 20px;
  background: rgba(255, 250, 240, .76);
  color: var(--ink);
  font-size: clamp(.95rem, 4vw, 1.2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 5px 0 rgba(57,42,52,.09);
  white-space: nowrap;
}

.brand span { color: #e75f63; }

.sound-toggle {
  position: relative;
  width: 42px;
  min-height: 42px;
  padding: 0;
  border: 2px solid rgba(57,42,52,.1);
  border-radius: 50%;
  background: rgba(255,250,240,.82);
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 900;
  box-shadow: 0 5px 0 rgba(57,42,52,.1);
  cursor: pointer;
  pointer-events: auto;
}

.sound-toggle::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 7px;
  height: 7px;
  border: 2px solid #fffaf0;
  border-radius: 50%;
  background: #48c98b;
}

.sound-toggle.muted { color: #a7979e; }
.sound-toggle.muted::after { background: #b8adb2; }
.sound-toggle:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(57,42,52,.1); }

.power {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  width: min(56vw, 240px);
  height: 14px;
  padding: 3px;
  overflow: hidden;
  border: 2px solid rgba(57, 42, 52, 0.58);
  border-radius: 99px;
  background: rgba(255,250,240,.7);
  box-shadow: 0 4px 0 rgba(57,42,52,.1);
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity .18s ease, transform .18s ease;
}

.power.visible { opacity: 1; transform: translate(-50%, 0); }

.power span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffe564, #ffb62f 52%, #ff6571);
  transition: width 40ms linear;
}

.tip {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 99px;
  border: 2px solid rgba(57,42,52,.09);
  background: rgba(255,250,240,.82);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 900;
  letter-spacing: .03em;
  transform: translateX(-50%);
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}

.tip.hide { opacity: 0; transform: translate(-50%, 12px); }

.combo {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 22%;
  color: #fff;
  font-size: clamp(1.35rem, 7vw, 2.25rem);
  font-weight: 1000;
  text-shadow: 0 3px 0 rgba(57,42,52,.2);
  opacity: 0;
  transform: translate(-50%, 18px) scale(.85);
  pointer-events: none;
}

.combo.pop { animation: combo-pop .75s cubic-bezier(.2,.8,.2,1); }

@keyframes combo-pop {
  0% { opacity: 0; transform: translate(-50%, 18px) scale(.7); }
  25% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  70% { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -22px) scale(.95); }
}

.game-over {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(52, 35, 31, .28);
  backdrop-filter: blur(7px);
}

.game-over[hidden] { display: none; }

.game-over-card {
  width: min(88vw, 340px);
  padding: 30px 24px 24px;
  border: 3px solid rgba(53,35,31,.15);
  border-radius: 30px;
  background: var(--cream);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 16px 0 rgba(53,35,31,.14), 0 28px 60px rgba(53,35,31,.22);
  animation: card-in .35s cubic-bezier(.2,.9,.25,1.2);
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(24px) scale(.94); }
}

.eyebrow { display: block; color: #8c6d5f; font-size: .95rem; font-weight: 700; }
.game-over-card strong { display: inline-block; margin: 4px 2px 0; font-size: 4.8rem; line-height: 1; }
.unit { font-weight: 800; }
.game-over-card p { margin: 12px 0 22px; color: #755f55; font-size: 1rem; }

.game-over-card button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 18px;
  background: var(--coral);
  color: #fff;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 900;
  box-shadow: 0 7px 0 #d95449;
  cursor: pointer;
}

.game-over-card button:active { transform: translateY(4px); box-shadow: 0 3px 0 #d95449; }
button:focus-visible { outline: 4px solid #3a87d8; outline-offset: 3px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 720px) {
  #game { max-width: 520px; margin: 0 auto; box-shadow: 0 0 90px rgba(30, 69, 102, .32); }
  body { background: #54bce9; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
