/* ============================================================
   HEIRLOOM — "Chartered" design system
   Palette derived from club heraldry: pine ink, parchment,
   a marigold wax seal, oxblood, sage. Almanac typography.
   ============================================================ */

:root {
  --pine-900: #10201a;
  --pine-800: #16241c;
  --pine-700: #1f3629;
  --pine-600: #2c4a39;
  --parchment: #f3ecd9;
  --parchment-hi: #faf6ea;
  --parchment-lo: #e8dfc6;
  --marigold: #e3a21a;
  --marigold-hi: #f6c65a;
  --oxblood: #8c2b2b;
  --sage: #9fae93;
  --sage-deep: #6f7f64;
  --ink-soft: rgba(16, 32, 26, 0.66);
  --ink-faint: rgba(16, 32, 26, 0.38);
  --line: rgba(16, 32, 26, 0.16);
  --line-strong: rgba(16, 32, 26, 0.32);

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Hanken Grotesk", system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, monospace;

  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.4) inset,
    0 10px 26px -14px rgba(16, 32, 26, 0.5);
  --ease-spring: cubic-bezier(0.22, 1.4, 0.4, 1);
  --page: min(1340px, 100% - 2.5rem);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--parchment);
  color: var(--pine-800);
  font-family: var(--font-body);
  font-size: clamp(15px, 1vw + 12px, 17px);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Paper grain — a faint fixed noise wash over everything. */
.grain {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection {
  background: var(--marigold);
  color: var(--pine-900);
}

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

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

/* ---------- shared bits ---------- */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--sage-deep);
}

.btn {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.62em 1.1em;
  border: 1px solid var(--pine-800);
  background: var(--pine-800);
  color: var(--parchment-hi);
  border-radius: 2px;
  transition: transform 0.18s var(--ease-spring), background 0.2s, box-shadow 0.2s;
}
.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px -10px rgba(16, 32, 26, 0.7);
  background: var(--pine-700);
}
.btn:active {
  transform: translateY(0);
}
.btn--ghost {
  background: transparent;
  color: var(--pine-800);
}
.btn--ghost:hover {
  background: rgba(16, 32, 26, 0.06);
  box-shadow: none;
}

/* ============================================================
   MASTHEAD
   ============================================================ */
.masthead {
  width: var(--page);
  margin-inline: auto;
  padding: clamp(1.4rem, 4vh, 3rem) 0 clamp(2rem, 5vh, 3.4rem);
  text-align: center;
}

.masthead__rule {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0.7rem 0;
  border-block: 1.5px solid var(--line-strong);
}
.masthead__rule--top {
  border-top: none;
}
.masthead__rule--bottom {
  margin-top: clamp(1.6rem, 4vh, 2.6rem);
}
.masthead__enter {
  color: var(--oxblood);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.masthead__enter:hover {
  border-color: var(--oxblood);
}

.masthead__crest {
  display: flex;
  justify-content: center;
  margin: clamp(1.4rem, 4vh, 2.6rem) 0 0.6rem;
}

/* ---------- the wax seal (signature element) ---------- */
.seal {
  width: clamp(96px, 14vw, 148px);
  aspect-ratio: 1;
}
.seal svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}
.seal__ring {
  fill: none;
  stroke: var(--pine-800);
}
.seal__ring--outer {
  stroke-width: 3;
}
.seal__ring--inner {
  stroke-width: 1.5;
  stroke-dasharray: 2 5;
}
.seal__type text {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 2.6px;
  fill: var(--pine-800);
}
.seal__type {
  transform-origin: 100px 100px;
  animation: sealSpin 34s linear infinite;
}
.seal__handle {
  fill: var(--pine-800);
}
.seal__cross {
  stroke: var(--pine-800);
  stroke-width: 3;
  stroke-linecap: round;
}
.seal__flame {
  transform-origin: 100px 96px;
  animation: flicker 3.4s ease-in-out infinite;
}

