@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Oxanium:wght@400;600;700&family=Rajdhani:wght@400;600;700&family=Share+Tech+Mono&family=Audiowide&display=swap');

:root {
  --glow: #00E5FF;
  --glow-amber: #FFB300;
  --glow-green: #00FF88;
  --glow-red: #FF5A5A;
  --glow-white: #E5F1FF;
  --metal: #1a2a3a;
  --bg-deep: #000810;
  --panel-bg: rgba(0,8,20,0.88);
  --border-glow: rgba(0,229,255,0.25);
  --btn-past: #FF8C00;
  --btn-future: #00E5FF;
  --btn-present: #FFD700;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  background: var(--bg-deep);
  font-family: "Oxanium", "Audiowide", sans-serif;
  color: var(--glow);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 68px 0 24px;
}

/* ============ TOP NAV ============ */
#top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: linear-gradient(90deg, rgba(0,8,20,0.97) 0%, rgba(0,20,40,0.97) 50%, rgba(0,8,20,0.97) 100%);
  border-bottom: 1px solid rgba(0,229,255,0.18);
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 12px;
  z-index: 200;
  box-shadow: 0 2px 20px rgba(0,229,255,0.08);
}
#top-nav .nav-spacer { flex: 1; }
.nav-icon-btn {
  background: rgba(0,229,255,0.06);
  border: 1px solid rgba(0,229,255,0.22);
  color: var(--glow);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 1em;
  cursor: pointer;
  font-family: "Oxanium", sans-serif;
  letter-spacing: 0.04em;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}
.nav-icon-btn:hover {
  background: rgba(0,229,255,0.15);
  box-shadow: 0 0 12px rgba(0,229,255,0.3);
  transform: translateY(-1px);
}
.nav-icon-btn:active { transform: translateY(1px); }

/* ============ PROFILE PANEL ============ */
#profile-panel {
  position: fixed;
  top: 56px; right: 16px;
  width: 280px;
  background: linear-gradient(160deg, rgba(0,10,25,0.97), rgba(0,20,45,0.97));
  border: 1px solid rgba(0,229,255,0.28);
  border-radius: 10px;
  padding: 16px;
  z-index: 300;
  display: none;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0,229,255,0.1);
}
#profile-panel label { font-size: 0.82em; opacity: 0.75; font-family: "Share Tech Mono", monospace; letter-spacing: 0.06em; }
#profile-panel input {
  background: rgba(0,229,255,0.04);
  border: 1px solid rgba(0,229,255,0.2);
  color: var(--glow);
  border-radius: 6px;
  padding: 7px 10px;
  font-family: "Share Tech Mono", monospace;
  font-size: 0.9em;
  width: 100%;
}
#profile-panel button { padding: 8px 14px; font-size: 0.9em; }

/* ============ RESEARCH SIDEBAR ============ */
#research-sidebar {
  position: fixed;
  top: 52px; right: -440px;
  width: 420px;
  height: calc(100vh - 52px);
  background: linear-gradient(160deg, rgba(0,8,22,0.98), rgba(0,15,35,0.98));
  border-left: 1px solid rgba(0,229,255,0.18);
  display: flex;
  flex-direction: column;
  z-index: 190;
  transition: right 0.3s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
  box-shadow: -8px 0 30px rgba(0,0,0,0.6);
}
#research-sidebar.open { right: 0; }
#research-sidebar-header {
  display: flex; align-items: center; padding: 12px 14px;
  border-bottom: 1px solid rgba(0,229,255,0.1);
  gap: 10px;
  background: rgba(0,229,255,0.04);
}
#research-sidebar-header strong { font-size: 0.9em; font-family: "Orbitron", sans-serif; letter-spacing: 0.08em; }
#research-list {
  flex: 1; overflow-y: auto; padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.research-item {
  background: rgba(0,229,255,0.03);
  border: 1px solid rgba(0,229,255,0.1);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.83em;
  position: relative;
  transition: border-color 0.2s;
}
.research-item:hover { border-color: rgba(0,229,255,0.25); }
.research-item .ri-title { font-weight: 700; margin-bottom: 4px; opacity: 0.95; font-family: "Oxanium", sans-serif; }
.research-item .ri-meta { opacity: 0.6; font-size: 0.82em; margin-bottom: 6px; font-family: "Share Tech Mono", monospace; }
.research-item .ri-excerpt { opacity: 0.8; line-height: 1.45; max-height: 60px; overflow: hidden; font-family: "Rajdhani", sans-serif; font-size: 1.05em; }
.research-item .ri-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.research-item .ri-actions button { padding: 4px 8px; font-size: 0.82em; }
.ri-delete-btn { position: absolute; top: 8px; right: 8px; background: transparent; border: none; color: var(--glow-red); font-size: 1em; cursor: pointer; padding: 2px 6px; }
#research-sidebar-footer {
  padding: 10px 14px; border-top: 1px solid rgba(0,229,255,0.08);
  display: flex; gap: 8px; flex-wrap: wrap;
}
#research-sidebar-footer button { padding: 7px 12px; font-size: 0.85em; }

/* ============ THREE.JS CANVAS BACKGROUND ============ */
#three-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

#hyperspeed-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}
#hyperspeed-canvas.active { opacity: 1; }

/* ============ TIME MACHINE ============ */
.time-machine {
  position: relative;
  width: 820px;
  max-height: none;
  background: linear-gradient(160deg, rgba(0,12,30,0.94) 0%, rgba(0,20,50,0.94) 50%, rgba(0,12,30,0.94) 100%);
  border-radius: 20px;
  padding: 18px;
  border: 1px solid rgba(0,229,255,0.2);
  box-shadow:
    0 0 60px rgba(0,229,255,0.08),
    0 0 120px rgba(0,229,255,0.04),
    inset 0 0 40px rgba(0,229,255,0.03);
  z-index: 10;
  overflow: visible;
  transform-style: preserve-3d;
  transition: transform 0.1s ease-out, height 0.28s ease, padding 0.28s ease, border-radius 0.28s ease;
}

/* collapsed "mini" state for footer preview */
.time-machine.mini {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 72px;
  width: auto;
  height: 84px;
  padding: 8px;
  border-radius: 12px;
  z-index: 260;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

/* hide inner heavy visuals when mini */
.time-machine.mini .display,
.time-machine.mini .historical-events,
.time-machine.mini .controls,
.time-machine.mini .context-bar {
  display: none;
}
.time-machine.mini .year-display {
  display: block;
  font-size: 1.1em;
  margin-left: 8px;
  color: var(--glow-white);
}

/* mini footer reopen bar */
#mini-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 18px;
  z-index: 270;
  background: rgba(0,8,20,0.88);
  border: 1px solid rgba(0,229,255,0.12);
  color: var(--glow);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  min-width: 220px;
  pointer-events: auto;
}
#mini-bar.hidden { display: none; }
#mini-bar .mini-label { font-family: "Share Tech Mono", monospace; font-size:0.92em; opacity:0.9; }
#mini-bar button { padding:8px 10px; border-radius:8px; font-size:0.9em; }

/* mini events panel above footer (visible when machine is collapsed) */
#mini-events-panel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 108px; /* sits above the mini-bar (18px) + mini-bar height */
  z-index: 268;
  max-height: 50vh;
  background: linear-gradient(180deg, rgba(0,8,20,0.95), rgba(0,12,26,0.95));
  border: 1px solid rgba(0,229,255,0.06);
  color: var(--glow);
  border-radius: 10px;
  padding: 8px;
  display: none;
  overflow: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
#mini-events-panel.visible { display: block; }
#mini-events-panel .mini-evt-header { display:flex;align-items:center;gap:8px;margin-bottom:6px;font-family:Orbitron, sans-serif;font-size:0.92em;opacity:0.95; }
#mini-events-panel .mini-evt-list { display:flex;flex-direction:column;gap:8px; }
#mini-events-panel .mini-event { background: rgba(0,229,255,0.02); border:1px solid rgba(0,229,255,0.04); padding:8px;border-radius:8px; font-size:0.9em; display:flex; gap:8px; align-items:flex-start; }
#mini-events-panel .mini-event .mini-symbol { font-size:1.2em; width:30px; text-align:center; margin-top:2px; opacity:0.9; }
#mini-events-panel .mini-event .mini-text { flex:1; line-height:1.3; color:var(--glow); opacity:0.95; }

/* reposition existing BG view so it doesn't overlap mini-bar */
#bg-dl-btn { bottom: 82px; }

