/* ── RESET ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: #05030e; color: rgba(255,255,255,0.85); overflow: hidden; }
body { font-family: 'Space Grotesk', sans-serif; -webkit-font-smoothing: antialiased; }
button { cursor: pointer; font-family: 'Space Mono', monospace; background: none; border: none; }
a { text-decoration: none; color: inherit; }

/* ── KEYFRAMES ──────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes blink  { 0%, 49% { opacity: 1; } 50%, 99% { opacity: 0; } }
@keyframes pulse  { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }

.fade-in { animation: fadeIn 0.55s ease-out both; }
.blink   { animation: blink 1s step-end infinite; }
.pulse   { animation: pulse 2.2s ease-in-out infinite; }

/* ── SCROLLBARS ─────────────────────────────────────────────── */
::-webkit-scrollbar        { width: 3px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: rgba(255,255,255,0.10); }

/* ── LOADING SCREEN ─────────────────────────────────────────── */
#loading-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: #020810;
  transition: opacity 1s ease;
}
#loading-screen.done { opacity: 0; pointer-events: none; }
#loading-canvas { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }
#loading-ui {
  position: fixed; inset: 0; pointer-events: none;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-family: 'Space Mono', monospace;
}
#loading-title {
  color: #39e8a0; font-size: 12px; letter-spacing: 0.32em;
  opacity: 0; transition: opacity 1s ease;
  text-shadow: 0 0 24px rgba(2,8,16,1), 0 0 8px rgba(2,8,16,1);
}
.loading-cur {
  display: inline-block; width: 8px; height: 13px;
  background: #39e8a0; margin-left: 2px; vertical-align: middle;
  animation: loading-blink 1s step-end infinite;
}
@keyframes loading-blink { 50% { opacity: 0; } }
#loading-status {
  margin-top: 20px; color: rgba(57,232,160,0.42);
  font-size: 9px; letter-spacing: 0.28em;
  opacity: 0; transition: opacity 0.35s ease; min-height: 14px;
  text-shadow: 0 0 16px rgba(2,8,16,1);
}
#loading-pgwrap {
  margin-top: 12px; width: 155px; height: 1px;
  background: rgba(57,232,160,0.10);
  opacity: 0; transition: opacity 0.8s ease; overflow: hidden;
}
#loading-pgbar { height: 100%; width: 0%; background: rgba(57,232,160,0.75); transition: width 0.14s linear; }
#loading-cta {
  display: none; position: fixed; bottom: 32px; right: 44px;
  color: rgba(57,232,160,0.28); font-size: 9px; letter-spacing: 0.22em;
  opacity: 0; transition: color 0.3s, opacity 0.7s;
}
#loading-cta:hover { color: rgba(57,232,160,0.65); }

/* ── FIXED BACKGROUND LAYERS ────────────────────────────────── */
#nebula-canvas {
  position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0;
}
#deep-parallax {
  position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden;
}
#sci-hud {
  position: fixed; inset: 0; z-index: 10; pointer-events: none; mix-blend-mode: screen;
}

/* ── PAGE SHELL ─────────────────────────────────────────────── */
#page {
  position: relative; z-index: 20;
  height: 100dvh; display: flex; flex-direction: column; overflow: hidden;
}

