:root {
  --ink: #17201b;
  --muted: #647068;
  --paper: #fffaf0;
  --paper-strong: #fffdf7;
  --sage: #dfe9dc;
  --sage-strong: #b9d0bd;
  --rust: #b84d32;
  --rust-dark: #87341f;
  --line: rgba(23, 32, 27, 0.13);
  --shadow: 0 24px 70px rgba(39, 57, 45, 0.16);
  --radius: 30px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(184, 77, 50, 0.12), transparent 26rem),
    radial-gradient(circle at top right, rgba(91, 126, 95, 0.2), transparent 30rem),
    linear-gradient(135deg, #edf3ec 0%, #fbf3e4 52%, #e5efdf 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background-image:
    linear-gradient(120deg, rgba(23, 32, 27, 0.035) 1px, transparent 1px),
    linear-gradient(30deg, rgba(23, 32, 27, 0.028) 1px, transparent 1px);
  background-size: 44px 44px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  color: #fffaf0;
  background: var(--rust);
  padding: 0.9rem 1.15rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(135, 52, 31, 0.18);
  background: var(--rust-dark);
}

button.secondary {
  color: #24493e;
  background: #e2e8dc;
}

button.secondary:hover {
  background: #d1ddcf;
}

button.compact {
  padding: 0.7rem 1rem;
  white-space: nowrap;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.94);
  color: var(--ink);
  padding: 0.9rem 1rem;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(184, 77, 50, 0.55);
  box-shadow: 0 0 0 4px rgba(184, 77, 50, 0.12);
}

label {
  display: grid;
  gap: 0.45rem;
  color: #2e3a34;
  font-size: 0.86rem;
  font-weight: 800;
}

.page-shell {
  width: min(1460px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.hero,
.panel {
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2rem;
  align-items: end;
  border-radius: 34px;
  padding: clamp(1.5rem, 3vw, 3.2rem);
}

.eyebrow {
  margin: 0 0 0.8rem;
  color: #68766d;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 820px;
  margin-bottom: 0.9rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.5rem, 8vw, 7.8rem);
  line-height: 0.88;
  letter-spacing: -0.07em;
}

h2 {
  margin-bottom: 1rem;
  font-size: clamp(1.7rem, 3vw, 2.65rem);
  letter-spacing: -0.045em;
}

h3 {
  margin-bottom: 0.3rem;
  font-size: 1rem;
}

.lede {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.22rem);
  line-height: 1.65;
}

.stats-card {
  display: grid;
  min-width: 260px;
  gap: 0.8rem;
  border-radius: 26px;
  background: var(--paper-strong);
  padding: 1.25rem;
  border: 1px solid var(--line);
}

.stats-card span {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
}

.stats-card strong {
  color: var(--ink);
}

.stats-card small {
  color: #7a827c;
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.38fr) minmax(0, 1fr);
  gap: 24px;
  margin-top: 24px;
}

.panel {
  border-radius: var(--radius);
  padding: clamp(1rem, 2vw, 1.5rem);
}

.search-panel {
  align-self: start;
}

.search-form {
  display: grid;
  gap: 1rem;
}

#searchQuery {
  min-height: 60px;
  font-size: 1.04rem;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0.72fr;
  gap: 0.75rem;
}

.button-row,
.quick-searches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.quick-searches {
  margin: 1rem 0 0.25rem;
}

.quick-searches button {
  border: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.78);
  color: #293730;
  padding: 0.62rem 0.9rem;
  font-size: 0.92rem;
  font-weight: 700;
}

.note {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.map-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.map {
  position: relative;
  min-height: 560px;
  overflow: hidden;
  border: 1px solid rgba(37, 53, 41, 0.18);
  border-radius: 26px;
  background: #d6e8ee;
}

.map-loading {
  display: grid;
  min-height: 560px;
  place-items: center;
  color: var(--muted);
}

.atlas-marker {
  background: transparent;
}

.atlas-marker span {
  position: relative;
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 4px solid var(--paper);
  border-radius: 999px 999px 999px 10px;
  color: var(--paper);
  background: var(--rust);
  box-shadow: 0 10px 24px rgba(56, 40, 31, 0.25);
  transform: rotate(-45deg);
}

.atlas-marker b {
  font-size: 0.8rem;
  transform: rotate(45deg);
}

.popup {
  max-width: 270px;
  color: var(--ink);
}

.popup strong {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 1rem;
}

.popup p,
.popup ul {
  margin: 0.35rem 0;
}

.popup ul {
  padding-left: 1rem;
}

.library-list,
.results {
  display: grid;
  gap: 0.8rem;
  margin-top: 1rem;
}

.database-summary-card,
.library-card,
.result-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 253, 247, 0.78);
  padding: 1rem;
}