/* ============ CONTEXT BAR ============ */
#context-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  background: rgba(0,229,255,0.04);
  border: 1px solid rgba(0,229,255,0.14);
  border-radius: 8px;
  padding: 7px 12px;
  margin-bottom: 10px;
}
#context-bar select, #context-bar input {
  background: rgba(0,8,20,0.7);
  border: 1px solid rgba(0,229,255,0.2);
  color: var(--glow);
  border-radius: 5px;
  padding: 5px 8px;
  font-family: "Share Tech Mono", monospace;
  font-size: 0.85em;
  cursor: pointer;
  transition: border-color 0.2s;
}
#context-bar select:focus, #context-bar input:focus { border-color: rgba(0,229,255,0.5); outline: none; }
#context-bar select option { background: #010810; color: var(--glow); }
#context-bar label { font-size: 0.85em; opacity: 0.75; white-space: nowrap; font-family: "Share Tech Mono", monospace; }

/* ============ TOPIC MODAL ============ */
#topic-modal {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%,-50%) scale(0.98);
  width: 88%; max-width: 800px; max-height: 80vh;
  background: linear-gradient(160deg, rgba(0,8,22,0.98), rgba(0,18,42,0.98));
  border: 1px solid rgba(0,229,255,0.3);
  border-radius: 12px;
  z-index: 300;
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0,229,255,0.12);
}
#topic-modal-header {
  display: flex; align-items: center; padding: 10px 14px;
  border-bottom: 1px solid rgba(0,229,255,0.08);
  gap: 10px;
  background: rgba(0,229,255,0.04);
  font-family: "Orbitron", sans-serif;
  font-size: 0.88em;
  letter-spacing: 0.08em;
}
#topic-modal-body {
  padding: 14px; overflow-y: auto; flex: 1;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px;
}
.topic-category { display: flex; flex-direction: column; gap: 5px; }
.topic-category h4 { margin: 0 0 4px; font-size: 0.8em; opacity: 0.65; letter-spacing: 0.08em; font-family: "Orbitron", sans-serif; text-transform: uppercase; }
.topic-chip {
  padding: 5px 10px; border: 1px solid rgba(0,229,255,0.18);
  border-radius: 20px; cursor: pointer; font-size: 0.83em;
  transition: all 0.15s; font-family: "Rajdhani", sans-serif; font-weight: 600;
  background: rgba(0,229,255,0.02); color: var(--glow-white); text-align: left;
}
.topic-chip:hover { background: rgba(0,229,255,0.1); border-color: rgba(0,229,255,0.35); }
.topic-chip.selected { background: rgba(0,229,255,0.18); border-color: var(--glow); color: var(--glow); box-shadow: 0 0 8px rgba(0,229,255,0.2); }

/* ============ BG VIEW BTN ============ */
#bg-dl-btn {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 250;
  background: rgba(0,8,20,0.85);
  border: 1px solid rgba(0,229,255,0.3);
  color: var(--glow);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.82em;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  font-family: "Share Tech Mono", monospace;
}
body:hover #bg-dl-btn { opacity: 1; pointer-events: auto; }

/* ============ BG PREVIEW MODAL ============ */
#bg-preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 500;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}
#bg-preview-modal.open { display: flex; }
#bg-preview-modal-img {
  max-width: 96vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 0 60px rgba(0,229,255,0.12);
  display: block;
}
#bg-preview-modal-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(0,8,22,0.92);
  border-top: 1px solid rgba(0,229,255,0.12);
  width: 96vw;
  max-width: 1200px;
  border-radius: 0 0 10px 10px;
  margin-top: 2px;
}
#bg-preview-modal-bar .bg-modal-caption {
  font-family: "Share Tech Mono", monospace;
  font-size: 0.82em;
  opacity: 0.75;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ DATE DISPLAY ============ */
.display {
  background: linear-gradient(180deg, rgba(0,5,15,0.9) 0%, rgba(0,10,25,0.9) 100%);
  border-radius: 12px;
  padding: 12px 18px 10px;
  margin-bottom: 12px;
  border: 1px solid rgba(0,229,255,0.2);
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 30px rgba(0,229,255,0.05), 0 0 20px rgba(0,229,255,0.05);
}

#location-aerial-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 1.2s ease;
  z-index: 0;
  border-radius: 12px;
}
#location-aerial-bg.loaded {
  opacity: 0.22;
}
#location-aerial-bg-spinner {
  position: absolute;
  top: 8px; right: 10px;
  width: 16px; height: 16px;
  border: 2px solid rgba(0,229,255,0.15);
  border-top-color: var(--glow);
  border-radius: 50%;
  animation: tw-spin 0.7s linear infinite;
  z-index: 2;
  display: none;
}
.display > *:not(#location-aerial-bg):not(#location-aerial-bg-spinner) {
  position: relative;
  z-index: 1;
}
.display::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,229,255,0.4), transparent);
}

/* Temporal reactor container */
#temporal-reactor {
  width: 100%;
  height: 100px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}
#reactor-canvas {
  width: 100px;
  height: 100px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.year-display {
  font-family: "Orbitron", sans-serif;
  font-size: 3em;
  font-weight: 900;
  text-align: center;
  color: var(--glow);
  text-shadow:
    0 0 10px rgba(0,229,255,0.8),
    0 0 20px rgba(0,229,255,0.5),
    0 0 40px rgba(0,229,255,0.25),
    2px 2px 0 rgba(255,0,255,0.15),
    -1px -1px 0 rgba(0,100,255,0.15);
  letter-spacing: 0.06em;
  animation: ledPulse 2s ease-in-out infinite;
  position: relative;
}

@keyframes ledPulse {
  0%, 100% { opacity: 1; text-shadow: 0 0 10px rgba(0,229,255,0.9), 0 0 25px rgba(0,229,255,0.6), 0 0 50px rgba(0,229,255,0.25), 2px 2px 0 rgba(255,0,255,0.12), -1px -1px 0 rgba(0,100,255,0.12); }
  50% { opacity: 0.9; text-shadow: 0 0 8px rgba(0,229,255,0.7), 0 0 18px rgba(0,229,255,0.4), 0 0 35px rgba(0,229,255,0.15), 2px 2px 0 rgba(255,0,255,0.1), -1px -1px 0 rgba(0,100,255,0.1); }
}

@keyframes digitFlicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.75; }
  98% { opacity: 0.95; }
  99% { opacity: 0.72; }
}

.year-display.flickering { animation: digitFlicker 0.15s; }

/* Temporal recalculation overlay */
#temporal-recalc {
  position: absolute;
  inset: 0;
  background: rgba(0,5,15,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 50;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
#temporal-recalc.active { opacity: 1; pointer-events: auto; }
#temporal-recalc .tr-year {
  font-family: "Orbitron", sans-serif;
  font-size: 2em;
  font-weight: 900;
  color: var(--glow-amber);
  text-shadow: 0 0 20px rgba(255,179,0,0.8);
  letter-spacing: 0.1em;
  min-height: 1.2em;
}
#temporal-recalc .tr-status {
  font-family: "Share Tech Mono", monospace;
  font-size: 0.8em;
  color: var(--glow);
  opacity: 0.85;
  letter-spacing: 0.06em;
}
#temporal-recalc .tr-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 12px;
  overflow: hidden;
}

/* ============ CONTROLS ============ */
.controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}

/* SQUISHY 3D BUTTONS */
button {
  background: linear-gradient(180deg, rgba(40,60,90,0.9) 0%, rgba(15,30,55,0.95) 100%);
  color: var(--glow);
  border: 1px solid rgba(0,229,255,0.25);
  border-radius: 8px;
  padding: 10px 6px;
  font-size: 0.9em;
  cursor: pointer;
  font-family: "Oxanium", sans-serif;
  font-weight: 600;
  letter-spacing: 0.03em;
  transition: transform 0.12s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.12s, background 0.12s;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 4px 0 rgba(0,0,0,0.5),
    0 2px 8px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.06);
  transform: translateY(0);
}

button:hover {
  background: linear-gradient(180deg, rgba(0,80,120,0.9) 0%, rgba(0,50,90,0.95) 100%);
  box-shadow:
    0 6px 0 rgba(0,0,0,0.4),
    0 4px 16px rgba(0,229,255,0.2),
    inset 0 1px 0 rgba(255,255,255,0.08);
  transform: translateY(-3px);
  border-color: rgba(0,229,255,0.45);
  color: #fff;
}

