/* ==========================================================================
   AI Doomscroll — design tokens
   Black stays the medium (it is a reels feed); identity comes from a colour
   per content type, a hue per source and condensed Archivo headlines.
   ========================================================================== */
@font-face {
  font-family: 'Archivo';
  src: url('fonts/archivo-wdth.woff2') format('woff2');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/ibm-plex-mono-500.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}

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

:root {
  --ink: #07080b;
  --fg: #f4f4f1;
  --fg-dim: rgba(244, 244, 241, 0.74);
  --fg-faint: rgba(244, 244, 241, 0.5);
  --glass: rgba(7, 8, 11, 0.55);
  --line: rgba(244, 244, 241, 0.18);

  /* one colour per content type */
  --news: #5ab0ff;
  --paper: #c8a2ff;
  --video: #ff6b81;

  --font-display: 'Archivo', 'Arial Narrow', system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --col: 100vw; /* feed column width (phone: full screen) */
  --top-bar: calc(env(safe-area-inset-top, 0px) + 56px);
}

html, body {
  height: 100%;
  background: var(--ink);
  color: var(--fg);
  font-family: var(--font-body);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

/* ---------- Desktop backdrop (blurred copy of the active card) ---------- */
#backdrop {
  position: fixed;
  inset: -10%;
  background: var(--ink) center / cover no-repeat;
  filter: blur(60px) saturate(1.4) brightness(0.45);
  transition: background-image 0.6s ease;
  display: none;
}

.key-hints {
  display: none;
}

/* ---------- Top bar: filters + position ---------- */
.top-bar {
  position: fixed;
  top: 0;
  left: 50%;
  translate: -50% 0;
  width: var(--col);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 8px;
  background: linear-gradient(to bottom, rgba(7, 8, 11, 0.7), rgba(7, 8, 11, 0));
}

.filter-chip {
  font: 600 13px/1 var(--font-body);
  color: var(--fg-dim);
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 13px;
  min-height: 36px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.filter-chip[aria-pressed="true"] {
  color: var(--ink);
  background: var(--fg);
  border-color: var(--fg);
}

.counter {
  margin-left: auto;
  font: 500 12px/1 var(--font-mono);
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Thin progress rail on the right edge of the column */
.progress-rail {
  position: fixed;
  top: var(--top-bar);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  left: calc(50% + var(--col) / 2 - 5px);
  width: 2px;
  border-radius: 2px;
  background: rgba(244, 244, 241, 0.12);
  z-index: 20;
  pointer-events: none;
}

.progress-fill {
  width: 100%;
  height: var(--progress, 0%);
  border-radius: 2px;
  background: var(--fg);
  transition: height 0.25s ease;
}

/* ---------- Feed ---------- */
#feed {
  position: relative;
  width: var(--col);
  margin: 0 auto;
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#feed::-webkit-scrollbar { display: none; }

.card {
  --type: var(--news);
  --src: #4c8dff;
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: var(--ink);
}

.card[data-type="paper"] { --type: var(--paper); }
.card[data-type="video"] { --type: var(--video); }

/* Photo layer (news with image, video thumbnails) */
.card-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: brightness(0.55);
  transform: scale(1.02);
}

/* YouTube "hqdefault" thumbnails are 4:3 with black bars baked in;
   zooming by 4/3 crops the bars away */
.card[data-type="video"] .card-bg:not(.placeholder) {
  transform: scale(1.34);
}

/* Cards without a photo: a glow in the source's hue plus fine grain.
   This is what imageless news and every paper card look like. */
.card-bg.placeholder {
  filter: none;
  transform: none;
  background:
    radial-gradient(90% 60% at 88% 8%, color-mix(in srgb, var(--src) 55%, transparent), transparent 70%),
    radial-gradient(80% 55% at 0% 100%, color-mix(in srgb, var(--src) 28%, transparent), transparent 70%),
    var(--ink);
}

.card-bg.placeholder::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.09;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* Paper cards: faint ruled lines like a printed preprint */
.card[data-type="paper"] .card-bg.placeholder {
  background:
    repeating-linear-gradient(to bottom, transparent 0 31px, rgba(244, 244, 241, 0.045) 31px 32px),
    radial-gradient(90% 60% at 88% 8%, color-mix(in srgb, var(--paper) 42%, transparent), transparent 70%),
    radial-gradient(80% 55% at 0% 100%, color-mix(in srgb, var(--src) 30%, transparent), transparent 70%),
    var(--ink);
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(7, 8, 11, 0.9) 0%, rgba(7, 8, 11, 0.35) 45%, rgba(7, 8, 11, 0.1) 100%);
  pointer-events: none;
}

.card.no-image::after {
  background: linear-gradient(to top, rgba(7, 8, 11, 0.55) 0%, transparent 50%);
}

/* Without a photo the text block sits in the optical centre of the card */
.card.no-image {
  justify-content: center;
}

.card.no-image .card-content {
  padding-top: calc(var(--top-bar) + 56px);
}

/* Source badge + time */
.badge-row {
  position: absolute;
  top: calc(var(--top-bar) + 6px);
  left: 14px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 3;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
}

.type-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--src);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--src) 30%, transparent);
}

