/* Ungvarium — design system + animations */

/* ====================  CUSTOM DISPLAY FONTS  ===================== */
@font-face {
  font-family: 'Ancient Medium';
  src: url('/web/fonts/Ancient_Medium.ttf') format('truetype');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Chopsic';
  src: url('/web/fonts/Chopsic.otf') format('opentype');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Long Shot';
  src: url('/web/fonts/Long_Shot.ttf') format('truetype');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Pieces of Eight';
  src: url('/web/fonts/Pieces_of_Eight.ttf') format('truetype');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

html, body { -webkit-text-size-adjust: 100%; }
body {
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  letter-spacing: -0.005em;
  /* Smooth dark/light theme swap */
  transition: background-color 280ms cubic-bezier(0.2, 0.8, 0.2, 1),
              color 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Newspaper touch 1 — newsprint cream with a faint paper grain */
body {
  background-color: #f3ecd8;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.10 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-repeat: repeat;
  background-blend-mode: multiply;
}
html.dark body {
  background-color: rgb(10 10 10);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-blend-mode: screen;
}

/* Header now sits on the cream too — soften the white-translucent so cream
   reads through it (instead of looking solid white). */
header.sticky {
  background-color: rgba(243, 236, 216, 0.85) !important;
}
html.dark header.sticky {
  background-color: rgba(10, 10, 10, 0.85) !important;
}
/* Same for the composer footer */
#composer {
  background-color: rgba(243, 236, 216, 0.95) !important;
}
html.dark #composer {
  background-color: rgba(10, 10, 10, 0.95) !important;
}

/* Newspaper touch 2 — masthead double-rule under the sticky header */
header.sticky {
  position: sticky;
  border-bottom: 1px solid rgb(196 184 152) !important;
  box-shadow: 0 3px 0 -2px rgb(196 184 152);
}
html.dark header.sticky {
  border-bottom-color: rgb(64 64 64) !important;
  box-shadow: 0 3px 0 -2px rgb(64 64 64);
}

/* (Drop-cap removed — it relied on a Latin-only display font and ate the first
   glyph of Cyrillic / non-Latin replies.) */

/* Old-style numerals where they read more like a printed paper */
.hero-title,
.card-year,
.card-meta,
.search-tile .head,
.chip-value {
  font-variant-numeric: oldstyle-nums proportional-nums;
}

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

/* ============================================================
   BUTTONS
   ============================================================ */