/* stamp-in on load */
.seal {
  animation: stampIn 0.9s var(--ease-spring) both;
}
@keyframes stampIn {
  0% {
    opacity: 0;
    transform: scale(0.4) rotate(-24deg);
  }
  60% {
    opacity: 1;
    transform: scale(1.06) rotate(4deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}
@keyframes sealSpin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes flicker {
  0%, 100% {
    transform: scaleY(1) scaleX(1);
    opacity: 1;
  }
  50% {
    transform: scaleY(1.08) scaleX(0.95);
    opacity: 0.86;
  }
}

/* ---------- wordmark ---------- */
.wordmark {
  margin: 0.1rem 0 0;
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 560;
  font-size: clamp(3.6rem, 15vw, 9.5rem);
  line-height: 0.9;
  letter-spacing: -0.02em;
  color: var(--pine-800);
}
.wordmark__letters span {
  display: inline-block;
  animation: riseIn 0.7s var(--ease-spring) both;
}
.wordmark__letters span:nth-child(1) { animation-delay: 0.18s; }
.wordmark__letters span:nth-child(2) { animation-delay: 0.24s; }
.wordmark__letters span:nth-child(3) { animation-delay: 0.30s; }
.wordmark__letters span:nth-child(4) { animation-delay: 0.36s; }
.wordmark__letters span:nth-child(5) { animation-delay: 0.42s; }
.wordmark__letters span:nth-child(6) { animation-delay: 0.48s; }
.wordmark__letters span:nth-child(7) { animation-delay: 0.54s; }
.wordmark__letters span:nth-child(8) { animation-delay: 0.60s; }
@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(0.5em) rotate(3deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(0);
  }
}

.masthead__thesis {
  max-width: 46ch;
  margin: 1.2rem auto 0;
  font-size: clamp(1.05rem, 1.4vw + 0.7rem, 1.4rem);
  line-height: 1.5;
  color: var(--ink-soft);
  animation: fadeUp 0.9s ease 0.5s both;
}
.masthead__thesis em {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  color: var(--pine-800);
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   WORKSPACE GRID
   ============================================================ */
.workspace {
  width: var(--page);
  margin: 0 auto clamp(3rem, 8vh, 6rem);
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: clamp(1.2rem, 3vw, 2.4rem);
  align-items: start;
}

.panel__head {
  margin-bottom: 1.2rem;
}
.panel__title {
  margin: 0.4rem 0 0;
  font-family: var(--font-display);
  font-weight: 460;
  font-size: clamp(1.5rem, 2.4vw, 2.1rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

/* ---------- The Stacks ---------- */
.stacks {
  position: sticky;
  top: 1.5rem;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  padding: 1.9rem 1.2rem;
  border: 1.5px dashed var(--line-strong);
  border-radius: 6px;
  background: rgba(250, 246, 234, 0.5);
  transition: border-color 0.2s, background 0.2s, transform 0.2s var(--ease-spring);
}
.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--marigold);
  background: var(--parchment-hi);
}
.dropzone.is-drag {
  border-color: var(--marigold);
  border-style: solid;
  background: var(--parchment-hi);
  transform: scale(1.015);
}
.dropzone__mark {
  font-size: 1.9rem;
  line-height: 1;
  color: var(--marigold);
  transition: transform 0.3s var(--ease-spring);
}
.dropzone:hover .dropzone__mark {
  transform: rotate(90deg) scale(1.1);
}
.dropzone__title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 500;
}
.dropzone__hint {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
}
.dropzone__paste {
  margin-top: 0.55rem;
  border: none;
  background: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--oxblood);
  border-bottom: 1px solid transparent;
  padding: 0;
}
.dropzone__paste:hover {
  border-color: var(--oxblood);
}

