*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0a1628;
  --text: #e8f4ff;
  --muted: rgba(232, 244, 255, 0.65);
  --accent: #5eead4;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  box-sizing: border-box;
}

/* Full-viewport playfield (respects safe area so canvas isn’t under notch/home bar) */
#main {
  position: absolute;
  inset: 0;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  box-sizing: border-box;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Match planet-destroyer: fixed offset from WebView top (native chrome / safe area). */
#hud {
  position: absolute;
  top: max(10px, calc(env(safe-area-inset-top, 0px) + 8px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  z-index: 10;
  pointer-events: none;
}

#hud-center {
  grid-column: 2;
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#pause-wrap {
  grid-column: 3;
  justify-self: end;
  align-self: start;
  pointer-events: auto;
}

#pause-wrap.hidden {
  visibility: hidden;
  pointer-events: none;
}

#pause-btn {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

#pause-btn:active {
  transform: scale(0.96);
  opacity: 0.92;
}

#pause-btn .icon-play {
  display: none;
}

#pause-btn.is-paused .icon-pause {
  display: none;
}

#pause-btn.is-paused .icon-play {
  display: block;
}

#score-wrap {
  min-width: 6ch;
  font-size: clamp(1.5rem, 5.5vw, 2.5rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#score-wrap.pulse {
  animation: scoreBounce 0.3s ease-out;
}

@keyframes scoreBounce {
  0% {
    transform: scale(1.1);
  }
  50% {
    transform: scale(1.35);
  }
  100% {
    transform: scale(1.25);
  }
}

/* Size set in JS: fixed grid, square cells scaled to capped board area. */
#game-canvas {
  display: block;
  flex-shrink: 0;
  touch-action: none;
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  border: 1px solid rgba(94, 234, 212, 0.15);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.hints-panel {
  position: absolute;
  left: 50%;
  bottom: max(10px, calc(env(safe-area-inset-bottom, 0px) + 8px));
  transform: translateX(-50%);
  width: min(92vw, 360px);
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.hint-short {
  margin: 0;
  padding: 8px 12px;
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9);
  background: rgba(10, 22, 40, 0.55);
  border-radius: 10px;
  width: 100%;
  box-sizing: border-box;
}

.hint-toggle {
  pointer-events: auto;
  margin: 0;
  padding: 6px 14px;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(10, 22, 40, 0.72);
  border: 1px solid rgba(94, 234, 212, 0.35);
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hint-toggle:active {
  opacity: 0.85;
}

.hint-details {
  margin: 0;
  padding: 10px 12px;
  text-align: left;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9);
  background: rgba(10, 22, 40, 0.72);
  border-radius: 10px;
  width: 100%;
  box-sizing: border-box;
  pointer-events: auto;
  max-height: 38vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.hint-details.hidden {
  display: none;
}

.hints-panel.playing .hint-short,
.hints-panel.playing .hint-toggle,
.hints-panel.playing .hint-details {
  display: none;
}

.float-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  overflow: visible;
}

.float-score-pop {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, 0);
  font-size: clamp(1.25rem, 5vw, 1.75rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #fef08a;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
  animation: floatScoreUp 0.55s ease-out forwards;
  z-index: 7;
}

@keyframes floatScoreUp {
  0% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -36px) scale(1.08);
  }
}

.game-over-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) 16px env(safe-area-inset-bottom, 0px);
  pointer-events: none;
  animation: goFadeIn 0.22s ease-out;
}

.game-over-overlay.hidden {
  display: none;
}

@keyframes goFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.game-over-card {
  max-width: 300px;
  width: 100%;
  padding: 18px 20px;
  text-align: center;
  background: rgba(10, 22, 40, 0.88);
  border: 1px solid rgba(94, 234, 212, 0.28);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.go-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
}

.go-reason {
  margin: 0 0 10px;
  font-size: 0.85rem;
  line-height: 1.35;
  color: #fca5a5;
  font-weight: 600;
}

.go-score {
  margin: 0 0 4px;
  font-size: 1.65rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.go-best {
  margin: 0 0 12px;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
}

.go-best.hidden {
  display: none;
}

.go-dismiss {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
}

@media (min-width: 700px) {
  #hud {
    top: max(16px, calc(env(safe-area-inset-top, 0px) + 12px));
    left: calc(20px + env(safe-area-inset-left, 0px));
    right: calc(20px + env(safe-area-inset-right, 0px));
  }

  #score-wrap {
    font-size: clamp(2rem, 4.5vw, 3.1rem);
  }

  #pause-btn {
    width: 44px;
    height: 44px;
    border-radius: 22px;
  }

  #game-canvas {
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.38);
  }

  .hints-panel {
    width: min(72vw, 440px);
    bottom: max(14px, calc(env(safe-area-inset-bottom, 0px) + 12px));
    gap: 8px;
  }

  .hint-short {
    padding: 10px 16px;
    font-size: 0.9rem;
    border-radius: 12px;
  }

  .hint-toggle {
    padding: 8px 18px;
    font-size: 0.82rem;
  }

  .hint-details {
    padding: 12px 16px;
    font-size: 0.84rem;
    border-radius: 12px;
  }

  .float-score-pop {
    font-size: clamp(1.5rem, 3.5vw, 2.2rem);
  }

  .game-over-card {
    max-width: 360px;
    padding: 24px 28px;
    border-radius: 20px;
  }

  .go-title { font-size: 1.25rem; }
  .go-reason { font-size: 0.95rem; }
  .go-score { font-size: 2rem; }
  .go-best { font-size: 0.92rem; }
  .go-dismiss { font-size: 0.82rem; }
}

@media (min-width: 900px) {
  #score-wrap {
    font-size: clamp(2.4rem, 4vw, 3.5rem);
  }

  #pause-btn {
    width: 48px;
    height: 48px;
    border-radius: 24px;
  }

  .hints-panel {
    width: min(56vw, 500px);
  }

  .game-over-card {
    max-width: 400px;
    padding: 28px 32px;
  }

  .go-score { font-size: 2.35rem; }
}