/* Header brand mark — display-font letter "U" (matches the hero title) */
.brand-mark {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: transparent;
  border: none;
  flex-shrink: 0;
  color: rgb(23 23 23);
  transition: background-color 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
              transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.brand-mark .brand-letter {
  font-family: 'Pieces of Eight', 'Georgia', serif;
  font-size: 32px;
  font-weight: 400;
  line-height: 1;
  margin-top: -2px;     /* optical centering of display glyph */
  user-select: none;
}
.brand-mark:hover {
  background: rgba(0, 0, 0, 0.05);
  transform: scale(1.06) rotate(-3deg);
}
.brand-mark:active { transform: scale(0.94) rotate(0); }
.dark .brand-mark { color: #fff; }
.dark .brand-mark:hover { background: rgba(255, 255, 255, 0.07); }

.ico-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  color: rgb(82 82 82);
  background: transparent;
  transition: background-color 140ms ease, color 140ms ease, transform 100ms ease;
}
.ico-btn:hover { background: rgb(244 244 244); color: rgb(23 23 23); transform: scale(1.04); }
.ico-btn:active { transform: scale(0.92); }
.dark .ico-btn { color: rgb(163 163 163); }
.dark .ico-btn:hover { background: rgb(31 31 31); color: #fff; }

/* Send button (toggles to stop) */
.send-btn {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 14px;
  background: rgb(23 23 23);
  color: #fff;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  transition:
    background-color 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    color 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 140ms cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 200ms ease,
    box-shadow 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.dark .send-btn { background: #fff; color: rgb(23 23 23); }
.send-btn:hover {
  opacity: 0.92;
  transform: scale(1.03);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.10);
}
.dark .send-btn:hover { box-shadow: 0 4px 14px rgba(255, 255, 255, 0.10); }
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.30; cursor: not-allowed; transform: none; box-shadow: none; }

/* Icon swap inside the send button */
#send-icon, #stop-icon {
  transition: opacity 200ms cubic-bezier(0.2, 0.8, 0.2, 1),
              transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.send-btn.stopping #send-icon { opacity: 0; transform: scale(0.6) rotate(-45deg); }
.send-btn.stopping #stop-icon { opacity: 1; transform: scale(1) rotate(0); }
.send-btn:not(.stopping) #stop-icon { opacity: 0; transform: scale(0.6); position: absolute; }

/* Stop state — same color as send, just a different icon. */
.send-btn.stopping { /* color unchanged */ }

/* Hero brand mark — display font */
.hero-title {
  font-family: 'Pieces of Eight', 'Inter', sans-serif;
  font-weight: 400;
  font-size: clamp(56px, 14vw, 120px);
  line-height: 1;
  letter-spacing: 0.01em;
  color: rgb(23 23 23);
  user-select: none;
  transform-origin: 50% 60%;
  animation: title-snap 1100ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.dark .hero-title { color: #fff; }

/* Hero subtitle "1878 — 1918" — smaller, lighter, wider tracking, light italic */
.hero-subtitle {
  font-family: 'Pieces of Eight', 'Georgia', serif;
  font-weight: 400;
  font-size: clamp(15px, 3.4vw, 22px);
  letter-spacing: 0.28em;
  text-indent: 0.28em;  /* visually centers letter-spaced text */
  line-height: 1;
  color: rgb(115 115 115);
  margin-top: 6px;
  user-select: none;
  font-variant-numeric: oldstyle-nums proportional-nums;
  animation: subtitle-rise 700ms 720ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.dark .hero-subtitle { color: rgb(140 140 140); }
/* The display font doesn't have an en-dash glyph — render it in a fallback */
.hero-dash {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-weight: 400;
  margin: 0 0.45em;
  letter-spacing: 0;
}
@keyframes subtitle-rise {
  from { opacity: 0; transform: translateY(8px); letter-spacing: 0.45em; }
  to   { opacity: 1; transform: translateY(0); letter-spacing: 0.28em; }
}

@keyframes title-snap {
  0% {
    opacity: 0;
    transform: translateY(34px) scale(0.84);
    filter: blur(12px);
    letter-spacing: 0.28em;
  }
  35% {
    opacity: 0.85;
    filter: blur(2px);
    letter-spacing: 0.14em;
  }
  60% {
    opacity: 1;
    transform: translateY(0) scale(1.025);
    filter: blur(0);
    letter-spacing: 0.04em;
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
    letter-spacing: 0.01em;
  }
}

/* Single CTA pill in empty state — modern glass with sparkle */
.suggest {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  isolation: isolate;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0.005em;
  padding: 12px 22px 12px 18px;
  border-radius: 9999px;
  color: rgb(38 38 38);
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 8px 24px -10px rgba(0, 0, 0, 0.10);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
          backdrop-filter: blur(10px) saturate(140%);
  cursor: pointer;
  animation: cta-rise 600ms 1080ms cubic-bezier(0.16, 1, 0.3, 1) both;
  transition:
    transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1),
    color 240ms cubic-bezier(0.2, 0.8, 0.2, 1),
    background-color 240ms cubic-bezier(0.2, 0.8, 0.2, 1),
    border-color 240ms cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* Soft conic-gradient sheen that fades in on hover */
.suggest::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(
    from 140deg,
    rgba(255, 255, 255, 0)   0deg,
    rgba(255, 255, 255, 0.6) 90deg,
    rgba(255, 255, 255, 0)   180deg,
    rgba(0, 0, 0, 0.06)      270deg,
    rgba(255, 255, 255, 0)   360deg
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms ease;
  z-index: -1;
}
.suggest:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.85);
  border-color: rgba(0, 0, 0, 0.10);
  color: rgb(23 23 23);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 2px 4px rgba(0, 0, 0, 0.04),
    0 14px 36px -12px rgba(0, 0, 0, 0.18);
}
.suggest:hover::after { opacity: 1; }
.suggest:active   { transform: translateY(0) scale(0.985); }
.suggest:focus-visible {
  outline: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 0 0 3px rgba(110, 80, 35, 0.18),
    0 14px 36px -12px rgba(0, 0, 0, 0.18);
}

.suggest-icon {
  flex: 0 0 auto;
  color: rgb(140 110 50);            /* warm newspaper-ink accent */
  filter: drop-shadow(0 0 4px rgba(255, 200, 100, 0.25));
  transition: transform 700ms cubic-bezier(0.34, 1.56, 0.64, 1),
              color 240ms ease,
              filter 240ms ease;
}
.suggest:hover .suggest-icon {
  transform: rotate(180deg);
  color: rgb(180 130 40);
  filter: drop-shadow(0 0 6px rgba(255, 200, 100, 0.45));
}

/* Dark theme */
.dark .suggest {
  color: rgb(220 220 220);
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 2px 8px rgba(0, 0, 0, 0.25),
    0 14px 32px -14px rgba(0, 0, 0, 0.50);
}
.dark .suggest::after {
  background: conic-gradient(
    from 140deg,
    rgba(255, 255, 255, 0)    0deg,
    rgba(255, 255, 255, 0.22) 90deg,
    rgba(255, 255, 255, 0)    180deg,
    rgba(255, 255, 255, 0.06) 270deg,
    rgba(255, 255, 255, 0)    360deg
  );
}
.dark .suggest:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    0 4px 12px rgba(0, 0, 0, 0.35),
    0 18px 42px -14px rgba(0, 0, 0, 0.65);
}
.dark .suggest-icon { color: rgb(220 180 110); }
.dark .suggest:hover .suggest-icon { color: rgb(255 210 140); }

@keyframes cta-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   SETTINGS POPOVER
   ============================================================ */
.popover {
  visibility: hidden;
  opacity: 0;
  transform: translateY(-4px) scale(0.96);
  transition: opacity 160ms ease, transform 160ms ease, visibility 0s 160ms;
  z-index: 40;
}
.popover.open {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 160ms ease, transform 160ms ease;
}

.setting-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgb(115 115 115);
  margin-bottom: 6px;
}

/* Segmented control (lang / depth / theme) */
.seg-control {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: rgb(244 244 244);
  border-radius: 10px;
  padding: 3px;
  gap: 0;
}
.dark .seg-control { background: rgb(31 31 31); }
.seg-btn {
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 0;
  border-radius: 8px;
  background: transparent;
  color: rgb(82 82 82);
  transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.dark .seg-btn { color: rgb(163 163 163); }
.seg-btn:hover { color: rgb(23 23 23); }
.dark .seg-btn:hover { color: #fff; }
.seg-btn.active {
  background: #fff;
  color: rgb(23 23 23);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 1px 1px rgba(0,0,0,0.04);
}
.dark .seg-btn.active {
  background: rgb(64 64 64);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* Backdrop on mobile so taps outside close the popover */
#settings-backdrop.open { background-color: rgba(0,0,0,0.0); }

/* ====================  CHATS POPOVER  ===================== */
#chats-popover { width: 320px; max-width: calc(100vw - 32px); z-index: 40; }
.chats-popover-shell {
  background: #fff;
  border: 1px solid rgb(228 228 228);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.04);
  padding: 6px;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}
.dark .chats-popover-shell {
  background: rgb(23 23 23);
  border-color: rgb(64 64 64);
  box-shadow: 0 12px 32px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.25);
}

.chats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 4px;
}
.chats-head-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(115 115 115);
}
.chats-new-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgb(244 244 244);
  color: rgb(38 38 38);
  transition: background-color 140ms ease, color 140ms ease, transform 100ms ease;
}
.chats-new-btn:hover { background: rgb(228 228 228); color: rgb(0 0 0); }
.chats-new-btn:active { transform: scale(0.96); }
.dark .chats-new-btn { background: rgb(38 38 38); color: rgb(229 229 229); }
.dark .chats-new-btn:hover { background: rgb(64 64 64); color: #fff; }

.chats-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 12px 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  transition: background-color 140ms ease;
}
.chat-item:hover { background: rgb(244 244 244); }
.chat-item.active { background: rgb(236 236 236); }
.dark .chat-item:hover { background: rgb(38 38 38); }
.dark .chat-item.active { background: rgb(48 48 48); }

.chat-item .title {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 24px;        /* room for the delete icon */
  color: rgb(23 23 23);
}
.dark .chat-item .title { color: rgb(245 245 245); }
.chat-item .time {
  font-size: 11px;
  color: rgb(115 115 115);
}

.chat-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px; height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: transparent;
  color: rgb(115 115 115);
  opacity: 0;
  transition: opacity 140ms ease, background-color 140ms ease, color 140ms ease;
}
.chat-item:hover .chat-delete { opacity: 1; }
.chat-delete:hover {
  background: rgb(229 229 229);
  color: rgb(220 38 38);
}
.dark .chat-delete:hover {
  background: rgb(64 64 64);
  color: rgb(248 113 113);
}