/* paste drawer */
.paste[hidden] {
  display: none;
}
.paste {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.6rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--parchment-hi);
  animation: fadeUp 0.35s ease both;
}
.paste__name,
.paste__body {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--pine-800);
  background: var(--parchment);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  resize: vertical;
}
.paste__name {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}
.paste__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ---------- the shelf of index cards ---------- */
.shelf {
  margin-top: 1.1rem;
  display: grid;
  gap: 0.7rem;
}
.shelf__empty {
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-faint);
  text-align: center;
}
.shelf:empty + .shelf__empty {
  display: block;
}

.card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 0.95rem 0.85rem 1.1rem;
  background: var(--parchment-hi);
  border: 1px solid var(--line);
  border-left: 4px solid var(--kind, var(--sage-deep));
  border-radius: 5px;
  box-shadow: var(--shadow-card);
  transform-origin: left center;
  transition: transform 0.28s var(--ease-spring), box-shadow 0.28s, border-color 0.2s;
  animation: cardIn 0.5s var(--ease-spring) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) rotate(-1.2deg); }
  to { opacity: 1; transform: translateY(0) rotate(0); }
}
.card:hover {
  transform: translateY(-3px) rotate(-0.6deg);
  box-shadow: 0 16px 30px -18px rgba(16, 32, 26, 0.6);
}
/* punched filing hole */
.card__hole {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--parchment);
  border: 1px solid var(--line-strong);
  box-shadow: inset 0 1px 2px rgba(16, 32, 26, 0.25);
}
.card__main {
  min-width: 0;
}
.card__name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card__meta {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-top: 0.15rem;
}
.card__kind {
  color: var(--kind, var(--sage-deep));
}
.card__remove {
  border: none;
  background: none;
  color: var(--ink-faint);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s, background 0.2s;
}
.card:hover .card__remove,
.card__remove:focus-visible {
  opacity: 1;
}
.card__remove:hover {
  color: var(--oxblood);
  background: rgba(140, 43, 43, 0.1);
}
.card.is-leaving {
  animation: cardOut 0.35s ease forwards;
}
@keyframes cardOut {
  to { opacity: 0; transform: translateX(-16px) rotate(-3deg); height: 0; }
}

/* ============================================================
   READING ROOM
   ============================================================ */
.reading {
  display: flex;
  flex-direction: column;
  min-height: 60vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--parchment-hi), rgba(250, 246, 234, 0.35));
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.reading .panel__head {
  padding: 1.3rem 1.5rem 0;
  margin-bottom: 0.6rem;
}

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem 1.5rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--sage) transparent;
}

.welcome {
  margin: auto 0;
  padding: 1rem 0;
  animation: fadeUp 0.6s ease 0.3s both;
}
.welcome__seal {
  font-size: 1.8rem;
  color: var(--marigold);
}
.welcome__lead {
  max-width: 48ch;
  font-size: 1.05rem;
  color: var(--ink-soft);
  margin: 0.4rem 0 1.2rem;
}

.prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}
.prompt {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.02em;
  color: var(--pine-800);
  background: rgba(159, 174, 147, 0.18);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5em 0.95em;
  transition: transform 0.2s var(--ease-spring), background 0.2s, border-color 0.2s;
}
.prompt:hover {
  transform: translateY(-2px);
  background: var(--marigold-hi);
  border-color: var(--marigold);
}

/* ---------- messages ---------- */
.msg {
  max-width: 90%;
  animation: fadeUp 0.4s ease both;
}
.msg--user {
  align-self: flex-end;
  text-align: right;
}
.msg__tag {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.3rem;
}
.msg--user .bubble {
  display: inline-block;
  background: var(--pine-800);
  color: var(--parchment-hi);
  padding: 0.7rem 1rem;
  border-radius: 12px 12px 3px 12px;
  font-size: 0.98rem;
  text-align: left;
}
.msg--archivist {
  align-self: flex-start;
  border-left: 2px solid var(--marigold);
  padding-left: 1rem;
}
.msg--archivist .bubble {
  font-size: 1rem;
  line-height: 1.62;
}