/* ── NAV ─────────────────────────────────────────────────────── */
.nav {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 48px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  background: rgba(2,1,14,0.6);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.nav-logo {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700;
  font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase;
  color: rgba(255,255,255,0.85); transition: color 0.15s;
}
.nav-logo:hover { color: #34d399; }
.nav-links {
  display: flex; gap: 0;
  font-family: 'Space Mono', monospace; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.1em;
}
.nav-link {
  color: rgba(255,255,255,0.42);
  padding: 6px 20px;
  border-left: 1px solid rgba(255,255,255,0.10);
  transition: color 0.15s, background 0.15s;
}
.nav-link:last-child { border-right: 1px solid rgba(255,255,255,0.10); }
.nav-link:hover { color: #34d399; }
.nav-link.active { color: #34d399; background: rgba(52,211,153,0.08); border-color: rgba(52,211,153,0.3); }

/* ── TITLE SECTION ──────────────────────────────────────────── */
#page-title-section {
  flex-shrink: 0; padding: 8px clamp(16px, 4vw, 40px) 22px;
}
#page-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(2.2rem, 5.5vw, 4.6rem);
  font-weight: 700; letter-spacing: -0.025em; color: #fff; line-height: 1;
}
#cursor-blink {
  display: inline-block; height: 0.88em; width: 0.44ch;
  background: #34d399; vertical-align: middle;
  transform: translateY(0.04em); margin-left: 8px;
}
#page-subtitle {
  margin-top: 12px; font-family: 'Space Mono', monospace;
  font-size: 12px; color: rgba(255,255,255,0.40);
}
.engine-ok { color: #34d399; }

/* ── FILTER BAR ─────────────────────────────────────────────── */
#filter-bar { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }

.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filter-row-label {
  font-family: 'Space Mono', monospace; font-size: 10px;
  letter-spacing: 0.14em; color: rgba(255,255,255,0.50);
  width: 72px; text-align: right; flex-shrink: 0; margin-right: 10px;
}

.filter-btn {
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,0.22); background: transparent;
  color: rgba(255,255,255,0.72); font-family: 'Space Mono', monospace;
  font-size: 10px; letter-spacing: 0.1em; transition: all 0.2s;
}
.filter-btn:hover:not(.active) {
  border-color: rgba(255,255,255,0.45); color: rgba(255,255,255,0.95);
}
.filter-btn.active {
  border-color: rgba(52,211,153,0.85); background: rgba(52,211,153,0.08); color: #34d399;
}

/* ── CARDS TRACK ─────────────────────────────────────────────── */
#cards-track {
  flex: 1; min-height: 0; overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none; -ms-overflow-style: none;
}
#cards-track::-webkit-scrollbar { display: none; }

#scroll-progress {
  position: sticky; top: 0; left: 0; z-index: 25; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, rgba(52,211,153,0.5), rgba(100,70,180,0.3));
  width: 0%; transition: width 0.1s linear;
}

#cards-flex {
  display: flex; align-items: flex-start; gap: 18px;
  padding: 32px clamp(16px, 4vw, 40px);
  padding-bottom: calc(176px + 20px);
  min-width: max-content; height: 100%;
}

/* ── LOADING STATE ───────────────────────────────────────────── */
#cards-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 32px clamp(16px, 4vw, 40px);
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: rgba(255,255,255,0.28);
}
#cards-loading::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #34d399;
  animation: pulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
}

/* ── RESEARCH CARD ───────────────────────────────────────────── */
.research-card {
  position: relative; flex-shrink: 0; width: 355px;
  border: 1px solid rgba(255,255,255,0.09);
  background: rgba(2,1,14,0.58);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  padding: 20px 22px;
  transition: border-color 0.26s, transform 0.26s, box-shadow 0.26s;
  cursor: default; display: flex; flex-direction: column;
}
.research-card:hover {
  border-color: rgba(52,211,153,0.38); transform: translateY(-3px);
  box-shadow: 0 0 48px -14px rgba(52,211,153,0.25), 0 0 80px -30px rgba(100,70,180,0.20);
}

/* Corner ticks */
.corner-tick {
  position: absolute; width: 12px; height: 12px;
  border-color: #34d399; border-style: solid;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
}
.research-card:hover .corner-tick { opacity: 1; }
.corner-tick-tl { top: 0; left: 0; border-width: 1px 0 0 1px; }
.corner-tick-tr { top: 0; right: 0; border-width: 1px 1px 0 0; }
.corner-tick-bl { bottom: 0; left: 0; border-width: 0 0 1px 1px; }
.corner-tick-br { bottom: 0; right: 0; border-width: 0 1px 1px 0; }
.research-card:hover .corner-tick-tl { transform: translate(-2px,-2px); }
.research-card:hover .corner-tick-tr { transform: translate(2px,-2px); }
.research-card:hover .corner-tick-bl { transform: translate(-2px,2px); }
.research-card:hover .corner-tick-br { transform: translate(2px,2px); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  font-family: 'Space Mono', monospace; font-size: 10px;
  letter-spacing: 0.12em; color: rgba(255,255,255,0.36); flex-shrink: 0;
}
.card-header-right { display: flex; align-items: center; gap: 8px; }