.chats-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: rgb(115 115 115);
}

/* ============================================================
   CITATIONS
   ============================================================ */
.cite {
  display: inline-flex;
  align-items: center;
  padding: 0.1em 0.55em;
  margin: 0 0.12em;
  border-radius: 9999px;
  font-size: 0.78em;
  line-height: 1.4;
  background: rgb(244 244 244);
  color: rgb(38 38 38);
  border: 1px solid rgb(228 228 228);
  text-decoration: none;
  cursor: pointer;
  vertical-align: baseline;
  white-space: nowrap;
  animation: cite-pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  transition: background-color 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
              color 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
              border-color 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
              transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes cite-pop {
  from { opacity: 0; transform: translateY(2px) scale(0.78); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.cite:hover {
  background: rgb(229 229 229);
  border-color: rgb(82 82 82);
  color: rgb(0 0 0);
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
}
.cite:active { transform: translateY(0) scale(0.96); }
.dark .cite {
  background: rgb(31 31 31);
  color: rgb(212 212 212);
  border-color: rgb(64 64 64);
}
.dark .cite:hover {
  background: rgb(64 64 64);
  color: #fff;
  border-color: rgb(115 115 115);
}

/* ============================================================
   MESSAGE BUBBLES
   ============================================================ */
.msg-row {
  animation: msg-in 320ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* User bubble — light gray, ChatGPT-style */
.msg.user {
  background: rgb(244 244 244);
  color: rgb(23 23 23);
  border-radius: 18px 18px 4px 18px;
}
.dark .msg.user {
  background: rgb(47 47 47);
  color: rgb(245 245 245);
}

/* Assistant bubble — no bg, just text */
.msg.assistant {
  color: rgb(23 23 23);
}
.dark .msg.assistant { color: rgb(229 229 229); }
.msg.assistant p { margin: 0 0 0.7em 0; }
.msg.assistant p:last-child { margin-bottom: 0; }

/* Streaming cursor — smooth pulse instead of hard blink */
.cursor {
  display: inline-block;
  width: 0.5rem;
  height: 0.95em;
  background: currentColor;
  margin-left: 2px;
  vertical-align: -0.16em;
  border-radius: 2px;
  animation: cursor-pulse 1.05s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes cursor-pulse {
  0%, 100% { opacity: 0.95; transform: scaleY(1); }
  50%      { opacity: 0.30; transform: scaleY(0.96); }
}

/* Status label fade for humor message rotation */
.msg-status .label {
  display: inline-block;
  transition: opacity 140ms ease;
}
.msg-status .label.fading { opacity: 0; }

/* Typing dots (status row) — smoother wave */
.dots span {
  display: inline-block;
  width: 0.34rem;
  height: 0.34rem;
  border-radius: 9999px;
  background: currentColor;
  opacity: 0.5;
  animation: bounce 1.2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
.dots span:nth-child(1) { animation-delay: 0s; }
.dots span:nth-child(2) { animation-delay: 0.18s; }
.dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0)    scale(1);   opacity: 0.35; }
  40%          { transform: translateY(-5px) scale(1.15); opacity: 1; }
}

/* Copy button on assistant messages — hover-reveal on desktop, always visible mobile */
.msg-actions {
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.msg-row.has-actions:hover .msg-actions,
.msg-row:focus-within .msg-actions {
  opacity: 1;
  transform: translateY(0);
}
@media (hover: none) {
  .msg-actions { opacity: 0.6; }
}
.copy-btn {
  font-size: 12px;
  color: rgb(115 115 115);
  padding: 4px 8px;
  border-radius: 8px;
  background: transparent;
  transition: background-color 140ms ease, color 140ms ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.copy-btn:hover { background: rgb(244 244 244); color: rgb(23 23 23); }
.dark .copy-btn { color: rgb(163 163 163); }
.dark .copy-btn:hover { background: rgb(31 31 31); color: #fff; }
.copy-btn.copied { color: rgb(34 197 94); }

/* ============================================================
   SCROLL-TO-BOTTOM FAB
   ============================================================ */
.scroll-fab {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  width: 36px; height: 36px;
  border-radius: 9999px;
  background: #fff;
  color: rgb(23 23 23);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgb(228 228 228);
  box-shadow: 0 8px 24px rgba(0,0,0,0.10);
  transition: opacity 160ms ease, transform 160ms ease;
}
.dark .scroll-fab {
  background: rgb(31 31 31);
  color: #fff;
  border-color: rgb(64 64 64);
  box-shadow: 0 8px 24px rgba(0,0,0,0.40);
}
.scroll-fab.visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

/* ============================================================
   COMPOSER FOCUS + UTILITIES
   ============================================================ */
#input {
  transition:
    background-color 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    border-color     220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow       220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
#input:focus {
  box-shadow:
    0 0 0 4px rgba(38, 38, 38, 0.06),
    0 1px 2px rgba(0, 0, 0, 0.04);
}
.dark #input:focus {
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.06),
    0 1px 2px rgba(0, 0, 0, 0.30);
}
#input::placeholder {
  color: rgb(163 163 163);
  transition: opacity 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.dark #input::placeholder { color: rgb(82 82 82); }
#input:focus::placeholder { opacity: 0.55; }

/* Scrollbar */
#messages {
  scrollbar-width: thin;
  scrollbar-color: rgba(115,115,115,0.25) transparent;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb {
  background: rgba(115,115,115,0.25);
  border-radius: 9999px;
}
#messages::-webkit-scrollbar-thumb:hover {
  background: rgba(115,115,115,0.5);
}

/* Long words don't break layout */
.msg, .msg p { overflow-wrap: anywhere; }

/* ============================================================
   NEWSPAPER PAGE VIEWER — modal with 3D page-flip animation
   ============================================================ */
body.paper-open { overflow: hidden; }

.paper-viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(20, 14, 6, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
              visibility 0s 220ms;
  touch-action: pan-y;   /* allow horizontal swipe to be captured */
}
@media (max-width: 720px) {
  .paper-viewer {
    padding: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}
.paper-viewer.open {
  opacity: 1;
  visibility: visible;
  transition: opacity 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.dark .paper-viewer { background: rgba(0, 0, 0, 0.92); }

.paper-shell {
  width: min(920px, 100%);
  height: min(1100px, 100%);
  background: #f3ecd8;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.50),
    0 8px 20px rgba(0, 0, 0, 0.25);
  position: relative;
  transform: scale(0.96);
  transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
}
@media (max-width: 720px) {
  .paper-shell {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
}
.paper-viewer.open .paper-shell { transform: scale(1); }
.dark .paper-shell { background: rgb(20 20 20); }

.paper-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(110, 80, 35, 0.30);
  flex: 0 0 auto;
}
.dark .paper-head { border-bottom-color: rgb(64 64 64); }

.paper-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}
.paper-year {
  font-family: 'Pieces of Eight', 'Georgia', serif;
  font-size: 22px;
  font-weight: 400;
  color: rgb(38 30 18);
  letter-spacing: 0.02em;
  font-variant-numeric: oldstyle-nums proportional-nums;
  white-space: nowrap;
}
.dark .paper-year { color: rgb(232 220 188); }
.paper-sep { color: rgba(110, 80, 35, 0.5); }
.dark .paper-sep { color: rgb(115 115 115); }
.paper-page-num {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgb(115 115 115);
}

.paper-actions { display: flex; gap: 2px; flex-shrink: 0; }
.paper-action {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: rgb(60 40 20);
  background: transparent;
  transition: background-color 140ms ease, color 140ms ease, transform 120ms cubic-bezier(0.34, 1.56, 0.64, 1);
  text-decoration: none;
}
.paper-action:hover {
  background: rgba(60, 40, 20, 0.08);
  transform: scale(1.06);
}
.paper-action:active { transform: scale(0.94); }
.dark .paper-action { color: rgb(212 212 212); }
.dark .paper-action:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

/* Body row: stage on the left, optional translation aside on the right. */
.paper-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}
.paper-stage {
  flex: 1 1 auto;
  position: relative;
  perspective: 2400px;
  padding: 18px;
  min-width: 0;
  background:
    radial-gradient(ellipse at center, rgba(0,0,0,0.05) 0%, rgba(0,0,0,0) 70%);
}

/* Translation panel — slides in from the right on desktop, full overlay on phone */
.paper-translation {
  flex: 0 0 auto;
  width: 42%;
  max-width: 480px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(110, 80, 35, 0.22);
  background:
    repeating-linear-gradient(
      0deg, rgba(110, 80, 35, 0.018) 0 1px, transparent 1px 28px),
    rgba(247, 240, 220, 0.92);
  animation: paper-translation-slide 320ms cubic-bezier(0.32, 0.08, 0.24, 1) both;
}
.paper-translation[hidden] { display: none; }
@keyframes paper-translation-slide {
  from { transform: translateX(8%); opacity: 0; }
  to   { transform: translateX(0);  opacity: 1; }
}
.paper-translation-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px 9px 16px;
  border-bottom: 1px solid rgba(110, 80, 35, 0.22);
  background: rgba(247, 240, 220, 0.96);
}
.paper-translation-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgb(91 72 38);
}
.paper-translation-actions { display: flex; gap: 2px; }
.paper-translation-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 22px 28px;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 14.5px;
  line-height: 1.72;
  color: rgb(38 30 18);
  white-space: pre-wrap;
  hyphens: auto;
}
.paper-translation-body:first-letter {
  font-size: 1.05em;
}
.paper-translation-status {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 13px;
  color: rgb(115 115 115);
  font-family: 'Inter', system-ui, sans-serif;
}
.paper-translation-status .dots {
  display: inline-flex;
  gap: 3px;
  margin-right: 8px;
}
.paper-translation-status .dots span {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
  animation: trans-dot 1.2s infinite ease-in-out;
}
.paper-translation-status .dots span:nth-child(2) { animation-delay: 0.15s; }
.paper-translation-status .dots span:nth-child(3) { animation-delay: 0.30s; }
@keyframes trans-dot {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.75); }
  40%           { opacity: 1;    transform: scale(1.1); }
}

