:root {
  color-scheme: light;
  --ink: #18211e;
  --muted: #5d665f;
  --line: #d8d2c4;
  --paper: #fbfaf6;
  --band: #f0eee6;
  --forest: #315b45;
  --rust: #985f35;
  --blue: #315f7f;
  --gold: #9a7a2d;
  --shadow: 0 18px 50px rgba(30, 28, 22, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

a { color: #234f72; text-decoration-thickness: 1px; text-underline-offset: 3px; }
button, input, select { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 4vw, 48px);
  background: rgba(251, 250, 246, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  font-weight: 750;
  color: var(--ink);
  text-decoration: none;
}

nav { display: flex; gap: 18px; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; font-size: 14px; }
nav a:hover { color: var(--ink); }

main { width: min(1480px, 100%); margin: 0 auto; }
.page-main { width: min(1480px, 100%); margin: 0 auto; }
.compact-intro { min-height: 180px; }
.content-section {
  padding: 36px clamp(18px, 4vw, 48px) 40px;
  border-top: 1px solid var(--line);
}
.content-section:first-of-type { border-top: 0; }

.intro {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(300px, 1.1fr);
  gap: 24px;
  align-items: end;
  min-height: 230px;
  padding: clamp(28px, 6vw, 72px) clamp(18px, 4vw, 48px) 28px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--rust);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 700;
}

h1, h2, h3 { margin: 0; line-height: 1.08; letter-spacing: 0; }
h1 { font-size: clamp(36px, 6vw, 80px); max-width: 900px; }
h2 { font-size: clamp(24px, 3vw, 38px); }
h3 { font-size: 19px; }

.intro-copy {
  margin: 0;
  max-width: 760px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.55;
}

.workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  align-items: start;
  gap: 28px;
  padding: 28px clamp(18px, 4vw, 48px);
}

.filters {
  position: sticky;
  top: 72px;
  display: grid;
  gap: 16px;
  padding: 18px;
  background: var(--band);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filters label, .filter-group span {
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #bdb6a7;
  border-radius: 6px;
  padding: 9px 10px;
  background: #fffdf8;
  color: var(--ink);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip, .secondary {
  border: 1px solid #b9b09f;
  background: #fffdf8;
  color: var(--ink);
  border-radius: 6px;
  min-height: 34px;
  padding: 7px 10px;
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--forest);
  border-color: var(--forest);
  color: white;
}
.secondary { width: 100%; }

.timeline-panel, .map-section, .gazetteer-section, .regions-section, .anthology-section, .sources-section {
  padding: 0 clamp(18px, 4vw, 48px) 40px;
}
.workspace .timeline-panel { padding: 0; }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
.heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.heading-actions p { font-size: 13px; }

.timeline-list {
  display: grid;
  gap: 12px;
}

.event {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 18px;
  padding: 18px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.event-date {
  color: var(--blue);
  font-weight: 800;
}
.event-real, .event-era {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}
.event p { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.tagrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 11px; }
.tag {
  border-radius: 999px;
  border: 1px solid #d1c8b7;
  padding: 4px 8px;
  color: #4e554f;
  font-size: 12px;
  background: #f8f2e5;
}
.citation-line {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.date-basis {
  margin: 10px 0 0;
  color: #5b6258;
  font-size: 13px;
  line-height: 1.45;
}
.source-link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid #c9bea9;
  border-radius: 6px;
  padding: 5px 9px;
  color: #244a65;
  background: #fffdf8;
  text-decoration: none;
  font-size: 13px;
}

.map-section {
  padding-top: 36px;
  border-top: 1px solid var(--line);
}
.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
}
.map-stage {
  position: relative;
  overflow: auto;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2efe6;
  box-shadow: var(--shadow);
}
.map-image-wrap {
  position: relative;
  line-height: 0;
  min-width: 680px;
}
.main-map-image {
  display: block;
  width: 100%;
  height: auto;
}
.map-pins {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.region-map-button {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 18px;
  border: 1px solid rgba(37, 45, 39, .82);
  border-radius: 50%;
  padding: 0;
  background: rgba(255, 250, 240, .9);
  color: #27342d;
  box-shadow: 0 1px 4px rgba(24, 29, 24, .28);
  font-size: 10px;
  line-height: 16px;
  font-weight: 850;
  cursor: pointer;
  pointer-events: auto;
}
.region-map-button:hover,
.region-map-button:focus,
.region-map-button.is-active {
  background: #2f5d52;
  color: #fffaf0;
  outline: 2px solid rgba(255, 248, 216, .95);
  outline-offset: 2px;
}
.map-spot-marker {
  position: absolute;
  display: none;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 3px solid #fff8d8;
  border-radius: 50%;
  background: rgba(223, 165, 61, .75);
  box-shadow: 0 0 0 3px rgba(20, 32, 28, .65), 0 0 20px rgba(223, 165, 61, .8);
  pointer-events: none;
  z-index: 3;
}
.map-spot-marker.is-visible { display: block; }
.map-details {
  min-height: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 18px;
}
.map-details p { color: var(--muted); line-height: 1.5; }
.paper-cites {
  display: inline;
  white-space: normal;
  color: #4f554d;
  font-size: .95em;
}
.paper-cites a {
  color: #234f72;
  text-decoration: none;
  font-weight: 700;
}
.paper-cites a:hover { text-decoration: underline; }

.region-atlas-section {
  padding: 36px clamp(18px, 4vw, 48px) 40px;
  border-top: 1px solid var(--line);
}
.atlas-tools {
  display: grid;
  grid-template-columns: minmax(220px, 360px);
  gap: 8px;
  margin-bottom: 16px;
}
.atlas-tools label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}
.atlas-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 20px;
  align-items: start;
}
.detail-map-panel,
.detail-region-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 16px;
}
.detail-map {
  overflow: auto;
  min-width: 0;
  background: #f5f0e6;
  border-radius: 6px;
}
.detail-map-image {
  display: block;
  width: 100%;
  min-width: 620px;
  height: auto;
}
.detail-map-meta {
  margin: 10px 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.detail-region-panel h3,
.detail-region-panel h4 { margin: 0; }
.detail-region-panel p,
.location-list p,
.location-list li {
  color: var(--muted);
  line-height: 1.45;
}
.location-list {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}
.location-item {
  padding-top: 10px;
  border-top: 1px solid #e3dac8;
}
.location-item h4 {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
}
.location-item small {
  color: var(--muted);
  font-weight: 650;
}
.detail-region-panel ul {
  padding-left: 18px;
}
.detail-region-panel li + li { margin-top: 6px; }
.gazetteer-section {
  padding-top: 36px;
  border-top: 1px solid var(--line);
}
.gazetteer-tools {
  display: grid;
  grid-template-columns: minmax(220px, 420px) auto;
  gap: 12px 18px;
  align-items: end;
  margin-bottom: 14px;
}
.gazetteer-tools label {
  grid-column: 1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}
.gazetteer-tools input { grid-column: 1; }
.gazetteer-tools p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}
.table-wrap {
  overflow-x: auto;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}
