@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --ink-navy: #1b2530;
  --ink-navy-deep: #131b23;
  --panel: #212d3a;
  --panel-line: #33414f;
  --paper: #efe8d8;
  --paper-shadow: #c7bea3;
  --paper-hole: var(--ink-navy);
  --card-text: #2a2318;
  --card-text-dim: #6b6250;
  --brass: #cb9a44;
  --brass-deep: #a97c2f;
  --sage: #6f9376;
  --dusty-rose: #b6605c;
  --teal: #4f8f92;
  --text: #ece6d7;
  --text-dim: #a79d87;
  --focus: #e0b562;

  --font-display: 'Fraunces', 'Iowan Old Style', serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink-navy);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(circle at 12% 8%, rgba(203, 154, 68, 0.08), transparent 40%),
    radial-gradient(circle at 88% 82%, rgba(111, 147, 118, 0.08), transparent 45%);
}

::selection { background: var(--brass); color: var(--ink-navy-deep); }

a { color: inherit; }

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--brass);
  color: var(--ink-navy-deep);
  padding: 10px 16px;
  z-index: 100;
}
.skip-link:focus { left: 16px; top: 16px; }

/* ---------- shell ---------- */

.shell {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 24px 96px;
}

.spine-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0;
  border-bottom: 1px solid var(--panel-line);
  margin-bottom: 64px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.spine-bar .mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.spine-bar .mark::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brass);
  box-shadow: 0 0 0 3px rgba(203, 154, 68, 0.18);
}

/* ---------- hero ---------- */

.hero { padding: 40px 0 56px; }

.hero .eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--sage);
  margin: 0 0 18px;
}

.hero h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(34px, 5.4vw, 54px);
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
  max-width: 20ch;
}

.hero h1 em {
  font-style: italic;
  font-weight: 500;
  color: var(--brass);
}

.hero p.lede {
  font-size: 17px;
  line-height: 1.6;
  color: var(--text-dim);
  max-width: 52ch;
  margin: 0 0 40px;
}

/* ---------- the "catalog slot" form ---------- */

.slot {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
}

.slot::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  padding: 1px;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(203,154,68,0.35), transparent 40%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.slot-row {
  display: flex;
  gap: 10px;
}

.field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink-navy-deep);
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  padding: 0 14px;
}

.field svg { flex: none; opacity: 0.55; }

.field input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 14px 0;
}

.field input::placeholder { color: var(--text-dim); }

.btn {
  appearance: none;
  border: none;
  border-radius: 9px;
  padding: 14px 22px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--brass);
  color: var(--ink-navy-deep);
  box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset, 0 8px 20px -8px rgba(203,154,68,0.6);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset, 0 12px 24px -8px rgba(203,154,68,0.75); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  background: #6b6250;
  color: rgba(19,27,35,0.6);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.slot-options {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 2px 4px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  flex-wrap: wrap;
  row-gap: 10px;
}

.kw-toggle-sub {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: opacity 150ms ease;
}
.kw-toggle-sub.hidden {
  opacity: 0;
  pointer-events: none;
  width: 0;
  overflow: hidden;
  gap: 0;
}

.kw-toggle {
  display: inline-flex;
  flex: none;
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  overflow: hidden;
}
.kw-toggle button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 12px;
  white-space: nowrap;
  cursor: pointer;
}
.kw-toggle button.active {
  background: var(--brass);
  color: var(--ink-navy-deep);
}

.upload-alt {
  color: var(--text-dim);
  text-decoration: underline;
  text-decoration-color: var(--panel-line);
  text-underline-offset: 3px;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 0;
}
.upload-alt:hover { color: var(--text); text-decoration-color: var(--brass); }

/* ---------- status ---------- */

.status {
  margin-top: 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
  display: none;
  align-items: center;
  gap: 10px;
}
.status.visible { display: flex; }
.status.error { color: var(--dusty-rose); }

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--panel-line);
  border-top-color: var(--brass);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- divider ---------- */

.stitch-divider {
  margin: 56px 0 40px;
  height: 1px;
  background-image: repeating-linear-gradient(90deg, var(--panel-line) 0 6px, transparent 6px 12px);
}

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

.results-head h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 24px;
  margin: 0;
}

.results-head .count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.download-all {
  background: transparent;
  border: 1px solid var(--sage);
  color: var(--sage);
  border-radius: 8px;
  padding: 10px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.download-all:hover { background: var(--sage); color: var(--ink-navy-deep); }

/* ---------- chapter cards (tabbed index cards) ---------- */

.cards { display: flex; flex-direction: column; gap: 12px; }

.group-header {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass);
  padding: 18px 4px 2px;
  opacity: 0;
  animation: fan-in 400ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: var(--delay, 0ms);
}
.group-header:first-child { padding-top: 4px; }

.card-nested {
  margin-left: 22px;
  border-radius: 4px 10px 10px 4px;
}
@media (max-width: 620px) {
  .card-nested { margin-left: 12px; }
}

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--paper);
  color: var(--card-text);
  border-radius: 4px 12px 12px 4px;
  padding: 16px 20px 16px 34px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.4) inset, 0 10px 24px -14px rgba(0,0,0,0.55);
  opacity: 0;
  transform: translateY(14px) rotate(var(--tilt, 0deg));
  animation: fan-in 480ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: var(--delay, 0ms);
}

@keyframes fan-in {
  to { opacity: 1; transform: translateY(0) rotate(0deg); }
}

.card::before {
  /* spine stripe */
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 10px;
  border-radius: 4px 0 0 4px;
  background: var(--stripe, var(--brass));
}

.card::after {
  /* punched hole */
  content: "";
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-navy);
  box-shadow: 0 0 0 2px var(--paper-shadow) inset;
}

.card-num {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  color: var(--stripe, var(--brass-deep));
  min-width: 2ch;
  text-align: right;
  flex: none;
}

.card-body { flex: 1; min-width: 0; }

.card-title {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15.5px;
  margin: 0 0 4px;
  overflow-wrap: break-word;
}

.card-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--card-text-dim);
  letter-spacing: 0.02em;
}

.card-dl {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--card-text);
  background: transparent;
  color: var(--card-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}
.card-dl:hover { background: var(--card-text); color: var(--paper); transform: scale(1.05); }

/* ---------- empty / error states ---------- */

.empty-state, .error-panel {
  border: 1px dashed var(--panel-line);
  border-radius: 12px;
  padding: 28px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  display: none;
}
.empty-state.visible, .error-panel.visible { display: block; }

.error-panel { border-color: var(--dusty-rose); color: var(--dusty-rose); }
.error-panel strong { display: block; color: var(--text); font-family: var(--font-display); font-size: 17px; margin-bottom: 6px; font-weight: 600; }

footer.foot {
  margin-top: 72px;
  padding-top: 20px;
  border-top: 1px solid var(--panel-line);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; opacity: 1; transform: none; }
  .spinner { animation: none; }
}

/* ---------- responsive ---------- */

@media (max-width: 620px) {
  .shell { padding: 0 16px 72px; }
  .spine-bar { font-size: 10.5px; }
  .slot-row { flex-direction: column; }
  .btn-primary { justify-content: center; }
  .slot-options { flex-wrap: wrap; row-gap: 10px; }
  .kw-toggle button { padding: 7px 10px; }
  .card { padding: 14px 14px 14px 30px; gap: 12px; }
  .card-num { font-size: 20px; }
  .results-head { flex-direction: column; align-items: flex-start; }
}
