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

:root {
  --bg-deep: #0a0806;
  --mars-rust: #c1440e;
  --mars-ember: #e8621a;
  --mars-sand: #d4a574;
  --text-primary: #e8e0d8;
  --text-secondary: #8a7e74;
  --text-dim: #5a5048;
}

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'Instrument Sans', sans-serif;
  overflow: hidden;
}

/* Grain overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

/* ── Brand ── */
.brand {
  position: fixed;
  top: 1.5rem;
  left: 1.5rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.brand-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.35em;
  color: var(--mars-rust);
  text-transform: uppercase;
}

.brand-tagline {
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-secondary);
  max-width: 18rem;
  line-height: 1.4;
}

.brand-subtitle {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.5rem;
  font-weight: 400;
  letter-spacing: 0.25em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ── Fullscreen Photo ── */
.photo-viewport {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.photo-viewport img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.8s ease;
  filter: saturate(0.9) contrast(1.05);
}

.photo-viewport img.revealed {
  opacity: 1;
}

/* ── Scan Effect ── */
.scan-effect {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.scan-effect.active {
  opacity: 1;
}

.scan-effect::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(180deg, var(--mars-ember), transparent);
  box-shadow: 0 0 30px rgba(232,98,26,0.3);
  animation: scanDown 1.8s ease-in-out infinite;
}

@keyframes scanDown {
  0% { top: -3px; }
  100% { top: 100%; }
}

.scan-effect::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(10,8,6,0.1) 2px,
    rgba(10,8,6,0.1) 4px
  );
}

/* ── Photo Overlay (bottom) ── */
.photo-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4rem 1.5rem 1.5rem;
  background: linear-gradient(0deg, rgba(10,8,6,0.88) 0%, rgba(10,8,6,0.5) 60%, transparent 100%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  opacity: 0;
  transition: opacity 0.6s ease 0.3s, background 0.4s ease;
}

.photo-overlay.visible {
  opacity: 1;
}

.overlay-toggle {
  align-self: center;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,8,6,0.4);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(193,68,14,0.3);
  border-radius: 50%;
  color: var(--mars-sand);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.3s ease, color 0.3s ease, background 0.3s ease;
  margin-bottom: -0.25rem;
}

.overlay-toggle:hover {
  border-color: var(--mars-rust);
  color: var(--mars-ember);
  background: rgba(10,8,6,0.7);
}

.overlay-toggle-icon {
  display: inline-block;
  transition: transform 0.4s ease;
  line-height: 1;
}

.app.expanded .overlay-toggle-icon {
  transform: rotate(180deg);
}

/* ── Description Panel (centered) ── */
.description-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-50% + 12px));
  z-index: 4;
  width: min(92%, 640px);
  max-height: min(70vh, 560px);
  padding: 2rem 2.25rem;
  background: rgba(10,8,6,0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(193,68,14,0.22);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.description-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 1.5rem;
  width: 24px;
  height: 1px;
  background: var(--mars-rust);
  opacity: 0.6;
}

.description-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.55rem;
  font-weight: 500;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--mars-sand);
  margin-bottom: -0.5rem;
}

.app.expanded .description-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.photo-description {
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-primary);
  overflow-y: auto;
  overscroll-behavior: contain;
  white-space: pre-wrap;
}

.photo-meta-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.photo-meta {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.full-image-link {
  align-self: flex-end;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--mars-sand);
  text-decoration: none;
  padding: 0.55rem 1rem;
  border: 1px solid rgba(193,68,14,0.3);
  background: rgba(10,8,6,0.4);
  transition: color 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}

.full-image-link:hover {
  color: var(--mars-ember);
  border-color: var(--mars-rust);
  background: rgba(10,8,6,0.7);
}

.rover-name {
  font-family: 'DM Serif Display', serif;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.camera-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--mars-sand);
  text-transform: uppercase;
}

.photo-data {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.data-row {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.data-label { color: var(--text-dim); }
.data-value { color: var(--mars-sand); }

/* ── Controls (bottom-right, above overlay) ── */
.controls {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.explore-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--text-primary);
  background: rgba(10,8,6,0.5);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(193,68,14,0.3);
  padding: 0.7rem 1.4rem;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 1px;
}

.explore-btn:hover {
  border-color: var(--mars-rust);
  color: var(--mars-sand);
  background: rgba(10,8,6,0.7);
}

.explore-btn:active {
  transform: scale(0.98);
}

.explore-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.photo-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.5rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
}

/* ── Loading State ── */
.loading-state {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.loading-state.active {
  opacity: 1;
}

.loading-ring {
  width: 40px;
  height: 40px;
  border: 1.5px solid rgba(193,68,14,0.15);
  border-top-color: var(--mars-ember);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.25em;
  color: var(--text-dim);
  text-transform: uppercase;
  text-align: center;
}

.loading-rover {
  color: var(--mars-ember);
  font-weight: 500;
}

/* ── Error State ── */
.error-state {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.error-state.active {
  opacity: 1;
}

.error-icon {
  font-size: 1.5rem;
  color: var(--mars-rust);
  opacity: 0.6;
}

.error-msg {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  text-align: center;
  max-width: 280px;
  line-height: 1.6;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .brand { top: 1rem; left: 1rem; }
  .controls {
    top: 1rem;
    right: 1rem;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
  }
  .photo-overlay {
    padding: 3rem 1rem 1rem;
  }
  .photo-meta-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .photo-data { align-items: flex-start; }
  .rover-name { font-size: 1.3rem; }
  .description-panel {
    padding: 1.5rem 1.25rem;
    width: calc(100% - 2rem);
    max-height: 65vh;
  }
  .photo-description { font-size: 0.85rem; line-height: 1.6; }
}
