:root {
  --bg: #0c0f12;
  --ink: #e8eff6;
  --accent: #37d0ff;
  --danger: #ff6f5e;
  --safe: #1a222d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(circle at 50% -12%, #1a2a3d 0%, rgba(26, 42, 61, 0) 48%),
    linear-gradient(180deg, #0b1622 0%, #0c1118 60%, #0a0f16 100%);
}
body {
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: var(--ink);
  touch-action: manipulation;
  user-select: none;
}

#app {
  height: 100svh;
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: 1fr;
  padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom);
}

.stagehud {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 3;
  pointer-events: none;
}
.topstats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.topstats p {
  margin: 0;
  padding: 2px 4px;
  font-size: 1rem;
  transition: transform 0.12s ease, color 0.12s ease, text-shadow 0.12s ease;
  text-shadow: 0 1px 0 #000, 0 2px 6px #000;
}
.topstats b { font-size: 0.9rem; letter-spacing: 0.06em; color: #b8cbe0; margin-right: 8px; }
.topstats span { color: #e9f6ff; font-weight: 900; font-size: 1.38em; }
#timeCard { text-align: left; }
#scoreCard { text-align: right; }
#scoreCard.fx {
  transform: translateY(-1px) scale(1.03);
  text-shadow: 0 1px 0 #000, 0 0 12px #37d0ffcc, 0 0 24px #37d0ff66;
}
#timeCard.danger {
  animation: dangerPulse 0.45s infinite;
  text-shadow: 0 1px 0 #000, 0 0 11px #ff6f5ea8;
}
#timeCard.danger span { color: #ff8f7a; }

#gameWrap {
  position: relative;
  min-height: 0;
  border: 1px solid #223040;
  border-radius: 14px;
  overflow: hidden;
  background: transparent;
}
canvas { width: 100%; height: 100%; display: block; }

.stagecontrols {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  pointer-events: none;
}
#gameWrap.title-mode .stagehud,
#gameWrap.title-mode .stagecontrols {
  display: none;
}
.move-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  pointer-events: auto;
}
.move-actions > * { min-width: 0; }
.charge-panel {
  height: 14px;
  background: transparent;
  padding: 0;
  display: flex;
  align-items: center;
  pointer-events: auto;
}
.charge-meter {
  height: 100%;
  width: 100%;
  margin-top: 0;
  border-radius: 0;
  background: #0b1118cc;
  overflow: hidden;
}
.charge-meter i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #2c89ff 0%, #37d0ff 55%, #9af4ff 100%);
  box-shadow: 0 0 12px #2ca8ff88;
}

button {
  border: none;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0.06em;
}
.move-btn {
  width: 100%;
  height: 54px;
  border-radius: 14px;
  background: linear-gradient(180deg, #1a2a3f, #101b2a);
  border: 1px solid #355174;
  color: #e9f4ff;
  font-size: 1.45rem;
  line-height: 1;
  touch-action: manipulation;
}
.move-btn:active { transform: scale(0.98); }
.fire {
  width: 100%;
  height: 54px;
  border-radius: 14px;
  background: linear-gradient(180deg, #5a8a1f, #2e4f12);
  border: 1px solid #9ad94a;
  color: #f4ffe6;
  text-shadow: 0 1px 0 #1e330c;
  touch-action: manipulation;
}
.fire.enabled {
  background: linear-gradient(180deg, #b8f233, #5ea81e);
  border-color: #d4ff70;
  box-shadow: 0 0 20px #8cd63b99, inset 0 0 10px #e8ff9b66;
}
.fire.pulse { animation: pulse 0.95s infinite; }
.fire:disabled { opacity: 0.45; }

.overlay, .result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #060a10cc;
}
.panel {
  width: min(88%, 360px);
  padding: 16px;
  border-radius: 14px;
  border: 1px solid #2d4158;
  background: #101722f2;
  text-align: center;
}
.overlay.title .panel {
  width: min(92%, 420px);
  padding: 20px 18px;
}
.title-image {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  margin: 2px auto 10px;
  border-radius: 10px;
  border: 1px solid #2a3b50;
}
.overlay.title .title-image {
  max-width: 390px;
  margin: 0 auto 12px;
}
.overlay.title h2 {
  font-size: 1.36rem;
  margin: 8px 0 12px;
}
.panel h2 { margin: 6px 0 10px; font-size: 1.15rem; }
.panel p { margin: 7px 0; }
.panel .small { font-size: 0.75rem; opacity: 0.8; }
.panel .legal {
  margin-top: 10px;
  font-size: 0.66rem;
  opacity: 0.72;
  letter-spacing: 0.02em;
}
.panel .share-status {
  margin-top: 8px;
  color: #b7ddff;
  text-shadow: 0 1px 0 #000;
}
.panel .seed { color: var(--accent); font-size: 0.8rem; }
.row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.ad-wrap {
  margin-top: 12px;
  min-height: 54px;
  border: 1px dashed #3a5068;
  border-radius: 8px;
  padding: 4px;
}
.primary, .ghost {
  padding: 10px 14px;
  border-radius: 10px;
  min-width: 110px;
}
.primary { background: var(--accent); color: #00131a; }
.ghost { background: #1d2530; border: 1px solid #345; }
.hidden { display: none; }

@keyframes pulse {
  0% { transform: scale(1); filter: brightness(1); }
  60% { transform: scale(1.06); filter: brightness(1.25); }
  100% { transform: scale(1); filter: brightness(1); }
}
@keyframes dangerPulse {
  0% { transform: translateX(0); box-shadow: 0 0 0 #ff6f5e00; }
  25% { transform: translateX(-0.5px); box-shadow: 0 0 14px #ff6f5e55; }
  75% { transform: translateX(0.5px); box-shadow: 0 0 10px #ff6f5e35; }
  100% { transform: translateX(0); box-shadow: 0 0 0 #ff6f5e00; }
}

@media (max-height: 680px) {
  .topstats p { padding: 7px; font-size: 0.7rem; }
  .stagecontrols { bottom: calc(8px + env(safe-area-inset-bottom)); }
  .move-btn, .fire { height: 48px; }
  .charge-panel { height: 12px; }
}