.database-summary-card {
  display: grid;
  gap: 0.2rem;
  margin-top: 1rem;
}

.database-summary-card .note {
  margin-top: 0.3rem;
}

.database-summary-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.database-summary-heading h3 {
  margin: 0;
  font-size: 1.08rem;
}

.database-summary-heading .eyebrow {
  margin-bottom: 0.18rem;
}

.database-summary-heading > span {
  border-radius: 999px;
  background: rgba(184, 77, 50, 0.12);
  color: var(--rust-dark);
  padding: 0.42rem 0.68rem;
  font-size: 0.8rem;
  font-weight: 900;
  white-space: nowrap;
}

.library-card {
  cursor: pointer;
}

.library-card:hover,
.result-card:hover {
  border-color: rgba(184, 77, 50, 0.26);
  box-shadow: 0 14px 30px rgba(40, 59, 47, 0.1);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.card-meta span {
  border-radius: 999px;
  background: #edf0e8;
  color: #526057;
  padding: 0.34rem 0.62rem;
  font-size: 0.78rem;
  font-weight: 800;
}

.genre-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
  margin-top: 0.78rem;
}

.genre-chip {
  border: 1px solid rgba(67, 95, 74, 0.14);
  border-radius: 999px;
  background: rgba(223, 233, 220, 0.68);
  color: #34513f;
  padding: 0.34rem 0.58rem;
  font-size: 0.76rem;
  font-weight: 800;
}

.genre-chip b {
  display: inline-grid;
  place-items: center;
  min-width: 1.35rem;
  margin-left: 0.28rem;
  border-radius: 999px;
  background: rgba(184, 77, 50, 0.13);
  color: var(--rust-dark);
}

.genre-chip.muted {
  color: var(--muted);
}

.genre-details {
  margin-top: 0.8rem;
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
  cursor: auto;
}

.genre-details summary {
  color: var(--rust-dark);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 900;
}

.genre-summary {
  display: grid;
  gap: 0.58rem;
  margin-top: 0.7rem;
}

.genre-summary.empty {
  color: var(--muted);
  font-size: 0.84rem;
}

.genre-summary-title {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.genre-group {
  border: 1px solid rgba(23, 32, 27, 0.09);
  border-radius: 16px;
  background: rgba(255, 253, 247, 0.72);
  padding: 0.64rem;
}

.genre-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.7rem;
}

.genre-heading strong {
  font-size: 0.88rem;
}

.genre-heading span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.genre-group ol {
  display: grid;
  gap: 0.28rem;
  margin: 0.48rem 0 0;
  padding-left: 1.08rem;
}

.genre-group li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: start;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

.genre-group li b {
  border-radius: 999px;
  background: #edf0e8;
  color: var(--ink);
  padding: 0.02rem 0.36rem;
  font-size: 0.72rem;
}

.popup .genre-summary {
  gap: 0.45rem;
}

.popup .genre-summary-title {
  margin-top: 0.48rem;
}

.popup .genre-group {
  padding: 0.52rem;
}

.result-card {
  display: grid;
  gap: 0.55rem;
}

.result-card h3 {
  font-size: 1.06rem;
}

.result-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.result-card button {
  justify-self: start;
  padding: 0.62rem 0.9rem;
}

.empty-state {
  color: var(--muted);
  line-height: 1.55;
}

@media (max-width: 980px) {
  .hero,
  .workspace {
    grid-template-columns: 1fr;
  }

  .stats-card {
    min-width: 0;
  }

  .map {
    min-height: 470px;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 1460px);
    padding-top: 10px;
  }

  .hero,
  .panel {
    border-radius: 24px;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .map-heading {
    display: grid;
  }

  .map {
    min-height: 380px;
  }
}
