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

:root {
  --bg: #f5f0e8;
  --surface: #ece8de;
  --border: #c4bba4;
  --text: #2a2520;
  --muted: #7a6a54;
  --accent: #6a8898;
  --era-color: #5a3a18;
  font-family: 'Georgia', 'Times New Roman', serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Layout ────────────────────────────────────────────── */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ── Globe ─────────────────────────────────────────────── */
#globe-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

#globe-canvas {
  width: 100%;
  height: 100%;
  cursor: grab;
  display: block;
}

#globe-canvas:active { cursor: grabbing; }

/* ── Controls overlay ──────────────────────────────────── */
#controls-overlay {
  position: absolute;
  top: 40px;
  left: 40px;
  width: 320px;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 10;
  pointer-events: none; /* Let clicks pass through empty spaces */
}

#controls-overlay > * {
  pointer-events: auto; /* Re-enable clicks for actual controls */
}

#controls-overlay h2 {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 32px;
  font-weight: 400;
  letter-spacing: 0.05em;
  color: #2a2520;
  margin-bottom: 4px;
  text-shadow: 2px 2px 0px rgba(253, 251, 247, 0.8);
  transition: color 0.4s ease;
}

#era-info {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-style: italic;
  font-size: 15px;
  color: rgba(42, 37, 32, 0.8);
  line-height: 1.6;
  min-height: 48px;
  text-shadow: 1px 1px 0px rgba(253, 251, 247, 0.8);
  padding-right: 20px;
  transition: opacity 0.3s ease;
}

.control-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

#age-range, #model-provider {
  background: rgba(253, 251, 247, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(42, 37, 32, 0.2);
  color: #2a2520;
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: 0; /* Blueprint style sharp corners */
  flex: 1;
  font-family: system-ui, -apple-system, sans-serif;
  cursor: pointer;
}

#generate-btn {
  background: rgba(42, 37, 32, 0.85);
  border: 1px solid #2a2520;
  color: #fdfbf7;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  padding: 14px 24px;
  margin-top: 12px;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 4px 4px 0px rgba(42, 37, 32, 0.15);
}

#generate-btn:hover {
  background: #2a2520;
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0px rgba(42, 37, 32, 0.15);
}
#generate-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0px 0px 0px rgba(42, 37, 32, 0.15);
}
#generate-btn:disabled { 
  opacity: 0.4; 
  cursor: not-allowed; 
  transform: none; 
  box-shadow: none; 
}

/* ── Timeline overlay ──────────────────────────────────── */
#timeline-row {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  border-top: 1px solid rgba(42, 37, 32, 0.2);
  background: rgba(253, 251, 247, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 16px 40px 24px; /* More breathing room */
  z-index: 10;
  font-family: system-ui, -apple-system, sans-serif;
  box-shadow: 0 -4px 32px rgba(42, 37, 32, 0.05);
}

/* ── Scene Viewer Overlay ───────────────────────────────── */
#scene-modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  /* Paper Texture + Technical Grid Background */
  background-color: #f8f4ec;
  background-image: 
    linear-gradient(rgba(42, 37, 32, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 37, 32, 0.03) 1px, transparent 1px),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
  background-size: 40px 40px, 40px 40px, auto;
  
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.4s ease;
}

#scene-modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#scene-wrap.centered-view {
  position: relative;
  width: 1024px;
  height: 768px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  background: #fdfbf7;
  border: 1px solid rgba(42, 37, 32, 0.2);
  border-radius: 0; /* Sharp technical edges */
  box-shadow: 0 20px 80px rgba(42, 37, 32, 0.15);
  overflow: hidden;
}

#scene-canvas {
  flex: 1;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border: none;
  cursor: crosshair;
}

.scene-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 1024px;
  max-width: 90vw;
}

.scene-header-outside {
  width: 100%;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  padding-left: 10px;
}

/* Anchored Lead Line for Header */
.scene-header-outside::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, rgba(42, 37, 32, 0.2), transparent);
}

.scene-footer-outside {
  width: 100%;
  position: relative;
  display: flex;
  justify-content: flex-start;
  margin-top: 24px;
  padding-left: 10px;
}

/* Anchored Lead Line for Footer */
.scene-footer-outside::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, rgba(42, 37, 32, 0.2), transparent);
}

#scene-title {
  font-family: "Georgia", "Times New Roman", serif;
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #2a2520;
  margin-bottom: 4px;
}

#scene-subtitle {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(42, 37, 32, 0.6);
}


#stream-status {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  color: rgba(42, 37, 32, 0.5);
  display: block;
  margin-top: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

#close-modal-btn {
  font-family: system-ui, -apple-system, sans-serif;
  background: rgba(42, 37, 32, 0.05);
  border: 1px solid rgba(42, 37, 32, 0.1);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 24px;
  line-height: 1;
  color: #2a2520;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#close-modal-btn:hover {
  background: rgba(42, 37, 32, 0.15);
  transform: scale(1.05);
}

