:root {
  --bg: #0b0d12;
  --bg-2: #121620;
  --surface: rgba(22, 27, 38, 0.78);
  --surface-solid: #171c28;
  --ink: #f3eee4;
  --muted: #9aa3b4;
  --faint: #6d7688;
  --gold: #e4b56a;
  --gold-2: #f0d09a;
  --teal: #79cfc6;
  --rose: #e08b7a;
  --line: rgba(243, 238, 228, 0.1);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Outfit", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

img {
  max-width: 100%;
  display: block;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.glow {
  position: fixed;
  z-index: 0;
  pointer-events: none;
  filter: blur(70px);
  opacity: 0.55;
}

.glow-a {
  width: 280px;
  height: 280px;
  top: -80px;
  right: -40px;
  background: radial-gradient(circle, rgba(228, 181, 106, 0.28), transparent 68%);
}

.glow-b {
  width: 340px;
  height: 340px;
  bottom: 8%;
  left: -120px;
  background: radial-gradient(circle, rgba(121, 207, 198, 0.16), transparent 70%);
}

.app {
  position: relative;
  z-index: 1;
  width: min(860px, calc(100% - 28px));
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 0 calc(40px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  color: var(--gold);
  background: linear-gradient(180deg, rgba(228, 181, 106, 0.16), rgba(228, 181, 106, 0.05));
  border: 1px solid rgba(228, 181, 106, 0.22);
  flex: 0 0 auto;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-copy strong {
  font-family: var(--font-display);
  font-size: 1.12rem;
  letter-spacing: -0.02em;
}

.brand-copy span {
  color: var(--muted);
  font-size: 0.78rem;
}

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

.status-pill,
.icon-btn,
.btn,
.chip-like,
.chips button,
.source,
.kind {
  border-radius: 999px;
}

.status-pill {
  display: inline-flex;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.icon-btn,
.btn,
.chips button,
.paper,
.related-item {
  touch-action: manipulation;
}

.icon-btn,
.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  min-height: 44px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  font-size: 0.88rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 18px;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn.primary {
  background: linear-gradient(180deg, #f0c27a, #d7a352);
  color: #2a1c08;
  border-color: transparent;
  font-weight: 650;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.04);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: -6px 0 22px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  backdrop-filter: blur(16px);
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.filters .wide {
  grid-column: 1 / -1;
}

.filters input,
.filters select,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #10141c;
  border-radius: 12px;
  padding: 11px 12px;
  min-height: 44px;
}

.hero h1 {
  margin: 8px 0 10px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-weight: 620;
}

.eyebrow,
.lede,
.hint-note {
  color: var(--muted);
}

.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lede {
  margin: 0 0 22px;
  max-width: 38rem;
  font-size: 1.02rem;
}

.dropzone {
  position: relative;
  min-height: 240px;
  border-radius: var(--radius);
  border: 1px dashed rgba(228, 181, 106, 0.28);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01)),
    var(--bg-2);
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.dropzone.dragover {
  border-color: var(--gold);
  background: rgba(228, 181, 106, 0.06);
}

.empty-capture,
.preview-wrap {
  min-height: 240px;
}

.empty-capture {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 28px 18px;
}

.empty-capture p {
  margin: 0;
  color: var(--muted);
  max-width: 20rem;
}

.lens {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid rgba(228, 181, 106, 0.55);
  box-shadow: inset 0 0 0 10px rgba(228, 181, 106, 0.08), 0 0 30px rgba(228, 181, 106, 0.12);
  position: relative;
}

.lens::after {
  content: "";
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.85;
}

.capture-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.preview-wrap img {
  width: 100%;
  height: min(52dvh, 420px);
  object-fit: cover;
}

.scan {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(228, 181, 106, 0.28), transparent);
  animation: scan 1.6s ease-in-out infinite;
}

.clear-photo {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(10, 12, 16, 0.7);
  color: white;
  font-size: 1.4rem;
  line-height: 1;
}

.composer {
  margin-top: 14px;
}

.composer textarea {
  resize: vertical;
  min-height: 72px;
  border-radius: 16px;
  line-height: 1.45;
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.hint-note {
  margin: 0;
  font-size: 0.8rem;
}

.search-btn {
  min-width: 132px;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 0 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chips button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}

.progress,
.analysis,
.results,
.banner {
  margin-top: 26px;
}

.progress ol {
  list-style: none;
  margin: 0;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  gap: 10px;
}

.progress li {
  color: var(--faint);
  position: relative;
  padding-left: 28px;
}

.progress li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--faint);
}

.progress li.active {
  color: var(--gold-2);
}

.progress li.active::before {
  background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(228, 181, 106, 0.15);
}

.progress li.done {
  color: var(--teal);
}

.progress li.done::before {
  background: var(--teal);
  border-color: var(--teal);
}

.analysis-card,
.paper,
.sheet-body,
.filters {
  box-shadow: var(--shadow);
}

.analysis-card {
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(16px);
}

.analysis-top {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.kind,
.source {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  font-size: 0.75rem;
  border: 1px solid var(--line);
  background: rgba(121, 207, 198, 0.08);
  color: var(--teal);
}

.analysis-card h2,
.results-head h2,
.sheet-body h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.analysis-card p,
.paper p,
.sheet-body p {
  margin: 0 0 10px;
  color: var(--muted);
}

.query-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.query-row input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #10141c;
  padding: 0 12px;
}

.extracted {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  white-space: pre-wrap;
  color: var(--faint);
  font-size: 0.9rem;
  max-height: 160px;
  overflow: auto;
}

.results-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.results-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.paper-list {
  display: grid;
  gap: 12px;
}

.paper {
  width: 100%;
  text-align: left;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface-solid);
}

.paper:hover,
.paper:focus-visible {
  border-color: rgba(228, 181, 106, 0.35);
}

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

.paper-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.rank {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
}

.paper h3 {
  margin: 0 0 8px;
  font-size: 1.08rem;
  line-height: 1.3;
}

.abstract {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sheet-actions a {
  text-decoration: none;
}

.score {
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  margin-top: 12px;
}

.score span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.banner {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(224, 139, 122, 0.12);
  color: #f0c2b8;
  border: 1px solid rgba(224, 139, 122, 0.25);
}

.foot {
  margin-top: 36px;
  color: var(--faint);
  font-size: 0.78rem;
  text-align: center;
}

.sheet {
  width: min(720px, 100%);
  max-height: min(92dvh, 900px);
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #12161f;
  color: var(--ink);
  padding: 0;
  overflow: hidden;
}

.sheet::backdrop {
  background: rgba(5, 6, 10, 0.62);
}

.sheet-handle {
  display: none;
  width: 42px;
  height: 4px;
  margin: 10px auto 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.18);
}

.sheet-head {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px 0;
}

.sheet-body {
  padding: 4px 18px calc(22px + var(--safe-bottom));
  overflow: auto;
  max-height: calc(92dvh - 58px);
  overscroll-behavior: contain;
}

.sheet-actions,
.mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.passages,
.related-list {
  display: grid;
  gap: 10px;
}

.passage,
.related-item {
  padding: 12px;
  border-radius: 14px;
  background: #1a2030;
  border: 1px solid var(--line);
}

.related-item {
  text-align: left;
  color: inherit;
  width: 100%;
}

@keyframes scan {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

@media (min-width: 720px) {
  .status-pill {
    max-width: none;
  }

  .app {
    width: min(920px, calc(100% - 48px));
    padding-top: 28px;
  }

  .filters {
    grid-template-columns: 140px 1fr 140px 140px;
  }

  .filters .wide {
    grid-column: auto;
  }
}

@media (max-width: 719px) {
  .app {
    width: min(100% - 20px, 860px);
  }

  .composer-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-btn {
    width: 100%;
    min-height: 48px;
  }

  .sheet {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    max-height: 92dvh;
  }

  .sheet-handle {
    display: block;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .hero h1 {
    font-size: 1.7rem;
  }

  .preview-wrap img,
  .empty-capture,
  .dropzone,
  .preview-wrap {
    min-height: 160px;
    height: 160px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scan,
  .btn {
    animation: none;
    transition: none;
  }
}
