:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #03050b;
  color: #f6f5f0;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #03050b;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button {
  color: inherit;
  font: inherit;
}

.app {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-width: 280px;
  min-height: 520px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(33, 41, 61, 0.19), transparent 44%),
    linear-gradient(180deg, #070a12 0%, #020309 100%);
  isolation: isolate;
  touch-action: none;
  transform-origin: 0 0;
}

#space {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#planet-stage {
  position: absolute;
  z-index: 2;
  inset: 0;
  opacity: 0;
  transform: scale(0.86);
  pointer-events: none;
  transition:
    opacity 480ms ease,
    transform 700ms cubic-bezier(.18, .82, .2, 1);
  will-change: opacity, transform;
}

#planet-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.topbar {
  position: absolute;
  z-index: 3;
  top: max(24px, calc(env(safe-area-inset-top) + 14px));
  left: max(22px, calc(env(safe-area-inset-left) + 18px));
  right: max(22px, calc(env(safe-area-inset-right) + 18px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: rgba(246, 245, 240, 0.56);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.19em;
  pointer-events: none;
  transition: opacity 380ms ease;
}

.eyebrow::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 1px;
  margin: 0 8px 3px 0;
  background: #d7b978;
}

.planet-hits {
  position: absolute;
  z-index: 4;
  inset: 0;
  transition: opacity 300ms ease;
  pointer-events: none;
}

.planet-hit {
  position: absolute;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.planet-hit:focus-visible {
  outline: 1px solid rgba(255, 224, 163, 0.9);
  outline-offset: 2px;
}

.planet-hit.is-sun {
  width: 64px;
  height: 64px;
}

.planet-hit.is-moon {
  width: 38px;
  height: 38px;
}

.planet-hit[class*="is-satellite-"] {
  width: 32px;
  height: 32px;
}

.close {
  position: absolute;
  z-index: 8;
  top: max(20px, calc(env(safe-area-inset-top) + 12px));
  right: max(18px, calc(env(safe-area-inset-right) + 14px));
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: rgba(9, 12, 21, 0.52);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.82) rotate(-30deg);
  transition: opacity 300ms ease, transform 420ms cubic-bezier(.2, .8, .2, 1), background 200ms ease;
  cursor: pointer;
}

.close:active {
  background: rgba(255, 255, 255, 0.1);
}

.close span {
  position: absolute;
  top: 21px;
  left: 13px;
  width: 17px;
  height: 1px;
  background: rgba(255, 255, 255, 0.84);
}

.close span:first-child { transform: rotate(45deg); }
.close span:last-child { transform: rotate(-45deg); }

.planet-info {
  position: absolute;
  z-index: 6;
  right: max(26px, calc(env(safe-area-inset-right) + 22px));
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 18px));
  left: max(26px, calc(env(safe-area-inset-left) + 22px));
  opacity: 0;
  pointer-events: none;
  transform: translateY(22px);
  transition: opacity 420ms ease 80ms, transform 520ms cubic-bezier(.2, .8, .2, 1) 80ms;
}

.planet-info h1 {
  margin: 0 0 2px;
  font-family: "Songti SC", "STSong", serif;
  font-size: clamp(32px, 10vw, 46px);
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1.05;
}

.planet-info p {
  margin: 0;
  color: #d7b978;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.36em;
}

.planet-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 12px;
}

.planet-tags span {
  padding: 4px 7px;
  border: 1px solid rgba(215, 185, 120, 0.2);
  border-radius: 999px;
  background: rgba(215, 185, 120, 0.055);
  color: rgba(236, 216, 172, 0.78);
  font-size: 8px;
  line-height: 1;
  letter-spacing: 0.04em;
}

.planet-description {
  max-width: 46em;
  margin-top: 10px;
  padding-right: 48px;
  color: rgba(246, 245, 240, 0.66);
  font-size: clamp(10px, 2.75vw, 11px);
  line-height: 1.62;
  letter-spacing: 0.035em;
  text-align: justify;
}