/* markdown-ish typesetting inside answers */
.bubble p { margin: 0 0 0.7rem; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { color: var(--pine-900); font-weight: 700; }
.bubble em { font-family: var(--font-display); font-style: italic; }
.bubble ul, .bubble ol { margin: 0 0 0.7rem; padding-left: 1.2rem; }
.bubble li { margin-bottom: 0.3rem; }
.bubble h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 560;
  margin: 0.2rem 0 0.5rem;
}
.bubble code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(16, 32, 26, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

/* streaming caret */
.caret::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 1px;
  vertical-align: -0.15em;
  background: var(--marigold);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* the Archivist "consulting the records" indicator */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--sage-deep);
}
.thinking__dots {
  display: inline-flex;
  gap: 3px;
}
.thinking__dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--marigold);
  animation: bob 1.1s ease-in-out infinite;
}
.thinking__dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking__dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bob {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- ask bar ---------- */
.ask {
  border-top: 1px solid var(--line);
  padding: 0.9rem 1.5rem 1.1rem;
  background: rgba(250, 246, 234, 0.7);
}
.ask__field {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  background: var(--parchment-hi);
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  padding: 0.5rem 0.5rem 0.5rem 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.ask__field:focus-within {
  border-color: var(--marigold);
  box-shadow: 0 0 0 3px rgba(227, 162, 26, 0.18);
}
.ask__input {
  flex: 1;
  border: none;
  background: none;
  resize: none;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--pine-800);
  max-height: 40vh;
}
.ask__input:focus {
  outline: none;
}
.ask__send {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 9px;
  background: var(--pine-800);
  color: var(--parchment-hi);
  transition: transform 0.2s var(--ease-spring), background 0.2s;
}
.ask__send:hover:not(:disabled) {
  background: var(--marigold);
  color: var(--pine-900);
  transform: translateX(2px);
}
.ask__send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.ask__meta {
  margin: 0.5rem 0 0;
  min-height: 1em;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}

/* ============================================================
   FOOTER + TOAST
   ============================================================ */
.colophon {
  width: var(--page);
  margin: 0 auto;
  padding: 1.6rem 0 2.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  border-top: 1.5px solid var(--line-strong);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 200%);
  z-index: 10000;
  background: var(--pine-800);
  color: var(--parchment-hi);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.7rem 1.1rem;
  border-radius: 6px;
  box-shadow: 0 12px 30px -12px rgba(16, 32, 26, 0.7);
  transition: transform 0.4s var(--ease-spring);
  max-width: min(90vw, 420px);
}
.toast.is-up {
  transform: translate(-50%, 0);
}
.toast--error {
  background: var(--oxblood);
}

/* ============================================================
   FOLDERS (auto-sorted record shelf)
   ============================================================ */
.folder {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--parchment-hi);
  overflow: hidden;
  animation: fadeUp 0.4s ease both;
}
.folder__head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  background: none;
  border: none;
  border-left: 4px solid var(--kind);
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--pine-800);
  transition: background 0.2s;
}
.folder__head:hover {
  background: rgba(16, 32, 26, 0.04);
}
.folder__tab {
  width: 15px;
  height: 12px;
  border-radius: 2px 2px 0 0;
  background: var(--kind);
  box-shadow: inset 0 -3px 0 rgba(16, 32, 26, 0.12);
}
.folder__name {
  flex: 1;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.folder__count {
  font-size: 0.72rem;
  color: var(--ink-soft);
  background: rgba(16, 32, 26, 0.07);
  border-radius: 999px;
  padding: 0.05em 0.55em;
}
.folder__chev {
  color: var(--ink-faint);
  transition: transform 0.25s var(--ease-spring);
}
.folder.is-closed .folder__chev {
  transform: rotate(-90deg);
}
.folder__body {
  display: grid;
  gap: 0.55rem;
  padding: 0.65rem;
}
.folder.is-closed .folder__body {
  display: none;
}

.card {
  cursor: pointer;
}
.card__sub {
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--ink-soft);
  margin-top: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   CITATIONS + SOURCES
   ============================================================ */
.cite {
  font-family: var(--font-mono);
  font-size: 0.6em;
  font-weight: 700;
  color: var(--parchment-hi);
  background: var(--kind, var(--sage-deep));
  border-radius: 4px;
  padding: 0.15em 0.4em;
  margin-left: 2px;
  cursor: pointer;
  vertical-align: super;
  line-height: 1;
  transition: transform 0.15s var(--ease-spring), filter 0.2s;
}
.cite:hover {
  transform: translateY(-1px);
  filter: brightness(1.12);
}

.sources {
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.sources[hidden] {
  display: none;
}
.sources__label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 0.15rem;
}
.source {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--pine-800);
  background: var(--parchment);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.32em 0.7em;
  transition: transform 0.18s var(--ease-spring), border-color 0.2s, background 0.2s;
}
.source:hover {
  transform: translateY(-2px);
  border-color: var(--kind);
  background: var(--parchment-hi);
}
.folder-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--kind, var(--sage-deep));
  flex: none;
}

