:root {
  color-scheme: light;
  --bg-top: #8edcff;
  --bg-bottom: #f2fbff;
  --card-bg: rgba(255, 255, 255, 0.2);
  --card-border: rgba(255, 255, 255, 0.48);
  --text-main: #17304b;
  --text-soft: rgba(23, 48, 75, 0.72);
  --accent: #4678ff;
  --accent-strong: #2f5cf1;
  --accent-soft: rgba(70, 120, 255, 0.18);
  --danger: #ff6d6d;
  --shadow-lg: 0 24px 80px rgba(39, 74, 124, 0.22);
  --shadow-md: 0 12px 32px rgba(31, 54, 87, 0.16);
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.72), transparent 28%),
    linear-gradient(180deg, var(--bg-top) 0%, #b8ebff 42%, var(--bg-bottom) 100%);
  color: var(--text-main);
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: grid;
  place-items: center;
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.phone-frame {
  width: min(100vw, 480px);
}

.game-card {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  min-height: min(100vh - 24px, 720px);
  max-height: 100vh;
  border-radius: 34px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.12));
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
  transform: translateZ(0);
  touch-action: none;
  outline: none;
}

.game-card:focus {
  outline: none;
}

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

.sky-glow {
  position: absolute;
  border-radius: 999px;
  filter: blur(18px);
  opacity: 0.55;
  pointer-events: none;
}

.sky-glow-left {
  width: 140px;
  height: 140px;
  top: 12%;
  left: -8%;
  background: rgba(255, 255, 255, 0.7);
}

.sky-glow-right {
  width: 180px;
  height: 180px;
  top: 38%;
  right: -10%;
  background: rgba(121, 196, 255, 0.55);
}

.hud {
  position: absolute;
  top: var(--safe-top);
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 4;
}

.hud-pill,
.hud-button {
  min-height: 48px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.44);
  background: rgba(255, 255, 255, 0.26);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-md);
}

.hud-pill {
  min-width: 84px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hud-pill-secondary {
  background: rgba(235, 247, 255, 0.3);
}

.hud-label {
  font-size: 12px;
  color: var(--text-soft);
}

.hud-pill strong {
  font-size: 22px;
  line-height: 1.15;
}

.hud-button {
  margin-left: auto;
  padding: 0 18px;
  color: var(--text-main);
  font-weight: 700;
  transition: transform 0.18s ease, background 0.18s ease;
}

.hud-button:active,
.primary-button:active,
.ghost-button:active {
  transform: scale(0.97);
}

.overlay-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px var(--safe-bottom);
  pointer-events: none;
}

.panel {
  width: min(100%, 390px);
  padding: 24px 20px;
  border-radius: 28px;
  background: rgba(249, 253, 255, 0.78);
  backdrop-filter: blur(22px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 24px 60px rgba(32, 62, 99, 0.18);
  text-align: center;
  pointer-events: auto;
  animation: panelFloat 0.45s ease;
}

.panel h1,
.panel h2 {
  margin: 14px 0 10px;
  font-size: clamp(28px, 7vw, 40px);
  line-height: 1.08;
}

.panel h2 {
  font-size: clamp(26px, 6vw, 34px);
}

.panel-subtitle {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.7;
}

.brand-chip,
.state-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(70, 120, 255, 0.14);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.state-badge-danger {
  background: rgba(255, 109, 109, 0.14);
  color: #cb4141;
}

.feature-grid,
.result-grid {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.feature-card,
.result-card {
  padding: 14px 14px 15px;
  border-radius: 20px;
  text-align: left;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 30px rgba(78, 111, 154, 0.08);
}

.feature-title,
.result-card span {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--text-soft);
}

.feature-copy {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-main);
}

.result-card {
  text-align: center;
}

.result-card strong {
  font-size: 32px;
}

.start-actions,
.pause-actions {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.difficulty-section {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

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

.difficulty-button {
  min-height: 48px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(149, 180, 219, 0.32);
  color: var(--text-main);
  font-weight: 800;
}

.difficulty-button-active {
  color: white;
  background: linear-gradient(180deg, #5c8dff 0%, #3f6ef7 100%);
  box-shadow: 0 12px 24px rgba(63, 110, 247, 0.24);
}

.debug-tip {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(19, 39, 66, 0.08);
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
  display: none;
}

.primary-button,
.ghost-button {
  min-height: 56px;
  width: 100%;
  border-radius: 20px;
  font-weight: 800;
  letter-spacing: 0.01em;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.primary-button {
  color: white;
  background: linear-gradient(180deg, #5c8dff 0%, #3f6ef7 100%);
  box-shadow: 0 18px 36px rgba(63, 110, 247, 0.32);
}

.ghost-button {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(149, 180, 219, 0.32);
}

.gesture-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-soft);
}

.debug-tip {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(19, 39, 66, 0.08);
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.tip-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(70, 120, 255, 0.13);
}

.touch-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.touch-ring {
  position: absolute;
  width: 88px;
  height: 88px;
  margin-left: -44px;
  margin-top: -44px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.42) 0%, rgba(92, 141, 255, 0.18) 48%, rgba(92, 141, 255, 0) 72%);
  transform: scale(0.6);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.touch-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 28px);
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(19, 39, 66, 0.2);
  color: white;
  font-size: 13px;
  letter-spacing: 0.04em;
  opacity: 0.9;
  transition: opacity 0.2s ease;
}

.touch-layer.active .touch-ring {
  transform: scale(1);
  opacity: 1;
}

.touch-layer.active .touch-hint {
  opacity: 0.35;
}

.hidden {
  display: none;
}

@keyframes panelFloat {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 0;
  }

  .phone-frame {
    width: 100vw;
  }

  .game-card {
    min-height: 100vh;
    border-radius: 0;
    border: 0;
  }

  .overlay-layer {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (max-height: 720px) {
  .panel {
    padding: 20px 16px;
  }

  .feature-grid,
  .result-grid,
  .start-actions,
  .pause-actions {
    gap: 10px;
    margin-top: 16px;
  }

  .feature-card,
  .result-card {
    padding: 12px;
  }
}
