/* ------------------------------------------------------------------ base */

:root {
  --bg: #faf9f7;
  --paper: #ffffff;
  --surface: rgba(20, 24, 35, 0.035);
  --surface-2: rgba(20, 24, 35, 0.065);
  --line: rgba(20, 24, 35, 0.11);
  --line-2: rgba(20, 24, 35, 0.20);
  --text: #16181d;
  --muted: #5a6170;
  --faint: #878e9c;
  --accent: #2f5bd8;
  --accent-ink: #2647a8;
  --accent-wash: rgba(47, 91, 216, 0.09);

  --arxiv: #b3401f;
  --biorxiv: #16714a;
  --journal: #33459c;

  --topbar-h: 58px;
  --tabbar-h: 58px;
  --gutter: clamp(18px, 5vw, 44px);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(1100px 700px at 12% -10%, #e9eefc 0%, transparent 62%),
    radial-gradient(900px 600px at 92% 105%, #f5eef8 0%, transparent 58%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) clamp(12px, 3vw, 22px) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 40;
  background: linear-gradient(180deg, rgba(250, 249, 247, 0.94) 55%, rgba(250, 249, 247, 0));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  display: flex; align-items: center; gap: 9px;
  background: none; border: 0; padding: 6px 2px;
  font-size: 15px; font-weight: 620; letter-spacing: -0.015em;
}
.brand-mark { font-size: 17px; }
.brand-dim { color: var(--faint); font-weight: 500; }
@media (max-width: 560px) { .brand-name { display: none; } }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  max-width: min(46vw, 300px);
  padding: 8px 12px 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--paper);
  font-size: 13.5px; font-weight: 560;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(20, 24, 35, 0.05);
  transition: background 0.16s, border-color 0.16s;
}
.pill:hover { background: #fff; border-color: rgba(20, 24, 35, 0.32); }
.pill > span { overflow: hidden; text-overflow: ellipsis; }
.chev { width: 14px; height: 14px; flex: none; color: var(--muted); }

.icon-btn {
  position: relative;
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 16px;
  box-shadow: 0 1px 2px rgba(20, 24, 35, 0.05);
  transition: background 0.16s, border-color 0.16s;
}
.icon-btn:hover { background: #fff; border-color: var(--line-2); }
.icon-btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.icon-btn.ghost:hover { background: var(--surface-2); }

.badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 10.5px; font-weight: 750; line-height: 17px;
  text-align: center;
}

.foryou {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-wash);
  border: 1px solid rgba(47, 91, 216, 0.30);
  color: var(--accent-ink);
  font-size: 11px; font-weight: 660;
  letter-spacing: 0.04em; text-transform: uppercase;
  white-space: nowrap;
}
.foryou[hidden] { display: none; }
@media (max-width: 620px) { .foryou { display: none; } }

/* ------------------------------------------------------------- tab bar */

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 45;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(250, 249, 247, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  border: 0; background: none;
  color: var(--faint);
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.03em;
  transition: color 0.15s;
}
.tab svg { width: 21px; height: 21px; }
.tab:hover { color: var(--muted); }
.tab[aria-pressed="true"] { color: var(--accent); }

/* Full-width thirds read as a phone tab bar; on a wide screen they'd be
   marooned in the corners, so group them in the middle instead. */
@media (min-width: 640px) {
  .tabbar { justify-content: center; gap: 6px; }
  .tab { flex: 0 0 auto; width: 104px; border-radius: 10px; }
}