/* Dark theme */
.dark .paper-translation {
  background:
    repeating-linear-gradient(
      0deg, rgba(255, 255, 255, 0.015) 0 1px, transparent 1px 28px),
    rgba(20, 20, 20, 0.92);
  border-left-color: rgb(64 64 64);
}
.dark .paper-translation-head {
  background: rgba(26, 26, 26, 0.96);
  border-bottom-color: rgb(64 64 64);
}
.dark .paper-translation-label { color: rgb(180 180 180); }
.dark .paper-translation-body { color: rgb(229 229 229); }
.dark .paper-translation-status { color: rgb(150 150 150); }

/* Mobile: translation becomes a full-width overlay on top of the stage */
@media (max-width: 720px) {
  .paper-translation {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: none;
    min-width: 0;
    border-left: 0;
    z-index: 5;
  }
}

/* Two stacked pages. The page ABOVE rotates around its left or right edge to
   reveal the page BELOW. We animate opacity around the 90° mark so the
   mirrored iframe-back never flashes through. */
.paper-pages {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}
.paper-page {
  position: absolute;
  inset: 0;
  background: white;
  border-radius: 3px;
  overflow: hidden;
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.05),
    0 8px 26px rgba(0, 0, 0, 0.20);
}
.paper-page-below { z-index: 1; }
.paper-page-above {
  z-index: 2;
  transform: rotateY(0deg);
}
.paper-page iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
  display: block;
}

/* Light/shadow gradient overlay simulating the curl of a turning page */
.paper-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(to right,
    rgba(0,0,0,0.00) 0%,
    rgba(0,0,0,0.05) 50%,
    rgba(0,0,0,0.30) 100%);
}

/* Flip animations — rotate around the leading edge, fade out at 90° so the
   iframe back doesn't appear backward. */
.paper-page-above.flipping-next {
  animation: paper-flip-next 0.95s cubic-bezier(0.32, 0.08, 0.24, 1) forwards;
}
.paper-page-above.flipping-prev {
  animation: paper-flip-prev 0.95s cubic-bezier(0.32, 0.08, 0.24, 1) forwards;
}
.paper-page-above.flipping-next .paper-shade,
.paper-page-above.flipping-prev .paper-shade {
  animation: paper-shade 0.95s cubic-bezier(0.32, 0.08, 0.24, 1) forwards;
}

@keyframes paper-flip-next {
  0%   { transform-origin: left center;  transform: rotateY(0deg);    opacity: 1; }
  45%  { opacity: 1; }
  55%  { opacity: 0; }
  100% { transform-origin: left center;  transform: rotateY(-180deg); opacity: 0; }
}
@keyframes paper-flip-prev {
  0%   { transform-origin: right center; transform: rotateY(0deg);   opacity: 1; }
  45%  { opacity: 1; }
  55%  { opacity: 0; }
  100% { transform-origin: right center; transform: rotateY(180deg); opacity: 0; }
}
@keyframes paper-shade {
  0%   { opacity: 0; }
  45%  { opacity: 0.7; }
  55%  { opacity: 0; }
  100% { opacity: 0; }
}