.overview-hint {
  position: absolute;
  z-index: 3;
  bottom: max(26px, calc(env(safe-area-inset-bottom) + 18px));
  left: 50%;
  color: rgba(255, 255, 255, 0.35);
  font-size: 10px;
  letter-spacing: 0.18em;
  transform: translateX(-50%);
  transition: opacity 250ms ease;
  pointer-events: none;
}

.music-toggle {
  position: absolute;
  z-index: 9;
  right: max(20px, calc(env(safe-area-inset-right) + 16px));
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 16px));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(8, 11, 19, 0.52);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.speech-toggle {
  position: absolute;
  z-index: 9;
  right: max(20px, calc(env(safe-area-inset-right) + 16px));
  bottom: max(74px, calc(env(safe-area-inset-bottom) + 68px));
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(8, 11, 19, 0.52);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 280ms ease, transform 320ms ease, background 180ms ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.speech-toggle svg {
  width: 25px;
  height: 25px;
  overflow: visible;
}

.speaker-body {
  fill: rgba(255, 255, 255, 0.88);
}

.speaker-waves {
  fill: none;
  stroke: rgba(255, 255, 255, 0.52);
  stroke-width: 1.7;
  stroke-linecap: round;
  transition: stroke 180ms ease;
}

.speech-toggle.is-speaking {
  background: rgba(215, 185, 120, 0.1);
  border-color: rgba(215, 185, 120, 0.34);
}

.speech-toggle.is-speaking .speaker-waves {
  stroke: #d7b978;
}

.music-toggle span {
  width: 2px;
  height: 5px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.46);
  transition: height 220ms ease, background 220ms ease;
}

.music-toggle.is-on span {
  background: #d7b978;
  animation: sound-wave 1.1s ease-in-out infinite alternate;
}

.music-toggle.is-on span:nth-child(2) { animation-delay: -0.45s; }
.music-toggle.is-on span:nth-child(3) { animation-delay: -0.75s; }

@keyframes sound-wave {
  from { height: 5px; }
  to { height: 15px; }
}

.app.is-focused .topbar,
.app.is-focused .overview-hint,
.app.is-focused .planet-hits {
  opacity: 0;
  pointer-events: none;
}

.app.is-focused .close,
.app.is-focused .planet-info,
.app.is-focused .speech-toggle {
  opacity: 1;
  pointer-events: auto;
}

.app.is-focused .speech-toggle {
  transform: translateY(0);
}

.app.is-focused #planet-stage {
  opacity: 1;
  transform: scale(1);
}

.app.is-focused .close {
  transform: scale(1) rotate(0deg);
}

.app.is-focused .planet-info {
  transform: translateY(0);
}

@media (max-height: 650px) {
  .planet-info h1 { font-size: 30px; }
  .planet-info { bottom: max(14px, calc(env(safe-area-inset-bottom) + 8px)); }
  .planet-tags { margin-top: 7px; }
  .planet-tags span { padding: 3px 6px; font-size: 7px; }
  .planet-description { margin-top: 7px; font-size: 9px; line-height: 1.45; }
}

@media (min-width: 768px) and (orientation: landscape) {
  .planet-info {
    top: 61%;
    right: auto;
    bottom: auto;
    width: min(620px, 56vw);
    max-height: 36%;
    overflow-y: auto;
    padding: 0 0 max(18px, env(safe-area-inset-bottom));
    scrollbar-width: none;
  }

  .planet-info::-webkit-scrollbar { display: none; }
  .planet-info h1 { font-size: 42px; }
  .planet-tags { margin-top: 8px; }

  .planet-description {
    margin-top: 8px;
    padding-right: 0;
    font-size: 10px;
    line-height: 1.48;
  }

  .speech-toggle {
    top: max(82px, calc(env(safe-area-inset-top) + 70px));
    bottom: auto;
  }

  .music-toggle {
    top: max(136px, calc(env(safe-area-inset-top) + 124px));
    bottom: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