.card-type-badge { padding: 2px 6px; border-style: solid; border-width: 1px; }
.card-type-to-review  { border-color: rgba(52,211,153,0.44);  color: #34d399; }
.card-type-to-search  { border-color: rgba(245,158,11,0.44);  color: #f59e0b; }
.card-type-done       { border-color: rgba(147,197,253,0.44); color: #93c5fd; }

.card-title {
  margin-top: 14px; font-family: 'Space Grotesk', sans-serif;
  font-size: 17px; font-weight: 600; line-height: 1.3;
  color: rgba(255,255,255,0.92); letter-spacing: -0.015em; flex-shrink: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 44px;
}
.card-abstract {
  margin-top: 12px; font-size: 13px; line-height: 1.70;
  color: rgba(255,255,255,0.60); flex-grow: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.card-bottom { margin-top: auto; padding-top: 16px; flex-shrink: 0; }

.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.card-tag {
  font-family: 'Space Mono', monospace; font-size: 9px; letter-spacing: 0.1em;
  padding: 2px 8px; border: 1px solid rgba(52,211,153,0.28);
  color: rgba(52,211,153,0.75); background: rgba(52,211,153,0.04);
}

.card-link {
  display: inline-block; margin-bottom: 10px;
  font-family: 'Space Mono', monospace; font-size: 10px;
  letter-spacing: 0.12em; color: #93c5fd;
  border-bottom: 1px solid rgba(147,197,253,0.35);
  transition: color 0.2s, border-color 0.2s;
}

.card-link-wrapper {
  display: contents;
  text-decoration: none;
  color: inherit;
}
.card-link-wrapper .research-card { cursor: pointer; }
.card-link-wrapper:hover .card-link { color: #bfdbfe; border-color: rgba(147,197,253,0.7); }

.hover-coord {
  position: absolute; top: -18px; right: 0;
  font-family: 'Space Mono', monospace; font-size: 10px;
  color: rgba(52,211,153,0.72); opacity: 0; transition: opacity 0.18s; pointer-events: none;
}
.research-card:hover .hover-coord { opacity: 1; }

/* ── PAGE CTA (prev / next) ──────────────────────────────────── */
#load-more-cta, #load-prev-cta {
  flex-shrink: 0; width: 180px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; opacity: 0.45;
}
.load-more-line { width: 1px; height: 60px; }
#load-more-btn, #load-prev-btn {
  font-size: 10px; color: rgba(255,255,255,0.5);
  letter-spacing: 0.12em; transition: color 0.2s; text-align: center; line-height: 1.6;
}
#load-more-btn:hover, #load-prev-btn:hover { color: #34d399; }

/* ── THINKING LOG ────────────────────────────────────────────── */
#thinking-log {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(2,1,14,0.92); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  height: 6.5rem;
}

#log-bar {
  display: flex; align-items: center;
  padding: 0 clamp(16px, 4vw, 40px); height: 36px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  font-family: 'Space Mono', monospace; font-size: 10px;
  letter-spacing: 0.14em; color: rgba(255,255,255,0.40);
}
#log-status { display: flex; align-items: center; gap: 8px; }
#log-dot { width: 6px; height: 6px; border-radius: 50%; background: #34d399; display: inline-block; }

#log-lines {
  height: calc(100% - 2.25rem); overflow: hidden;
  padding: 10px clamp(16px, 4vw, 40px);
  font-family: 'Space Mono', monospace; font-size: 11px; line-height: 1.75;
}
.log-line { color: rgba(255,255,255,0.68); }

/* ── TABLET ──────────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1100px) {
  .research-card { width: clamp(280px, 30vw, 355px); }
}

/* ── MOBILE ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .nav { padding: 16px 20px; }
  .nav-link { padding: 6px 12px; }
}

@media (max-width: 767px) {
  html, body { overflow: auto; }
  #page { height: auto; overflow: visible; }
  #cards-track { overflow: visible; flex: none; }
  #cards-flex {
    flex-direction: column; align-items: stretch;
    min-width: auto; height: auto;
    padding-bottom: 180px;
  }
  .research-card { width: 100%; }
  #load-more-cta, #load-prev-cta { width: 100%; }
}
