* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  background: #0f172a;
  /* Always allow vertical scrolling so content is never clipped in a short viewport */
  overflow-y: auto;
  overflow-x: hidden;
}

body {
  font-family: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(to bottom, #0f172a, #1e293b, #0f172a);
  color: white;
  min-height: 100vh;
  /* Let the page grow with its content rather than clipping it */
  height: auto;
  overflow: visible;
}

/* Fit mode (set by script.js in the wide layout): the app is laid out at a fixed design width and
   scaled with a transform to fill the frame, so nothing is ever clipped at any frame size. */
html.fit,
html.fit body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

html.fit body {
  position: relative;
}

html.fit .app-container {
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  margin: 0;
  background: none;
  transform-origin: 0 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Fluid width so the interactive fills whatever iframe it is embedded in */
.app-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  background: linear-gradient(to bottom, #0f172a, #1e293b, #0f172a);
}

.main-content {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0.75rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
}

/* Header Styles */
.header {
  margin-bottom: 0.75rem;
  text-align: left;
}

.header h1 {
  font-family: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: clamp(1.5rem, 1rem + 2.5vw, 2rem);
  font-weight: bold;
  line-height: 1.2;
  margin-bottom: 0.5rem;
}

.header p {
  font-size: 1rem;
  line-height: 1.5;
  color: #cbd5e1;
}

/* Input Card Styles */
.input-card {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
  width: 100%;
}

.input-content {
  padding: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1rem;
}

.input-label {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1f2937;
}

.input-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.weight-input {
  width: 5rem;
  padding: 0.5rem;
  text-align: center;
  background: #fff;
  color: #1f2937;
  border: 1px solid #6b7280;
  border-radius: 0.375rem;
  font-size: 1rem;
}

.weight-input::placeholder {
  color: #6b7280;
  opacity: 1;
}

.weight-input[aria-invalid="true"] {
  border: 2px solid #b91c1c;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.enter-button {
  padding: 0.5rem 1rem;
  background: #1d4ed8;
  color: #fff;
  border: 1px solid #1d4ed8;
  border-radius: 0.375rem;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.enter-button:hover {
  background: #1e40af;
  border-color: #1e40af;
}

.weight-input:focus-visible,
.enter-button:focus-visible,
.radio-item input[type="radio"]:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
}

.input-error {
  color: #b91c1c;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}

.input-error:not(:empty) {
  padding: 0 1rem 1rem;
}

.radio-group {
  display: flex;
  gap: 1rem;
  border: 0;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.5rem;
}

.radio-item input[type="radio"] {
  margin: 0;
  width: 1.25rem;
  height: 1.25rem;
  accent-color: #1d4ed8;
  cursor: pointer;
}

.radio-item label {
  font-size: 1rem;
  color: #1f2937;
  padding: 0.25rem 0.25rem 0.25rem 0;
  cursor: pointer;
}

/* Current Weight Display Section */
.current-weight-display {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
  width: 100%;
  text-align: center;
  padding: 0.75rem;
}

.current-weight-display[hidden],
.results-card[hidden] {
  display: none;
}

.current-weight-display p {
  font-size: 1.35rem;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
}

/* Solar System Container */
.solar-system-container {
  position: relative;
  width: 100%;
  background: linear-gradient(to right, #000000, #1e293b, #000000);
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
}

.stars-background {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

.star {
  position: absolute;
  width: 1px;
  height: 1px;
  background: white;
  border-radius: 50%;
  opacity: 0.7;
  /* Finite iteration count keeps total twinkling under 5 seconds (WCAG 2.2.2) */
  animation: twinkle 2s linear 2;
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.7;
  }
  25% {
    opacity: 0.3;
  }
  75% {
    opacity: 1;
  }
}

/* Narrow layout: compact vertical list, Sun at the top through Neptune at the bottom */
.planets-list {
  --slot: 2.5rem;
  --stack-unit: 1.75rem;
  position: relative;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: fit-content;
  margin: 0 auto;
  /* Right padding leaves room for the astronaut beside the longest name */
  padding: 1rem 3.5rem 1rem 1rem;
}

.planet-button {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-width: 1.5rem;
  min-height: 1.75rem;
  padding: 0.125rem 0.75rem 0.125rem 0.25rem;
  background: none;
  border: none;
  border-radius: 0.5rem;
  color: white;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.planet-button:focus {
  outline: none;
}

.planet-button:focus-visible {
  outline: 3px solid white;
  outline-offset: 2px;
}

.planet-button:disabled {
  cursor: not-allowed;
}

/* The wrapper carries the round selection ring so the image itself is never
   clipped to a circle (Saturn's rings extend into the corners). */
.planet-image {
  display: block;
  flex-shrink: 0;
  width: calc(var(--stack-unit) * var(--stack-scale, 1));
  margin-inline: calc((var(--slot) - var(--stack-unit) * var(--stack-scale, 1)) / 2);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  transition: transform 0.3s ease;
}

.planet-image img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
}

.planet-button:not(:disabled):hover .planet-image {
  transform: scale(1.1);
}

.planet-button[aria-pressed="true"] {
  background: rgba(251, 191, 36, 0.15);
}

.planet-button[aria-pressed="true"] .planet-image {
  box-shadow: 0 0 0 3px #fbbf24;
}

.planet-label {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

/* Wide layout: single row of planets sized relative to one another */
@media (min-width: 44em) {
  .planets-list {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0;
    width: auto;
    margin: 0;
    /* Kept compact so the whole interactive fits in a 700px-tall frame */
    padding: clamp(1.5rem, 3vw, 2rem) 2%;
  }

  /* Reserve the weight bar's space before a weight is entered so the layout (and the
     fit-to-frame scale) does not jump when it appears */
  .current-weight-display[hidden] {
    display: block;
    visibility: hidden;
  }

  .planets-list li {
    flex: 0 0 calc(var(--row-share) * 1%);
    min-width: 0;
  }

  .planet-button {
    flex-direction: column;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0;
    text-align: center;
  }

  .planet-button:focus-visible {
    outline-offset: 4px;
  }

  .planet-button[aria-pressed="true"] {
    background: none;
  }

  .planet-image {
    width: 100%;
    margin-inline: 0;
  }

  .planet-label {
    font-size: clamp(0.875rem, 2vw, 1rem);
  }

  /* Where supported, size planets from the row width so each slot can grow to fit its label */
  @supports (width: 1cqw) {
    .planets-list {
      container-type: inline-size;
    }

    .planets-list li {
      flex: 0 0 auto;
    }

    .planet-image {
      width: calc(var(--row-share) * 1cqw);
    }
  }
}

.astronaut {
  position: absolute;
  left: 0;
  top: 0;
  transition: left 0.5s ease, top 0.5s ease;
  pointer-events: none;
  z-index: 10;
  transform: translate(-50%, -50%);
}

.astronaut.no-transition {
  transition: none;
}

.astronaut img {
  display: block;
  width: clamp(32px, 5vw, 56px);
  height: clamp(32px, 5vw, 56px);
}

/* Results Card */
.results-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
}

.results-content {
  padding: 1rem;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.results-header h2 {
  font-size: clamp(1.125rem, 3vw, 1.25rem);
  font-weight: bold;
  color: #1f2937;
}

.planet-description {
  color: #374151;
  line-height: 1.6;
  font-size: clamp(0.875rem, 2vw, 1rem);
}

/* Credits */
.credits {
  text-align: center;
}

.credits p {
  font-size: 0.75rem;
  color: #9ca3af;
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  .star {
    animation: none;
  }

  .astronaut,
  .planet-image {
    transition: none;
  }

  .planet-button:not(:disabled):hover .planet-image {
    transform: none;
  }
}
