/* Foundation */
:root {
  --bg: #FAF8F4;
  --ink: #1A1A1A;
  --ink-secondary: #6B6359;
  --accent: #1B3A5C;
  --border: #E8E2D6;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 6px 24px rgba(0,0,0,0.06);

  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130F;
    --ink: #F2EDE2;
    --ink-secondary: #9A9082;
    --accent: #6FA1D6;
    --border: #2A2620;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 6px 24px rgba(0,0,0,0.5);
  }
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-feature-settings: "tnum";
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

.page { max-width: 720px; margin: 0 auto; padding: 0 24px 200px; }

/* Hero */
.hero { padding: 120px 0 48px; text-align: center; }
.hero__title { font-family: var(--serif); font-weight: 600; font-size: 40px; letter-spacing: -0.01em; margin: 0 0 12px; }
.hero__subtitle { color: var(--ink-secondary); margin: 0 0 36px; font-size: 16px; }

.search__input {
  width: 100%; height: 64px; padding: 0 24px;
  font-family: var(--serif); font-size: 22px;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--border); border-radius: 12px;
  transition: border-color 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}
.search__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(27,58,92,0.12); }

.recent { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.recent__tag {
  padding: 4px 12px; font-size: 13px; color: var(--ink-secondary);
  background: transparent; border: 1px solid var(--border); border-radius: 999px;
  transition: transform 160ms var(--ease-out), background 160ms var(--ease-out);
}
.recent__tag:active { transform: scale(0.97); }

/* Filters */
.filters {
  position: sticky; top: 12px; z-index: 5;
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; margin: 0 0 24px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 13px;
}
.filters__group { display: flex; gap: 4px; }
.pill {
  padding: 6px 14px; border: 0; background: transparent; color: var(--ink-secondary);
  border-radius: 999px; font-size: 13px;
  transition: transform 160ms var(--ease-out), background 160ms var(--ease-out), color 160ms var(--ease-out);
}
.pill:active { transform: scale(0.97); }
.pill.is-active { background: var(--accent); color: white; }
.filters__year input { width: 64px; border: 1px solid var(--border); background: transparent; color: var(--ink); border-radius: 8px; padding: 4px 6px; font: inherit; }

/* Feed */
.feed { display: flex; flex-direction: column; gap: 20px; }

/* Focus + a11y */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
:focus:not(:focus-visible) { outline: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Cards */
.card {
  padding: 28px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 16px; transition: transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
}
.card--skeleton { height: 140px; opacity: 0.4; animation: shimmer 1.6s infinite var(--ease-in-out); }
@keyframes shimmer { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.55; } }
.card--result { opacity: 0; animation: cardIn 320ms var(--ease-out) forwards; }
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.card__meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--ink-secondary); margin-bottom: 12px; }
.card__sources { display: flex; gap: 6px; }
.badge { padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 11px; text-transform: lowercase; }
.card__title { font-family: var(--serif); font-size: 22px; line-height: 1.25; margin: 0 0 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card__byline { color: var(--ink-secondary); font-size: 13px; margin: 0 0 12px; }
.card__abstract { color: var(--ink); font-size: 15px; line-height: 1.6; margin: 0 0 16px; }
.card__actions { display: flex; gap: 8px; align-items: center; }

.btn {
  padding: 8px 14px; font-size: 13px; font-weight: 500; color: white; background: var(--accent);
  border: 0; border-radius: 8px;
  transition: transform 160ms var(--ease-out), background 160ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn--ghost { color: var(--ink); background: transparent; border: 1px solid var(--border); text-decoration: none; display: inline-block; }
.btn--icon { padding: 8px 12px; }
.empty { color: var(--ink-secondary); padding: 48px 0; text-align: center; }
.error { padding: 24px; text-align: center; color: var(--ink-secondary); }

/* Fallback notice */
.fallback-notice { padding: 12px; font-size: 13px; color: var(--ink-secondary); background: var(--border); border-radius: 8px; }

/* Sidebar */
.sidebar {
  position: fixed; top: 0; right: 0; height: 100vh; width: 360px;
  padding: 80px 28px 24px; background: var(--bg); border-left: 1px solid var(--border);
  overflow-y: auto; z-index: 4;
  transform: translateX(100%);
  transition: transform 320ms var(--ease-drawer);
}
.sidebar.is-open { transform: translateX(0); }
.sidebar__close { position: absolute; top: 16px; right: 16px; background: transparent; border: 0; font-size: 22px; color: var(--ink-secondary); }
.sidebar__close:active { transform: scale(0.9); }
.sidebar__block { margin-bottom: 32px; }
.sidebar__h { font-family: var(--serif); font-size: 14px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-secondary); margin: 0 0 12px; }
.sidebar__overview { font-size: 14px; line-height: 1.6; }
.sidebar__tldr { font-family: var(--serif); font-size: 16px; line-height: 1.55; margin: 0; padding-left: 12px; border-left: 2px solid var(--accent); }
.sidebar__concepts { display: flex; flex-wrap: wrap; gap: 8px; }
.concept-chip { padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; background: transparent; color: var(--ink); transition: transform 160ms var(--ease-out), background 160ms var(--ease-out); }
.concept-chip:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .concept-chip:hover { background: var(--border); } }

