/**
 * SDO Solar Image Explorer — Stylesheet
 *
 * Dark space theme built with CSS custom properties.
 * Layout sections:
 *   Header → Time Controls → Wavelength Bar → Main Content
 *   Main Content contains: Single View | Comparison View | Animation View
 *   Animation View: sidebar (.anim-sidebar) + display (.anim-display) + .playback-bar (fixed bottom)
 *   Info Panel: fixed right slide-in overlay
 *
 * Responsive breakpoints: 768px (tablet/mobile), 480px (small mobile)
 */

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

:root {
  --bg: #0a0a0f;
  --bg-card: #0d1117;
  --bg-card-hover: #161b22;
  --border: #21262d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #ff6a00;
  --accent-glow: rgba(255, 106, 0, 0.3);
  --cyan: #00d4ff;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.25s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(13,17,23,0.95), rgba(10,10,15,0.98));
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.logo { display: flex; align-items: center; gap: 12px; }
.logo-sun {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #ffcc00, #ff6600, #cc3300);
  box-shadow: 0 0 12px rgba(255,106,0,0.6), 0 0 24px rgba(255,106,0,0.3);
  animation: pulse-glow 3s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 12px rgba(255,106,0,0.6), 0 0 24px rgba(255,106,0,0.3); }
  50% { box-shadow: 0 0 18px rgba(255,106,0,0.8), 0 0 36px rgba(255,106,0,0.4); }
}
.logo-text h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }

.header-right { display: flex; gap: 4px; }
.view-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
}
.view-btn:hover { background: var(--bg-card-hover); color: var(--text); }
.view-btn.active { background: var(--bg-card-hover); color: var(--accent); border-color: var(--accent); }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-card-hover); border-color: #444; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-accent:hover { background: #e05e00; }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-close {
  background: none; border: none; color: var(--text-dim); font-size: 1.4rem;
  cursor: pointer; padding: 4px 8px; line-height: 1;
}
.btn-close:hover { color: var(--text); }
.btn-export {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #000;
  font-weight: 700;
}
.btn-export:hover { background: #00b8dd; }

/* === Time Controls === */
.time-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,17,23,0.6);
  flex-wrap: wrap;
}
.time-group { display: flex; align-items: center; gap: 8px; }
.datetime-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.8rem;
  color-scheme: dark;
}
.utc-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.step-buttons .btn { padding: 6px 10px; font-size: 0.75rem; font-weight: 600; }

/* === Wavelength Pills === */
.wavelength-bar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,17,23,0.4);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.wavelength-pills {
  display: flex;
  gap: 6px;
  min-width: max-content;
  justify-content: center;
}
.wl-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition: var(--transition);
  min-width: 80px;
  position: relative;
  overflow: hidden;
}
.wl-pill::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--wl-color);
  opacity: 0.5;
  transition: var(--transition);
}
.wl-pill:hover { background: var(--bg-card-hover); border-color: var(--wl-color); }
.wl-pill:hover::before { opacity: 1; }
.wl-pill.active {
  border-color: var(--wl-color);
  background: var(--bg-card-hover);
  box-shadow: 0 0 12px color-mix(in srgb, var(--wl-color) 30%, transparent);
}
.wl-pill.active::before { opacity: 1; height: 3px; }
.wl-name { font-size: 0.8rem; font-weight: 700; color: var(--text); }
.wl-desc { font-size: 0.6rem; color: var(--text-dim); margin-top: 2px; text-align: center; line-height: 1.3; }

/* === Main Content === */
.main-content {
  display: flex;
  position: relative;
  min-height: calc(100vh - 160px);
}
.view { display: none; flex: 1; }
.view.active { display: flex; justify-content: center; align-items: flex-start; padding: 24px; }

/* === Solar Viewer === */
.solar-viewer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 900px;
  width: 100%;
}
.solar-viewer.small { max-width: 100%; }

.solar-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  height: 80%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--glow-color, rgba(255,106,0,0.15)) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  filter: blur(40px);
  transition: background 0.5s ease;
}
.solar-glow.small { filter: blur(20px); }

.image-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: calc(100vh - 260px);
  max-width: calc(100vh - 260px);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #050508;
  border: 1px solid var(--border);
  z-index: 1;
  cursor: grab;
  margin: 0 auto;
}
.image-container:active { cursor: grabbing; }

.solar-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.4s ease;
  user-select: none;
  transform-origin: center center;
}
.solar-image.loaded { opacity: 1; }

.image-label {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
  z-index: 1;
}

/* Loading Skeleton */
.loading-skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: opacity 0.3s ease;
}
.loading-skeleton.hidden { opacity: 0; pointer-events: none; }
.skeleton-pulse {
  width: 60%;
  height: 60%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.04) 0%, transparent 70%);
  animation: skeleton-anim 1.5s ease-in-out infinite;
}
@keyframes skeleton-anim {
  0%, 100% { opacity: 0.3; transform: scale(0.95); }
  50% { opacity: 0.6; transform: scale(1.05); }
}

