/* =============================================
   PLANET POP — clean mobile-friendly layout
============================================= */

:root {
  --pink: #ff6fb1;
  --yellow: #ffdc5e;
  --blue: #62d2ff;
  --purple: #7957c8;
  --deep: #07091f;
  --text: #263238;
  --card: rgba(255,255,255,0.92);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  width: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--text);
  font-family: "Nunito", "Comic Sans MS", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 12%, rgba(255,220,94,0.32) 0 7%, transparent 8%),
    radial-gradient(circle at 88% 18%, rgba(167,139,250,0.28) 0 10%, transparent 11%),
    linear-gradient(135deg, #090b2a 0%, #1b2358 48%, #4b286d 100%);
}

/* Same home button style as the newer games */
.home-btn {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 15px;
  border-radius: 999px;
  background: rgba(255,255,255,0.88);
  border: 3px solid rgba(255,255,255,0.96);
  color: var(--purple);
  font-family: "Baloo 2", system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 7px 24px rgba(0,0,0,0.22);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  touch-action: manipulation;
}

.home-btn:active {
  transform: scale(0.94);
}

.home-icon {
  font-size: 1.25rem;
  line-height: 1;
}

/* Mobile-first stacked layout */
.game-shell {
  width: min(980px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(70px, calc(env(safe-area-inset-top) + 62px))
    10px
    max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.intro-card,
.space-card {
  background: var(--card);
  border: 5px solid #fff;
  border-radius: 26px;
  box-shadow: 0 18px 48px rgba(0,0,0,0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.intro-card {
  text-align: center;
  padding: 16px 14px 14px;
}

.mini-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff7cc;
  border: 3px dashed #ffb703;
  color: #8a5a00;
  font-family: "Baloo 2", cursive;
  font-size: 0.8rem;
  font-weight: 900;
  margin-bottom: 7px;
}

h1 {
  font-family: "Baloo 2", cursive;
  font-size: clamp(2.35rem, 11vw, 4.8rem);
  line-height: 0.88;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--pink), 6px 6px 0 rgba(98,210,255,0.72);
  margin-bottom: 8px;
}

.instructions {
  font-size: clamp(0.95rem, 3.6vw, 1.25rem);
  line-height: 1.25;
  font-weight: 800;
  color: #4b6070;
  margin-bottom: 12px;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 9px;
  flex-wrap: wrap;
}

.stat {
  min-width: 96px;
  padding: 7px 13px;
  border-radius: 18px;
  background: rgba(255,255,255,0.76);
  border: 3px solid rgba(255,255,255,0.95);
}

.stat span {
  display: block;
  font-family: "Baloo 2", cursive;
  font-size: 0.62rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #8066a0;
  font-weight: 900;
}

.stat strong {
  display: block;
  font-family: "Baloo 2", cursive;
  font-size: 1.2rem;
  line-height: 1;
  color: #2a2258;
  font-weight: 900;
}

.space-card {
  min-height: 0;
  padding: 9px;
  display: grid;
  grid-template-rows: minmax(260px, 1fr) auto auto;
  gap: 9px;
  overflow: hidden;
}

#spaceCanvas {
  width: 100%;
  height: 100%;
  min-height: 260px;
  display: block;
  border-radius: 20px;
  background: radial-gradient(circle at 50% 20%, #263789 0%, #11183f 55%, #07091f 100%);
  touch-action: none;
}

.planet-name {
  min-height: 44px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 6px 12px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255,220,94,0.94), rgba(98,210,255,0.86));
  color: #2a2258;
  font-family: "Baloo 2", cursive;
  font-size: clamp(1.15rem, 5vw, 1.85rem);
  font-weight: 900;
  text-shadow: 1px 2px 0 rgba(255,255,255,0.45);
}

.game-btn {
  justify-self: center;
  border: none;
  border-radius: 999px;
  padding: 11px 24px;
  color: #fff;
  background: linear-gradient(135deg, #ff6fb1, #a78bfa);
  box-shadow: 0 8px 24px rgba(160,90,190,0.26);
  font-family: "Baloo 2", cursive;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.game-btn:active {
  transform: scale(0.96);
}

/* Phones */
@media (max-width: 520px) {
  .home-btn {
    width: 52px;
    height: 52px;
    min-height: 52px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .home-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
  }

  .game-shell {
    padding-top: max(70px, calc(env(safe-area-inset-top) + 58px));
  }

  .intro-card {
    padding-top: 14px;
  }

  .mini-badge {
    font-size: 0.74rem;
  }

  .space-card {
    grid-template-rows: minmax(300px, 1fr) auto auto;
  }
}

/* Portrait tablets */
@media (orientation: portrait) and (min-width: 700px) {
  .game-shell {
    max-width: 920px;
    padding-left: 16px;
    padding-right: 16px;
    gap: 16px;
  }

  .intro-card,
  .space-card {
    border-radius: 32px;
    border-width: 6px;
  }

  .space-card {
    min-height: calc(100dvh - 330px);
    grid-template-rows: minmax(430px, 1fr) auto auto;
    padding: 12px;
  }
}

/* Landscape tablets/desktops: side-by-side, but controlled and not cramped */
@media (orientation: landscape) and (min-width: 760px) {
  body {
    overflow: hidden;
  }

  .game-shell {
    width: 100%;
    max-width: 1180px;
    height: 100dvh;
    min-height: 0;
    padding:
      max(14px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left));
    grid-template-columns: minmax(230px, 31%) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
    gap: 14px;
  }

  .intro-card {
    min-height: 0;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  h1 {
    font-size: clamp(2.2rem, 5vw, 4rem);
  }

  .instructions {
    font-size: clamp(0.9rem, 1.7vw, 1.15rem);
  }

  .space-card {
    min-height: 0;
    height: 100%;
    grid-template-rows: minmax(0, 1fr) auto auto;
    padding: 10px;
  }

  #spaceCanvas {
    min-height: 0;
    height: 100%;
  }

  .planet-name {
    min-height: 40px;
    font-size: clamp(1.05rem, 2vw, 1.55rem);
  }

  .game-btn {
    padding: 9px 20px;
    font-size: 0.95rem;
  }
}

/* Very short landscape: hide badge and tighten spacing */
@media (orientation: landscape) and (max-height: 560px) {
  .mini-badge {
    display: none;
  }

  .intro-card {
    padding: 12px 10px;
  }

  .instructions {
    margin-bottom: 8px;
  }

  .stats {
    gap: 7px;
  }

  .stat {
    min-width: 82px;
    padding: 6px 9px;
    border-width: 2px;
  }

  .stat strong {
    font-size: 1rem;
  }

  .planet-name {
    min-height: 34px;
  }

  .game-btn {
    padding: 8px 18px;
  }
}
