/* ── NASA Image Viewer — Space Theme ─────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Inter:wght@400;500;600;700&display=swap');

:root {
  color-scheme: dark;
  --bg: #000;
  --card: rgba(11, 21, 48, 0.65);
  --card-border: rgba(100, 160, 255, 0.12);
  --text: #e8ecf4;
  --muted: #8a94a8;
  --accent: #4da3ff;
  --nasa-red: #e03c31;
  --nasa-blue: #0b3d91;
  --glow: rgba(77, 163, 255, 0.15);
  --radius: 16px;
}

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

/* ── Background & Body ───────────────────────────────────────── */

body {
  min-height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  overflow-x: hidden;

  /* NASA deep-space background */
  background: #000
    url('https://apod.nasa.gov/apod/image/2401/OrionMcc_Guzzini_1366.jpg')
    center top / cover no-repeat fixed;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(11, 61, 145, 0.35) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(90, 40, 120, 0.20) 0%, transparent 50%),
    linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.75) 100%);
  z-index: 0;
  pointer-events: none;
}

/* ── Container ───────────────────────────────────────────────── */

.container {
  position: relative;
  z-index: 1;
  width: min(1100px, 94vw);
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

/* ── Header / Branding ───────────────────────────────────────── */

header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.nasa-logo {
  width: 80px;
  height: 80px;
  margin-bottom: 0.6rem;
  filter: drop-shadow(0 0 20px rgba(77, 163, 255, 0.4));
  transition: transform 0.3s ease;
}

.nasa-logo:hover {
  transform: scale(1.08) rotate(-3deg);
}

h1 {
  font-family: 'Orbitron', monospace;
  font-weight: 900;
  font-size: clamp(1.6rem, 4.5vw, 2.6rem);
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.3rem;
}

.subtitle {
  font-size: 1rem;
  color: var(--muted);
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.5;
}

/* ── Cards (glassmorphism) ───────────────────────────────────── */

.card {
  background: var(--card);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.4rem 1.6rem;
  margin-bottom: 1.2rem;
  overflow: hidden;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.card:hover {
  border-color: rgba(100, 160, 255, 0.22);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.45),
    0 0 20px var(--glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ── Section Headers ─────────────────────────────────────────── */

h2 {
  font-family: 'Orbitron', monospace;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  margin-top: 0;
  margin-bottom: 0.5rem;
  color: #fff;
}

/* ── Controls & Subscription ─────────────────────────────────── */

.controls,
.subscription {
  display: grid;
  gap: 0.9rem;
}

.field-group {
  display: grid;
  gap: 0.35rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

/* ── Form Elements ───────────────────────────────────────────── */

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

input,
textarea,
select {
  font-family: inherit;
  font-size: 1rem;
  background: rgba(0, 10, 30, 0.6);
  color: var(--text);
  border: 1px solid rgba(100, 160, 255, 0.15);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

textarea {
  resize: vertical;
  max-height: 200px;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77, 163, 255, 0.15);
}

/* ── Buttons ─────────────────────────────────────────────────── */

button {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  padding: 0.6rem 1.2rem;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

button:active {
  transform: scale(0.97);
}

/* Primary button — NASA blue accent */
#search-btn,
#subscribe-btn,
#load-gallery-btn {
  background: linear-gradient(135deg, var(--accent), #2b7de9);
  color: #fff;
  box-shadow: 0 4px 14px rgba(77, 163, 255, 0.25);
}

#search-btn:hover,
#subscribe-btn:hover,
#load-gallery-btn:hover {
  box-shadow: 0 4px 20px rgba(77, 163, 255, 0.45);
  filter: brightness(1.1);
}

/* Secondary buttons */
.secondary-btn,
.open-btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.secondary-btn:hover,
.open-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Unsubscribe — subtle red */
#unsubscribe-btn:hover {
  background: rgba(224, 60, 49, 0.15);
  border-color: rgba(224, 60, 49, 0.3);
  color: #ff8a84;
}

/* ── Status ──────────────────────────────────────────────────── */

.status {
  min-height: 1.4rem;
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
  color: var(--accent);
  text-align: center;
}

.hidden {
  display: none !important;
}

/* ── Subscription Section ────────────────────────────────────── */

.subscription h2::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.6rem;
  vertical-align: middle;
  background: var(--muted);
  box-shadow: 0 0 6px var(--muted);
}

.subscription.connected h2::before {
  background: #34d399;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.meta {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.actions input {
  width: auto;
  flex: 1;
  min-width: 180px;
}

/* ── Result Card (APOD) ─────────────────────────────────────── */

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

.apod-date {
  color: var(--muted);
  font-family: 'Orbitron', monospace;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
}

.topic-pill {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid rgba(77, 163, 255, 0.25);
  background: rgba(77, 163, 255, 0.1);
  color: var(--accent);
}

.dedication-output {
  margin: 0.6rem 0 1rem;
  font-style: italic;
  color: #c7b3ff;
  padding-left: 1rem;
  border-left: 3px solid rgba(199, 179, 255, 0.3);
}

#media-wrapper {
  margin: 1rem 0;
  border-radius: 12px;
  overflow: hidden;
}

#media-wrapper img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#media-wrapper iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  border-radius: 12px;
}