/* Error Overlay */
.error-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(10,10,15,0.9);
  color: var(--text-dim);
  z-index: 3;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.error-overlay.visible { opacity: 1; pointer-events: auto; }
.error-overlay.hidden { opacity: 0; pointer-events: none; }

/* === Comparison View === */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}
.compare-cell { display: flex; flex-direction: column; gap: 6px; }
.compare-selector { display: flex; justify-content: center; }
.compare-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-family: var(--font);
  cursor: pointer;
}

/* === Animation View === */
#animate-view.active {
  display: flex;
  padding: 0;
  padding-bottom: 56px; /* space for playback bar */
}

.anim-sidebar {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--border);
  background: var(--bg-card);
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 160px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.anim-section { display: flex; flex-direction: column; gap: 8px; }
.anim-section h3 {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.anim-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.anim-label .datetime-input,
.anim-label .anim-select {
  width: 100%;
}
.anim-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: var(--font);
  color-scheme: dark;
}
.anim-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* Frames list */
.frames-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.frame-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s;
}
.frame-item:hover { background: var(--bg-card-hover); }
.frame-item.active { background: var(--bg-card-hover); color: var(--text); }
.frame-item.loading { opacity: 0.4; }
.frame-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.2s;
}
.frame-dot.loaded { background: #2ea043; }
.frame-dot.error { background: #da3633; }
.frame-pct {
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--text-dim);
}

.anim-progress { margin-bottom: 8px; }
.anim-status-text { font-size: 0.7rem; color: var(--text-dim); }

/* Animation display area */
.anim-display {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  overflow: hidden;
}
.anim-image-container {
  max-height: calc(100vh - 320px);
  max-width: calc(100vh - 320px);
}

/* === Playback Bar === */
.playback-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 150;
}
.playback-left {
  display: flex;
  align-items: center;
  gap: 4px;
}
.playback-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.frame-scrubber {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
.frame-scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--cyan);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(0,212,255,0.4);
}
.playback-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.playback-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.fps-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--text-dim);
}
.fps-slider {
  width: 60px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.fps-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cyan);
  cursor: pointer;
}
#fps-value {
  min-width: 16px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.export-buttons {
  display: flex;
  gap: 4px;
}

/* GIF export progress overlay */
.gif-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 300;
}
.gif-overlay p { font-size: 0.9rem; }
.gif-progress-bar {
  width: 200px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.gif-progress-fill {
  height: 100%;
  background: var(--cyan);
  width: 0%;
  transition: width 0.1s;
}

/* === Info Panel === */
.info-panel {
  position: fixed;
  right: -380px;
  top: 0;
  bottom: 0;
  width: 360px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 200;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.info-panel.open { right: 0; }
.info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}
.info-header h2 { font-size: 1rem; }
.info-content { padding: 16px; }
.info-section { padding: 0 16px 16px; }
.info-section h3 { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 8px; }

.info-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.info-card h4 { font-size: 0.8rem; margin-bottom: 4px; }
.info-card p { font-size: 0.75rem; color: var(--text-dim); line-height: 1.5; }
.info-card .info-swatch {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

/* Solar Weather */
.solar-weather {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.solar-weather.expanded { max-height: 600px; overflow-y: auto; }
.weather-loading { font-size: 0.75rem; color: var(--text-dim); padding: 12px 0; }
#weather-text {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  padding: 8px 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.chevron {
  font-size: 0.7rem;
  transition: transform 0.2s ease;
  display: inline-block;
}
.solar-weather.expanded ~ .btn .chevron,
.btn.active .chevron { transform: rotate(180deg); }

.hidden { display: none !important; }

/* === Responsive === */
@media (max-width: 768px) {
  .header { padding: 8px 12px; }
  .logo-text h1 { font-size: 0.95rem; }
  .time-controls { padding: 8px 12px; gap: 8px; }
  .step-buttons { order: 1; width: 100%; justify-content: center; }
  .wavelength-bar { padding: 8px 12px; }
  .wavelength-pills { justify-content: flex-start; }
  .wl-pill { min-width: 70px; padding: 6px 10px; }
  .wl-name { font-size: 0.7rem; }
  .view.active { padding: 12px; }
  .compare-grid { grid-template-columns: 1fr; max-width: 500px; }
  .info-panel { width: 100%; right: -105%; }
  .info-panel.open { right: 0; }

  /* Animation mobile */
  #animate-view.active { flex-direction: column; }
  .anim-sidebar {
    width: 100%;
    min-width: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .anim-display { padding: 12px; }
  .playback-bar { gap: 8px; padding: 0 8px; }
  .fps-label { display: none; }
}

@media (max-width: 480px) {
  .time-group:first-child { flex-wrap: wrap; justify-content: center; }
  .utc-label { width: 100%; text-align: center; }
}
