/* ─── Reset & Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #080814;
  --surface: rgba(255,255,255,0.05);
  --surface-hover: rgba(255,255,255,0.09);
  --border: rgba(255,255,255,0.12);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #475569;
  --accent: #818cf8;
  --accent2: #a78bfa;
  --cyan: #67e8f9;
  --green: #4ade80;
  --radius: 12px;
  --radius-sm: 8px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Star Background ───────────────────────────────────────────────── */
.stars {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(99,102,241,0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(167,139,250,0.1) 0%, transparent 60%),
    #080814;
}
.stars::before, .stars::after {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 15%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1px 1px at 25% 60%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 40% 25%, rgba(255,255,255,0.9) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 80%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 10%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 45%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 15% 85%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 75%, rgba(255,255,255,0.9) 0%, transparent 100%),
    radial-gradient(1px 1px at 35% 95%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 65% 55%, rgba(255,255,255,0.7) 0%, transparent 100%);
}
.stars::after {
  background-image:
    radial-gradient(1px 1px at 5%  40%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 20% 70%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 5%,  rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 35%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 75% 90%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 95% 20%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 50%, rgba(167,139,250,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 80% 60%, rgba(103,232,249,0.5) 0%, transparent 100%);
}

/* ─── Home Page ─────────────────────────────────────────────────────── */
.home-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.home-main {
  position: relative; z-index: 1;
  width: 100%; max-width: 480px;
  padding: 2rem 1.25rem;
  display: flex; flex-direction: column; gap: 2rem;
}

.home-header { text-align: center; }

.logo-star {
  display: inline-block;
  font-size: 2.5rem; color: var(--accent);
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.95); }
}

h1 {
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #818cf8, #c084fc, #67e8f9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline { color: var(--text-muted); font-size: 1.05rem; margin-top: 0.4rem; }

/* ─── Form ──────────────────────────────────────────────────────────── */
.sky-form { display: flex; flex-direction: column; gap: 1.25rem; }

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }

label {
  font-size: 0.875rem; font-weight: 600;
  color: var(--text-muted); letter-spacing: 0.03em; text-transform: uppercase;
}