/* Reels run their own dark, saturated world — the chrome follows. */
body[data-view="reels"] .tabbar {
  background: rgba(10, 10, 14, 0.72);
  border-top-color: rgba(255, 255, 255, 0.12);
}
body[data-view="reels"] .tab { color: rgba(255, 255, 255, 0.55); }
body[data-view="reels"] .tab[aria-pressed="true"] { color: #fff; }
body[data-view="reels"] .topbar {
  background: linear-gradient(180deg, rgba(10, 10, 14, 0.66), rgba(10, 10, 14, 0));
  color: #fff;
}
body[data-view="reels"] .topbar .pill,
body[data-view="reels"] .topbar .icon-btn {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
  color: #fff;
  box-shadow: none;
}
body[data-view="reels"] .brand-dim { color: rgba(255, 255, 255, 0.5); }
body[data-view="reels"] .scroll-hint { display: none; }

/* ------------------------------------------------------------ view shell */

.view { height: 100dvh; }
.view[hidden] { display: none; }

/* ------------------------------------------------------------ grid view */

#view-grid {
  overflow-y: auto;
  padding:
    calc(var(--topbar-h) + env(safe-area-inset-top) + 12px)
    clamp(12px, 3vw, 26px)
    calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  max-width: 1200px;
  margin: 0 auto;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 14px;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(20, 24, 35, 0.05);
  cursor: pointer;
  transition: transform 0.14s, box-shadow 0.14s, border-color 0.14s;
}
.tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(20, 24, 35, 0.10);
  border-color: var(--line-2);
}
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tile-head {
  display: flex; align-items: center; gap: 7px;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase;
}
.tile-emoji { font-size: 15px; }
.tile-src { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tile-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 16.5px;
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.01em;
  color: var(--text);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4;
  overflow: hidden;
}
.tile-meta { color: var(--faint); font-size: 11.5px; margin-top: auto; }

.tile-foot { display: flex; gap: 6px; padding-top: 2px; }

