:root {
  --paper: #f4f1ea;
  --white: #fcfbf8;
  --surface-subtle: #efece4;
  --ink: #201e1b;
  --muted: #666057;
  --line: rgba(32, 30, 27, 0.10);
  --line-strong: rgba(32, 30, 27, 0.18);
  --green: #2b4c43;
  --green-soft: rgba(43, 76, 67, 0.10);
  --rust: #9e3626;
  --rust-soft: rgba(158, 54, 38, 0.11);
  --gold: #9a7b42;
  --radius-card: 20px;
  --radius-pill: 999px;
  --shadow-card: 0 2px 12px rgba(32, 30, 27, 0.04), 0 12px 28px rgba(32, 30, 27, 0.05);
  --shadow-float: 0 8px 26px rgba(32, 30, 27, 0.10);
  --sans: "Noto Serif SC", "Songti SC", "STSong", "SimSun", system-ui, sans-serif;
  --serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif;
  --brush: "Ma Shan Zheng", "STKaiti", "KaiTi", cursive;
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--paper); color: var(--ink); min-height: 100vh; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Frosted Apple Masthead */
.mast {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 58px; padding: 8px clamp(16px, 3vw, 32px);
  background: rgb(250 248 242 / 0.84);
  backdrop-filter: saturate(170%) blur(20px);
  -webkit-backdrop-filter: saturate(170%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--brush); font-size: 1.4rem; font-weight: 400;
  letter-spacing: 0.12em; color: var(--ink); text-decoration: none;
}
.mast nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mast nav a {
  padding: 6px 13px; border-radius: var(--radius-pill);
  font-size: 0.87rem; font-weight: 500; color: var(--muted); text-decoration: none;
  transition: background 180ms ease, color 180ms ease;
}
.mast nav a:hover { background: var(--surface-subtle); color: var(--ink); }
.mast nav a[aria-current="page"] {
  background: var(--green); color: #fcfbf8; font-weight: 600;
}

/* Main Container */
.atlas-main {
  max-width: 1460px; margin: 0 auto;
  padding: clamp(16px, 2.2vw, 26px) clamp(14px, 2.6vw, 30px) 38px;
  display: flex; flex-direction: column; gap: 16px;
}

/* Header Row */
.atlas-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
}
.eyebrow {
  margin: 0 0 4px; font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.12em; color: var(--green);
}
.atlas-header h1 {
  margin: 0; font-family: var(--serif); font-size: clamp(1.55rem, 2.5vw, 2.1rem);
  font-weight: 600; letter-spacing: 0.06em; line-height: 1.25;
}
.atlas-header .lead {
  margin: 6px 0 0; font-size: 0.92rem; color: var(--muted); max-width: 660px; line-height: 1.55;
}

.header-search { position: relative; width: min(360px, 100%); }
.header-search input {
  width: 100%; height: 42px; padding: 0 16px;
  border-radius: var(--radius-pill); border: 1px solid var(--line-strong);
  background: var(--white); color: var(--ink); font-size: 0.88rem;
  box-shadow: 0 1px 4px rgba(32, 30, 27, 0.04);
  outline: none; transition: border-color 160ms ease, box-shadow 160ms ease;
}
.header-search input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(43, 76, 67, 0.14);
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  background: var(--white); border: 1px solid var(--line-strong);
  border-radius: 16px; box-shadow: var(--shadow-float);
  max-height: 320px; overflow-y: auto; padding: 6px;
}
.search-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 9px 12px; border: 0; background: transparent;
  border-radius: 11px; text-align: left; cursor: pointer; font-family: inherit;
  color: var(--ink); transition: background 140ms ease;
}
.search-item:hover { background: var(--surface-subtle); }
.search-item strong { font-size: 0.88rem; display: block; }
.search-item span { font-size: 0.76rem; color: var(--muted); }
.search-item .search-dyn {
  flex-shrink: 0; font-size: 0.74rem; padding: 2px 8px;
  border-radius: var(--radius-pill); background: var(--green-soft); color: var(--green); font-weight: 600;
}

