:root {
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ink: #0b1320;
  --orange: #FF8A3D;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b1320;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #0b1320;
}

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

/* ---------- pause ---------- */
.icon-btn {
  position: fixed;
  z-index: 12;
  top: calc(11px + var(--safe-t));
  left: calc(12px + var(--safe-l));
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 13px;
  background: rgba(17, 29, 48, 0.72);
  box-shadow: 0 6px 18px rgba(4, 10, 20, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.icon-btn span {
  display: block;
  width: 4px;
  height: 15px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.25);
}
.icon-btn:active { transform: scale(0.92); background: rgba(255, 138, 61, 0.55); }

/* ---------- lane pads ---------- */
.pad {
  position: fixed;
  z-index: 10;
  top: 45%;
  transform: translateY(-50%);
  width: clamp(52px, 15vh, 74px);
  height: clamp(52px, 15vh, 74px);
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: radial-gradient(circle at 36% 28%, rgba(255, 255, 255, 0.24), rgba(13, 25, 44, 0.55) 68%);
  box-shadow: 0 8px 22px rgba(3, 9, 18, 0.32), inset 0 0 16px rgba(255, 138, 61, 0.14);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease, border-color 0.1s ease;
}
.pad-left { left: calc(12px + var(--safe-l)); }
.pad-right { right: calc(12px + var(--safe-r)); }
.pad svg { width: 44%; height: 44%; filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.35)); }
.pad:active {
  transform: translateY(-50%) scale(0.92);
  border-color: rgba(255, 186, 120, 0.9);
  background: radial-gradient(circle at 36% 28%, rgba(255, 210, 160, 0.6), rgba(255, 122, 34, 0.55) 72%);
}

/* ---------- hint ---------- */
.hint {
  position: fixed;
  z-index: 11;
  top: calc(64px + var(--safe-t));
  left: 50%;
  transform: translate(-50%, -6px);
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 20, 36, 0.62);
  box-shadow: 0 8px 20px rgba(4, 10, 20, 0.24);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  color: rgba(255, 255, 255, 0.94);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(18px + var(--safe-r)) calc(16px + var(--safe-b)) calc(18px + var(--safe-l));
  background: rgba(5, 10, 19, 0.62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.22s ease;
}
.overlay[hidden] { display: none; }
.overlay.show { opacity: 1; }

.panel {
  width: min(360px, 100%);
  padding: 18px 20px 20px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 138, 61, 0.16), rgba(255, 138, 61, 0) 55%),
    linear-gradient(180deg, #1b2942 0%, #101b2e 100%);
  box-shadow: 0 26px 64px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.09);
  text-align: center;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.overlay.show .panel { transform: translateY(0) scale(1); }

.eyebrow {
  margin: 0 0 4px;
  color: rgba(255, 180, 120, 0.9);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
}
.panel h1 {
  margin: 0;
  color: #fff;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.stats {
  margin: 14px 0 2px;
  color: #ffb36c;
  font-size: 34px;
  line-height: 1.1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 6px 20px rgba(255, 122, 34, 0.25);
}
.overlay[data-mode="pause"] .stats {
  color: #f2f6ff;
  font-size: 16px;
  font-weight: 700;
  text-shadow: none;
}
.best {
  margin: 4px 0 16px;
  color: rgba(233, 241, 255, 0.62);
  font-size: 12px;
  font-weight: 600;
  min-height: 15px;
}
.btn {
  display: block;
  width: 100%;
  min-height: 46px;
  margin-top: 9px;
  padding: 0 16px;
  border-radius: 13px;
  border: 0;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.1s ease;
}
.btn:active { transform: scale(0.98); filter: brightness(0.96); }
.btn.primary {
  color: #2a1303;
  background: linear-gradient(180deg, #ffae6b 0%, #ff842e 60%, #ff7520 100%);
  box-shadow: 0 8px 22px rgba(255, 122, 34, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.btn.ghost {
  color: rgba(237, 243, 253, 0.9);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.btn[hidden] { display: none; }

@media (max-height: 430px) {
  .panel { padding: 14px 18px 16px; border-radius: 18px; }
  .panel h1 { font-size: 19px; }
  .stats { font-size: 29px; margin-top: 10px; }
  .overlay[data-mode="pause"] .stats { font-size: 15px; }
  .best { margin-bottom: 12px; }
  .btn { min-height: 42px; margin-top: 7px; font-size: 14px; }
  .hint { top: calc(58px + var(--safe-t)); }
}