/* ============================================================
   RECORD PREVIEW MODAL
   ============================================================ */
.modal[hidden] {
  display: none;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.modal__scrim {
  position: absolute;
  inset: 0;
  background: rgba(16, 32, 26, 0.55);
  opacity: 0;
  transition: opacity 0.22s;
}
.modal.is-open .modal__scrim {
  opacity: 1;
}
.modal__panel {
  position: relative;
  width: min(680px, 100%);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding: 1.4rem 1.5rem;
  background: var(--parchment-hi);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 30px 70px -20px rgba(16, 32, 26, 0.7);
  transform: translateY(14px) scale(0.98);
  opacity: 0;
  transition: transform 0.24s var(--ease-spring), opacity 0.24s;
}
.modal.is-open .modal__panel {
  transform: none;
  opacity: 1;
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__id {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.modal__close {
  border: none;
  background: none;
  font-size: 1.2rem;
  color: var(--ink-faint);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}
.modal__close:hover {
  color: var(--oxblood);
  background: rgba(140, 43, 43, 0.1);
}
.modal__name {
  font-family: var(--font-display);
  font-weight: 520;
  font-size: clamp(1.3rem, 2.5vw, 1.6rem);
  line-height: 1.15;
  margin: 0.5rem 0 0.15rem;
}
.modal__summary {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--ink-soft);
  margin: 0.15rem 0 0.4rem;
}
.modal__meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  margin-bottom: 0.85rem;
}
.modal__text {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 1rem 1.1rem;
  background: var(--parchment);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--pine-800);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .stacks {
    position: static;
  }
  .masthead__rule {
    font-size: 0.6rem;
  }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .seal__type {
    animation: none;
  }
}

/* ============================================================
   EDITORIAL ORNAMENT LAYER
   Almanac framing, dividers, tabs, watermark, folios.
   ============================================================ */

/* Warm the flat parchment with a subtle top-lit vignette. */
body {
  background: radial-gradient(
    125% 90% at 50% -15%,
    var(--parchment-hi),
    var(--parchment) 52%,
    var(--parchment-lo) 130%
  );
  background-attachment: fixed;
}

/* --- masthead cover details --- */
.masthead__rule {
  position: relative;
}
.masthead__vol {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: var(--oxblood);
  letter-spacing: 0.2em;
}

.ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  margin-top: 1.5rem;
  color: var(--marigold);
  font-size: 0.75rem;
  animation: fadeUp 0.9s ease 0.4s both;
}
.ornament span {
  height: 1px;
  width: min(90px, 16vw);
  background: linear-gradient(90deg, transparent, var(--line-strong));
}
.ornament span:last-child {
  background: linear-gradient(90deg, var(--line-strong), transparent);
}