/* Dynasty Timeline Bar */
.dynasty-bar {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius-card); padding: 12px 16px 14px;
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: 10px;
}
.dynasty-rail {
  display: flex; align-items: center; gap: 6px;
  overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
}
.dynasty-rail::-webkit-scrollbar { display: none; }
.dyn-pill {
  flex: 0 0 auto; padding: 7px 13px; border-radius: var(--radius-pill);
  border: 1px solid transparent; background: var(--surface-subtle);
  color: var(--ink); font-size: 0.84rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; font-family: inherit;
  transition: background 160ms ease, color 160ms ease, transform 140ms ease;
}
.dyn-pill:hover { background: #e6e1d6; }
.dyn-pill[aria-selected="true"] {
  background: var(--green); color: #fcfbf8; font-weight: 600;
  box-shadow: 0 4px 12px rgba(43, 76, 67, 0.22);
}

.dynasty-scrubber-row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
}
.step-btn {
  padding: 5px 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--line-strong); background: var(--white);
  color: var(--ink); font-size: 0.8rem; font-weight: 500; cursor: pointer;
  font-family: inherit; transition: background 150ms ease;
}
.step-btn:hover:not(:disabled) { background: var(--surface-subtle); }
.step-btn:disabled { opacity: 0.4; cursor: default; }

.scrubber-wrap { position: relative; height: 22px; display: flex; align-items: center; }
.scrubber-track {
  position: absolute; left: 0; right: 0; height: 5px;
  border-radius: 99px; background: rgba(32, 30, 27, 0.10); overflow: hidden;
  pointer-events: none;
}
.scrubber-fill {
  height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), var(--rust));
  transform-origin: left center; transform: scaleX(0.45);
  transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
#dynasty-slider {
  position: relative; z-index: 2; width: 100%; margin: 0;
  appearance: none; -webkit-appearance: none; background: transparent; cursor: pointer;
}
#dynasty-slider::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--white); border: 2.5px solid var(--green);
  box-shadow: 0 2px 6px rgba(32, 30, 27, 0.22);
}
#dynasty-slider::-moz-range-thumb {
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--white); border: 2.5px solid var(--green);
  box-shadow: 0 2px 6px rgba(32, 30, 27, 0.22);
}

/* Main 2-Column Bento Workspace */
.atlas-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 18px;
  align-items: start;
}

/* Map Stage */
.map-stage {
  position: relative;
  height: clamp(540px, 70vh, 760px);
  border-radius: 22px;
  overflow: hidden;
  background: #ede7da;
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-card);
  user-select: none;
}
#dynasty-canvas {
  display: block; width: 100%; height: 100%;
  cursor: grab;
}
#dynasty-canvas.is-dragging { cursor: grabbing; }
#dynasty-canvas.is-pointer { cursor: pointer; }

/* Floating HUDs */
.map-hud-top {
  position: absolute; top: 14px; left: 14px; right: 14px;
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; pointer-events: none; flex-wrap: wrap;
}
.era-badge {
  pointer-events: auto;
  background: rgb(252 251 248 / 0.88);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border: 1px solid rgba(32, 30, 27, 0.12);
  border-radius: 16px; padding: 10px 15px;
  box-shadow: var(--shadow-float);
}
.era-badge-head { display: flex; align-items: baseline; gap: 10px; }
.era-badge-head strong {
  font-family: var(--serif); font-size: 1.25rem; font-weight: 700; color: var(--ink);
}
.era-badge-head span {
  font-size: 0.79rem; font-weight: 600; color: var(--rust);
  letter-spacing: 0.03em;
}
.era-capitals {
  margin: 3px 0 0; font-size: 0.78rem; color: var(--muted);
}

.subsnap-pills {
  pointer-events: auto;
  display: flex; gap: 4px; padding: 4px;
  background: rgb(252 251 248 / 0.88);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(32, 30, 27, 0.12);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-float);
}
.subsnap-pills button {
  border: 0; background: transparent; padding: 5px 11px;
  border-radius: var(--radius-pill); font-size: 0.77rem; font-weight: 500;
  color: var(--muted); cursor: pointer; font-family: inherit;
}
.subsnap-pills button[aria-pressed="true"] {
  background: var(--green); color: #fcfbf8; font-weight: 600;
}

.map-hud-bottom-left {
  position: absolute; left: 14px; bottom: 14px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.layer-pills, .zoom-pills {
  display: flex; align-items: center; gap: 4px; padding: 4px;
  background: rgb(252 251 248 / 0.90);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(32, 30, 27, 0.12);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-float);
}
.layer-pills button, .zoom-pills button {
  border: 0; background: transparent; padding: 5px 10px;
  border-radius: var(--radius-pill); font-size: 0.77rem; font-weight: 500;
  color: var(--muted); cursor: pointer; font-family: inherit;
  transition: background 140ms ease, color 140ms ease;
}
.layer-pills button[aria-pressed="true"] {
  background: var(--green-soft); color: var(--green); font-weight: 600;
}
.zoom-pills button { color: var(--ink); font-weight: 600; }
.zoom-pills button:hover { background: var(--surface-subtle); }