.gazetteer-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}
.gazetteer-table th,
.gazetteer-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #e3dac8;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}
.gazetteer-table th {
  color: var(--muted);
  background: var(--band);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}
.gazetteer-table tr:last-child td { border-bottom: 0; }
.gazetteer-table tr.is-selected td { background: #fbefcf; }
.gazetteer-table a {
  color: #244a65;
  font-weight: 750;
}
.confidence {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef1e5;
  color: #475044;
  font-size: 12px;
}
.confidence.low {
  background: #f7e5db;
  color: #744731;
}
.confidence.medium {
  background: #f6edcf;
  color: #695322;
}

.region-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.resource-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.video-grid,
.channel-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.hub-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.region-card, .source-card, .anthology-card, .resource-card, .channel-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 16px;
}
.region-card p, .source-card p, .anthology-card p, .resource-card p, .channel-card p, .notes p { color: var(--muted); line-height: 1.45; }
.resource-card small,
.channel-card small {
  display: block;
  margin-bottom: 8px;
  color: var(--rust);
  font-weight: 750;
}
.resource-card h2,
.channel-card h2 {
  margin-bottom: 8px;
  font-size: 19px;
}
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 0;
}
.region-card ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.anthology-section, .sources-section {
  padding-top: 36px;
  border-top: 1px solid var(--line);
}
.notes {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}
.notes p {
  margin: 0;
  padding: 10px 12px;
  background: var(--band);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.sources-list, .anthology-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.source-card small, .anthology-card small {
  display: block;
  margin-bottom: 6px;
  color: var(--rust);
  font-weight: 700;
}
.source-card a, .anthology-card a {
  overflow-wrap: anywhere;
}

.anthology-card h2, .anthology-card h3 {
  margin-bottom: 8px;
  font-size: 19px;
}
.anthology-index, .document-page {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 32px clamp(18px, 4vw, 48px);
}
.document-body {
  background: var(--paper);
}
.document-page pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  line-height: 1.5;
}
.anthology-image {
  display: block;
  max-width: min(100%, 860px);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.media-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  overflow: hidden;
}
.media-card > a {
  display: block;
  background: #eee9dc;
}
.media-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.map-resource-card img {
  aspect-ratio: 4 / 5;
  object-fit: contain;
  background: #f7f6f0;
}
.video-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  overflow: hidden;
}
.video-preview-link {
  position: relative;
  display: block;
  background: #181a18;
  color: #fff;
  text-decoration: none;
}
.video-preview {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #181a18;
}
.video-preview-link.no-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  font-weight: 800;
}
.play-badge {
  position: absolute;
  right: 12px;
  bottom: 12px;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, .72);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.video-card div {
  padding: 14px;
}
.video-card h2 {
  margin-bottom: 8px;
  font-size: 18px;
}
.video-card p {
  color: var(--muted);
  line-height: 1.45;
}
.video-card small,
.video-channel {
  display: block;
  margin-bottom: 7px;
  color: var(--rust);
  font-weight: 750;
}
.media-card div {
  padding: 14px;
}
.media-card h2 {
  margin-bottom: 8px;
  font-size: 18px;
}
.media-card p {
  color: var(--muted);
  line-height: 1.45;
}
.media-card small {
  display: block;
  margin-bottom: 7px;
  color: var(--rust);
  font-weight: 750;
}
.static-map {
  max-height: none;
}
.muted-inline {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  .intro, .workspace, .map-layout, .atlas-layout { grid-template-columns: 1fr; }
  .filters { position: static; }
  .region-grid, .sources-list, .anthology-list, .resource-grid, .hub-grid, .media-grid, .video-grid, .channel-strip { grid-template-columns: 1fr; }
  .gazetteer-tools { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .event { grid-template-columns: 1fr; }
  h1 { font-size: 38px; }
}