/* file-folder tabs advertising what the archive reads */
.dossier {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 1.5rem 0 0;
  padding: 0;
  animation: fadeUp 0.9s ease 0.6s both;
}
.dossier li {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--parchment-hi);
  border: 1px solid var(--line);
  border-radius: 4px 4px 0 0;
  padding: 0.45em 0.85em;
  border-bottom: 3px solid var(--sage-deep);
  transition: transform 0.2s var(--ease-spring), color 0.2s;
}
.dossier li:nth-child(1) { border-bottom-color: #3f6f88; }
.dossier li:nth-child(2) { border-bottom-color: #5b8a72; }
.dossier li:nth-child(3) { border-bottom-color: #c07a1e; }
.dossier li:nth-child(4) { border-bottom-color: #8c2b2b; }
.dossier li:nth-child(5) { border-bottom-color: #7a5ea8; }
.dossier li:hover {
  transform: translateY(-4px);
  color: var(--pine-800);
}

/* ornamental section divider */
.rule-ornament {
  width: var(--page);
  margin: 0 auto clamp(1.6rem, 4vh, 2.6rem);
  display: flex;
  align-items: center;
  gap: 1.3rem;
  color: var(--marigold);
}
.rule-ornament::before,
.rule-ornament::after {
  content: "";
  flex: 1;
  height: 1.5px;
  background: var(--line-strong);
}
.rule-ornament span {
  font-size: 1.15rem;
}

/* --- panel heads get a note + a header rule --- */
.panel__head {
  margin-bottom: 1.2rem;
  padding-bottom: 0.9rem;
  border-bottom: 1.5px solid var(--line-strong);
}
.panel__note {
  margin: 0.55rem 0 0;
  max-width: 40ch;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
.reading .panel__head {
  padding: 1.3rem 1.5rem 0.9rem;
  margin-bottom: 0.6rem;
}

/* --- reading room: ruled paper + watermark seal --- */
.reading {
  position: relative;
}
.reading__watermark {
  position: absolute;
  right: -1.5rem;
  bottom: -3rem;
  font-family: var(--font-display);
  font-size: 22rem;
  line-height: 1;
  color: var(--sage);
  opacity: 0.08;
  pointer-events: none;
  z-index: 0;
}
.reading .panel__head,
.transcript,
.ask {
  position: relative;
  z-index: 1;
}
.transcript {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 31px,
    rgba(16, 32, 26, 0.045) 31px,
    rgba(16, 32, 26, 0.045) 32px
  );
}

/* --- record cards get a folded corner on hover --- */
.card::after {
  content: "";
  position: absolute;
  bottom: 0;
  right: 0;
  border-style: solid;
  border-width: 0 0 15px 15px;
  border-color: transparent transparent var(--parchment) transparent;
  box-shadow: -1px -1px 2px rgba(16, 32, 26, 0.16);
  border-radius: 0 0 5px 0;
  opacity: 0;
  transform: translate(3px, 3px);
  transition: opacity 0.25s, transform 0.25s var(--ease-spring);
}
.card:hover::after {
  opacity: 1;
  transform: translate(0, 0);
}

/* --- folio (page number) --- */
.folio {
  margin-top: 1.3rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  color: var(--ink-faint);
}

/* --- richer colophon --- */
.colophon {
  flex-direction: column;
  gap: 0.7rem;
}
.colophon__mark {
  color: var(--marigold);
  font-size: 1.15rem;
}
.colophon__line {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
}
.colophon__dot {
  color: var(--marigold);
}

/* ============================================================
   REVISION — study-notebook page, bounded panels, owl
   ============================================================ */

:root {
  --desk: #e5d9bb;
  --sheet-line: rgba(16, 32, 26, 0.05);
  --margin-line: rgba(140, 43, 43, 0.14);
}

/* The whole page becomes a ruled sheet resting on a warmer "desk", so the
   previously-bare outer margins read as part of a study notebook. */
body {
  background-color: var(--desk);
  background-image: radial-gradient(125% 95% at 50% -10%, rgba(255, 255, 255, 0.4), transparent 58%);
  background-attachment: fixed;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  left: 50%;
  transform: translateX(-50%);
  width: var(--page);
  max-width: 100vw;
  z-index: -2;
  pointer-events: none;
  background-color: var(--parchment-hi);
  background-image:
    linear-gradient(90deg, transparent 3.15rem, var(--margin-line) 3.15rem, var(--margin-line) calc(3.15rem + 1.5px), transparent calc(3.15rem + 1.5px)),
    repeating-linear-gradient(to bottom, transparent 0 32px, var(--sheet-line) 32px 33px);
  box-shadow: 0 0 0 1px rgba(16, 32, 26, 0.05), 0 40px 110px -50px rgba(16, 32, 26, 0.4);
}
/* three-hole-punch down the binding edge */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  left: 50%;
  transform: translateX(-50%);
  width: var(--page);
  max-width: 100vw;
  z-index: -1;
  pointer-events: none;
  background-repeat: no-repeat;
  background-image:
    radial-gradient(circle at 1.5rem 20%, var(--desk) 6px, rgba(16, 32, 26, 0.14) 6px, transparent 8px),
    radial-gradient(circle at 1.5rem 50%, var(--desk) 6px, rgba(16, 32, 26, 0.14) 6px, transparent 8px),
    radial-gradient(circle at 1.5rem 80%, var(--desk) 6px, rgba(16, 32, 26, 0.14) 6px, transparent 8px);
}

/* --- item 1: fewer rules around the record count, keep it subtle --- */
.masthead__rule--bottom {
  border: none;
  margin-top: clamp(1.1rem, 3vh, 1.9rem);
  padding: 0.3rem 0 0;
  font-size: 0.66rem;
  color: var(--ink-faint);
}
.masthead__rule--bottom [data-status] {
  letter-spacing: 0.14em;
}

/* --- item 4: filled, color-coded record dots --- */
.card__hole {
  width: 11px;
  height: 11px;
  border: none;
  background: var(--kind, var(--sage-deep));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--kind, var(--sage-deep)) 20%, transparent);
}

/* --- item 5: bound panel heights so the page can't grow lopsided --- */
@media (min-width: 861px) {
  .stacks {
    position: static;
    display: flex;
    flex-direction: column;
    height: clamp(600px, 84vh, 860px);
  }
  .stacks .panel__head,
  .dropzone,
  .paste,
  .shelf__empty,
  .folio {
    flex: none;
  }
  .shelf {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 5px;
    scrollbar-width: thin;
    scrollbar-color: var(--sage) transparent;
  }
  /* keep folders at natural height so the shelf scrolls instead of squashing */
  .shelf > .folder {
    flex: 0 0 auto;
  }
  .reading {
    height: clamp(600px, 84vh, 860px);
    min-height: 0;
    background: var(--parchment-hi);
  }
}

/* --- item 7: the Archivist owl beside the masthead --- */
.masthead {
  position: relative;
}
.masthead__owl {
  position: absolute;
  right: clamp(-8px, 1vw, 28px);
  top: 47%;
  width: clamp(150px, 16vw, 244px);
  height: auto;
  filter: drop-shadow(0 16px 22px rgba(16, 32, 26, 0.22));
  animation: owlIn 0.9s var(--ease-spring) 0.4s both, owlFloat 5.5s ease-in-out 1.4s infinite;
  pointer-events: none;
  z-index: 2;
}
@keyframes owlIn {
  from { opacity: 0; transform: translateY(-38%) rotate(4deg); }
  to { opacity: 1; transform: translateY(-50%) rotate(0); }
}
@keyframes owlFloat {
  0%, 100% { transform: translateY(-50%); }
  50% { transform: translateY(-56%); }
}
@media (max-width: 1040px) {
  .masthead__owl { display: none; }
}

/* ============================================================
   REVISION 2 — wooden desk, wider sheet, ink & hover play
   ============================================================ */

/* The desk is now warm wood (echoing the owl) so the sheet reads as paper
   resting on a real desk. */
:root {
  --desk: #6b482b;
}
body {
  background-color: var(--desk);
  background-image:
    radial-gradient(150% 120% at 50% -5%, rgba(255, 236, 200, 0.12), transparent 46%),
    radial-gradient(130% 130% at 50% 118%, rgba(0, 0, 0, 0.38), transparent 55%),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.055) 0 1px, transparent 1px 7px);
  background-attachment: fixed;
}