button:active {
  transform: translateY(3px) scale(0.97);
  box-shadow:
    0 1px 0 rgba(0,0,0,0.6),
    0 0 6px rgba(0,229,255,0.3),
    inset 0 2px 4px rgba(0,0,0,0.4);
}

/* Button ripple effect */
button .btn-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(0,229,255,0.3);
  transform: scale(0);
  animation: btnRipple 0.5s ease-out;
  pointer-events: none;
}
@keyframes btnRipple {
  to { transform: scale(4); opacity: 0; }
}

/* PAST buttons */
.btn-past {
  background: linear-gradient(180deg, rgba(80,50,10,0.9) 0%, rgba(50,30,5,0.95) 100%) !important;
  border-color: rgba(255,179,0,0.3) !important;
  color: var(--glow-amber) !important;
  box-shadow: 0 4px 0 rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,200,50,0.1) !important;
}
.btn-past:hover {
  background: linear-gradient(180deg, rgba(120,80,15,0.9) 0%, rgba(80,50,8,0.95) 100%) !important;
  box-shadow: 0 6px 0 rgba(0,0,0,0.4), 0 4px 16px rgba(255,179,0,0.3), inset 0 1px 0 rgba(255,200,50,0.15) !important;
  border-color: rgba(255,179,0,0.6) !important;
}

/* FUTURE buttons */
.btn-future {
  background: linear-gradient(180deg, rgba(0,50,80,0.9) 0%, rgba(0,30,60,0.95) 100%) !important;
  border-color: rgba(0,229,255,0.3) !important;
  color: var(--glow) !important;
}

/* PRESENT button */
.present-day {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, rgba(120,100,0,0.95) 0%, rgba(80,65,0,0.98) 100%) !important;
  color: #FFD700 !important;
  border: 1px solid rgba(255,215,0,0.5) !important;
  font-family: "Orbitron", sans-serif !important;
  font-weight: 700 !important;
  letter-spacing: 0.08em !important;
  font-size: 0.88em !important;
  box-shadow: 0 4px 0 rgba(0,0,0,0.5), 0 0 20px rgba(255,215,0,0.15), inset 0 1px 0 rgba(255,215,0,0.2) !important;
  position: relative;
}
.present-day:hover {
  background: linear-gradient(180deg, rgba(160,130,0,0.95) 0%, rgba(120,95,0,0.98) 100%) !important;
  box-shadow: 0 6px 0 rgba(0,0,0,0.4), 0 0 30px rgba(255,215,0,0.3), inset 0 1px 0 rgba(255,215,0,0.25) !important;
  transform: translateY(-3px) !important;
}

/* TEMPORAL ANOMALY FLASH */
#temporal-anomaly {
  position: fixed;
  inset: 0;
  background: rgba(255,90,90,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  font-family: "Orbitron", sans-serif;
  font-size: 1.4em;
  color: var(--glow-red);
  text-shadow: 0 0 20px rgba(255,90,90,0.8);
  letter-spacing: 0.12em;
}
#temporal-anomaly.visible {
  animation: anomalyFlash 0.5s ease-out forwards;
}
@keyframes anomalyFlash {
  0% { opacity: 0; }
  20% { opacity: 1; }
  60% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* TEMPORAL FLASH on travel */
#travel-flash {
  position: fixed;
  inset: 0;
  background: white;
  opacity: 0;
  pointer-events: none;
  z-index: 998;
}

/* ============ HISTORICAL EVENTS ============ */
.historical-events {
  background: rgba(0,5,15,0.7);
  border: 1px solid rgba(0,229,255,0.15);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
  height: 185px;
  overflow-y: auto;
}

.historical-events::-webkit-scrollbar { width: 5px; }
.historical-events::-webkit-scrollbar-track { background: rgba(0,0,0,0.3); }
.historical-events::-webkit-scrollbar-thumb { background: rgba(0,229,255,0.3); border-radius: 3px; }

@media (min-width: 821px) {
  .historical-events {
    height:clamp(300px, 38dvh, 460px);
    padding-bottom:16px;
    scroll-padding-top:12px;
  }
}