/* Citation popover */
.cite-popover {
  width: 360px; padding: 20px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--ink); box-shadow: var(--shadow);
}
.cite-popover[open] { animation: popoverIn 180ms var(--ease-out); }
@keyframes popoverIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.cite-popover__formats { display: flex; gap: 4px; margin-bottom: 16px; padding: 4px; background: var(--border); border-radius: 8px; }
.cite-popover__formats button { flex: 1; padding: 6px; border: 0; background: transparent; color: var(--ink-secondary); border-radius: 6px; font-size: 13px; transition: background 160ms var(--ease-out), color 160ms var(--ease-out); }
.cite-popover__formats button.is-active { background: var(--bg); color: var(--ink); box-shadow: var(--shadow); }
.cite-popover__output { padding: 12px; border-radius: 8px; background: var(--border); font-size: 13px; line-height: 1.55; min-height: 80px; transition: filter 200ms ease, opacity 200ms ease; }
.cite-popover__output.is-swapping { filter: blur(2px); opacity: 0.7; }
.cite-popover__actions { display: flex; gap: 8px; margin-top: 16px; }

/* Microtoast */
.microtoast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); padding: 8px 16px; background: var(--ink); color: var(--bg); border-radius: 999px; font-size: 13px; opacity: 0; transition: opacity 240ms var(--ease-out); z-index: 100; }
.microtoast.is-visible { opacity: 1; }

/* Tray */
.tray-pill {
  position: fixed; right: 24px; bottom: 24px;
  padding: 12px 18px; border: 1px solid var(--border); background: var(--bg); color: var(--ink);
  border-radius: 999px; font-size: 14px; box-shadow: var(--shadow);
  transition: transform 160ms var(--ease-out);
  animation: trayIn 280ms var(--ease-out);
}
@keyframes trayIn { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.tray-pill:active { transform: scale(0.97); }

.tray-panel { width: 400px; padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--bg); color: var(--ink); }
.tray-panel::backdrop { background: rgba(0,0,0,0.2); }
.tray-panel__header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.tray-panel__header h2 { margin: 0; font-family: var(--serif); font-size: 18px; }
.tray-panel__close { background: transparent; border: 0; font-size: 22px; color: var(--ink-secondary); }
.tray-panel__list { list-style: none; padding: 8px 0; margin: 0; max-height: 50vh; overflow-y: auto; }
.tray-row { display: flex; align-items: center; gap: 8px; padding: 10px 20px; }
.tray-row__title { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-row__format { font: inherit; padding: 4px; }
.tray-row__remove { background: transparent; border: 0; color: var(--ink-secondary); font-size: 18px; }
.tray-panel__footer { display: flex; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* Source status row */
.source-status { padding: 10px 14px; margin-bottom: 16px; font-size: 12px; color: var(--ink-secondary); border: 1px dashed var(--border); border-radius: 8px; }
