/* ============================================================
   The Reading Room — design tokens
   ------------------------------------------------------------
   Palette:  warm putty paper, deep moss ink, ochre "stamp" accent,
             muted teal for confirmations.
   Type:     Fraunces (display serif with character) for headings,
             IBM Plex Sans for body copy, IBM Plex Mono for labels,
             counters and the confidence "stamp".
   Signature: a rotated rubber-stamp badge reporting match confidence,
             and folder-tab navigation styled like a card-catalog drawer.
   ============================================================ */

:root {
  --paper: #ece6d8;
  --surface: #fbf9f3;
  --ink: #242b26;
  --ink-soft: #6b6a5c;
  --border: #d8cfba;
  --accent: #b9851b;
  --accent-soft: #f1e3c2;
  --teal: #4f756a;
  --teal-soft: #dde6e2;
  --brick: #a8442e;
  --brick-soft: #f3ddd6;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", monospace;

  --radius: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 3rem;
}

/* ---------- Masthead ---------- */

.masthead {
  text-align: center;
  margin-bottom: 1.75rem;
}

.masthead__index {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  margin-bottom: 0.85rem;
}

.masthead__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.1rem, 6vw, 2.75rem);
  letter-spacing: -0.01em;
  margin: 0 0 0.35rem;
}

.masthead__subtitle {
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin: 0;
}

/* ---------- Folder-tab navigation ---------- */

.tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0 0.75rem;
}

.tab {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.65rem 1.1rem;
  cursor: pointer;
  position: relative;
  top: 1px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  border-bottom: 1px solid var(--surface);
}

.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Card / panels ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 1.75rem;
  /* faint ruled-paper texture */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 38px,
    rgba(36, 43, 38, 0.035) 39px
  );
}

.panel[hidden] {
  display: none;
}

/* ---------- Dropzone ---------- */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone__title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.dropzone__hint {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0;
}

/* ---------- File row ---------- */

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.file-row[hidden] {
  display: none;
}

.file-row__name {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.08s ease, background-color 0.15s ease, border-color 0.15s ease;
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--ink);
  color: var(--surface);
  margin-top: 1rem;
}

.btn--primary:hover {
  background: var(--accent);
}

.btn--primary:disabled {
  background: var(--border);
  color: var(--ink-soft);
  cursor: not-allowed;
}

.btn--ghost {
  background: transparent;
  color: var(--brick);
  border-color: var(--border);
  margin-top: 1.75rem;
}

.btn--ghost:hover {
  background: var(--brick-soft);
  border-color: var(--brick);
}

/* ---------- Status line ---------- */

.status-line {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
  min-height: 1.2em;
  margin: 0.75rem 0 0;
}

.status-line.is-error {
  color: var(--brick);
}

.status-line.is-success {
  color: var(--teal);
}

/* ---------- Shelf list ---------- */

.shelf {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.shelf[hidden] {
  display: none;
}

.shelf__title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
}

.shelf__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.shelf__list li {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink-soft);
  padding-left: 1.1rem;
  position: relative;
}

.shelf__list li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--accent);
}

.shelf__count {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0.75rem 0 0;
}

/* ---------- Q&A panel ---------- */

.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}

.question-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  resize: vertical;
}

.question-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Answer card + signature "stamp" ---------- */

.answer {
  position: relative;
  margin-top: 1.5rem;
  padding: 1.5rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: visible;
}

.answer[hidden] {
  display: none;
}

.answer__title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.answer__text {
  margin: 0;
  white-space: pre-wrap;
}

.stamp {
  position: absolute;
  top: -14px;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 86px;
  height: 56px;
  border: 2px dashed var(--teal);
  border-radius: 10px;
  color: var(--teal);
  background: rgba(255, 255, 255, 0.6);
  transform: rotate(-7deg);
  font-family: var(--font-mono);
}

.stamp.is-low {
  border-color: var(--brick);
  color: var(--brick);
}

.stamp__label {
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.stamp__value {
  font-size: 1.05rem;
  font-weight: 500;
}

/* ---------- Sources ---------- */

.sources {
  margin-top: 1.1rem;
}

.sources summary {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
}

.sources__text {
  margin: 0.75rem 0 0;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
}

/* ---------- Footer ---------- */

.colophon {
  text-align: center;
  margin-top: 1.5rem;
}

.colophon p {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 480px) {
  .page {
    padding: 1.5rem 0.85rem 2rem;
  }

  .card {
    padding: 1.25rem;
  }

  .tab {
    flex: 1;
    text-align: center;
    padding: 0.65rem 0.5rem;
    font-size: 0.72rem;
  }

  .stamp {
    width: 70px;
    height: 48px;
    top: -12px;
    right: 0.75rem;
  }

  .stamp__value {
    font-size: 0.9rem;
  }
}