#story-entry {
  position: sticky;
  top: -10px;
  z-index: 2;
  padding: 5px 0 9px;
  background: linear-gradient(180deg, #041325 80%, rgba(4,19,37,0));
}
#picture-story-btn, #picture-story-btn-mini {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid rgba(217,164,255,0.75);
  border-radius: 9px;
  background: linear-gradient(90deg, rgba(114,54,150,0.35), rgba(60,31,99,0.25));
  color: #f1d7ff;
  font: 700 0.88em "Orbitron", sans-serif;
  letter-spacing: 0.03em;
  text-align: left;
  box-shadow: 0 0 18px rgba(190,112,230,0.14);
}
#picture-story-btn:hover, #picture-story-btn-mini:hover { background: rgba(130,69,168,0.4); }
.story-mode-control { display:flex; align-items:center; gap:8px; margin:6px 0; color:#d9c4e6; font:600 .78rem "Rajdhani",sans-serif; }
.story-mode-control select { min-height:34px; padding:4px 8px; border:1px solid rgba(217,164,255,.4); border-radius:6px; color:#f0d9ff; background:#160e24; font:inherit; }
.story-local-context { margin:5px 0 8px; color:#d9c4e6; font:600 .78rem "Rajdhani",sans-serif; }
.story-local-context summary { cursor:pointer; }
.story-local-context textarea { display:block; width:min(100%,560px); margin-top:7px; padding:9px; border:1px solid rgba(217,164,255,.4); border-radius:6px; background:#100a1b; color:#f6effa; font:14px/1.4 "Rajdhani",sans-serif; }
.story-local-context small { display:block; max-width:560px; margin-top:5px; opacity:.8; }
.mini-story-entry { margin: 4px 0 9px; }

.library-group-title {
  padding: 7px 3px 2px;
  font: 700 0.75em "Orbitron", sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--glow);
}
.library-group-title.stories-title { color: #dba8fa; }
.story-item {
  border-color: rgba(217,164,255,0.34);
  background: rgba(118,62,151,0.11);
}
.story-item:hover { border-color: rgba(217,164,255,0.65); }
.story-item .ri-title { color: #edd0ff; }
.story-item .ri-meta { color: #d4b1e7; opacity: 0.9; }
.story-item .ri-actions button { border-color: rgba(217,164,255,0.45); color: #eed4ff; }

/* Full-screen story reader */
#story-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 12000;
  background: #090713;
  color: #251e2c;
}
#story-modal.open { display: block; }
.story-modal-shell { display: flex; flex-direction: column; width: 100%; height: 100vh; height: 100dvh; }
.story-modal-header, .story-modal-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px clamp(14px,3vw,38px);
  background: #160e24;
  color: #f0d9ff;
  border-color: rgba(217,164,255,0.2);
}
.story-modal-header { border-bottom: 1px solid rgba(217,164,255,0.2); }
.story-modal-footer { border-top: 1px solid rgba(217,164,255,0.2); flex-wrap: wrap; }
.story-modal-kicker { display: block; color: #c59ad9; font: 700 0.66em "Orbitron", sans-serif; letter-spacing: 0.16em; }
#story-modal-title { margin: 3px 0 0; font: 700 clamp(1rem,2vw,1.4rem) "Orbitron", sans-serif; }
#story-close-btn { margin-left: auto; padding: 8px 12px; }
.story-modal-body { flex: 1; min-height: 0; overflow-y: auto; background: #e9e0ed; outline: none; }
.story-modal-body.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.story-modal-body.loading #story-status { text-align: center; font-size: 1rem; }
.story-modal-body.loading #story-status::before { content: '✦'; display: block; margin-bottom: 14px; color: #9863b1; font-size: 3rem; animation: story-pulse 1.6s ease-in-out infinite; }
@keyframes story-pulse { 50% { opacity: .35; transform: scale(.82) rotate(22deg); } }
#story-status { max-width: 820px; margin: 18px auto; padding: 0 22px; color: #5a3d68; font: 0.88em "Share Tech Mono", monospace; }
#story-status:empty { display: none; }
#story-retry-btn { display: block; max-width: 820px; margin: 0 auto 18px; border-color: #9c73b2; color: #6c417f; background: #fffaf2; }
#story-retry-btn[hidden] { display: none; }
.story-downloads { display: flex; flex-wrap: wrap; gap: 7px; margin-left: auto; }
.story-modal-footer button { border-color: rgba(217,164,255,0.5); color: #f0d9ff; padding: 7px 10px; }
.story-modal-footer button:disabled { opacity: .42; }
body.story-modal-open { overflow: hidden; }
.story-document { max-width: 900px; margin: 0 auto; padding: 28px clamp(22px,6vw,80px) 70px; background: #fffaf2; box-shadow: 0 0 45px rgba(46,25,61,.14); font: 1.04rem/1.78 Georgia, serif; color: #2a2430; min-height: 100%; }
.story-cover { padding: 40px 0 35px; text-align: center; border-bottom: 1px solid #d8c8dc; }
.story-kicker, .story-chapter-number, .story-chapter-topic { font: 700 .72rem/1.4 "Orbitron", sans-serif; letter-spacing: .12em; text-transform: uppercase; color: #8f5da5; }
.story-cover h1 { margin: 14px 0 8px; font: 700 clamp(2.2rem,5vw,4.4rem)/1.12 Georgia, serif; color: #33203c; }
.story-cover p { margin: 0; color: #725f78; }
.story-disclosure { margin: 25px 0; padding: 11px 15px; border-left: 3px solid #a676ba; background: #f2eaf4; color: #5b4961; font: .84rem/1.5 "Rajdhani", sans-serif; }
.story-opening { padding: 12px 0 23px; font-size: 1.13em; }
.story-chapter { padding: 35px 0; border-top: 1px solid #e1d3e4; }
.story-chapter h2, .story-closing h2 { margin: 9px 0 3px; font: 700 clamp(1.7rem,3vw,2.4rem)/1.18 Georgia, serif; color: #392240; }
.story-chapter p, .story-opening p, .story-closing p { margin: 1em 0; }
.story-sdg { margin-top: 24px; padding: 12px 16px; border-radius: 7px; background: #f0e8f3; color: #513e59; font: .84rem/1.55 "Rajdhani", sans-serif; }
.story-sdg ul { margin: 6px 0 0; padding-left: 20px; }
.story-sdg-badges, .event-sdg-badges, .datareef-sdg-badges { display:flex; flex-wrap:wrap; align-items:center; gap:6px; }
.story-sdg-badges { margin-top:12px; }
.sdg-badge {
  display:inline-flex; align-items:center; justify-content:center; min-height:24px; padding:3px 8px;
  border:1px solid currentColor; border-radius:999px; background:rgba(255,255,255,.06);
  font:700 .72rem/1.2 "Share Tech Mono",monospace; text-decoration:none; white-space:nowrap;
}
.story-document .sdg-badge { background:#fff; }
.event-sdg-badges { flex-basis:100%; }
.datareef-sdg-badges { display:inline-flex; vertical-align:middle; margin:0 3px; }
.story-closing { padding: 35px 0; border-top: 1px solid #e1d3e4; }
.story-provenance { padding-top: 20px; border-top: 1px solid #e1d3e4; color: #6a5a70; font: .86rem/1.6 "Rajdhani", sans-serif; }
.story-provenance h2 { font: 700 1rem "Orbitron", sans-serif; }
.story-provenance a { color: #774b8d; }
.story-cover { position:relative; display:grid; place-items:center; min-height:420px; color:#fff; background-color:#30263a; background-image:var(--story-cover-image,none); background-position:center; background-size:cover; background-repeat:no-repeat; break-after:page; }
.story-cover::before { content:""; position:absolute; inset:0; background:linear-gradient(135deg,rgba(15,9,25,.42),rgba(15,9,25,.82)); }
.story-cover-content { position:relative; max-width:760px; padding:24px; }
.story-cover .story-kicker { color:#eedfff; }
.story-cover h1 { overflow-wrap:anywhere; }
.story-cover p { color:#eee5f4; }
.story-flag { white-space:nowrap; }
.story-toc { margin:22px 0; padding:20px 25px; background:#f4eef5; border-radius:10px; }
.story-toc h2 { margin-top:0; font:700 1.2rem "Orbitron",sans-serif; }
.story-toc a { color:#65427b; text-decoration:none; }
.story-actions, .story-appendix { padding:24px 0; border-top:1px solid #e1d3e4; }
.story-actions-note { color:#65566b; font:.88rem/1.5 "Rajdhani",sans-serif; }
.story-action { margin:14px 0; padding:15px 18px; border-left:5px solid #8f5da5; border-radius:6px; background:#f1eaf4; }
.story-action h3, .story-appendix-item h3, .story-input-group h3 { margin:0 0 7px; font:700 1rem "Orbitron",sans-serif; color:#392240; }
.story-action p { margin:7px 0; }
.story-appendix-item { margin:16px 0; }
.story-input-group { margin:15px 0; }
.story-page-footer { display:none; }
.content-class-badge { display:inline-block; margin:0 5px 3px 0; padding:2px 7px; border:1px solid currentColor; border-radius:999px; color:#765590; background:#f4eef5; font:700 .62rem/1.3 "Share Tech Mono",monospace; letter-spacing:.02em; vertical-align:middle; }
.class-verified_observation { color:#22664a; background:#e5f4eb; }
.class-sourced_projection { color:#275c84; background:#e7f1fa; }
.class-conditional_scenario { color:#8a5a12; background:#fff3d7; }
.class-fictional_scene { color:#7b3a72; background:#f8e8f4; }
.class-unknown_or_unresolved { color:#665b6d; background:#eee9f0; }
.claim-note { display:block; margin:4px 0 0; color:#645d6b; font: .78em/1.4 "Rajdhani",sans-serif; }
.story-claim { margin:1em 0; }
.story-appendix-item .content-class-badge { margin:6px 0; }

/* ============ EVENT CARDS ============ */
.event-container {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0,229,255,0.08);
  background: rgba(0,229,255,0.02);
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.event-container::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--event-stripe, rgba(0,229,255,0.4));
  border-radius: 2px 0 0 2px;
}
.event-container:hover {
  border-color: rgba(0,229,255,0.22);
  background: rgba(0,229,255,0.05);
  transform: translateX(2px);
  box-shadow: 0 0 12px rgba(0,229,255,0.06);
}

.event-icon { width: 28px; height: 28px; flex: 0 0 28px; margin-top: 2px; }
.icon-galaxy { fill: var(--glow); }
.icon-government { fill: var(--glow-amber); }
.icon-music { fill: var(--glow-green); }
.icon-geology { fill: var(--glow-red); }

/* Future events - cyan */
.future-event {
  color: var(--glow) !important;
  text-shadow: 0 0 8px rgba(0,229,255,0.5);
  font-weight: 600;
  font-family: "Rajdhani", sans-serif;
  font-size: 1.05em;
}
/* Historical events - amber */
.hist-event {
  color: var(--glow-amber);
  font-family: "Rajdhani", sans-serif;
  font-size: 1.05em;
  text-shadow: 0 0 6px rgba(255,179,0,0.3);
}

.event-text { line-height: 1.35; }

/* Event elaborate/bg buttons */
.elaborate-btn, .bg-btn {
  font-size: 0.78em !important;
  padding: 4px 8px !important;
  border-radius: 4px !important;
  letter-spacing: 0.02em;
  font-family: "Share Tech Mono", monospace !important;
}
.elaborate-btn { border-color: rgba(0,229,255,0.25) !important; color: var(--glow) !important; }
.bg-btn { border-color: rgba(255,179,0,0.22) !important; color: var(--glow-amber) !important; }

/* Category/confidence badges */
.event-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.72em;
  font-family: "Share Tech Mono", monospace;
  letter-spacing: 0.05em;
  vertical-align: middle;
  margin-left: 6px;
  opacity: 0.8;
}
.badge-future { background: rgba(0,229,255,0.12); border: 1px solid rgba(0,229,255,0.25); color: var(--glow); }
.badge-hist { background: rgba(255,179,0,0.1); border: 1px solid rgba(255,179,0,0.25); color: var(--glow-amber); }

/* ============ COORDINATES ============ */
.coordinates {
  font-family: "Share Tech Mono", monospace;
  font-size: 0.8em;
  opacity: 0.7;
  text-align: center;
  letter-spacing: 0.06em;
}

/* ============ VORTEX (legacy) ============ */
.vortex {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; opacity: 0;
  transition: opacity 2s;
}
.time-traveling .vortex { opacity: 1; }

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

/* ============ OUTPUT PANEL ============ */
#output-panel {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  width: 92%;
  max-width: 1100px;
  background: rgba(0,5,15,0.92);
  border: 1px solid rgba(0,229,255,0.2);
  border-radius: 10px;
  color: var(--glow);
  z-index: 60;
  overflow: hidden;
  transition: transform 0.35s ease, opacity 0.35s ease;
  pointer-events: auto;
  box-shadow: 0 0 30px rgba(0,0,0,0.6);
}
#output-panel.collapsed {
  transform: translateX(-50%) translateY(88%);
  opacity: 0.04;
  pointer-events: none;
}

/* ============ TABLE & HTML CONTENT STYLES ============ */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  margin: 14px 0;
}
.table-responsive table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
  background: rgba(0,8,20,0.6);
  border-radius: 6px;
  overflow: hidden;
}
.table-responsive th, .table-responsive td {
  padding: 10px 14px;
  border: 1px solid rgba(0,229,255,0.15);
  text-align: left;
}
.table-responsive th {
  background: rgba(0,229,255,0.12);
  color: var(--glow-white);
  font-family: "Orbitron", sans-serif;
  letter-spacing: 0.05em;
}
.table-responsive tr:nth-child(even) {
  background: rgba(0,229,255,0.03);
}
.table-responsive tr:hover {
  background: rgba(0,229,255,0.08);
}

.sdg-1 { color: #E5243B; font-weight: bold; }
.sdg-2 { color: #DDA63A; font-weight: bold; }
.sdg-3 { color: #4C9F38; font-weight: bold; }
.sdg-4 { color: #C5192D; font-weight: bold; }
.sdg-5 { color: #FF3A21; font-weight: bold; }
.sdg-6 { color: #26BDE2; font-weight: bold; }
.sdg-7 { color: #FCC30B; font-weight: bold; }
.sdg-8 { color: #A21942; font-weight: bold; }
.sdg-9 { color: #FD6925; font-weight: bold; }
.sdg-10 { color: #DD1367; font-weight: bold; }
.sdg-11 { color: #FD9D24; font-weight: bold; }
.sdg-12 { color: #BF8B2E; font-weight: bold; }
.sdg-13 { color: #3F7E44; font-weight: bold; }
.sdg-14 { color: #0A97D9; font-weight: bold; }
.sdg-15 { color: #56C02B; font-weight: bold; }
.sdg-16 { color: #00689D; font-weight: bold; }
.sdg-17 { color: #19486A; font-weight: bold; }

.event-evidence {
  margin-top: 5px;
  color: rgba(229,241,255,0.68);
  font: 0.78em/1.4 "Share Tech Mono", monospace;
}
.event-sdg-links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}
.sdg-link, .event-sdg-note {
  padding: 4px 7px;
  border: 1px solid rgba(0,229,255,0.14);
  border-radius: 5px;
  background: rgba(0,229,255,0.035);
  color: rgba(229,241,255,0.8);
  font: 0.76em/1.4 "Share Tech Mono", monospace;
}
.event-sdg-note {
  display: inline-block;
  margin-top: 7px;
  opacity: 0.65;
}

#tw-body h2 {
  font-family: "Orbitron", sans-serif;
  font-size: 1.1em;
  color: var(--glow-amber);
  margin-top: 1.5em;
  margin-bottom: 0.8em;
  border-bottom: 1px solid rgba(255,179,0,0.3);
  padding-bottom: 4px;
}
#tw-body h3 {
  font-family: "Orbitron", sans-serif;
  font-size: 1em;
  color: var(--glow-white);
  margin-top: 1.2em;
}
#tw-body p {
  margin-bottom: 1em;
  line-height: 1.6;
}
#tw-body ul {
  margin-bottom: 1em;
  padding-left: 1.5em;
}
#tw-body li {
  margin-bottom: 0.5em;
}
#tw-body .typed-claim {
  display:block;
  margin:0 0 14px;
  padding:10px 12px;
  border-left:3px solid rgba(0,229,255,.45);
  border-radius:0 8px 8px 0;
  background:rgba(0,229,255,.045);
  line-height:1.65;
}
#tw-body .typed-claim.class-verified_observation { border-left-color:#65d9a5; }
#tw-body .typed-claim.class-sourced_projection { border-left-color:#f0c46a; }
#tw-body .typed-claim.class-conditional_scenario { border-left-color:#b9a0ff; }
#tw-body .typed-claim.class-fictional_scene { border-left-color:#f09ec8; }
#tw-body .typed-claim.class-unknown_or_unresolved { border-left-color:#ffad75; }
#tw-body .content-class-badge { color:#d8edff; background:rgba(2,12,24,.9); }
#tw-body hr {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,229,255,0.4), transparent);
  margin: 1.5em 0;
}

/* ============ TYPEWRITER PANEL ============ */
#typewriter-panel {
  position: fixed;
  left: 50%;
  bottom: -55vh;
  transform: translateX(-50%);
  width: 94%;
  max-width: 920px;
  height: 54vh;
  background: linear-gradient(180deg, rgba(0,8,22,0.97), rgba(0,12,30,0.99));
  border: 1px solid rgba(0,229,255,0.28);
  border-radius: 12px 12px 0 0;
  color: var(--glow);
  z-index: 10000;
  box-shadow: 0 -12px 60px rgba(0,0,0,0.9), 0 -2px 0 rgba(0,229,255,0.4);
  transition: bottom 0.25s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#typewriter-panel.open { bottom: 0; }

@media (min-width: 821px) {
  #typewriter-panel {
    height:min(88dvh, 960px);
    max-height:calc(100dvh - 18px);
    bottom:-90dvh;
    border-radius:14px 14px 0 0;
  }
  #typewriter-panel.open { bottom:0; }
  #typewriter-panel .tw-body { padding:20px clamp(20px, 4vw, 48px); font-size:.96rem; line-height:1.65; }
  #tw-body h2 { font-size:1.22rem; margin-top:1.4em; }
  #tw-body h3 { font-size:1.08rem; }
}

/* Loading overlay */
#tw-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,5,18,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
  transition: opacity 0.4s ease;
  border-radius: 12px 12px 0 0;
}
#tw-loading-overlay.hidden { opacity: 0; pointer-events: none; }
#tw-loading-spinner {
  width: 48px; height: 48px;
  border: 2px solid rgba(0,229,255,0.12);
  border-top-color: var(--glow);
  border-right-color: rgba(0,229,255,0.4);
  border-radius: 50%;
  animation: tw-spin 0.7s linear infinite;
}
@keyframes tw-spin { to { transform: rotate(360deg); } }
#tw-loading-status {
  font-family: "Share Tech Mono", monospace;
  font-size: 0.83em;
  opacity: 0.9;
  text-align: center;
  max-width: 320px;
  min-height: 1.2em;
  letter-spacing: 0.04em;
  color: var(--glow);
}
#tw-progress-bar-wrap {
  width: 280px; height: 2px;
  background: rgba(0,229,255,0.08);
  border-radius: 2px; overflow: hidden;
}
#tw-progress-bar {
  height: 100%; width: 0%;
  background: var(--glow);
  border-radius: 2px;
  transition: width 0.4s ease;
  box-shadow: 0 0 10px var(--glow);
}
@keyframes tw-bar-indeterminate {
  0% { transform: translateX(-100%); width: 60%; }
  100% { transform: translateX(280px); width: 60%; }
}
#tw-progress-bar.indeterminate { animation: tw-bar-indeterminate 1.3s ease-in-out infinite; }

#typewriter-panel .tw-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0,229,255,0.08);
  flex: 0 0 42px;
  background: rgba(0,229,255,0.03);
  font-family: "Orbitron", sans-serif;
}
#typewriter-panel .tw-header .tw-title { font-weight: 700; font-size: 0.85em; letter-spacing: 0.08em; }
#typewriter-panel .tw-header .tw-sub { color:#c9d9ec; font-size:.85em; }
#typewriter-panel .tw-close {
  margin-left: auto; background: transparent;
  border: 1px solid rgba(0,229,255,0.3); color: var(--glow);
  padding: 5px 9px; border-radius: 5px; font-size: 0.9em;
}
#typewriter-panel .tw-body {
  padding: 12px;
  font-family: "Share Tech Mono", monospace;
  font-size: 0.88em;
  line-height: 1.5;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  color: #f2f7ff;
}

/* Elaboration reading contrast and expandable research sections */
#tw-body { color:#f2f7ff; }
#tw-body .tw-sub, #tw-body .typed-claim,
#tw-body .typed-claim p, #tw-body .typed-claim li { color:#e7eefb; opacity:1; }
#tw-body .typed-claim { background:rgba(8,23,42,.96); }
#tw-body .content-class-badge { color:#f3f8ff; border:1px solid rgba(219,235,255,.42); }
#tw-body .sdg-1 { color:#ff8190; } #tw-body .sdg-2 { color:#f3ca6c; }
#tw-body .sdg-3 { color:#8dd27d; } #tw-body .sdg-4 { color:#ff7180; }
#tw-body .sdg-5 { color:#ff8978; } #tw-body .sdg-6 { color:#65d8f0; }
#tw-body .sdg-7 { color:#ffda55; } #tw-body .sdg-8 { color:#f07aa6; }
#tw-body .sdg-9 { color:#ff9b65; } #tw-body .sdg-10 { color:#fa78b2; }
#tw-body .sdg-11 { color:#ffc16b; } #tw-body .sdg-12 { color:#e8bd6e; }
#tw-body .sdg-13 { color:#a6dfa0; } #tw-body .sdg-14 { color:#67c8f4; }
#tw-body .sdg-15 { color:#9cdb74; } #tw-body .sdg-16 { color:#72c9f5; }
#tw-body .sdg-17 { color:#92c7ed; }
#tw-body .elab-section {
  margin:12px 0; border:1px solid rgba(100,190,220,.32); border-radius:10px;
  background:rgba(4,15,30,.8); overflow:hidden;
}
#tw-body .elab-section > summary {
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  cursor:pointer; list-style:none; padding:15px 18px; color:#ffca52;
  background:linear-gradient(100deg,rgba(255,179,0,.09),rgba(0,229,255,.045));
  font:700 1rem/1.4 "Orbitron",sans-serif;
}
#tw-body .elab-section > summary::-webkit-details-marker { display:none; }
#tw-body .elab-section > summary:focus-visible { outline:2px solid #70f2df; outline-offset:-3px; }
#tw-body .section-chevron { color:#c5f6ff; font-size:1.3em; transition:transform .18s ease; }
#tw-body details[open] > summary .section-chevron { transform:rotate(180deg); }
#tw-body .elab-section-content { padding:14px 16px 16px; }
#tw-body .elab-section-content > div:first-child:empty { display:none; }
#tw-body .section-dive-btn, #tw-body .section-graph-btn {
  margin:8px 8px 0 0; padding:8px 12px; border-radius:7px;
  color:#eaf7ff; background:#10253a; border:1px solid #5590a9; cursor:pointer;
  font:600 .82rem "Share Tech Mono",monospace;
}
#tw-body .section-dive-btn:hover, #tw-body .section-graph-btn:hover { background:#163852; border-color:#70f2df; }
#tw-body .section-dive-btn:disabled, #tw-body .section-graph-btn:disabled { opacity:.7; cursor:wait; }
#tw-body .section-dive-body, #tw-body .section-graph-body {
  margin-top:12px; padding:12px; border:1px solid rgba(112,242,223,.28);
  border-radius:8px; background:rgba(7,21,35,.88); color:#ecf3ff;
}
#tw-body .dive-loading, #tw-body .graph-limit { color:#d4e1f2; }
#tw-body .evidence-chart-wrap { margin:12px 0 16px; }
#tw-body .evidence-chart-note { color:#dce8f7; font-size:.9em; }
#tw-body .evidence-chart { margin:0; padding:12px; border-radius:8px; background:#071526; border:1px solid rgba(112,242,223,.25); }
#tw-body .evidence-chart figcaption { display:flex; flex-wrap:wrap; justify-content:space-between; gap:8px; color:#f2f7ff; font-weight:700; }
#tw-body .evidence-chart figcaption span, #tw-body .evidence-chart small { color:#d2dfef; font-size:.8em; font-weight:400; }
#tw-body .evidence-chart svg { width:100%; max-height:230px; overflow:visible; }
#tw-body .evidence-chart svg line { stroke:rgba(207,226,244,.4); stroke-width:1; }
#tw-body .evidence-chart svg polyline { fill:none; stroke:#70f2df; stroke-width:3; }
#tw-body .evidence-chart svg text { fill:#e6efff; font:11px "Share Tech Mono",monospace; }
#tw-body .causal-graph { display:flex; align-items:stretch; gap:10px; overflow:auto; padding:8px 0; }
#tw-body .causal-node { min-width:120px; max-width:200px; padding:12px; border:1px solid #5c9cab; border-radius:8px; background:#10293b; color:#f2f7ff; font-size:.84em; }
#tw-body .causal-node span { display:block; color:#70f2df; font:700 .75em "Share Tech Mono",monospace; margin-bottom:5px; }
#tw-body .causal-links { display:grid; gap:7px; margin-top:8px; }
#tw-body .causal-link { display:grid; grid-template-columns:minmax(70px,1fr) auto minmax(70px,1fr); align-items:center; gap:8px; color:#eaf2ff; font-size:.82em; }
#tw-body .causal-link b { color:#70f2df; }
#tw-body .causal-link small { grid-column:1/-1; color:#d2dfef; }
#tw-body .causal-link.status-supported small { color:#a9e7c7; }
#tw-body .causal-link.status-inferred small { color:#f3d28a; }
#tw-body .causal-link.status-unresolved small { color:#ffc199; }
#tw-body .expert-results { margin-top:14px; color:#edf4ff; }
#tw-body .expert-results h3 { margin:8px 0; color:#ffcf66; }
#tw-body .expert-search-status, #tw-body .expert-coverage-note { color:#dbe7f5; font-size:.86em; line-height:1.55; }
#tw-body .expert-search-status.error { color:#ffb7a7; }
#tw-body .expert-candidate-list { display:grid; gap:12px; margin-top:12px; }
#tw-body .expert-candidate { padding:14px; border:1px solid rgba(112,242,223,.32); border-radius:9px; background:#081a2c; }
#tw-body .expert-candidate h4 { margin:0 0 8px; color:#f2f7ff; font:700 1em/1.4 "Orbitron",sans-serif; }
#tw-body .expert-candidate p { margin:7px 0; line-height:1.5; }
#tw-body .expert-reason { color:#f1f5ff; }
#tw-body .expert-meta, #tw-body .expert-role-note { color:#d2deee; font-size:.86em; }
#tw-body .expert-role-note { border-left:2px solid #f3c86f; padding-left:9px; }
#tw-body .expert-contact { color:#e9f1ff; font-size:.87em; }
#tw-body .expert-subheading { display:block; margin-top:10px; color:#a7e8df; font:600 .8em "Share Tech Mono",monospace; }
#tw-body .expert-work-list { margin:5px 0; padding-left:20px; font-size:.84em; }
#tw-body .expert-work-list li { margin:5px 0; color:#dfeafa; }
#tw-body .expert-candidate a { color:#86e6f3; text-decoration:underline; text-underline-offset:2px; }
#tw-body .expert-candidate a:focus-visible { outline:2px solid #70f2df; outline-offset:2px; }
#tw-body .expert-sources { margin-top:10px; padding-top:9px; border-top:1px solid rgba(200,225,245,.16); }
#tw-body .expert-sources > strong { color:#cbd8ea; font:600 .76em "Share Tech Mono",monospace; }
#tw-body .expert-source-links { display:flex; flex-wrap:wrap; gap:8px 14px; margin-top:6px; font-size:.8em; }
#typewriter-panel .tw-footer {
  padding: 7px 12px;
  border-top: 1px solid rgba(0,229,255,0.06);
  display: flex; gap: 8px; align-items: center;
  flex: 0 0 42px;
}
#typewriter-panel .tw-progress {
  opacity: 0.6; font-size: 0.82em;
  font-family: "Share Tech Mono", monospace;
}


/* Compact mobile layout */
@media (max-width: 820px) {
  /* Mobile: keep essential time controls pinned for easy reach */
  .controls {
    position: fixed;
    bottom: 100px;
    left: 12px;
    right: 12px;
    z-index: 280;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    background: rgba(0,8,20,0.6);
    padding: 8px;
    border-radius: 10px;
    border: 1px solid rgba(0,229,255,0.06);
    box-shadow: 0 8px 20px rgba(0,0,0,0.5);
    min-height: 56px;
  }
  .time-machine.mini .controls { display: grid; }
  :root {
    --panel-padding: 12px;
  }
  /* Allow vertical scrolling on mobile so long panels (topics, typewriter, research) can scroll */
  body {
    font-size: 14px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Make the time-machine fit the viewport, remove heavy 3D tilt and allow taller content */
  .time-machine {
    width: calc(100vw - 24px);
    margin: 56px 12px 12px;
    padding: 12px;
    border-radius: 12px;
    transform: none !important;
    max-height: none;
  }
  /* Collapse large header nav icons into smaller touch targets */
  #top-nav {
    height: 48px;
    padding: 6px 12px;
    gap: 8px;
  }
  #top-nav img { height:28px; }
  .nav-icon-btn { padding: 6px 8px; font-size:0.92em; border-radius:8px; }
  /* Context bar becomes stacked and compact */
  #context-bar {
    gap: 6px;
    padding: 8px;
    flex-wrap: wrap;
  }
  #context-bar select, #context-bar input, #context-bar button {
    font-size: 0.82em;
    padding: 7px 8px;
  }
  #selected-topic-display { font-size:0.8em; }
  /* Display area scales down */
  .display { padding: 10px; border-radius:10px; }
  #temporal-reactor { height:76px; }
  #reactor-canvas { width:76px; height:76px; left:50%; transform:translateX(-50%); }
  .year-display { font-size:2.2em; }
  .coordinates { font-size:0.75em; }
  /* Controls: change grid to 3 columns with larger touch targets */
  .controls {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .controls button {
    padding: 12px 8px;
    min-height: 48px;
    font-size: 0.88em;
    border-radius: 10px;
  }
  .present-day { grid-column: 1 / -1; font-size:0.86em; padding:10px; }
  /* Historical events compress */
  .historical-events { height: 180px; padding:8px; }
  .event-container { padding:8px; }
  .event-text { font-size:0.95em; }
  /* Output panel: keep compact and full width */
  #output-panel {
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100vw - 20px);
    max-width: none;
  }
  #output-panel.collapsed { transform: translateX(-50%) translateY(56%); }
  #output-panel .tw-header { flex-wrap:wrap; }
  #output-body { display:flex; flex-direction:column; gap:8px; padding:10px; }
  #bg-thumb { width:100%; height:120px; flex:0 0 auto; }
  #elaboration { width:100%; height:120px; flex:0 0 auto; }
  /* BG view button remains bottom center, increase size for touch */
  #bg-dl-btn {
    bottom: 14px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.95em;
  }
  /* BG preview modal ensure image fits vertically on mobile */
  #bg-preview-modal-img { max-height: calc(84vh - 72px); max-width: 96vw; }
  #bg-preview-modal-bar { padding: 10px 12px; width: 96vw; }
  /* Topic modal full-screen sheet on mobile */
  #topic-modal {
    left: 50%;
    top: 100%;
    transform: translate(-50%,-100%);
    width: 100%;
    height: 72vh;
    max-width: none;
    border-radius: 12px 12px 0 0;
    bottom: 0;
    overflow: auto;
    display: none;
  }
  #topic-modal.show { display:flex; transform: translate(-50%,-55%); }
  #topic-modal-body { padding:10px; grid-template-columns: repeat(2, minmax(140px, 1fr)); gap:10px; }
  /* Typewriter panel: make it full-width bottom sheet and allow internal scrolling */
  #typewriter-panel {
    width: 100vw !important;
    left: 50%;
    transform: translateX(-50%);
    bottom: -100vh;
    max-width: none;
    height: 56vh;
    border-radius: 12px 12px 0 0;
    overflow: auto;
  }
  #typewriter-panel.open { bottom: 0; }
  /* Make touch targets minimum size */
  button, .nav-icon-btn { min-height: 44px; min-width: 44px; }
  /* Hide non-essential visual noise for clarity */
  .vortex, svg.vortex { display: none !important; }
  /* Ensure three-canvas does not steal pointer on mobile, keep lightweight */
  #three-canvas { pointer-events: none; opacity:0.9; }
}

/* Very small devices tweak */
@media (max-width:420px) {
  .controls { grid-template-columns: repeat(2,1fr); gap:6px; }
  .year-display { font-size:1.8em; }
  #temporal-reactor { height:64px; }
  #reactor-canvas { width:64px; height:64px; }
  #output-panel.collapsed { transform: translateX(-50%) translateY(68%); }
}

/* Production accessibility and resilience defaults. */
:root { color-scheme: dark; }

button:focus-visible,
select:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--glow-white);
  outline-offset: 3px;
}

button:disabled { cursor: wait; opacity: 0.6; }

img { max-width: 100%; }

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

  #three-canvas,
  .vortex,
  #reactor-canvas { display: none !important; }
}

@media (max-width: 640px) {
  #context-bar select { min-width: min(100%, 220px); max-width: 100%; }
  #research-sidebar { width: 100%; right: -100%; }
  #topic-modal-body { grid-template-columns: 1fr; }
  #bg-preview-modal-bar { flex-wrap: wrap; }
  #bg-preview-modal-bar .bg-modal-caption { flex-basis: 100%; }
}

/* Data Reef evidence view */
.datareef-panel {
  margin-top: 12px;
  max-height: min(52vh, 480px);
  overflow: auto;
  border: 1px solid rgba(0,229,255,.18);
  border-radius: 12px;
  background: rgba(0,8,20,.92);
}
.datareef-panel[hidden] { display: none; }
.datareef-panel > header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px; border-bottom: 1px solid rgba(0,229,255,.14);
  background: rgba(0,229,255,.04);
}
.datareef-panel > header > div:first-child { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.datareef-panel > header span, .datareef-meta, .datareef-note, .datareef-disclaimer { color: rgba(229,241,255,.7); font-size: .84rem; }
.datareef-panel > header > div:last-child { display:flex; gap:8px; }
#datareef-content { padding: 12px; }
.datareef-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 10px; }
.datareef-card { min-width:0; padding:12px; border:1px solid rgba(0,229,255,.14); border-radius:10px; background:rgba(0,229,255,.035); }
.datareef-card-heading { display:flex; align-items:flex-start; justify-content:space-between; gap:10px; }
.datareef-card h3 { margin:0; font-size:1rem; line-height:1.35; color:var(--glow-white); }
.datareef-value { color:var(--glow); text-align:right; white-space:nowrap; }
.datareef-meta { line-height:1.5; margin:7px 0; }
.datareef-goals { font-size:.82rem; color:#bcecf4; }
.datareef-source { display:inline-block; margin:5px 10px 0 0; color:var(--glow); }
.datareef-forecast { margin-top:10px; padding:9px; border-radius:8px; background:rgba(0,0,0,.24); font-size:.84rem; line-height:1.5; }
.datareef-forecast p { margin:2px 0 0; }
.datareef-forecast.forecast { border-left:3px solid #9bdc9e; }
.datareef-forecast.scenario { border-left:3px solid var(--glow-amber); }
.datareef-forecast.unavailable { border-left:3px solid #df9d76; }
.datareef-forecast.observed { border-left:3px solid var(--glow); }
.datareef-error { color:#ff9f9f; }
.datareef-disclaimer { line-height:1.5; margin:12px 2px 0; }
.datareef-section-title { margin:16px 2px 8px; font:700 .9rem "Orbitron",sans-serif; color:var(--glow-white); }
.datareef-gap-list { display:grid; gap:8px; }
.datareef-gap { padding:10px; border:1px solid rgba(255,179,0,.2); border-radius:8px; background:rgba(255,179,0,.035); }
.datareef-gap strong, .datareef-gap span { display:block; }
.datareef-gap span, .datareef-gap p { margin:5px 0 0; color:rgba(229,241,255,.72); font-size:.82rem; line-height:1.45; }
.time-machine.with-datareef { overflow-y:auto; }

#mobile-content-nav, .mobile-travel { display:none; }
#jump-sheet {
  width:min(92vw, 480px); padding:0; border:1px solid rgba(0,229,255,.32);
  border-radius:16px; color:var(--glow-white); background:#071323;
}
#jump-sheet::backdrop { background:rgba(0,4,12,.72); backdrop-filter:blur(5px); }
.jump-sheet-header { display:flex; justify-content:space-between; align-items:center; gap:12px; padding:14px; border-bottom:1px solid rgba(0,229,255,.16); }
.jump-sheet-header h2 { margin:0; font:700 1rem "Orbitron",sans-serif; }
.jump-sheet-grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; padding:12px; }

/* Phone layout: context, year, one compact dock, then one content view. */
@media (max-width: 820px) {
  html { min-height:100%; }
  body {
    display:block; height:auto; min-height:100svh; overflow-x:hidden; overflow-y:auto;
    padding:0 0 calc(160px + env(safe-area-inset-bottom)); font-size:15px;
    -webkit-overflow-scrolling:touch;
  }
  button, input[type="button"], input[type="submit"], select {
    min-height:44px;
    touch-action:manipulation;
  }
  button { padding-block:8px; }
  #top-nav { height:52px; padding:5px 12px; gap:8px; }
  #top-nav img { height:27px !important; }
  .nav-icon-btn { min-height:44px; min-width:44px; padding:7px; }
  .time-machine {
    width:calc(100% - 20px); max-height:none; height:auto; margin:62px 10px 14px;
    padding:10px; overflow:visible; border-radius:14px; transform:none !important;
  }
  #context-bar {
    display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; gap:7px;
    padding:9px; margin-bottom:9px;
  }
  #context-bar > label { display:none; }
  #context-bar #location-select, #context-bar #state-bar { grid-column:1/-1; width:100%; min-width:0 !important; max-width:none !important; }
  #context-bar #state-bar { display:flex; }
  #context-bar #state-bar[style*="display: none"] { display:none !important; }
  #context-bar #open-topic-modal, #context-bar #open-datareef-btn { min-height:46px; }
  #context-bar #selected-topic-display { grid-column:1/-1; white-space:nowrap; max-width:100%; font-size:.82rem; }
  #context-bar #selected-topic-display:empty { display:none; }
  .display { min-height:206px; padding:10px; border-radius:12px; }
  #temporal-reactor { height:66px; }
  #reactor-canvas { width:66px; height:66px; left:50%; transform:translateX(-50%); }
  .year-display { font-size:clamp(2rem,10vw,3rem); }
  .coordinates { max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.72rem; }
  .controls { display:none !important; }
  .mobile-travel {
    position:fixed; left:0; right:0; bottom:0; z-index:180;
    display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px;
    padding:9px 12px calc(9px + env(safe-area-inset-bottom));
    background:rgba(2,10,22,.97); border-top:1px solid rgba(0,229,255,.22);
    box-shadow:0 -8px 24px rgba(0,0,0,.45); backdrop-filter:blur(12px);
  }
  #mobile-travel-dock { display:grid !important; visibility:visible; }
  .mobile-travel-label { grid-column:1 / -1; padding:0 2px; color:rgba(229,241,255,.68); font:600 .68rem "Share Tech Mono",monospace; letter-spacing:.1em; text-transform:uppercase; }
  .mobile-travel button { min-width:0; min-height:46px; padding:6px 4px; font-size:.72rem; border-radius:9px; }
  .mobile-travel button { white-space:nowrap; }
  .mobile-travel .present-day { grid-column:auto; font-size:.72rem !important; letter-spacing:0 !important; }
  #mobile-content-nav {
    position:sticky; top:52px; z-index:20; display:grid; grid-template-columns:repeat(3,1fr);
    gap:5px; padding:6px; margin:6px 0 8px; border:1px solid rgba(0,229,255,.12);
    border-radius:10px; background:rgba(0,8,20,.96);
  }
  #mobile-content-nav button { min-height:44px; padding:6px 4px; background:transparent; border-color:transparent; }
  #mobile-content-nav button[aria-pressed="true"] { color:#fff; background:rgba(0,229,255,.12); border-color:rgba(0,229,255,.35); }
  .historical-events { height:auto; max-height:none; min-height:130px; margin-top:0; padding:8px; overflow:visible; }
  #story-entry { position:sticky; top:106px; z-index:3; margin:-1px -1px 8px; padding:4px 1px 8px; background:#041325; }
  #picture-story-btn { min-height:50px; padding:10px 12px; font-size:.82rem; color:#fff !important; background:linear-gradient(100deg,rgba(109,48,148,.96),rgba(66,35,111,.96)) !important; border-color:rgba(222,170,255,.9); box-shadow:0 0 18px rgba(190,112,230,.3); }
  .event-container { padding:10px; gap:9px; }
  .elaborate-btn, .bg-btn { min-height:44px !important; padding:8px 11px !important; font-size:.82rem !important; }
  .datareef-panel { max-height:none; min-height:260px; margin-top:0; overflow:visible; }
  .datareef-panel > header { position:sticky; top:106px; z-index:2; }
  #datareef-content { padding:9px; }
  .datareef-card-heading { flex-wrap:wrap; }
  .datareef-value { text-align:left; }
  .datareef-card { padding:10px; }
  .time-machine.with-datareef { overflow:visible; }
  #output-panel {
    position:relative; inset:auto; transform:none !important; opacity:1 !important; pointer-events:auto !important;
    width:calc(100% - 20px); max-width:none; margin:0 10px 18px; border-radius:12px;
  }
  #output-panel.collapsed { transform:none !important; opacity:1 !important; pointer-events:auto !important; }
  #output-panel > div:first-child { display:flex !important; flex-wrap:wrap; gap:7px !important; }
  #output-panel #mini-status { flex:1 1 100%; order:3; }
  #output-body { display:flex; flex-direction:column; align-items:stretch !important; padding:10px !important; }
  #bg-thumb { width:100% !important; height:145px !important; flex:0 0 auto !important; }
  #elaboration { width:100% !important; height:auto !important; min-height:150px; max-height:42vh; flex:0 0 auto !important; }
  #regen-bg-verbose, #clear-elab-verbose { flex:1; }
  #mini-bar, #mini-events-panel, #bg-dl-btn { display:none !important; }
  body.mobile-panel-events #datareef-panel, body.mobile-panel-events #output-panel,
  body.mobile-panel-evidence .historical-events, body.mobile-panel-evidence #output-panel,
  body.mobile-panel-elaboration .historical-events, body.mobile-panel-elaboration #datareef-panel { display:none !important; }
  body.mobile-panel-elaboration #output-panel { display:block !important; }
  #profile-panel { position:fixed; left:10px; right:10px; top:58px; width:auto; max-width:none; }
  #topic-modal { left:0; right:0; top:auto; bottom:0; transform:none; width:100%; max-width:none; height:min(84dvh,760px); max-height:84dvh; border-radius:16px 16px 0 0; }
  #topic-modal.show { transform:none; }
  #topic-modal-header { display:grid; grid-template-columns:1fr auto; gap:8px; align-items:center; }
  #topic-modal-header > span { grid-column:1/-1; margin:0 !important; }
  #topic-modal-header > div { grid-column:1/-1; margin:0 !important; justify-content:flex-end; }
  #topic-search { grid-column:1/-1; width:100% !important; margin:0 !important; min-height:44px; font-size:16px !important; }
  #topic-modal-body { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; overflow:auto; }
  .topic-chip { min-height:44px; padding:8px 10px; font-size:.86rem; }
  #research-sidebar { top:0; height:100dvh; padding-bottom:env(safe-area-inset-bottom); }
  #research-sidebar-footer { display:grid; grid-template-columns:1fr 1fr; }
  #research-sidebar-footer button:last-child { grid-column:1/-1; }
  #gallery-modal { width:100vw !important; max-height:100dvh !important; height:100dvh; border-radius:0 !important; }
  #story-modal { z-index:900; }
  .story-modal-footer { padding-bottom:calc(10px + env(safe-area-inset-bottom)); }
  #jump-sheet { position:fixed; inset:auto 0 0; width:100%; max-width:none; max-height:80dvh; margin:0; border-radius:16px 16px 0 0; }
  #jump-sheet::backdrop { background:rgba(0,4,12,.72); }
  .jump-sheet-grid { grid-template-columns:1fr 1fr; max-height:70dvh; overflow:auto; padding-bottom:calc(12px + env(safe-area-inset-bottom)); }
  .jump-sheet-grid button { min-height:50px; }
  #temporal-recalc { z-index:150; }
  #hyperspeed-canvas { opacity:0; }
  #hyperspeed-canvas.active { opacity:.55; }
}

@media (max-width: 390px) {
  #context-bar { grid-template-columns:minmax(0,1fr) auto; }
  #context-bar #selected-topic-display { font-size:.76rem; }
  .mobile-travel { gap:5px; padding-left:8px; padding-right:8px; }
  .mobile-travel button, .mobile-travel .present-day { font-size:.68rem !important; }
  #topic-modal-body { grid-template-columns:1fr; }
  .datareef-card-heading { display:block; }
  .datareef-value { display:block; margin-top:5px; }
}