/* Give the content real margins so nothing crowds the sheet edge or the ruled
   margin line, and let it run wider. */
.masthead,
.workspace,
.colophon,
.rule-ornament {
  padding-inline: clamp(2.5rem, 5.5vw, 6rem);
}

/* --- owl: wrapper floats, image reacts to hover --- */
.masthead__owl {
  pointer-events: auto;
  cursor: pointer;
  filter: none;
  right: clamp(30px, 9vw, 150px);
  width: clamp(132px, 12.5vw, 200px);
}
.masthead__owl img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 16px 22px rgba(16, 32, 26, 0.28));
  transition: transform 0.45s var(--ease-spring), filter 0.3s;
}
.masthead__owl:hover img {
  transform: scale(1.05) rotate(-3deg);
  filter: drop-shadow(0 24px 30px rgba(16, 32, 26, 0.34));
}

/* --- seal reacts to hover: swells and spins faster --- */
.seal svg {
  transition: transform 0.45s var(--ease-spring);
}
.seal:hover svg {
  transform: scale(1.06);
}
.seal:hover .seal__type {
  animation-duration: 9s;
}

/* --- wordmark letters bob on hover --- */
.wordmark__letters span {
  animation-fill-mode: backwards;
  transition: transform 0.28s var(--ease-spring), color 0.2s;
}
.wordmark__letters span:hover {
  transform: translateY(-9px) rotate(-4deg);
  color: var(--oxblood);
}