input[type="date"], input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 0.75rem 1rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  -webkit-appearance: none;
  color-scheme: dark;
}
input:focus {
  border-color: var(--accent);
  background: rgba(129,140,248,0.08);
}
input.error { border-color: #f87171; }

.city-wrap { position: relative; }

.city-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: #1a1a3e; border: 1px solid var(--border);
  border-radius: var(--radius-sm); list-style: none;
  z-index: 100; max-height: 260px; overflow-y: auto;
  display: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.city-dropdown.open { display: block; }
.city-dropdown li {
  padding: 0.65rem 1rem; cursor: pointer; font-size: 0.95rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  transition: background 0.15s;
}
.city-dropdown li:last-child { border-bottom: none; }
.city-dropdown li:hover, .city-dropdown li.highlighted { background: var(--surface-hover); }
.city-dropdown li .city-country { font-size: 0.8rem; color: var(--text-muted); margin-left: 0.5rem; }

.field-error { font-size: 0.82rem; color: #f87171; min-height: 1.2em; }
.form-error {
  font-size: 0.9rem; color: #f87171; background: rgba(248,113,113,0.1);
  border-radius: var(--radius-sm); padding: 0.6rem 0.8rem;
  display: none;
}
.form-error.visible { display: block; }

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white; border: none; border-radius: var(--radius-sm);
  padding: 0.85rem 1.5rem; font-size: 1rem; font-weight: 700;
  cursor: pointer; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  transition: opacity 0.2s, transform 0.1s;
  position: relative; overflow: hidden;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary.btn-alt { background: linear-gradient(135deg, #0891b2, #0e7490); }
.btn-primary.btn-wide { margin-bottom: 0.25rem; }

.btn-secondary {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.75rem 1.5rem; font-size: 0.9rem; cursor: pointer; width: 100%;
  transition: border-color 0.2s, color 0.2s; text-decoration: none;
  display: block; text-align: center;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { width: auto; padding: 0.4rem 0.9rem; font-size: 0.82rem; }

/* "Make one for a friend" — small ghost link on home page */
.link-friend {
  display: block; text-align: center;
  color: var(--text-dim); font-size: 0.85rem;
  text-decoration: underline; text-decoration-color: rgba(255,255,255,0.15);
  padding: 0.5rem; cursor: pointer;
  transition: color 0.2s;
}
.link-friend:hover { color: var(--text-muted); }

.btn-spinner {
  display: none; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-primary.loading .btn-spinner { display: block; }
.btn-primary.loading .btn-text { opacity: 0.7; }

/* ─── Home Footer ───────────────────────────────────────────────────── */
.home-footer { text-align: center; color: var(--text-dim); font-size: 0.78rem; line-height: 1.8; }

/* ─── Result Page ───────────────────────────────────────────────────── */
.result-body { display: block; }

.result-nav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: rgba(8,8,20,0.8); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-logo {
  font-weight: 800; font-size: 1.1rem; color: var(--accent);
  text-decoration: none; letter-spacing: 0.02em;
}

.result-header {
  position: relative; z-index: 1;
  text-align: center; padding: 2.5rem 1.25rem 1rem;
}
.result-date {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 800; letter-spacing: -0.02em;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.result-city { font-size: 1.15rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ─── Panels ────────────────────────────────────────────────────────── */
.result-main {
  position: relative; z-index: 1;
  max-width: 700px; margin: 0 auto;
  padding: 0 1rem 3rem;
  display: flex; flex-direction: column; gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  backdrop-filter: blur(8px);
}

.panel-title {
  font-size: 0.8rem; font-weight: 700;
  color: var(--text-muted); letter-spacing: 0.1em; text-transform: uppercase;
  margin-bottom: 1rem;
}

.panel-sub { font-size: 0.82rem; color: var(--text-dim); margin-top: 0.75rem; }
.panel-credit { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.5rem; }
.panel-unavailable { color: var(--text-muted); font-style: italic; font-size: 0.95rem; }

/* APOD */
.apod-img {
  width: 100%; border-radius: var(--radius-sm);
  display: block; margin-bottom: 1rem;
  object-fit: cover; max-height: 400px;
}
.apod-video-wrap {
  background: rgba(0,0,0,0.4); border-radius: var(--radius-sm);
  padding: 2rem; text-align: center; margin-bottom: 1rem;
}
.apod-video-link { color: var(--cyan); font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.apod-video-link:hover { text-decoration: underline; }
.apod-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.5rem; }
.apod-explanation { font-size: 0.88rem; color: var(--text-muted); line-height: 1.65; margin-bottom: 0.5rem; }
.apod-credit { font-size: 0.78rem; color: var(--text-dim); }
.apod-credit a { color: var(--accent); text-decoration: none; }
.apod-credit a:hover { text-decoration: underline; }
.apod-no-img { padding: 1rem; text-align: center; color: var(--text-dim); }

.fallback-banner {
  background: rgba(251,191,36,0.1); border: 1px solid rgba(251,191,36,0.3);
  border-radius: var(--radius-sm); padding: 0.65rem 0.85rem;
  font-size: 0.83rem; color: #fbbf24; margin-bottom: 1rem; line-height: 1.5;
}

/* Asteroids — bars share a common left origin; percentage widths prevent overflow */
.asteroid-list { display: flex; flex-direction: column; gap: 0.6rem; }
.asteroid-row {
  display: grid;
  /* name col: shrinks if needed; bar col: fills remaining space; dist: auto */
  grid-template-columns: minmax(0, 140px) minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: 0.5rem; row-gap: 0.1rem;
  align-items: center; font-size: 0.87rem;
  min-width: 0; /* prevent grid from overflowing parent */
}
.asteroid-name {
  font-weight: 600; color: var(--accent2); grid-column:1; grid-row:1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.asteroid-bar-track {
  grid-column:2; grid-row:1;
  display: flex; align-items: center;
  width: 100%; min-width: 0; overflow: hidden;
}
.asteroid-bar {
  height: 6px; background: linear-gradient(90deg, #8b5cf6, #a78bfa);
  border-radius: 3px; min-width: 2px;
  /* width set inline as %; no fixed px so narrow viewports stay within bounds */
}
.asteroid-dist { grid-column:3; grid-row:1; color: var(--cyan); font-size: 0.82rem; white-space: nowrap; }
.asteroid-size { grid-column:2; grid-row:2; color: var(--text-dim); font-size: 0.76rem; }

/* Weather */
.weather-badge { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 0.75rem; }
.weather-icon { font-size: 3rem; flex-shrink: 0; line-height: 1; }
.weather-info { display: flex; flex-direction: column; gap: 0.25rem; }
.weather-condition { font-size: 1.15rem; font-weight: 700; }
.weather-temp {
  display: flex; align-items: baseline; gap: 0.4rem;
  font-size: 1.05rem; font-weight: 600; color: var(--cyan);
  flex-wrap: wrap;
}
.temp-sep { color: var(--text-muted); font-size: 0.85rem; font-weight: 400; }

/* Story */
.story-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem;
  margin-bottom: 1rem;
}
.story-controls .panel-title { flex: 1; margin-bottom: 0; }

.tone-toggle, .unit-toggle {
  display: flex; gap: 0; border-radius: var(--radius-sm);
  border: 1px solid var(--border); overflow: hidden;
}
.tone-btn, .unit-btn {
  background: transparent; border: none;
  padding: 0.35rem 0.75rem; font-size: 0.8rem; cursor: pointer; color: var(--text-muted);
  transition: background 0.2s, color 0.2s;
}
.tone-btn.active, .unit-btn.active {
  background: var(--accent); color: white; font-weight: 700;
}
.tone-btn:not(.active):hover, .unit-btn:not(.active):hover {
  background: var(--surface-hover); color: var(--text);
}

.story-text { line-height: 1.8; color: var(--text); }
.story-text p { margin-bottom: 0.75rem; }
.story-text p:last-child { margin-bottom: 0; }

/* Share section */
.share-section {
  padding: 0.5rem 0;
  display: flex; flex-direction: column; gap: 0.6rem;
}
.share-credits { text-align: center; color: var(--text-dim); font-size: 0.75rem; line-height: 1.7; }

/* ─── Animations ────────────────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.panel { animation: fadeInUp 0.4s ease both; }
.panel:nth-child(1) { animation-delay: 0.05s; }
.panel:nth-child(2) { animation-delay: 0.12s; }
.panel:nth-child(3) { animation-delay: 0.19s; }
.panel:nth-child(4) { animation-delay: 0.26s; }

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(120px);
  background: #1e293b; color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.65rem 1.25rem;
  font-size: 0.9rem; z-index: 999; transition: transform 0.3s ease;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ─── Link styling (dark theme) ─────────────────────────────────────── */
a {
  color: var(--accent2);
  text-decoration: none;
}
a:hover { text-decoration: underline; }
/* Exceptions: nav logo and APOD link keep their accent colour */
.nav-logo { color: var(--accent); }
.nav-logo:hover { text-decoration: none; opacity: 0.85; }
.apod-credit a { color: var(--accent); }

/* ─── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .result-main { padding: 0 0.75rem 3rem; }
  .panel { padding: 1.1rem; }
  .asteroid-row { grid-template-columns: 120px 1fr auto; }
  .asteroid-name { font-size: 0.82rem; }
  .weather-icon { font-size: 2.5rem; }
}

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