/*Root variables*/
:root {
  --bg:       #080c14;
  --surface:  #0d1420;
  --card:     #111826;
  --border:   #1e2d45;
  --accent:   #4f9fff;
  --accent2:  #e05c3a;
  --text:     #d8e4f0;
  --muted:    #5a7a99;
  --mono:     'DM Mono', monospace;
  --display:  'DM Sans', sans-serif;
}

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

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  top: -100%;
  left: 8px;
  background: var(--accent);
  color: #000;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 0 0 6px 6px;
  text-decoration: none;
  z-index: 9999;
  transition: top .2s;
}
.skip-link:focus { top: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--display);
  font-size: 14px;
  line-height: 1.7;
  min-height: 100vh;
}

/* Stars background */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 10%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 80% 60%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 10% 80%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 70%, rgba(255,255,255,.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 40%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 35% 50%, rgba(255,255,255,.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 85%, rgba(255,255,255,.4) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

/* Layout*/
.wrapper {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

/*Header*/
header {
  padding: 48px 0 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 48px;
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.logo-area h1 {
  font-family: var(--display);
  font-size: clamp(28px, 5vw, 46px);
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
  color: #fff;
}

.logo-area h1 span {
  color: var(--accent);
}

.logo-area p {
  color: var(--muted);
  margin-top: 6px;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.api-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.api-badge a { color: var(--accent); text-decoration: none; }
.api-badge a:hover { text-decoration: underline; }

/* Section labels (h2 styled as small caps label) */
.section-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 20px;
  line-height: 1;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.dot.red { background: var(--accent2); }

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

/*APOD*/
#apod-section { margin-bottom: 64px; }

.apod-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

@media (max-width: 700px) {
  .apod-grid { grid-template-columns: 1fr; }
}

.apod-media {
  aspect-ratio: 4/3;
  background: #000;
  overflow: hidden;
  position: relative;
}

.apod-media img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .4s ease;
}

.apod-media img:hover { transform: scale(1.03); }

.apod-media iframe {
  width: 100%; height: 100%;
  border: none;
  display: block;
}

.apod-info {
  padding: 28px 28px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-left: 1px solid var(--border);
}

@media (max-width: 700px) {
  .apod-info { border-left: none; border-top: 1px solid var(--border); }
}

.apod-date {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.apod-title {
  font-family: var(--display);
  font-size: clamp(18px, 2.5vw, 26px);
  font-weight: 700;
  color: #fff;
  line-height: 1.25;
  margin-bottom: 16px;
}

.apod-explanation {
  font-size: 13px;
  color: var(--text);
  line-height: 1.75;
  flex: 1;
  overflow-y: auto;
  max-height: 220px;
  padding-right: 4px;
}

.apod-explanation { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.apod-explanation::-webkit-scrollbar { width: 4px; }
.apod-explanation::-webkit-scrollbar-track { background: transparent; }
.apod-explanation::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.apod-copyright {
  font-size: 11px;
  color: var(--muted);
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Controls*/
.apod-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
}

input[type="date"], input[type="number"], input[type="search"], select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color .2s;
  color-scheme: dark;
}

input[type="date"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
select:focus { border-color: var(--accent); }

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #000;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 9px 18px;
  transition: opacity .2s, transform .1s;
  text-transform: uppercase;
}

button:hover { opacity: .85; }
button:active { transform: scale(.97); }
button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
button.secondary:hover { border-color: var(--accent); color: var(--accent); }

/* Mars rover */
.mars-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.photo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform .2s, border-color .2s;
}

.photo-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent2);
}

.photo-card img {
  width: 100%; aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.photo-meta {
  padding: 10px 12px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.photo-meta strong { color: var(--text); display: block; margin-bottom: 2px; }

/* Loading */
.state-box {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.loader {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-text { color: var(--accent2); }

/*Stats strip*/
.stats-strip {
  display: flex;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 48px;
}

.stat {
  flex: 1;
  background: var(--card);
  padding: 18px 20px;
  text-align: center;
}

.stat-val {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 800;
  color: #fff;
}

.stat-lbl {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-top: 2px;
}

/*Footer*/
footer {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
}

footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/*Fade-in animation*/
.fade-in { animation: fadeIn .5s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Back to top button */
#back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  background: var(--accent);
  color: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
  z-index: 100;
}
#back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}
#back-to-top:hover { transform: translateY(-3px); }

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

/* High contrast */
@media (prefers-contrast: more) {
  :root {
    --border: #ffffff;
    --text:   #ffffff;
    --muted:  #c0d0e0;
  }
}

/* Print */
@media print {
  body::before { display: none; }
  .apod-media  { display: none; }
  .stats-strip { display: none; }
}