.time-ago {
  margin-left: auto;
  font: 500 12px/1 var(--font-mono);
  color: var(--fg-dim);
  background: var(--glass);
  border-radius: 999px;
  padding: 8px 11px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* Content block */
.card-content {
  position: relative;
  z-index: 2;
  padding: 0 22px calc(env(safe-area-inset-bottom, 0px) + 36px) 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-type-label {
  font: 500 11px/1.2 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--type);
}

.card-title {
  font-family: var(--font-display);
  font-stretch: 82%;
  font-weight: 760;
  font-size: 27px;
  line-height: 1.08;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-wrap: balance;
}

/* Typographic cards: the headline carries the card */
.card.no-image .card-title {
  font-size: clamp(40px, 12vw, 54px);
  font-stretch: 72%;
  font-weight: 800;
  line-height: 1;
  -webkit-line-clamp: 6;
}

.card[data-type="paper"] .card-title {
  font-size: clamp(28px, 8vw, 36px);
  -webkit-line-clamp: 5;
}

.paper-meta,
.paper-authors {
  font: 500 12px/1.45 var(--font-mono);
  color: var(--fg-faint);
}

.paper-meta {
  color: var(--paper);
}

.card-summary {
  font-size: 15px;
  line-height: 1.45;
  color: var(--fg-dim);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-summary:empty { display: none; }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.read-more {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--fg);
  background: rgba(244, 244, 241, 0.14);
  border: 1px solid rgba(244, 244, 241, 0.25);
  border-radius: 999px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.read-more.primary {
  color: var(--ink);
  background: var(--fg);
  border-color: var(--fg);
}

/* Entry motion: the active card's text rises in once */
.card .card-content > * {
  opacity: 0;
  translate: 0 14px;
  transition: opacity 0.45s ease, translate 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.card.is-active .card-content > * { opacity: 1; translate: 0 0; }
.card.is-active .card-content > *:nth-child(2) { transition-delay: 40ms; }
.card.is-active .card-content > *:nth-child(3) { transition-delay: 80ms; }
.card.is-active .card-content > *:nth-child(4) { transition-delay: 120ms; }
.card.is-active .card-content > *:nth-child(n + 5) { transition-delay: 160ms; }

/* ---------- Video ---------- */
.video-area {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.play-button {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: rgba(7, 8, 11, 0.55) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white"><path d="M8 5v14l11-7z"/></svg>') center / 38px no-repeat;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(244, 244, 241, 0.3);
  cursor: pointer;
}

.video-area iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
  position: relative;
  z-index: 4;
}

.card.playing::after { background: rgba(7, 8, 11, 0.45); }
.card.playing .card-content { display: none; }

/* ---------- Status, skeleton and end cards ---------- */
.status-card { justify-content: center; align-items: center; }

.status-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px;
  max-width: 340px;
}

.status-inner p { color: var(--fg-dim); font-size: 16px; line-height: 1.45; }

.status-title {
  font-family: var(--font-display);
  font-stretch: 75%;
  font-weight: 800;
  font-size: 40px;
  line-height: 1;
}

.status-count {
  font: 500 12px/1 var(--font-mono);
  color: var(--fg-faint);
}

.refresh-button {
  background: var(--fg);
  color: var(--ink);
  border: none;
  border-radius: 999px;
  min-height: 48px;
  padding: 0 28px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

/* Skeleton shown while the feed loads */
.skeleton .card-content > * { opacity: 1; translate: none; }

.sk {
  display: block;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(244, 244, 241, 0.07) 25%, rgba(244, 244, 241, 0.16) 50%, rgba(244, 244, 241, 0.07) 75%);
  background-size: 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.sk-badge { position: absolute; top: calc(var(--top-bar) + 6px); left: 14px; width: 132px; height: 34px; border-radius: 999px; z-index: 3; }
.sk-label { width: 64px; height: 11px; }
.sk-title { width: 92%; height: 30px; }
.sk-title.short { width: 64%; }
.sk-line { width: 100%; height: 14px; }
.sk-line.short { width: 72%; }
.sk-button { width: 130px; height: 44px; border-radius: 999px; margin-top: 6px; }

@keyframes shimmer { to { background-position: -150% 0; } }

/* Pull-to-refresh indicator */
#refresh-indicator {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  translate: -50% -60px;
  z-index: 30;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(244, 244, 241, 0.92);
  color: var(--ink);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: translate 0.2s ease;
  pointer-events: none;
}

#refresh-indicator.visible { translate: -50% 0; }
#refresh-indicator.spinning { animation: spin 0.8s linear infinite; }

@keyframes spin { to { rotate: 360deg; } }

/* ---------- Desktop: phone-width column over a blurred backdrop ---------- */
@media (min-width: 720px) {
  :root { --col: 440px; }

  #backdrop { display: block; }

  #feed {
    box-shadow: 0 0 0 1px rgba(244, 244, 241, 0.08), 0 30px 120px rgba(0, 0, 0, 0.7);
  }

  .key-hints {
    display: block;
    position: fixed;
    left: 24px;
    bottom: 22px;
    z-index: 5;
    font: 500 12px/1.9 var(--font-mono);
    color: var(--fg-faint);
  }

  .key-hints kbd {
    font: inherit;
    color: var(--fg-dim);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 1px 6px;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .card .card-content > * { opacity: 1; translate: none; transition: none; }
  .sk { animation: none; }
  #backdrop, .progress-fill, #refresh-indicator { transition: none; }
  #refresh-indicator.spinning { animation: none; }
  #feed { scroll-behavior: auto; }
}