.paper-nav {
  position: absolute;
  z-index: 5;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(243, 236, 216, 0.95);
  color: rgb(38 30 18);
  border: 1px solid rgba(110, 80, 35, 0.40);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.20);
  transition: background-color 140ms ease,
              transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 140ms ease,
              opacity 140ms ease;
}
.paper-nav-prev { left: 14px; }
.paper-nav-next { right: 14px; }
.paper-nav:hover {
  background: #fff;
  transform: translateY(-50%) scale(1.08);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}
.paper-nav:active {
  transform: translateY(-50%) scale(0.95);
}
.paper-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: translateY(-50%) scale(1);
}
.paper-nav:disabled:hover {
  background: rgba(243, 236, 216, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.20);
}
.dark .paper-nav {
  background: rgb(40 40 40);
  border-color: rgb(82 82 82);
  color: #fff;
}
.dark .paper-nav:hover { background: rgb(64 64 64); }
@media (max-width: 720px) {
  .paper-nav-prev { left: 8px; }
  .paper-nav-next { right: 8px; }
  .paper-nav { width: 38px; height: 38px; }
}

.paper-foot {
  flex: 0 0 auto;
  padding: 10px 16px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgb(115 115 115);
  border-top: 1px solid rgba(110, 80, 35, 0.30);
  font-variant-numeric: oldstyle-nums proportional-nums;
}
.dark .paper-foot { border-top-color: rgb(64 64 64); }

/* ====================  IN-VIEWER SEARCH (scoped to current year)  ===== */
.paper-search-bar {
  flex: 0 0 auto;
  padding: 8px 14px 10px;
  border-bottom: 1px solid rgba(110, 80, 35, 0.30);
  background: rgba(243, 236, 216, 0.85);
  animation: paper-search-slide 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.dark .paper-search-bar {
  background: rgba(20, 20, 20, 0.9);
  border-bottom-color: rgb(64 64 64);
}
@keyframes paper-search-slide {
  from { opacity: 0; transform: translateY(-6px); max-height: 0; }
  to   { opacity: 1; transform: translateY(0);  max-height: 380px; }
}
.paper-search-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 6px 0 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid transparent;
  transition: background-color 200ms cubic-bezier(0.2, 0.8, 0.2, 1),
              border-color 200ms cubic-bezier(0.2, 0.8, 0.2, 1),
              box-shadow 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.paper-search-input-wrap:focus-within {
  background: #fff;
  border-color: rgba(110, 80, 35, 0.45);
  box-shadow: 0 0 0 3px rgba(110, 80, 35, 0.10);
}
.dark .paper-search-input-wrap {
  background: rgba(31, 31, 31, 0.7);
}
.dark .paper-search-input-wrap:focus-within {
  background: rgb(31 31 31);
  border-color: rgb(115 115 115);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}
.paper-search-icon { color: rgb(115 115 115); flex: 0 0 auto; }
#paper-search-input {
  flex: 1 1 auto;
  height: 100%;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 14px;
  font-weight: 450;
  color: rgb(38 30 18);
  -webkit-appearance: none;
}
.dark #paper-search-input { color: rgb(245 245 245); }
#paper-search-input::placeholder { color: rgb(115 115 115); }
#paper-search-input::-webkit-search-cancel-button { display: none; }
#paper-search-clear {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: rgb(115 115 115);
  background: transparent;
  transition: background-color 140ms ease, color 140ms ease;
}
#paper-search-clear:hover { background: rgba(0, 0, 0, 0.08); color: rgb(23 23 23); }
.dark #paper-search-clear:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.paper-search-results {
  max-height: 280px;
  overflow-y: auto;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.paper-search-results:empty { margin-top: 0; }