/* --- the ink cursor canvas --- */
.ink-canvas {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
}

@media (max-width: 860px) {
  .masthead,
  .workspace,
  .colophon,
  .rule-ornament {
    padding-inline: 0;
  }
}

/* ============================================================
   REVISION 3 — flat sections, obvious shelf scrolling
   ============================================================ */

/* Lay the sections flat on the paper — no drop shadows behind them. */
.card,
.card:hover,
.reading,
.folder,
.dropzone,
.paste {
  box-shadow: none;
}
/* Firm the borders a touch so flat sections still read on the sheet. */
.reading {
  border-color: var(--line-strong);
}

/* Make the stack obviously scrollable: fade the overflowing edges, show a real
   scrollbar, and drop a little cue when there's more below. */
@media (min-width: 861px) {
  .shelf {
    -webkit-mask-image: var(--shelf-mask, none);
    mask-image: var(--shelf-mask, none);
  }
  .shelf.fade-bottom {
    --shelf-mask: linear-gradient(to bottom, #000 0, #000 calc(100% - 36px), transparent 100%);
  }
  .shelf.fade-top {
    --shelf-mask: linear-gradient(to bottom, transparent 0, #000 30px, #000 100%);
  }
  .shelf.fade-top.fade-bottom {
    --shelf-mask: linear-gradient(to bottom, transparent 0, #000 30px, #000 calc(100% - 36px), transparent 100%);
  }
}
.shelf::-webkit-scrollbar {
  width: 9px;
}
.shelf::-webkit-scrollbar-track {
  background: rgba(16, 32, 26, 0.05);
  border-radius: 6px;
}
.shelf::-webkit-scrollbar-thumb {
  background: var(--sage);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.shelf::-webkit-scrollbar-thumb:hover {
  background: var(--sage-deep);
  background-clip: padding-box;
}

.scroll-cue {
  flex: none;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sage-deep);
}
.scroll-cue::after {
  content: "↓";
  animation: cueBob 1.5s ease-in-out infinite;
}
.stacks.has-more .scroll-cue {
  display: flex;
}
@keyframes cueBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}
