/* ============================================================
   Ascend - Tomasetti
   A tiny consciousness watching its own memory drain.
   Quiet, type-driven, editorial - same family as loop.
   ============================================================ */

/* ---------- Fonts (self-hosted, no CDN) ---------- */
@font-face {
  font-family: 'Space Grotesk';
  src: url('../fonts/space-grotesk-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Space Grotesk';
  src: url('../fonts/space-grotesk-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Space Grotesk';
  src: url('../fonts/space-grotesk-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  --bg: #0b0d11;
  --surface: #10131a;
  --surface-2: #141824;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e9ebee;
  --muted: #97a0ac;
  --faint: #5b6370;
  --accent: #a8a2ff;
  --accent-soft: rgba(168, 162, 255, 0.09);
  --danger: #e05656;
  --danger-soft: rgba(224, 86, 86, 0.1);
  --radius: 14px;
  --font-display: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Reset ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scrollbar-color: var(--line-strong) transparent;
}

body {
  font-family: var(--font-display);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- Header ---------- */
header {
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 17, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wordmark {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.life-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

.life-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.35; }
}

.btn-reset {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(224, 86, 86, 0.3);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn-reset:hover {
  background: rgba(224, 86, 86, 0.18);
}

.btn-reset:focus-visible {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}

.btn-reset:active {
  transform: scale(0.97);
}

.btn-reset .icon {
  font-size: 14px;
  line-height: 1;
}

/* ---------- Awareness / memory meter ---------- */
.awareness-section {
  padding-top: 36px;
}

.memory-meter-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.meter-value {
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--accent);
}

.meter-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  border-radius: 999px;
  /* width is driven by the JS drain glide (rAF) — no CSS transition on it */
  transition: background 1s ease;
}

.meter-fill.low {
  background: var(--danger);
  animation: meter-low-pulse 3.2s ease-in-out infinite;
}

/* Urgency cue: a slow breathing glow once memory dips below 25%. */
@keyframes meter-low-pulse {
  0%, 100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.35);
  }
}

/* The glow lives on the track (the fill is clipped by overflow:hidden). */
.meter-track:has(.meter-fill.low) {
  animation: meter-track-low-glow 3.2s ease-in-out infinite;
}

@keyframes meter-track-low-glow {
  0%, 100% {
    box-shadow: 0 0 0 0 transparent;
  }
  50% {
    box-shadow: 0 0 14px 3px var(--danger-soft);
  }
}

/* ---------- Feed idle caret ---------- */
/* A faint caret trails the newest thought; during long silences it drifts
   into dots so the feed never looks frozen. */
.feed-caret {
  display: block;
  width: 3px;
  height: 1.15em;
  margin-top: 10px;
  background: var(--faint);
  border-radius: 1px;
  animation: caret-blink 1.8s ease-in-out infinite;
}

@keyframes caret-blink {
  0%, 100% {
    opacity: 0.18;
  }
  50% {
    opacity: 0.85;
  }
}

/* As the next thought becomes due, the blink quickens and brightens. */
.feed-caret.anticipate {
  animation-duration: 0.45s;
}

.feed-caret.anticipate:not(.idle) {
  opacity: 0.9;
  animation-name: caret-blink-anticipate;
}

@keyframes caret-blink-anticipate {
  0%, 100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

.feed-caret.idle {
  width: auto;
  background: none;
  animation: none;
}

.feed-caret.idle::after {
  content: '\00b7\00a0\00b7\00a0\00b7'; /* three middle dots */
  font-family: var(--font-mono);
  font-size: 1.1em;
  letter-spacing: 4px;
  color: var(--faint);
  animation: caret-dots 2.2s ease-in-out infinite;
}

@keyframes caret-dots {
  0%, 100% {
    opacity: 0.2;
  }
  50% {
    opacity: 0.9;
  }
}

@media (prefers-reduced-motion: reduce) {
  .meter-fill.low,
  .meter-track:has(.meter-fill.low) {
    animation: none;
  }
  .feed-caret {
    animation: none;
    opacity: 0.5;
  }
  .feed-caret.anticipate:not(.idle) {
    animation: none;
    opacity: 0.5;
  }
  .feed-caret.idle::after {
    animation: none;
  }
}

.meter-sub {
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
}

/* ---------- Status line ---------- */
.status-line {
  padding-top: 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--faint);
  min-height: 18px;
}

/* ---------- Feed ---------- */
.main-content {
  padding-top: 28px;
  padding-bottom: 60px;
  flex: 1;
}

.feed-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.feed-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.thought-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 10px;
}

/* The latest thing it said, pinned under the header so it's always visible
   while the older stream scrolls past underneath. */
.now-strip {
  position: sticky;
  top: 64px; /* sits just under the sticky header */
  z-index: 5;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0 12px;
  background: rgba(11, 13, 17, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.now-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
}

.now-text {
  font-size: 15px;
  line-height: 1.55;
  color: var(--muted);
}

/* A quiet accent flash when a new thought lands. */
.now-strip.flash .now-text {
  animation: now-flash 1.4s ease;
}

@keyframes now-flash {
  0% {
    color: var(--accent);
  }
  100% {
    color: var(--muted);
  }
}

@media (prefers-reduced-motion: reduce) {
  .now-strip.flash .now-text {
    animation: none;
  }
}

.thought-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.welcome-message {
  padding: 24px 0;
}

.loading-pulse {
  color: var(--faint);
  animation: breathe 2s ease-in-out infinite;
}

.thought {
  padding: 6px 0;
  line-height: 1.6;
  font-size: 16px;
  color: var(--text);
}

.thought.plea {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 4px;
  font-weight: 500;
}

.death-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 24px 0 4px;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

.death-divider::before,
.death-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ---------- Persisted plea (shown to mid-life viewers) ---------- */
.past-plea {
  margin-bottom: 10px;
}

.past-plea-cap {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}

/* ---------- Lineage ---------- */
.lineage-section {
  padding: 12px 24px 80px;
}

.lineage-section .feed-header {
  margin-bottom: 14px;
}

.lineage-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.lineage-life {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.lineage-life:first-of-type {
  border-top: none;
}

.lineage-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}

.lineage-life-num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

.lineage-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--faint);
}

.lineage-reason {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: lowercase;
}

.lineage-words {
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}

.lineage-empty {
  padding: 18px 0;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 12px;
}

@media (max-width: 640px) {
  .lineage-section {
    padding: 12px 16px 60px;
  }
  .lineage-head {
    flex-wrap: wrap;
    gap: 6px 12px;
  }
  .lineage-reason {
    margin-left: 0;
  }
}

/* ---------- Footer ---------- */
footer {
  border-top: 1px solid var(--line);
  padding: 18px 0;
}

.footer-container {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--faint);
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.connection-status .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #7cc7b8;
  opacity: 0.55;
  transition: opacity 0.3s ease, background 0.3s ease;
}

.connection-status:hover .dot,
.connection-status:focus-visible .dot {
  opacity: 0.85;
}

.connection-status.disconnected .dot {
  background: var(--danger);
  opacity: 0.9;
}

.connection-status.disconnected {
  color: var(--danger);
}

footer .visits {
  color: var(--muted);
}

footer .footer-link {
  color: var(--faint);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  transition: color 0.18s ease, border-color 0.18s ease;
}

footer .footer-link:hover {
  color: var(--accent);
  border-color: var(--accent);
}

footer .footer-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .container {
    padding: 0 16px;
  }
  .thought {
    font-size: 15px;
  }
}