.mini {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 11.5px; font-weight: 560;
}
.mini svg { width: 13px; height: 13px; }
.mini:hover { border-color: var(--line-2); color: var(--text); }
.mini.on { color: var(--accent-ink); border-color: rgba(47, 91, 216, 0.45); background: var(--accent-wash); }
.mini.on svg { fill: currentColor; }
.mini.like.on { color: #c0325d; border-color: rgba(192, 50, 93, 0.4); background: rgba(192, 50, 93, 0.08); }

.grid-loading, .grid-empty {
  grid-column: 1 / -1;
  display: grid; place-items: center; gap: 12px;
  padding: 80px 0;
  color: var(--muted); font-size: 14px; text-align: center;
}
.grid-end { height: 1px; }

/* like button in the reader */

.act.like.on {
  color: #c0325d;
  border-color: rgba(192, 50, 93, 0.42);
  background: rgba(192, 50, 93, 0.08);
}
.act.like.on svg { fill: currentColor; }

/* ------------------------------------------------------------ reels view */

.reels {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  background: #0a0a0e;
}
.reels::-webkit-scrollbar { display: none; }

.reel {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: #fff;
  padding:
    calc(var(--topbar-h) + env(safe-area-inset-top) + 16px)
    clamp(20px, 6vw, 56px)
    calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
}

.reel-bg {
  position: absolute; inset: 0; z-index: 0;
  background-size: 220% 220%;
  animation: drift 18s ease-in-out infinite;
}
.reel-bg.k-arxiv    { background-image: linear-gradient(135deg, #ff5f3f, #b3201f 45%, #6d0f4c); }
.reel-bg.k-biorxiv  { background-image: linear-gradient(135deg, #17c07a, #068a63 45%, #084b6b); }
.reel-bg.k-openalex { background-image: linear-gradient(135deg, #6a6bff, #3a2fb8 45%, #7a1f8f); }
.reel-bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 90% at 50% 0%, rgba(0,0,0,0) 40%, rgba(0,0,0,0.5));
}
@keyframes drift {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}
@media (prefers-reduced-motion: reduce) { .reel-bg { animation: none; } }

/* Stacking: bg (0) < scene text (2) < tap zones (3) < chrome the user clicks (4).
   The text layer is inert so the tap zones underneath it stay reachable.
   Every selector here is `.reel > .thing` so they all carry the same
   specificity — a bare `.reel-top { z-index }` would lose to `.reel > *`
   and end up *under* the tap zones, swallowing its clicks. */
.reel > * { position: relative; z-index: 2; }
.reel > .reel-bg { position: absolute; z-index: 0; }
.reel > .reel-tap { position: absolute; z-index: 3; }
.reel > .reel-bars,
.reel > .reel-top,
.reel > .reel-foot { z-index: 4; }
.reel-body { pointer-events: none; }

.reel-bars { display: flex; gap: 4px; margin-bottom: 14px; }
.reel-bars i {
  flex: 1 1 0; height: 3px; border-radius: 2px;
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
}
.reel-bars i b { display: block; height: 100%; width: 0; background: #fff; }

.reel-top {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; font-weight: 640;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
}
.reel-emoji { font-size: 17px; }

.reel-speed {
  margin-left: auto;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 11.5px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  backdrop-filter: blur(6px);
}
.reel-speed:hover { background: rgba(255, 255, 255, 0.26); }

.reel-src {
  padding: 4px 9px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%;
}

.reel-body {
  flex: 1 1 auto;
  display: flex; align-items: center;
  min-height: 0;
  padding: 18px 0;
}
.reel-text {
  margin: 0;
  font-weight: 760;
  letter-spacing: -0.028em;
  line-height: 1.08;
  font-size: clamp(30px, 7.4vw, 62px);
  text-wrap: balance;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.28);
}
.reel-text span {
  display: inline-block;
  animation: pop 0.42s cubic-bezier(0.2, 1.1, 0.3, 1) both;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(0.35em) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .reel-text span { animation: none; }
}

/* Later scenes step down in size so long findings still fit. */
.reel-body.s-point .reel-text { font-size: clamp(22px, 5.1vw, 40px); font-weight: 700; }
.reel-body.s-why .reel-text  { font-size: clamp(24px, 5.6vw, 44px); }
.reel-body.s-why .reel-text::before {
  content: "So what? ";
  color: rgba(255, 255, 255, 0.6);
}

.reel-foot { display: flex; flex-direction: column; gap: 12px; }
.reel-title {
  font-size: 12.5px; line-height: 1.45;
  color: rgba(255, 255, 255, 0.8);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden;
}
.reel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.reel-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.14);
  color: #fff; text-decoration: none;
  font-size: 13px; font-weight: 600;
  backdrop-filter: blur(6px);
}
.reel-btn svg { width: 15px; height: 15px; }
.reel-btn:hover { background: rgba(255, 255, 255, 0.24); }
.reel-btn.on { background: #fff; color: #111; border-color: #fff; }
.reel-btn.on svg { fill: currentColor; }

.reel-tap {
  position: absolute; top: 0; bottom: 0; z-index: 3;
  width: 28%;
  cursor: pointer;
}
.reel-tap.left { left: 0; }
.reel-tap.right { right: 0; }

.reel.paused .reel-body::after {
  content: "❙❙";
  position: absolute; top: 50%; right: clamp(20px, 6vw, 56px);
  transform: translateY(-50%);
  font-size: 13px; letter-spacing: 2px;
  color: rgba(255, 255, 255, 0.7);
}

/* ------------------------------------------------------------------ feed */
/* Cards grow to fit their content — a long abstract makes a tall card you
   scroll through, rather than being clipped into one viewport. Proximity
   snapping keeps the card-to-card feel without fighting that scroll. */

.feed {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y proximity;
  scroll-behavior: smooth;
  outline: none;
  scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }

@media (prefers-reduced-motion: reduce) {
  .feed { scroll-behavior: auto; }
}

.card {
  scroll-snap-align: start;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding:
    calc(var(--topbar-h) + env(safe-area-inset-top) + 26px)
    var(--gutter)
    calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 34px);
}
.card + .card, .state { border-top: 1px solid var(--line); }

.card-inner {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* meta row */

.meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.source-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 680;
  letter-spacing: 0.045em; text-transform: uppercase;
  border: 1px solid currentColor;
  max-width: min(60vw, 340px);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.source-tag .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: none;
}
.k-arxiv   { color: var(--arxiv);   background: rgba(179, 64, 31, 0.07); }
.k-biorxiv { color: var(--biorxiv); background: rgba(22, 113, 74, 0.07); }
.k-openalex{ color: var(--journal); background: rgba(51, 69, 156, 0.07); }

.meta-dim { color: var(--faint); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.meta-sep { color: rgba(20, 24, 35, 0.22); }

/* title + body */

.title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.014em;
  line-height: 1.18;
  font-size: clamp(23px, 4.2vw, 37px);
  text-wrap: balance;
  color: var(--text);
}

.authors {
  margin: 0;
  color: var(--muted);
  font-size: clamp(13px, 1.7vw, 14.5px);
  line-height: 1.5;
}
.authors .more { color: var(--faint); }

.abstract {
  margin: 0;
  color: #2f3541;
  font-size: clamp(15px, 1.9vw, 16.5px);
  line-height: 1.68;
}

/* view toggle + panes */

.views {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  align-self: flex-start;
}
.view-tab {
  padding: 6px 13px;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px; font-weight: 570;
  transition: background 0.15s, color 0.15s;
}
.view-tab:hover { color: var(--text); }
.view-tab[aria-pressed="true"] {
  background: var(--paper);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(20, 24, 35, 0.10);
}

.pane { display: flex; flex-direction: column; gap: 14px; }
.pane[hidden] { display: none; }

/* explanation */

.ex { display: flex; flex-direction: column; gap: 14px; }

.ex-headline {
  margin: 0;
  font-size: clamp(16.5px, 2.1vw, 20px);
  line-height: 1.4;
  font-weight: 620;
  letter-spacing: -0.01em;
  color: var(--text);
}

.ex-summary {
  margin: 0;
  color: #2f3541;
  font-size: clamp(14.5px, 1.85vw, 16px);
  line-height: 1.65;
}

.ex-findings {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 8px;
}
.ex-findings li {
  position: relative;
  padding-left: 18px;
  color: #3b414e;
  font-size: clamp(14px, 1.75vw, 15.5px);
  line-height: 1.55;
}
.ex-findings li::before {
  content: "";
  position: absolute; left: 3px; top: 0.62em;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
}

.ex-note {
  margin: 0;
  font-size: 13.5px; line-height: 1.6;
  color: var(--muted);
}
.ex-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--accent-wash);
  color: var(--accent-ink);
  font-size: 10.5px; font-weight: 680;
  letter-spacing: 0.04em; text-transform: uppercase;
  vertical-align: 1px;
}
.ex-caveat .ex-tag { background: rgba(180, 83, 9, 0.12); color: #96470a; }

.ex-jargon { display: flex; flex-wrap: wrap; gap: 6px; }
.jchip {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px dashed rgba(47, 91, 216, 0.42);
  background: rgba(47, 91, 216, 0.06);
  color: var(--accent-ink);
  font-size: 11.5px; font-weight: 550;
}
.jchip:hover { background: rgba(47, 91, 216, 0.14); border-style: solid; }

.ex-foot {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.ex-level { color: var(--faint); font-size: 11.5px; letter-spacing: 0.02em; }
.ex-fb { display: flex; gap: 6px; }
.ex-btn {
  padding: 5px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-size: 11.5px; font-weight: 550;
}
.ex-btn:hover { color: var(--text); border-color: var(--line-2); }

.ex-loading, .ex-msg {
  display: flex; align-items: center; gap: 11px; flex-wrap: wrap;
  padding: 18px 0;
  color: var(--muted);
  font-size: 14px; line-height: 1.55;
}
.ex-loading .spinner { width: 18px; height: 18px; border-width: 2px; }

/* visuals */

.vz {
  margin: 0;
  padding: 14px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(20, 24, 35, 0.05);
}
.vz-cap {
  margin-bottom: 11px;
  color: var(--faint);
  font-size: 10.5px; font-weight: 660;
  letter-spacing: 0.07em; text-transform: uppercase;
}
.vz-row { display: flex; align-items: stretch; gap: 8px; }
.vz-emoji { font-size: 19px; line-height: 1; margin-bottom: 5px; }
.vz-lab { font-size: 12.5px; font-weight: 600; line-height: 1.3; color: var(--text); }
.vz-det { margin-top: 4px; font-size: 11.5px; line-height: 1.45; color: var(--muted); }

.vz-flow .vz-row { align-items: flex-start; }
.vz-step { flex: 1 1 0; min-width: 0; }
.vz-arrow { flex: none; align-self: center; color: rgba(20, 24, 35, 0.28); font-size: 15px; }

.vz-compare .vz-side {
  flex: 1 1 0; min-width: 0;
  padding: 11px;
  border-radius: 10px;
  background: var(--surface);
}
.vz-vs {
  flex: none; align-self: center;
  color: var(--faint); font-size: 10.5px;
  font-weight: 680; text-transform: uppercase; letter-spacing: 0.07em;
}

.vz-stats .vz-row { flex-wrap: wrap; }
.vz-stat {
  flex: 1 1 90px; min-width: 0;
  padding: 11px;
  border-radius: 10px;
  background: var(--surface);
}
.vz-val {
  font-size: clamp(18px, 2.4vw, 23px);
  font-weight: 680;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin-bottom: 3px;
}

@media (max-width: 560px) {
  .vz-flow .vz-row, .vz-compare .vz-row { flex-direction: column; }
  .vz-arrow { align-self: flex-start; margin-left: 6px; transform: rotate(90deg); }
  .vz-vs { align-self: center; }
}

/* clicking a word to define it */

::highlight(ds-define) {
  background: rgba(47, 91, 216, 0.20);
}

.title, .abstract, .ex-summary, .ex-headline, .ex-findings li, .ex-note {
  cursor: text;
}

.define-pop {
  position: fixed;
  z-index: 95;
  width: min(340px, calc(100vw - 20px));
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: 0 14px 44px rgba(20, 24, 35, 0.20), 0 2px 6px rgba(20, 24, 35, 0.08);
  animation: rise 0.14s ease;
}
.define-pop[hidden] { display: none; }
.dp-term {
  font-size: 14.5px; font-weight: 660;
  margin-bottom: 6px;
  color: var(--text);
}
.dp-def { font-size: 13.5px; line-height: 1.6; color: #2f3541; }
.dp-ctx {
  margin-top: 9px; padding-top: 9px;
  border-top: 1px solid var(--line);
  font-size: 12.5px; line-height: 1.55; color: var(--muted);
}
.dp-known { margin-top: 9px; font-size: 11px; color: var(--faint); }
.dp-loading { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; }
.dp-loading .spinner { width: 15px; height: 15px; border-width: 2px; }

/* tags + actions */

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  padding: 4px 9px;
  border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
}

.actions { display: flex; flex-wrap: wrap; gap: 9px; padding-top: 2px; }

.act {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px;
  border-radius: 11px;
  border: 1px solid var(--line-2);
  background: var(--paper);
  font-size: 13.5px; font-weight: 570;
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(20, 24, 35, 0.05);
  transition: background 0.16s, border-color 0.16s, transform 0.1s;
}
.act:hover { background: #fff; border-color: rgba(20, 24, 35, 0.32); }
.act:active { transform: scale(0.97); }
.act svg { width: 15px; height: 15px; }
.act.primary {
  background: var(--text); color: #fff; border-color: transparent; font-weight: 640;
}
.act.primary:hover { background: #000; }
.act.on {
  color: var(--accent-ink);
  border-color: rgba(47, 91, 216, 0.45);
  background: var(--accent-wash);
}
.act.on svg { fill: currentColor; }

/* ------------------------------------------------------- states + hint */

.state {
  min-height: 100dvh;
  scroll-snap-align: start;
  display: grid; place-content: center; justify-items: center;
  gap: 14px; text-align: center;
  padding: 0 var(--gutter);
  color: var(--muted);
}
.state h3 { margin: 0; color: var(--text); font-size: 20px; font-weight: 620; }
.state p { margin: 0; max-width: 42ch; line-height: 1.6; font-size: 14.5px; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid rgba(20, 24, 35, 0.14);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* Bottom-right, not centred: the action row is bottom-left and wraps rightward,
   so a centred hint lands on top of the last button. */
.scroll-hint {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--faint); font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase;
  pointer-events: none; z-index: 30;
  animation: bob 2.1s ease-in-out infinite;
  transition: opacity 0.35s;
}
.scroll-hint svg { width: 17px; height: 17px; }
.scroll-hint[hidden] { display: none; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(5px); } }
@media (prefers-reduced-motion: reduce) { .scroll-hint { animation: none; } }

/* ---------------------------------------------------------------- sheets */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 24, 35, 0.32);
  backdrop-filter: blur(3px);
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  z-index: 60;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: min(760px, 100%);
  max-height: min(84dvh, 760px);
  display: flex; flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -18px 60px rgba(20, 24, 35, 0.22);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes rise { from { transform: translate(-50%, 22px); opacity: 0; } }

/* `display: flex` above outranks the UA rule for [hidden], so restate it. */
.sheet[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

.sheet-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 20px clamp(16px, 3.5vw, 26px) 14px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0 0 3px; font-size: 18px; font-weight: 640; letter-spacing: -0.01em; }
.sheet-sub { margin: 0; color: var(--muted); font-size: 13px; }

.sheet-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px clamp(16px, 3.5vw, 26px);
  border-top: 1px solid var(--line);
}

.btn-primary {
  padding: 10px 20px; border-radius: 11px; border: 0;
  background: var(--text); color: #fff; font-weight: 640; font-size: 14px;
}
.btn-primary:hover { background: #000; }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-ghost {
  padding: 10px 14px; border-radius: 11px;
  border: 1px solid var(--line); background: transparent;
  color: var(--muted); font-size: 13.5px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--line-2); }

/* field grid */

.field-grid {
  overflow-y: auto;
  padding: 16px clamp(16px, 3.5vw, 26px);
  display: grid;
  gap: 9px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

.field-chip {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 13px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--bg);
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.field-chip:hover { background: var(--surface-2); border-color: var(--line-2); }
.field-chip[aria-pressed="true"] {
  border-color: rgba(47, 91, 216, 0.55);
  background: var(--accent-wash);
}
.field-chip .fe { font-size: 20px; line-height: 1; flex: none; }
.field-chip .ft { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field-chip .fn { font-size: 14px; font-weight: 600; }
.field-chip .fb { font-size: 11.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* saved list */

.saved-list {
  overflow-y: auto;
  padding: 8px clamp(16px, 3.5vw, 26px) 16px;
  display: flex; flex-direction: column;
}
.saved-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.saved-item:last-child { border-bottom: 0; }
.saved-item .si-body { flex: 1; min-width: 0; }
.saved-item a {
  color: var(--text); text-decoration: none;
  font-size: 14.5px; font-weight: 570; line-height: 1.4;
  display: block; margin-bottom: 4px;
}
.saved-item a:hover { color: var(--accent); }
.saved-item .si-meta { color: var(--faint); font-size: 12px; }
.saved-empty { padding: 34px 0; text-align: center; color: var(--faint); font-size: 14px; }

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  z-index: 90;
  padding: 11px 18px;
  border-radius: 11px;
  background: var(--text); color: #fff;
  font-size: 13.5px; font-weight: 570;
  box-shadow: 0 12px 34px rgba(20, 24, 35, 0.28);
  animation: rise 0.18s ease;
}
.toast[hidden] { display: none; }

/* Reels put their own action row where the toast normally sits. */
body[data-view="reels"] .toast {
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 118px);
}