/* ── Breadcrumb path ───────────────────────────────────── */
#path-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.path-item {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: rgba(42, 37, 32, 0.5);
  background: transparent;
  border: 1px solid rgba(42, 37, 32, 0.1);
  padding: 6px 14px;
  border-radius: 0; /* Technical stamp look */
  cursor: pointer;
  transition: all 0.2s ease;
}

.path-item:hover {
  background: rgba(42, 37, 32, 0.05);
  border-color: rgba(42, 37, 32, 0.3);
  color: #2a2520;
}

.path-item.active {
  background: rgba(42, 37, 32, 0.85);
  color: #fdfbf7;
  border-color: #2a2520;
  box-shadow: 2px 2px 0px rgba(42, 37, 32, 0.15);
}


/* ── Timeline ──────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 4px; }

.timeline-bar {
  position: relative;
  height: 22px;
  border-radius: 3px;
  overflow: visible;
  cursor: pointer;
  user-select: none;
  background: #ddd7c8;
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.10);
}

.timeline-era {
  position: absolute;
  top: 0;
  height: 100%;
  opacity: 0.65;
  transition: opacity 0.25s ease, filter 0.25s ease;
  filter: saturate(0.72);
}

.timeline-era:hover {
  opacity: 0.90;
  filter: saturate(0.90);
}

.timeline-cursor {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 2px;
  background: #1e1810;
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
  transform: translateX(-50%);
  pointer-events: none;
  border-radius: 1px;
}

.timeline-labels {
  position: relative;
  height: 16px;
}

.timeline-label {
  position: absolute;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
}

.timeline-era-name {
  font-size: 12px;
  font-weight: 600;
  border-left: 3px solid var(--era-color);
  padding-left: 8px;
  line-height: 1.4;
  transition: color 0.4s ease, border-color 0.4s ease;
}

/* Smooth cursor crosshair transition */
#globe-canvas {
  transition: cursor 0.15s;
}

/* Subtle globe container hover glow */
#globe-wrap:hover #globe-canvas {
  filter: drop-shadow(0 0 24px rgba(106, 136, 152, 0.12));
}

/* Path items micro-interaction */
.path-item {
  transition: all 0.18s ease;
}

/* Generate button loading state */
#generate-btn.loading {
  opacity: 0.65;
  cursor: wait;
  pointer-events: none;
}
#generate-btn.loading::after {
  content: '...';
  letter-spacing: 0.05em;
}

/* ── Globe loading fog ─────────────────────────────────── */
#globe-fog {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
  opacity: 1;
  transition: opacity 2.5s ease-out;
  background: rgba(225, 235, 248, 0.96);
}

#globe-fog.cleared {
  opacity: 0;
}

#globe-fog::before {
  content: '';
  position: absolute;
  inset: -40%;
  background:
    radial-gradient(ellipse 70% 55% at 28% 35%, rgba(255, 255, 255, 0.98) 0%, rgba(240, 247, 255, 0.80) 40%, transparent 65%),
    radial-gradient(ellipse 60% 50% at 72% 60%, rgba(220, 235, 255, 0.95) 0%, rgba(200, 220, 248, 0.75) 40%, transparent 62%),
    radial-gradient(ellipse 80% 45% at 50% 85%, rgba(210, 228, 252, 0.90) 0%, transparent 55%),
    radial-gradient(ellipse 65% 60% at 15% 70%, rgba(230, 242, 255, 0.92) 0%, transparent 58%),
    radial-gradient(ellipse 55% 50% at 85% 15%, rgba(255, 255, 255, 0.95) 0%, transparent 60%);
  filter: blur(40px);
  animation: fogLayer1 13s ease-in-out infinite alternate;
}

#globe-fog::after {
  content: '';
  position: absolute;
  inset: -40%;
  background:
    radial-gradient(ellipse 75% 60% at 65% 20%, rgba(255, 255, 255, 0.96) 0%, rgba(235, 245, 255, 0.78) 38%, transparent 60%),
    radial-gradient(ellipse 55% 65% at 18% 65%, rgba(215, 232, 254, 0.93) 0%, rgba(200, 222, 252, 0.72) 42%, transparent 62%),
    radial-gradient(ellipse 65% 40% at 50% 50%, rgba(245, 250, 255, 0.88) 0%, transparent 50%),
    radial-gradient(ellipse 50% 55% at 88% 78%, rgba(225, 238, 255, 0.90) 0%, transparent 55%),
    radial-gradient(ellipse 70% 45% at 35% 10%, rgba(255, 255, 255, 0.94) 0%, transparent 58%);
  filter: blur(32px);
  animation: fogLayer2 17s ease-in-out infinite alternate-reverse;
}

@keyframes fogLayer1 {
  0%   { transform: translate(0%, 0%)   scale(1.00); }
  35%  { transform: translate(3%, -2%)  scale(1.02); }
  70%  { transform: translate(-2%, 4%)  scale(0.98); }
  100% { transform: translate(4%, 2%)   scale(1.03); }
}

@keyframes fogLayer2 {
  0%   { transform: translate(0%, 0%)   scale(1.00); }
  35%  { transform: translate(-4%, 3%)  scale(1.03); }
  70%  { transform: translate(3%, -3%)  scale(0.97); }
  100% { transform: translate(-3%, -2%) scale(1.02); }
}