#apod-explanation {
  line-height: 1.7;
  color: #c8cdd6;
  font-size: 0.95rem;
}

/* ── Gallery Controls ────────────────────────────────────────── */

.gallery-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.gallery-controls label {
  font-size: 0.78rem;
}

.gallery-controls select {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

/* ── Gallery Grid ────────────────────────────────────────────── */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
  margin-top: 0.6rem;
}

.gallery-card {
  background: rgba(5, 12, 30, 0.7);
  border: 1px solid rgba(100, 160, 255, 0.1);
  border-radius: 12px;
  padding: 0.7rem;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.gallery-card:hover {
  transform: translateY(-4px);
  border-color: rgba(100, 160, 255, 0.25);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 0 12px var(--glow);
}

.gallery-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.gallery-card h3 {
  font-size: 0.92rem;
  margin: 0.2rem 0;
  color: #fff;
  line-height: 1.3;
}

.gallery-card .meta {
  font-size: 0.78rem;
}

.gallery-card .open-btn {
  margin-top: 0.5rem;
  width: 100%;
  font-size: 0.82rem;
  padding: 0.45rem;
}

/* ── Explore Section ─────────────────────────────────────────── */

.topic-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.topic-btn {
  font-size: 0.82rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.topic-btn:hover {
  background: rgba(77, 163, 255, 0.12);
  color: var(--text);
  border-color: rgba(77, 163, 255, 0.25);
}

.topic-btn.active {
  background: rgba(77, 163, 255, 0.2);
  color: #fff;
  border-color: var(--accent);
}

.explore-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

#random-btn {
  background: linear-gradient(135deg, var(--accent), #2b7de9);
  color: #fff;
  box-shadow: 0 4px 14px rgba(77, 163, 255, 0.25);
}

#random-btn:hover {
  box-shadow: 0 4px 20px rgba(77, 163, 255, 0.45);
  filter: brightness(1.1);
}

/* ── WhatsApp / Share ────────────────────────────────────────── */

.share-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.whatsapp-btn {
  background: #25d366 !important;
  color: #fff !important;
  border: none !important;
  font-weight: 700;
}

.whatsapp-btn:hover {
  background: #1fb855 !important;
  box-shadow: 0 4px 14px rgba(37, 211, 102, 0.35);
}

/* ── Scrollbar ───────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
}

::-webkit-scrollbar-thumb {
  background: rgba(77, 163, 255, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(77, 163, 255, 0.5);
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 600px) {
  .container {
    padding: 1rem 0 2rem;
  }

  .card {
    padding: 1rem 1.1rem;
    border-radius: 12px;
  }

  .result-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .gallery-controls {
    width: 100%;
  }
}

/* ── Print-only elements (hidden on screen) ──────────────────── */

.print-ornament {
  display: none !important;
}

/* ── Print — Navy & Gold Invitation Card ─────────────────────── */

@media print {
  @page {
    size: A4 landscape;
    margin: 0;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    margin: 0;
    background: #0f1442 !important;
    color: #d4af37;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
  }

  body::before {
    display: none;
  }

  /* ── Hide everything except the result card ── */
  header,
  .controls,
  .subscription,
  .explore,
  .gallery,
  [aria-label="favourites"],
  .status,
  .share-actions,
  #favorite-btn,
  #print-btn,
  .open-btn,
  #load-gallery-btn,
  .nasa-logo,
  .topic-pill {
    display: none !important;
  }

  .container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
  }

  /* ── The main card — invitation style ── */
  .result.card {
    position: relative;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    background: #0f1442 !important;
    backdrop-filter: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    padding: 3rem 4rem;
    text-align: center;
    overflow: hidden;
  }

  /* ── Gold inner border frame ── */
  .result.card::before {
    content: '';
    position: absolute;
    inset: 20px;
    border: 2px solid #d4af37;
    border-radius: 4px;
    pointer-events: none;
  }

  .result.card::after {
    content: '';
    position: absolute;
    inset: 26px;
    border: 1px solid rgba(212, 175, 55, 0.35);
    border-radius: 2px;
    pointer-events: none;
  }

  /* ── Corner ornaments ── */
  .print-ornament {
    display: block !important;
  }

  .print-corner {
    position: absolute;
    width: 60px;
    height: 60px;
    border-color: #d4af37;
    border-style: solid;
    border-width: 0;
  }

  .print-corner-tl {
    top: 34px;
    left: 34px;
    border-top-width: 3px;
    border-left-width: 3px;
  }

  .print-corner-tr {
    top: 34px;
    right: 34px;
    border-top-width: 3px;
    border-right-width: 3px;
  }

  .print-corner-bl {
    bottom: 34px;
    left: 34px;
    border-bottom-width: 3px;
    border-left-width: 3px;
  }

  .print-corner-br {
    bottom: 34px;
    right: 34px;
    border-bottom-width: 3px;
    border-right-width: 3px;
  }

  /* ── Top ornament star ── */
  .print-header-ornament {
    font-size: 28pt;
    color: #d4af37;
    letter-spacing: 0.3em;
    margin-bottom: 0.3rem;
    order: -3;
  }

  /* ── "NASA Astronomy Picture of the Day" label ── */
  .print-label {
    font-family: 'Cinzel', 'Georgia', serif;
    font-size: 10pt;
    font-weight: 400;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: rgba(212, 175, 55, 0.7);
    margin-bottom: 1.2rem;
    order: -2;
  }

  /* ── Title ── */
  .result-head {
    display: block;
    order: -1;
    margin-bottom: 0.3rem;
  }

  .result-head h2,
  #apod-title {
    font-family: 'Cinzel', 'Georgia', serif !important;
    font-size: 22pt !important;
    font-weight: 700;
    color: #d4af37 !important;
    letter-spacing: 0.06em;
    line-height: 1.3;
    margin: 0;
  }

  /* ── Date ── */
  #apod-date,
  .apod-date {
    font-family: 'Cinzel', 'Georgia', serif !important;
    font-size: 14pt !important;
    color: #d4af37 !important;
    letter-spacing: 0.15em;
    margin: 0.4rem 0 0.8rem;
    order: 0;
  }

  /* ── Dedication ── */
  .dedication-output {
    font-family: 'Cormorant Garamond', 'Georgia', serif !important;
    font-size: 12pt;
    font-style: italic;
    color: rgba(212, 175, 55, 0.85) !important;
    border-left: 2px solid rgba(212, 175, 55, 0.4) !important;
    padding-left: 14px;
    margin: 0.6rem auto 1rem;
    max-width: 500px;
    order: 1;
  }

  /* ── Image ── */
  #media-wrapper {
    order: 2;
    margin: 0.8rem auto;
    max-width: 480px;
    border-radius: 0 !important;
  }

  #media-wrapper img {
    max-height: 42vh;
    width: auto;
    max-width: 100%;
    border-radius: 4px !important;
    border: 2px solid #d4af37 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  }

  #media-wrapper iframe {
    display: none;
  }

  /* ── Explanation ── */
  #apod-explanation {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: 10pt;
    line-height: 1.6;
    color: rgba(212, 175, 55, 0.65) !important;
    max-width: 560px;
    margin: 0.8rem auto 0;
    text-align: center;
    order: 3;
  }

  /* ── Bottom ornament ── */
  .print-footer-ornament {
    font-size: 18pt;
    color: #d4af37;
    letter-spacing: 0.3em;
    margin-top: 1rem;
    order: 4;
  }

  .print-footer-text {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: 9pt;
    font-style: italic;
    letter-spacing: 0.2em;
    color: rgba(212, 175, 55, 0.5);
    order: 5;
    margin-top: 0.2rem;
  }
}
