:root {
  --bg: #0f0c08;
  --bg-deep: #080603;
  --paper: #dfcfab;
  --paper-shadow: rgba(0, 0, 0, 0.45);
  --ink: #2d2015;
  --ink-soft: #4d3a27;
  --accent: #8d5733;
  --accent-soft: rgba(141, 87, 51, 0.18);
  --edge: #b79f72;
  --line: rgba(43, 28, 18, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: #f1e7d0;
  background:
    radial-gradient(circle at top left, rgba(150, 88, 37, 0.18), transparent 30%),
    radial-gradient(circle at bottom right, rgba(95, 42, 16, 0.25), transparent 24%),
    linear-gradient(180deg, rgba(19, 13, 8, 0.94), rgba(7, 5, 3, 0.98)),
    var(--bg);
  font-family: "Cormorant Garamond", serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image:
    linear-gradient(transparent 0, rgba(255,255,255,0.08) 50%, transparent 100%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
}

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.masthead {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 12px 4px 24px;
}

.eyebrow,
.paper-kicker,
.meta-copy,
.doc-meta,
.filter-chip,
.archive-button {
  font-family: "Special Elite", "Courier New", monospace;
}

.eyebrow {
  margin: 0 0 8px;
  color: #d8c29b;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2.2rem, 4vw, 4.6rem);
  line-height: 0.92;
}

.dek {
  max-width: 680px;
  margin-bottom: 0;
  color: rgba(241, 231, 208, 0.82);
  font-size: 1.18rem;
}

.archive-button {
  border: 1px solid rgba(215, 185, 142, 0.3);
  background: linear-gradient(180deg, rgba(125, 74, 42, 0.34), rgba(65, 33, 16, 0.55));
  color: #f3e7d2;
  padding: 12px 16px;
  border-radius: 999px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: transform 120ms ease, background 120ms ease;
}

.archive-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(145, 86, 49, 0.4), rgba(75, 40, 21, 0.7));
}

.archive-button.ghost {
  background: transparent;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 24px;
  align-items: start;
}

.search-panel {
  position: sticky;
  top: 18px;
  padding: 18px;
  border: 1px solid rgba(214, 190, 149, 0.16);
  border-radius: 24px;
  background: rgba(22, 16, 10, 0.74);
  backdrop-filter: blur(8px);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.28);
}

.search-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.search-box input,
.chat-form textarea {
  width: 100%;
  border: 1px solid rgba(223, 204, 170, 0.18);
  background: rgba(241, 231, 208, 0.06);
  color: #f7efde;
  border-radius: 18px;
  padding: 14px 16px;
  outline: none;
  font: inherit;
}

.search-box input::placeholder,
.chat-form textarea::placeholder {
  color: rgba(247, 239, 222, 0.5);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 14px;
}

.filter-chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(223, 204, 170, 0.16);
  background: rgba(241, 231, 208, 0.05);
  color: rgba(247, 239, 222, 0.88);
  cursor: pointer;
  font-size: 0.8rem;
}

.filter-chip.active {
  background: var(--accent-soft);
  border-color: rgba(215, 185, 142, 0.4);
}

.meta-copy {
  color: rgba(241, 231, 208, 0.7);
  font-size: 0.84rem;
}

.result-list {
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 240px);
  overflow: auto;
  padding-right: 4px;
}

.result-card {
  border: 1px solid rgba(223, 204, 170, 0.12);
  border-radius: 18px;
  background: rgba(236, 216, 176, 0.06);
  padding: 14px 15px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}

.result-card:hover,
.result-card.active {
  transform: translateY(-1px);
  border-color: rgba(215, 185, 142, 0.35);
}

.result-card h3 {
  margin-bottom: 8px;
  font-size: 1.18rem;
}

.result-snippet {
  color: rgba(241, 231, 208, 0.78);
  font-size: 0.98rem;
}