.paper-search-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 12px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: rgb(91 72 38);
  border-bottom: 1px dashed rgba(110, 80, 35, 0.25);
  margin-bottom: 4px;
}
.dark .paper-search-meta {
  color: rgb(180 180 180);
  border-bottom-color: rgb(64 64 64);
}
.paper-search-tip {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: rgb(115 115 115);
}
.dark .paper-search-tip { color: rgb(150 150 150); }
.paper-search-hit {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms ease;
}
.paper-search-hit:hover { background: rgba(110, 80, 35, 0.10); }
.dark .paper-search-hit:hover { background: rgba(255, 255, 255, 0.06); }
.paper-search-hit.active {
  background: rgba(110, 80, 35, 0.18);
}
.dark .paper-search-hit.active { background: rgba(255, 255, 255, 0.10); }
.paper-search-hit .hit-head {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: rgb(115 115 115);
}
.paper-search-hit .hit-snippet {
  font-size: 13px;
  line-height: 1.45;
  color: rgb(38 30 18);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.dark .paper-search-hit .hit-snippet { color: rgb(229 229 229); }
.paper-search-hit mark {
  background: linear-gradient(180deg, transparent 55%, rgba(252, 211, 77, 0.65) 55%);
  color: inherit;
  font-weight: 500;
  padding: 0 1px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.paper-search-empty {
  padding: 16px;
  text-align: center;
  font-size: 12.5px;
  color: rgb(115 115 115);
}

/* ============================================================
   CATALOG OVERLAY
   ============================================================ */
.catalog {
  position: fixed;
  inset: 0;
  z-index: 50;
  visibility: hidden;
  opacity: 0;
  transition: opacity 200ms ease, visibility 0s 200ms;
}
.catalog.open {
  visibility: visible;
  opacity: 1;
  transition: opacity 200ms ease;
}
.catalog-shell {
  position: absolute;
  inset: 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  transform: translateY(8px);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.catalog.open .catalog-shell { transform: translateY(0); }
.dark .catalog-shell { background: rgb(10 10 10); }

.catalog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgb(244 244 244);
  padding: 14px 0;
}
.dark .catalog-head {
  background: rgba(10,10,10,0.85);
  border-bottom-color: rgb(31 31 31);
}

.catalog-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 80px;
}
.catalog-grid {
  max-width: 64rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
@media (min-width: 640px) {
  .catalog-body { padding: 32px 24px 80px; }
  .catalog-grid { gap: 14px; }
}

/* ====================  YEAR CARDS — UNG NEWSPAPER FRONT PAGE  ============
   Each tile is rendered as a miniature 'Ung' issue: italic strapline at the
   top, big blackletter-feel masthead, double rule, year in old-style figures,
   thin rule, then three faux columns of OCR-like text striping, capped with
   a page count. Outer card is "a folded sheet on a stack of papers": cream
   front with a 3-ply edge shadow underneath.
*/
.year-card {
  position: relative;
  display: block;
  text-decoration: none;
  aspect-ratio: 3 / 4;
  padding: 0;
  color: rgb(50 35 18);
  background: transparent;
  border: 0;
  border-radius: 0;
  transform-origin: 50% 100%;
  transition:
    transform 240ms cubic-bezier(0.16, 1, 0.3, 1),
    filter   240ms cubic-bezier(0.16, 1, 0.3, 1);
  animation: card-in 360ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Inner "paper" — the visible newspaper front page */
.year-card .card-paper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 8px 7px 6px;
  text-align: center;
  background:
    /* faint ink grid — gives a printed, slightly noisy texture */
    repeating-linear-gradient(
      90deg, rgba(80, 55, 25, 0.018) 0 1px, transparent 1px 14px),
    repeating-linear-gradient(
      0deg,  rgba(80, 55, 25, 0.018) 0 1px, transparent 1px 24px),
    linear-gradient(
      170deg,
      #f6ebcc 0%,
      #f2e4c0 38%,
      #ecdcaf 78%,
      #e3d09d 100%      /* age stain along the bottom */
    );
  border: 1px solid rgba(110, 80, 35, 0.30);
  border-radius: 1px;
  /* 3-ply edge shadow → a stack of papers behind this top sheet */
  box-shadow:
    1px 1px 0 #e0cea0,
    2px 2px 0 #d4c08c,
    3px 3px 0 #c7b079,
    4px 6px 14px rgba(60, 40, 20, 0.18);
  overflow: hidden;
}
/* Aged corner — a little brown vignette on the upper-left like a foxed
   newspaper. Decorative only. */
.year-card .card-paper::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(
      circle at 8% 12%,
      rgba(140, 90, 40, 0.10) 0,
      rgba(140, 90, 40, 0) 35%),
    radial-gradient(
      circle at 92% 88%,
      rgba(140, 90, 40, 0.12) 0,
      rgba(140, 90, 40, 0) 32%);
  pointer-events: none;
}

.card-strap {
  font-family: 'Georgia', serif;
  font-style: italic;
  font-size: 7px;
  line-height: 1;
  letter-spacing: 0.02em;
  color: rgba(60, 40, 20, 0.60);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.card-masthead {
  font-family: 'Pieces of Eight', 'Georgia', serif;
  font-weight: 500;
  font-size: clamp(28px, 5.5cqw, 42px);
  line-height: 0.88;
  letter-spacing: 0.04em;
  color: rgb(22 15 6);
  margin: 0 0 2px;
  /* tiny x-offset shadow to feel like ink hitting paper */
  text-shadow:
    0 0.5px 0 rgba(255, 240, 200, 0.8),
    0.4px 0.4px 0 rgba(0, 0, 0, 0.25);
}
.year-card { container-type: inline-size; }

.card-rule {
  height: 3px;
  margin: 4px 6px;
  border-top: 1px solid rgba(60, 40, 20, 0.80);
  border-bottom: 1px solid rgba(60, 40, 20, 0.80);
  background: transparent;
}
.card-rule-thin {
  height: 0;
  border-bottom: 0;
  border-top: 1px solid rgba(60, 40, 20, 0.35);
  margin: 3px 14px;
}

.card-year {
  font-family: 'Pieces of Eight', 'Georgia', serif;
  font-size: clamp(15px, 3cqw, 22px);
  font-variant-numeric: oldstyle-nums proportional-nums;
  color: rgb(40 25 10);
  letter-spacing: 0.05em;
  line-height: 1;
  margin: 3px 0 3px;
}

/* Faux columns of newsprint — three vertical stripes of fine horizontal
   ink lines, separated by hair-rules. */
.card-cols {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  margin: 4px 4px 4px;
  border-top: 0;
  min-height: 0;
}
.card-col {
  position: relative;
  min-width: 0;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(40, 25, 10, 0.55) 0 1px,
      transparent 1px 3px);
  opacity: 0.32;
  mask-image:    linear-gradient(0deg, transparent 0, #000 12%, #000 92%, transparent 100%);
  -webkit-mask-image: linear-gradient(0deg, transparent 0, #000 12%, #000 92%, transparent 100%);
}
.card-col + .card-col {
  border-left: 1px solid rgba(40, 25, 10, 0.15);
  margin-left: 2px;
  padding-left: 2px;
}

.card-meta {
  flex: 0 0 auto;
  font-family: 'Georgia', serif;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: rgba(50, 35, 18, 0.78);
  font-variant-numeric: oldstyle-nums proportional-nums;
  border-top: 1px dashed rgba(50, 35, 18, 0.30);
  padding-top: 3px;
  margin-top: 3px;
}

.year-card .arrow {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  color: rgba(60, 40, 20, 0.55);
  transition: opacity 200ms ease, transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: translate(-2px, 2px);
  z-index: 2;
}
.year-card:hover {
  transform: translateY(-5px) rotate(-1deg);
  filter: drop-shadow(0 14px 20px rgba(60, 40, 20, 0.20));
}
.year-card:active {
  transform: translateY(-1px) rotate(-0.3deg);
}
.year-card:hover .arrow {
  opacity: 1;
  transform: translate(0, 0);
}

/* Dark mode — "negative" of a newspaper: dark ink-paper with cream type */
.dark .year-card .card-paper {
  background:
    repeating-linear-gradient(
      90deg, rgba(255, 230, 180, 0.025) 0 1px, transparent 1px 14px),
    repeating-linear-gradient(
      0deg,  rgba(255, 230, 180, 0.025) 0 1px, transparent 1px 24px),
    linear-gradient(
      170deg,
      #1c1612 0%,
      #221913 38%,
      #261b15 78%,
      #2b1f17 100%);
  border-color: rgba(255, 230, 180, 0.18);
  box-shadow:
    1px 1px 0 #2b1f17,
    2px 2px 0 #261b15,
    3px 3px 0 #221913,
    4px 6px 14px rgba(0, 0, 0, 0.55);
}
.dark .year-card .card-paper::before {
  background:
    radial-gradient(circle at 8% 12%, rgba(220, 180, 110, 0.08) 0, transparent 35%),
    radial-gradient(circle at 92% 88%, rgba(220, 180, 110, 0.10) 0, transparent 32%);
}
.dark .card-strap   { color: rgba(232, 220, 188, 0.55); }
.dark .card-masthead {
  color: rgb(245 235 210);
  text-shadow:
    0 0.5px 0 rgba(0, 0, 0, 0.6),
    0.4px 0.4px 0 rgba(255, 240, 200, 0.10);
}
.dark .card-rule {
  border-top-color: rgba(255, 230, 180, 0.55);
  border-bottom-color: rgba(255, 230, 180, 0.55);
}
.dark .card-rule-thin {
  border-top-color: rgba(255, 230, 180, 0.25);
}
.dark .card-year   { color: rgb(245 235 210); }
.dark .card-col {
  background: repeating-linear-gradient(
    0deg, rgba(255, 230, 180, 0.55) 0 1px, transparent 1px 3px);
  opacity: 0.28;
}
.dark .card-col + .card-col { border-left-color: rgba(255, 230, 180, 0.12); }
.dark .card-meta {
  color: rgba(232, 220, 188, 0.72);
  border-top-color: rgba(232, 220, 188, 0.25);
}
.dark .year-card .arrow { color: rgba(232, 220, 188, 0.55); }
.dark .year-card:hover { filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.55)); }

.catalog-loading {
  text-align: center;
  padding: 48px 0;
  color: rgb(115 115 115);
  font-size: 14px;
}

/* ====================  FILTER BAR (chips + popovers)  ===================== */
.catalog-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 -4px;
  opacity: 0;
  transform: translateY(-4px);
  max-height: 0;
  overflow: visible;          /* let popovers escape */
  pointer-events: none;
  transition:
    opacity 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    max-height 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    margin 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.catalog-filters.visible {
  opacity: 1;
  transform: translateY(0);
  max-height: 60px;
  pointer-events: auto;
  margin: 12px 0 -4px;
}

.filter-chip-wrap { position: relative; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px 7px 11px;
  border-radius: 9999px;
  background: rgba(244, 244, 244, 0.7);
  border: 1px solid transparent;
  color: rgb(82 82 82);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 160ms cubic-bezier(0.2, 0.8, 0.2, 1),
    color 160ms cubic-bezier(0.2, 0.8, 0.2, 1),
    border-color 160ms cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 100ms ease;
}
.filter-chip:hover {
  background: rgb(236 236 236);
  color: rgb(23 23 23);
}
.filter-chip:active { transform: scale(0.97); }
.filter-chip.open {
  background: rgb(23 23 23);
  color: #fff;
}
.dark .filter-chip { background: rgba(31, 31, 31, 0.7); color: rgb(163 163 163); }
.dark .filter-chip:hover { background: rgb(31 31 31); color: #fff; }
.dark .filter-chip.open { background: #fff; color: rgb(23 23 23); }

.chip-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
}
.chip-value { font-weight: 500; }
.chip-caret {
  opacity: 0.55;
  transition: transform 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.filter-chip.open .chip-caret { transform: rotate(180deg); }

/* Popover */
.filter-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  padding: 6px;
  z-index: 60;
  background: #fff;
  border: 1px solid rgb(228 228 228);
  border-radius: 14px;
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.10),
    0 2px 6px rgba(0, 0, 0, 0.04);
  visibility: hidden;
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  transform-origin: top left;
  transition:
    opacity 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
    visibility 0s 180ms;
}
.filter-popover.open {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition:
    opacity 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.dark .filter-popover {
  background: rgb(23 23 23);
  border-color: rgb(64 64 64);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.45),
    0 2px 6px rgba(0, 0, 0, 0.25);
}

.popover-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  text-align: left;
  background: transparent;
  color: rgb(23 23 23);
  cursor: pointer;
  transition: background-color 160ms cubic-bezier(0.2, 0.8, 0.2, 1),
              color 160ms cubic-bezier(0.2, 0.8, 0.2, 1),
              transform 100ms ease;
}
.popover-option:hover { background: rgb(244 244 244); }
.popover-option:active { transform: scale(0.98); }
.filter-popover.open .popover-option {
  animation: opt-in 240ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.filter-popover.open .popover-option:nth-child(1) { animation-delay: 30ms; }
.filter-popover.open .popover-option:nth-child(2) { animation-delay: 70ms; }
.filter-popover.open .popover-option:nth-child(3) { animation-delay: 110ms; }
.filter-popover.open .popover-option:nth-child(4) { animation-delay: 150ms; }
.filter-popover.open .popover-row,
.filter-popover.open .popover-reset {
  animation: opt-in 240ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.filter-popover.open .popover-row:nth-child(1) { animation-delay: 30ms; }
.filter-popover.open .popover-row:nth-child(2) { animation-delay: 70ms; }
.filter-popover.open .popover-reset            { animation-delay: 110ms; }
@keyframes opt-in {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}
.popover-option.active {
  background: rgb(23 23 23);
  color: #fff;
}
.dark .popover-option { color: rgb(245 245 245); }
.dark .popover-option:hover { background: rgb(38 38 38); }
.dark .popover-option.active { background: #fff; color: rgb(23 23 23); }

.opt-label { font-size: 13.5px; font-weight: 500; }
.opt-desc {
  font-size: 11.5px;
  color: rgb(115 115 115);
}
.popover-option.active .opt-desc { color: rgba(255, 255, 255, 0.7); }
.dark .popover-option.active .opt-desc { color: rgba(23, 23, 23, 0.6); }

/* Years popover */
.popover-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}
.popover-row-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(115 115 115);
  width: 44px;
}
.popover-select {
  flex: 1;
  height: 32px;
  padding: 0 28px 0 10px;
  border-radius: 8px;
  background: rgb(244 244 244);
  border: 1px solid transparent;
  color: rgb(23 23 23);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: background-color 140ms ease, border-color 140ms ease;
}
.popover-select:hover { background-color: rgb(228 228 228); }
.popover-select:focus {
  outline: 0;
  border-color: rgb(163 163 163);
}
.dark .popover-select {
  background-color: rgb(38 38 38);
  color: #fff;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a3a3a3' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
}
.dark .popover-select:hover { background-color: rgb(64 64 64); }

.popover-reset {
  width: 100%;
  text-align: center;
  padding: 8px;
  margin-top: 2px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: rgb(115 115 115);
  background: transparent;
  transition: background-color 140ms ease, color 140ms ease;
}
.popover-reset:hover {
  background: rgb(244 244 244);
  color: rgb(23 23 23);
}
.dark .popover-reset:hover {
  background: rgb(38 38 38);
  color: #fff;
}

/* ====================  SEARCH INPUT (flex, focus-within)  ===================== */
.catalog-search {
  margin: 8px 0 16px;
}
.catalog-search-shell {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 8px 0 14px;
  border-radius: 14px;
  background: rgba(244, 244, 244, 0.7);
  border: 1px solid transparent;
  transition:
    background-color 200ms cubic-bezier(0.2, 0.8, 0.2, 1),
    border-color 200ms cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.catalog-search-shell:hover { background: rgba(236, 236, 236, 0.95); }
.catalog-search-shell:focus-within {
  background: #fff;
  border-color: rgb(212 212 212);
  box-shadow:
    0 0 0 4px rgba(38, 38, 38, 0.04),
    0 1px 2px rgba(0, 0, 0, 0.04);
}
.dark .catalog-search-shell {
  background: rgba(31, 31, 31, 0.7);
}
.dark .catalog-search-shell:hover { background: rgba(31, 31, 31, 1); }
.dark .catalog-search-shell:focus-within {
  background: rgb(23 23 23);
  border-color: rgb(82 82 82);
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.05),
    0 1px 2px rgba(0, 0, 0, 0.3);
}

.catalog-search-icon {
  flex: 0 0 auto;
  color: rgb(163 163 163);
  transition: color 180ms ease, transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.catalog-search-shell:focus-within .catalog-search-icon {
  color: rgb(23 23 23);
  transform: scale(1.05);
}
.dark .catalog-search-icon { color: rgb(115 115 115); }
.dark .catalog-search-shell:focus-within .catalog-search-icon { color: #fff; }

#catalog-search-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: rgb(23 23 23);
  font: inherit;
  font-size: 15.5px;
  font-weight: 450;
  letter-spacing: -0.005em;
  -webkit-appearance: none;
  appearance: none;
}
#catalog-search-input::placeholder { color: rgb(163 163 163); font-weight: 400; }
.dark #catalog-search-input { color: rgb(245 245 245); }
.dark #catalog-search-input::placeholder { color: rgb(82 82 82); }
#catalog-search-input::-webkit-search-cancel-button,
#catalog-search-input::-webkit-search-decoration { display: none; }
#catalog-search-input:focus { outline: 0; box-shadow: none; }

/* Right-edge slot — spinner and clear share this position via swap */
.search-spinner {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.catalog-search.loading .search-spinner { opacity: 1; }
.search-spinner::before {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(115, 115, 115, 0.22);
  border-top-color: rgb(23, 23, 23);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
.dark .search-spinner::before {
  border-color: rgba(255, 255, 255, 0.18);
  border-top-color: #fff;
}
@keyframes spin { to { transform: rotate(360deg); } }

#catalog-search-clear {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  color: rgb(115 115 115);
  background: transparent;
  transition: background-color 140ms ease, color 140ms ease, opacity 140ms ease;
}
#catalog-search-clear:hover {
  background: rgb(228 228 228);
  color: rgb(23 23 23);
}
.catalog-search.loading #catalog-search-clear {
  opacity: 0;
  pointer-events: none;
}
.dark #catalog-search-clear:hover {
  background: rgb(64 64 64);
  color: #fff;
}

/* Search-results list */
.search-list {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.search-count {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgb(115 115 115);
  padding: 0 4px 4px;
}
.search-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid rgb(236 236 236);
  background: rgb(250 250 250);
  text-decoration: none;
  color: inherit;
  transition:
    border-color 200ms cubic-bezier(0.2, 0.8, 0.2, 1),
    background-color 200ms cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 200ms cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
  animation: tile-enter 360ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.dark .search-tile {
  border-color: rgb(31 31 31);
  background: rgb(20 20 20);
}
.search-tile:hover {
  border-color: rgb(163 163 163);
  background: #fff;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.05);
}
.dark .search-tile:hover {
  border-color: rgb(115 115 115);
  background: rgb(31 31 31);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}
.search-tile:active { transform: translateY(0); }
@keyframes tile-enter {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.search-tile .head {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgb(115 115 115);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.search-tile .head .arrow { opacity: 0; transition: opacity 140ms ease; }
.search-tile:hover .head .arrow { opacity: 1; }
.search-tile .snippet {
  font-size: 14px;
  line-height: 1.55;
  color: rgb(38 38 38);
}
.dark .search-tile .snippet { color: rgb(212 212 212); }
.search-tile mark {
  background: linear-gradient(180deg, transparent 55%, rgba(252, 211, 77, 0.55) 55%);
  color: inherit;
  font-weight: 500;
  padding: 0 1px;
  border-radius: 1px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.dark .search-tile mark {
  background: linear-gradient(180deg, transparent 55%, rgba(252, 211, 77, 0.30) 55%);
  color: rgb(254 243 199);
}
.search-empty {
  text-align: center;
  padding: 64px 16px;
  color: rgb(115 115 115);
  font-size: 14px;
  max-width: 32rem;
  margin: 0 auto;
}
.search-empty .big {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: rgb(23 23 23);
  margin-bottom: 4px;
}
.dark .search-empty .big { color: #fff; }

@keyframes tile-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ====================  SKELETON LOADER  ===================== */
.search-skeleton {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: skeleton-fade 200ms ease both;
}
@keyframes skeleton-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.skeleton-tile {
  position: relative;
  padding: 16px 18px;
  border-radius: 14px;
  background: rgba(244, 244, 244, 0.7);
  border: 1px solid rgb(244 244 244);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  animation: tile-enter 320ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.search-skeleton .skeleton-tile:nth-child(1) { animation-delay: 0ms; }
.search-skeleton .skeleton-tile:nth-child(2) { animation-delay: 35ms; }
.search-skeleton .skeleton-tile:nth-child(3) { animation-delay: 70ms; }
.search-skeleton .skeleton-tile:nth-child(4) { animation-delay: 105ms; }
.search-skeleton .skeleton-tile:nth-child(5) { animation-delay: 140ms; }
.search-skeleton .skeleton-tile:nth-child(6) { animation-delay: 175ms; }
.dark .skeleton-tile {
  background: rgba(20, 20, 20, 0.7);
  border-color: rgb(31 31 31);
}
.sk-line {
  position: relative;
  height: 10px;
  border-radius: 4px;
  background: rgba(228, 228, 228, 0.7);
  overflow: hidden;
}
.dark .sk-line { background: rgba(64, 64, 64, 0.5); }
.sk-line::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.55) 50%,
    transparent 100%
  );
  animation: shimmer 1.4s linear infinite;
}
.dark .sk-line::after {
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.06) 50%,
    transparent 100%
  );
}
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.sk-line.head  { width: 25%; height: 8px; }
.sk-line.long  { width: 100%; }
.sk-line.med   { width: 88%; }
.sk-line.short { width: 60%; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Lock body scroll while overlay is open */
body.catalog-open { overflow: hidden; }