.map-hud-bottom-right {
  position: absolute; right: 14px; bottom: 14px;
  pointer-events: none;
}
.map-credit {
  display: inline-block; padding: 4px 10px; border-radius: var(--radius-pill);
  background: rgb(252 251 248 / 0.78); backdrop-filter: blur(8px);
  font-size: 0.72rem; color: var(--muted); border: 1px solid rgba(32, 30, 27, 0.08);
}

/* Right Inspector Column */
.inspector-panel {
  display: flex; flex-direction: column; gap: 14px;
}

.detail-card, .era-overview-card, .sites-list-card, .legend-card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
}

.detail-card { overflow: hidden; }
.detail-media {
  position: relative; height: 176px; background: #e5dfd2; overflow: hidden;
}
.detail-media img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.detail-chips {
  position: absolute; left: 12px; bottom: 10px; display: flex; gap: 6px; flex-wrap: wrap;
}
.chip {
  padding: 3px 9px; border-radius: var(--radius-pill);
  font-size: 0.72rem; font-weight: 600; color: #fcfbf8;
  background: rgba(32, 30, 27, 0.72); backdrop-filter: blur(8px);
}
.chip.chip-3d { background: var(--rust); }
.chip.chip-city { background: var(--green); }

.detail-body { padding: 15px 16px 16px; }
.detail-loc {
  margin: 0 0 3px; font-size: 0.77rem; font-weight: 600; color: var(--muted);
}
.detail-body h2 {
  margin: 0; font-family: var(--serif); font-size: 1.24rem; line-height: 1.3;
}
.detail-brief {
  margin: 8px 0 14px; font-size: 0.86rem; line-height: 1.62; color: #3c3832;
}
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.action-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 14px; border-radius: var(--radius-pill);
  font-size: 0.83rem; font-weight: 600; text-decoration: none;
  border: 1px solid var(--line-strong); color: var(--ink); background: var(--surface-subtle);
  transition: transform 140ms ease, background 150ms ease, box-shadow 150ms ease;
}
.action-btn:hover { background: #e5dfd2; transform: translateY(-1px); }
.action-btn.primary {
  background: var(--green); border-color: var(--green); color: #fcfbf8;
  box-shadow: 0 4px 12px rgba(43, 76, 67, 0.22);
}
.action-btn.primary:hover { background: #213c35; }

.era-overview-card { padding: 13px 16px; }
.era-overview-card h3, .sites-list-card h3 {
  margin: 0 0 6px; font-size: 0.86rem; font-weight: 700; color: var(--ink);
}
.era-overview-card p {
  margin: 0; font-size: 0.82rem; line-height: 1.6; color: var(--muted);
}

.sites-list-card { padding: 13px 14px 12px; }
.sites-list-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.sites-list-head h3 { margin: 0; }
.sites-count {
  font-size: 0.74rem; padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--surface-subtle); color: var(--muted); font-weight: 600;
}
.sites-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 5px;
  max-height: 230px; overflow-y: auto;
}
.site-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 12px; cursor: pointer;
  border: 1px solid transparent; transition: background 140ms ease, border-color 140ms ease;
}
.site-row:hover { background: var(--surface-subtle); }
.site-row.is-active {
  background: var(--green-soft); border-color: rgba(43, 76, 67, 0.28);
}
.site-row-main { display: flex; align-items: center; gap: 9px; min-width: 0; }
.site-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.85);
}
.site-row-text { min-width: 0; }
.site-row-text strong {
  display: block; font-size: 0.84rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.site-row-text span {
  display: block; font-size: 0.73rem; color: var(--muted);
}
.site-row-jump {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; text-decoration: none;
  background: var(--white); border: 1px solid var(--line-strong);
  color: var(--green); font-size: 0.82rem; font-weight: 700;
}
.site-row-jump:hover { background: var(--green); color: #fcfbf8; }

.legend-card { padding: 11px 14px; }
.legend-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px 8px;
}
.legend-item {
  display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--muted);
}
.legend-swatch { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* Responsive */
@media (max-width: 1040px) {
  .atlas-workspace { grid-template-columns: 1fr; }
  .map-stage { height: 520px; }
}
@media (max-width: 640px) {
  .map-stage { height: 440px; }
  .map-hud-bottom-right { display: none; }
}