.result-snippet mark {
  background: rgba(210, 173, 112, 0.3);
  color: inherit;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(245, 231, 198, 0.08);
  border: 1px solid rgba(245, 231, 198, 0.14);
  color: rgba(245, 231, 198, 0.8);
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.reader-panel {
  min-width: 0;
}

.paper {
  position: relative;
  min-height: calc(100vh - 120px);
  padding: 42px;
  overflow: hidden;
  border-radius: 18px 24px 20px 28px;
  background:
    radial-gradient(circle at 12% 18%, rgba(120, 68, 32, 0.18), transparent 13%),
    radial-gradient(circle at 80% 22%, rgba(111, 65, 32, 0.14), transparent 11%),
    radial-gradient(circle at 74% 84%, rgba(91, 54, 27, 0.12), transparent 14%),
    linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0.02)),
    var(--paper);
  box-shadow:
    0 24px 90px var(--paper-shadow),
    inset 0 0 0 1px rgba(87, 58, 27, 0.18),
    inset 0 0 40px rgba(114, 78, 35, 0.12);
}

.paper::before,
.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.paper::before {
  background:
    repeating-linear-gradient(0deg, transparent 0 30px, var(--line) 30px 31px),
    linear-gradient(90deg, rgba(136, 37, 26, 0.14) 0 2px, transparent 2px 100%);
  opacity: 0.55;
}

.paper::after {
  background:
    radial-gradient(circle at top right, rgba(58, 30, 15, 0.18), transparent 18%),
    radial-gradient(circle at bottom left, rgba(58, 30, 15, 0.1), transparent 22%);
  mix-blend-mode: multiply;
}

.paper-effects {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.stain,
.fold {
  position: absolute;
  display: block;
}

.stain {
  border-radius: 50%;
  filter: blur(1px);
  mix-blend-mode: multiply;
}

.stain-a {
  width: 180px;
  height: 180px;
  right: -25px;
  top: 34px;
  background: radial-gradient(circle, rgba(111, 73, 43, 0.26), rgba(111, 73, 43, 0.05) 62%, transparent 70%);
}

.stain-b {
  width: 210px;
  height: 120px;
  left: -30px;
  bottom: 60px;
  background: radial-gradient(circle, rgba(124, 68, 28, 0.15), rgba(124, 68, 28, 0.04) 54%, transparent 72%);
}

.fold-a {
  width: 130px;
  height: 130px;
  right: -1px;
  bottom: -1px;
  background: linear-gradient(135deg, transparent 0 50%, rgba(105, 78, 54, 0.25) 50% 52%, rgba(255,255,255,0.18) 52% 100%);
  clip-path: polygon(100% 0, 0 100%, 100% 100%);
}

.paper-content {
  position: relative;
  z-index: 1;
  color: var(--ink);
}

.paper-kicker {
  margin-bottom: 12px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.paper-content h2 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 0.94;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.doc-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Special Elite", "Courier New", monospace;
  font-size: 1.02rem;
  line-height: 1.75;
  color: #2e1f14;
}

.chat-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(520px, 100vw);
  transform: translateX(100%);
  transition: transform 180ms ease;
  z-index: 20;
}

.chat-drawer.open {
  transform: translateX(0);
}

.chat-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: linear-gradient(180deg, rgba(18, 11, 7, 0.98), rgba(10, 7, 4, 0.98));
  border-left: 1px solid rgba(223, 204, 170, 0.12);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.32);
  padding: 20px;
}

.chat-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.chat-log {
  overflow: auto;
  padding: 8px 0;
  display: grid;
  gap: 12px;
}

.chat-card {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(241, 231, 208, 0.06);
  border: 1px solid rgba(241, 231, 208, 0.1);
}

.chat-card.user {
  background: rgba(141, 87, 51, 0.16);
}

.chat-card p:last-child {
  margin-bottom: 0;
}

.chat-sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(241, 231, 208, 0.1);
}

.chat-sources button {
  margin: 0 8px 8px 0;
}

.chat-form {
  display: grid;
  gap: 12px;
}

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

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .search-panel {
    position: static;
  }

  .paper {
    min-height: auto;
    padding: 30px 22px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 20px, 1500px);
  }

  .masthead {
    flex-direction: column;
    align-items: start;
  }

  .search-box {
    grid-template-columns: 1fr;
  }
}
