:root {
  --paper: #faf7f0;
  --paper-dim: #f0ebe0;
  --ink: #2b2620;
  --ink-soft: #6b6255;
  --line: #ddd4c2;
  --accent: #8a3324;       /* Taos adobe red */
  --accent-soft: #c9704f;
  --gold: #a67c1f;
  --warn-bg: #fbeadb;
  --warn-ink: #8a5a1a;
  --error-bg: #f7dede;
  --error-ink: #8a2424;
  --shadow: 0 1px 3px rgba(43,38,32,0.12), 0 1px 2px rgba(43,38,32,0.08);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--accent); }

header.site-header {
  background: var(--ink);
  color: var(--paper);
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}

header.site-header h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

header.site-header .subtitle {
  font-size: 0.85rem;
  color: #cfc6b4;
  font-style: italic;
}

header.site-header nav {
  margin-left: auto;
  font-size: 0.85rem;
  display: flex;
  gap: 1rem;
}
header.site-header nav a { color: #e7dfcd; text-decoration: none; }
header.site-header nav a:hover { text-decoration: underline; }

.search-bar {
  background: var(--paper-dim);
  border-bottom: 1px solid var(--line);
  padding: 1rem 1.5rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-bar input[type=search] {
  flex: 1 1 320px;
  font-size: 1rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
}
.search-bar input[type=search]:focus { outline: 2px solid var(--accent-soft); }

.search-meta { font-size: 0.85rem; color: var(--ink-soft); }

main { flex: 1; padding: 1.25rem 1.5rem 3rem; max-width: 1200px; margin: 0 auto; width: 100%; }

.pile-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
}
.pile-nav a {
  display: inline-block;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
}
.pile-nav a:hover, .pile-nav a.active { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.pile-nav .count { color: var(--ink-soft); font-size: 0.72rem; }
.pile-nav a.active .count { color: #ecd8d0; }

section.pile-shelf { margin-bottom: 2.5rem; }
section.pile-shelf h2 {
  font-size: 1.05rem;
  margin: 0 0 0.15rem;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.3rem;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
section.pile-shelf h2 .pile-id { color: var(--accent); font-variant-numeric: tabular-nums; }
section.pile-shelf .pile-desc { font-size: 0.8rem; color: var(--ink-soft); margin: 0.2rem 0 0.9rem; }

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.9rem;
}

.item-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
  position: relative;
}
.item-card:hover { transform: translateY(-2px); }
.item-card .thumb-wrap {
  aspect-ratio: 3 / 4;
  background: var(--paper-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.item-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-card .cap {
  padding: 0.4rem 0.5rem 0.55rem;
  font-size: 0.72rem;
  line-height: 1.25;
}
.item-card .cap .t { font-weight: 600; display: block; }
.item-card .cap .c { color: var(--ink-soft); font-style: italic; display: block; }
.item-card .badge {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  font-size: 0.62rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-weight: 600;
}
.item-card .badge.dup { background: var(--warn-bg); color: var(--warn-ink); }
.item-card .badge.err { background: var(--error-bg); color: var(--error-ink); }
.item-card .badge.supp { background: #e3e9dd; color: #4c6b3a; }
.item-card .badge.uncat { background: #eee; color: #888; }

/* --- Detail / virtual browse view --- */
.detail-view { display: flex; gap: 2rem; flex-wrap: wrap; }
.detail-images { display: flex; gap: 1rem; flex-wrap: wrap; flex: 1 1 420px; }
.detail-images figure { margin: 0; flex: 1 1 200px; max-width: 420px; }
.detail-images img { width: 100%; border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 3px; }
.detail-images figcaption { font-size: 0.72rem; color: var(--ink-soft); margin-top: 0.3rem; text-align: center; }

.detail-meta { flex: 1 1 280px; }
.detail-meta h2 { margin: 0 0 0.2rem; font-size: 1.4rem; }
.detail-meta .composer { font-size: 1.05rem; font-style: italic; color: var(--ink-soft); margin-bottom: 1rem; }
.detail-meta dl { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.8rem; font-size: 0.9rem; }
.detail-meta dt { color: var(--ink-soft); }
.detail-meta dd { margin: 0; }

.shelf-walk {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1.75rem 0;
  padding: 0.8rem 1rem;
  background: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.85rem;
}
.shelf-walk a { text-decoration: none; }
.shelf-walk .center { color: var(--ink-soft); }

.back-link { display: inline-block; margin-bottom: 1rem; font-size: 0.85rem; text-decoration: none; }

.empty-state { color: var(--ink-soft); font-style: italic; padding: 2rem 0; text-align: center; }

footer.site-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--ink-soft);
  padding: 1.5rem;
  border-top: 1px solid var(--line);
}

/* --- Cataloging tool --- */
.catalog-layout { display: flex; gap: 2rem; flex-wrap: wrap; }
.catalog-images { flex: 1 1 380px; }
.catalog-images img { width: 100%; border: 1px solid var(--line); border-radius: 3px; box-shadow: var(--shadow); margin-bottom: 0.6rem; }
.catalog-form { flex: 1 1 380px; }
.catalog-form label { display: block; font-size: 0.8rem; color: var(--ink-soft); margin: 0.7rem 0 0.2rem; }
.catalog-form input[type=text], .catalog-form textarea, .catalog-form select {
  width: 100%; padding: 0.5rem 0.6rem; font-family: inherit; font-size: 0.95rem;
  border: 1px solid var(--line); border-radius: 4px; background: #fff;
}
.catalog-form textarea { min-height: 4.5em; resize: vertical; }
.catalog-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.2rem; }
button {
  font-family: inherit; font-size: 0.85rem; padding: 0.55rem 1rem;
  border-radius: 4px; border: 1px solid var(--line); background: #fff; cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: #6f2a1d; }
button.ghost { background: transparent; }
button.warn { border-color: var(--warn-ink); color: var(--warn-ink); }
button.danger { border-color: var(--error-ink); color: var(--error-ink); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.progress-bar { height: 6px; background: var(--paper-dim); border-radius: 4px; overflow: hidden; margin: 0.6rem 0 1rem; }
.progress-bar > div { height: 100%; background: var(--accent); }

.catalog-toggle-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.8rem; font-size: 0.85rem; }

.pile-picker { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.pile-picker a {
  padding: 0.6rem 0.9rem; border: 1px solid var(--line); border-radius: 6px;
  text-decoration: none; color: var(--ink); background: #fff; min-width: 140px;
}
.pile-picker a .n { display: block; font-size: 0.7rem; color: var(--ink-soft); }
.pile-picker a .pct { float: right; font-size: 0.72rem; color: var(--accent); }

.flash { font-size: 0.78rem; color: var(--ink-soft); margin-top: 0.5rem; height: 1.2em; }
.flash.ok { color: #3a6b2c; }
.flash.err { color: var(--error-ink); }

.kbd-hint { font-size: 0.72rem; color: var(--ink-soft); margin-top: 1rem; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0.05em 0.4em; font-size: 0.85em; background: var(--paper-dim); }

/* --- Finding aid / About page --- */
.finding-aid { max-width: 760px; margin: 0 auto; }
.finding-aid h1 { font-size: 1.9rem; margin: 0 0 0.3rem; line-height: 1.2; }
.finding-aid .subtitle-lg { font-size: 1.05rem; color: var(--ink-soft); font-style: italic; margin: 0 0 2rem; }
.finding-aid h2 {
  font-size: 1.3rem; margin: 2.6rem 0 0.9rem; padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--accent); color: var(--accent);
}
.finding-aid h2:first-of-type { margin-top: 1.8rem; }
.finding-aid h3 { font-size: 1.05rem; margin: 1.6rem 0 0.5rem; }
.finding-aid p { line-height: 1.65; margin: 0 0 1rem; }
.finding-aid ul, .finding-aid ol { line-height: 1.65; margin: 0 0 1rem; padding-left: 1.4rem; }
.finding-aid li { margin-bottom: 0.4rem; }
.finding-aid a.inline-link { text-decoration: underline; }

.stat-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.8rem; margin: 1.5rem 0 2.2rem;
}
.stat-strip .stat {
  background: var(--paper-dim); border: 1px solid var(--line); border-radius: 6px;
  padding: 0.8rem 0.6rem; text-align: center;
}
.stat-strip .stat .n { display: block; font-size: 1.5rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-strip .stat .l { display: block; font-size: 0.72rem; color: var(--ink-soft); margin-top: 0.15rem; }

.finding-card {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 4px; padding: 1rem 1.2rem; margin: 1.1rem 0; box-shadow: var(--shadow);
}
.finding-card h4 { margin: 0 0 0.4rem; font-size: 0.98rem; }
.finding-card p:last-child { margin-bottom: 0; }
.finding-card .item-links { margin-top: 0.5rem; font-size: 0.82rem; }
.finding-card .item-links a { margin-right: 0.7rem; }

.puzzle-card { border-left-color: var(--warn-ink); }
.puzzle-card h4 { color: var(--warn-ink); }

.pile-toc { columns: 2; column-gap: 2rem; font-size: 0.88rem; margin: 1rem 0 1.5rem; }
.pile-toc li { break-inside: avoid; margin-bottom: 0.5rem; }
.pile-toc .pn { color: var(--ink-soft); font-size: 0.78rem; }

.callout {
  background: var(--paper-dim); border: 1px solid var(--line); border-radius: 6px;
  padding: 1rem 1.2rem; margin: 1.5rem 0; font-size: 0.92rem;
}
.callout.methodology { border-color: var(--gold); }

@media (max-width: 600px) {
  .pile-toc { columns: 1; }
}

/* --- Browse index (composers / provenance) --- */
.index-page { max-width: 900px; margin: 0 auto; }
.index-page h1 { font-size: 1.7rem; margin: 0 0 0.3rem; }
.index-page > .subtitle-lg { font-size: 1rem; color: var(--ink-soft); font-style: italic; margin: 0 0 1.8rem; }
.index-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.index-tabs button {
  border: none; background: none; padding: 0.6rem 1rem; font-family: inherit; font-size: 0.95rem;
  cursor: pointer; border-bottom: 3px solid transparent; color: var(--ink-soft);
}
.index-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.index-section { display: none; }
.index-section.active { display: block; }
.index-section .section-meta { font-size: 0.82rem; color: var(--ink-soft); margin-bottom: 1rem; }
.index-filter {
  width: 100%; padding: 0.55rem 0.8rem; font-size: 0.95rem; font-family: inherit;
  border: 1px solid var(--line); border-radius: 4px; background: #fff; margin-bottom: 1.3rem;
}
.idx-letter-group { margin-bottom: 1.6rem; }
.idx-letter {
  font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent);
  border-bottom: 1px solid var(--line); padding-bottom: 0.3rem; margin: 0 0 0.6rem;
}
.idx-entry {
  border: 1px solid var(--line); border-radius: 4px; background: #fff;
  margin-bottom: 0.5rem; padding: 0.5rem 0.8rem;
}
.idx-entry summary {
  cursor: pointer; font-size: 0.92rem; display: flex; justify-content: space-between; align-items: baseline;
}
.idx-entry summary::marker { color: var(--accent); }
.idx-count { font-size: 0.75rem; color: var(--ink-soft); background: var(--paper-dim); border-radius: 999px; padding: 0.05em 0.55em; }
.idx-note { font-size: 0.82rem; color: var(--ink-soft); margin: 0.5rem 0 0.4rem; font-style: italic; }
.idx-item-list { list-style: none; margin: 0.5rem 0 0; padding: 0; font-size: 0.85rem; }
.idx-item-list li { padding: 0.2rem 0; border-top: 1px dotted var(--line); display: flex; justify-content: space-between; gap: 0.8rem; }
.idx-item-list li:first-child { border-top: none; }
.idx-meta { color: var(--ink-soft); font-size: 0.75rem; white-space: nowrap; }
