:root {
  --bg: #f7f4ee; --bg-2: #efe9df; --card: #fffdf9; --fg: #1d2330; --muted: #6b6f78; --line: #e2dccf;
  --accent: #c2571a; --accent-2: #2f6f8f; --person: #6c5ce7;
  --tl-a: #d9cdb5; --tl-b: #8fb0c2;
  --map-sea: #dbe7ee; --map-land: #efe9dc; --map-line: #8b8577;
  --shadow: 0 1px 2px rgba(30, 30, 40, .06), 0 4px 14px rgba(30, 30, 40, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #13161c; --bg-2: #1a1e26; --card: #1c2129; --fg: #e8e6e1; --muted: #9aa0aa; --line: #2c323d;
    --accent: #e8833f; --accent-2: #5fa8c9; --person: #9b8cff; --tl-a: #3b3a35; --tl-b: #2f4b5a;
    --map-sea: #0f1a22; --map-land: #232a33; --map-line: #59606b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #13161c; --bg-2: #1a1e26; --card: #1c2129; --fg: #e8e6e1; --muted: #9aa0aa; --line: #2c323d;
  --accent: #e8833f; --accent-2: #5fa8c9; --person: #9b8cff; --tl-a: #3b3a35; --tl-b: #2f4b5a;
  --map-sea: #0f1a22; --map-land: #232a33; --map-line: #59606b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--sans); }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: clamp(1.7rem, 3.2vw, 2.5rem); }
h2 { font-size: 1.35rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
button { font: inherit; }

/* header */
.top { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--fg); font: 600 1.3rem var(--serif); text-decoration: none !important; }
.search { position: relative; flex: 1; max-width: 560px; }
.search input { width: 100%; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--fg); font-size: 15px; }
.search input:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.suggest { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.sug { display: flex; align-items: center; gap: 10px; padding: 7px 12px; color: var(--fg); text-decoration: none !important; }
.sug.on, .sug:hover { background: var(--bg-2); }
.sug img, .sug-ph { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; background: var(--bg-2); flex: none; }
.sug b { display: block; font-weight: 600; } .sug small { color: var(--muted); }
.sug.all { justify-content: center; color: var(--accent-2); font-size: .9rem; border-top: 1px solid var(--line); }
.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--fg); }
.nav a.on, .nav a:hover { background: var(--bg-2); text-decoration: none; }
.icon { border: 0; background: none; color: var(--fg); font-size: 18px; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.icon:hover { background: var(--bg-2); }

main { max-width: 1320px; margin: 0 auto; padding: 24px; min-height: 70vh; }
.foot { padding: 28px 24px 40px; text-align: center; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }

#loading { position: fixed; inset: 0; display: grid; place-content: center; gap: 12px; background: var(--bg); z-index: 100; font-family: var(--serif); font-size: 1.2rem; text-align: center; }
#loading .bar { width: 240px; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.era-loading { display: grid; place-content: center; justify-items: center; gap: 10px; min-height: 40vh; font-family: var(--serif); }
.era-loading .bar { width: 240px; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.era-loading .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* buttons, chips */
.btn { border: 1px solid var(--line); background: var(--card); color: var(--fg); padding: 8px 16px; border-radius: 999px; cursor: pointer; }
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.sm { padding: 3px 10px; font-size: .85rem; }
.linkbtn { border: 0; background: none; color: var(--accent-2); cursor: pointer; padding: 4px 0; font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--fg); font-size: .85rem; }
.chip:hover { border-color: var(--accent-2); text-decoration: none; }
.chip .n { color: var(--muted); font-size: .8em; }
.chip.on { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.chip.on .x { opacity: .8; }
.chip.k-period { border-left: 3px solid var(--accent); }
.chip.k-event { border-left: 3px solid #c0392b; }
.chip.k-state { border-left: 3px solid var(--accent-2); }
.chips.big .chip { font-size: .95rem; padding: 6px 14px; }
.badge { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 6px; background: var(--bg-2); color: var(--muted); font-size: .78rem; vertical-align: 1px; }

/* hero */
.hero { padding: 26px 0 10px; }
.hero h1 { font-size: clamp(2rem, 4.6vw, 3.4rem); max-width: 18ch; }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 70ch; }
.hero-search { display: flex; gap: 8px; max-width: 640px; margin-top: 16px; }
.hero-search input { flex: 1; padding: 13px 18px; font-size: 17px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--fg); }
.sec { margin: 38px 0; }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); color: var(--fg); transition: transform .12s; }
.card:hover { transform: translateY(-2px); text-decoration: none; }
.card-img { position: relative; aspect-ratio: 4/3; background: var(--bg-2); overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph { width: 100%; height: 100%; display: grid; place-items: center; background: linear-gradient(135deg, color-mix(in srgb, var(--c) 30%, var(--bg-2)), var(--bg-2)); }
.ph span { font: 600 2rem var(--serif); color: color-mix(in srgb, var(--c) 70%, var(--fg)); opacity: .7; }
.ai-badge { position: absolute; top: 8px; right: 8px; background: rgba(0, 0, 0, .65); color: #fff; font-size: .7rem; padding: 2px 7px; border-radius: 6px; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.card-kind { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--c, var(--muted)); font-weight: 600; }
.card-title { font: 600 1.02rem/1.25 var(--serif); }
.card-when { font-size: .85rem; }
.card-where { font-size: .8rem; color: var(--muted); }

/* browse */
.browse { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 26px; align-items: start; }
.facets { position: sticky; top: 74px; max-height: calc(100vh - 90px); overflow: auto; padding-right: 6px; }
.facet { border-bottom: 1px solid var(--line); padding: 8px 0; }
.facet summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
.facet ul { list-style: none; margin: 6px 0 0; padding: 0; }
.facet li.more { display: none; } .facet ul.all li.more { display: block; }
.facet li a { display: flex; justify-content: space-between; gap: 8px; padding: 2px 6px; border-radius: 6px; color: var(--fg); font-size: .88rem; }
.facet li a:hover { background: var(--bg-2); text-decoration: none; }
.facet li a.on { background: var(--accent-2); color: #fff; }
.facet .n { color: var(--muted); font-size: .8rem; } .facet a.on .n { color: #fff; }
.res-head { margin-bottom: 8px; }
.tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 8px 0 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; color: var(--fg); padding: 5px 13px; cursor: pointer; font-size: .88rem; }
.seg button.on { background: var(--fg); color: var(--bg); }
.range { display: inline-flex; gap: 6px; align-items: center; }
.range input, select { padding: 5px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); font: inherit; font-size: .88rem; }
.results > .btn { display: block; margin: 20px auto; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* tag header */
.tag-head { display: grid; grid-template-columns: minmax(0, 360px) 1fr; gap: 26px; align-items: start; margin-bottom: 12px; }
.tag-head:not(:has(figure)) { grid-template-columns: 1fr; }
.eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--c, var(--accent)); font-weight: 700; margin-bottom: 4px; }
.when { font: 1.15rem var(--serif); margin-bottom: 6px; }
.summary { font-size: 1.04rem; max-width: 72ch; }
.links { font-size: .88rem; margin-top: 8px; }

/* item pages */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: .85rem; margin-bottom: 10px; }
.crumbs a::after { content: "›"; margin-left: 6px; color: var(--muted); }
.crumbs a:last-child::after { content: ""; }
.item { display: grid; grid-template-columns: 1fr minmax(0, 440px); gap: 32px; align-items: start; }
.desc { color: var(--muted); font-size: 1.05rem; margin-top: -2px; }
.summary .more { font-size: .9rem; white-space: nowrap; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 16px 0; padding: 14px 16px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
.facts dt { color: var(--muted); font-size: .88rem; }
.facts dd { margin: 0; }
.hero-img, .tag-img { margin: 0; background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.hero-img img, .tag-img img { width: 100%; display: block; max-height: 520px; object-fit: contain; background: var(--bg-2); }
.tag-img img { max-height: 300px; object-fit: cover; }
figcaption { padding: 7px 11px; font-size: .78rem; color: var(--muted); }
.ai-note { color: var(--accent); }
.noimg { aspect-ratio: 4/3; border-radius: 12px; overflow: hidden; position: relative; }
.noimg small { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; color: var(--muted); }
.item-side { display: flex; flex-direction: column; gap: 16px; }

/* timelines */
.htl-wrap { margin: 0 0 8px; }
.htl { width: 100%; height: auto; overflow: visible; }
.htl .tick, .ctl .tick { font-size: 11px; fill: var(--muted); }
.htl .ms { font-size: 11px; fill: var(--fg); opacity: .8; }
.htl .here, .ctl .here { font-size: 12px; font-weight: 700; fill: var(--accent); }
.ctl .lbl { font-size: 12px; fill: var(--fg); }
.htl-wrap figcaption { padding: 2px 0; }
.ctl { width: 100%; height: auto; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
.rtl { position: relative; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 8px 10px; }
.rtl canvas { display: block; cursor: grab; touch-action: none; }
.rtl-bar { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.tip { position: absolute; z-index: 5; max-width: 260px; padding: 7px 10px; background: var(--fg); color: var(--bg); border-radius: 8px; font-size: .82rem; pointer-events: none; box-shadow: var(--shadow); }
.tip .muted { color: color-mix(in srgb, var(--bg) 70%, var(--fg)); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: .85rem; }
.legend a { color: var(--fg); display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }

/* maps */
.map { position: relative; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); background: var(--map-sea); }
.map.big { height: 520px; }
.map.small { height: 300px; }
.map-note { position: absolute; left: 8px; bottom: 8px; background: color-mix(in srgb, var(--card) 85%, transparent); padding: 2px 8px; border-radius: 6px; font-size: .75rem; color: var(--muted); }
.slider { position: absolute; left: 12px; right: 60px; bottom: 12px; display: flex; gap: 10px; align-items: center; background: color-mix(in srgb, var(--card) 90%, transparent); padding: 6px 12px; border-radius: 10px; box-shadow: var(--shadow); max-width: 520px; }
.slider input { flex: 1; accent-color: var(--accent); }
.slider output { font: 600 1rem var(--serif); min-width: 4ch; }
.explorer { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; height: calc(100vh - 140px); align-items: start; }
.map.full { width: 100%; aspect-ratio: 1.75; max-height: 100%; }
.explorer .map-side { max-height: 100%; }
.map-side { overflow: auto; }
.map-side .slider { position: static; max-width: none; box-shadow: none; padding: 6px 0; background: none; }
.map-side .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin: 8px 0; }
.side-list { margin-top: 10px; }
.side-item { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 5px 4px; border-bottom: 1px solid var(--line); color: var(--fg); font-size: .88rem; }
.side-item i { width: 9px; height: 9px; border-radius: 50%; }
.side-item small { color: var(--muted); }
.maplibregl-ctrl-group { background: var(--card) !important; }

/* sources */
.sources { margin: 40px 0 10px; padding: 14px 18px; border: 1px dashed var(--line); border-radius: 12px; font-size: .88rem; }
.sources h3 { font-size: 1rem; }
.sources ul { margin: 0; padding-left: 18px; }
.prose { max-width: 760px; }

@media (max-width: 900px) {
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  main { padding: 16px; }
  .browse { grid-template-columns: 1fr; }
  .facets { position: static; max-height: none; }
  .item, .tag-head { grid-template-columns: 1fr; }
  .explorer { grid-template-columns: 1fr; height: auto; }
  .map.full { height: auto; aspect-ratio: 1.6; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .map.big { height: 380px; }
}

.ai-prompt { margin-top: .35rem; }
.ai-prompt summary { cursor: pointer; color: var(--accent); }
.ai-prompt p { margin: .35rem 0 0; font-size: .8rem; line-height: 1.45; color: var(--muted, inherit); }

.summary-wrap .summary + .summary { margin-top: .6rem; }
button.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
button.linkish:hover { text-decoration: underline; }
.summary-wrap h3.art-h { font-size: 1.15rem; margin: 1.4rem 0 .4rem; }
.summary-wrap h4.art-h { font-size: 1rem; margin: 1rem 0 .3rem; }
.summary-wrap .art-foot { margin-top: 1rem; font-size: .9rem; }
.muted { color: var(--muted, #888); }

.era-tabs { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.2rem; }
.era-tabs a { display: flex; flex-direction: column; padding: .6rem .9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--fg); text-decoration: none; min-width: 12rem; }
.era-tabs a small { color: var(--muted); }
.era-tabs a.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.era-tabs a:hover { border-color: var(--accent); }
.map-side > select { width: 100%; margin: .2rem 0 .6rem; }
.rel-badge { background: rgba(40, 40, 40, .72); }
.rel-note { color: var(--fg); }

/* top-down timeline */
.vt-nav { position: sticky; top: 64px; z-index: 5; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 10px 0; margin-bottom: 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.vt-nav a, .vt-nav .off { font-size: .82rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--fg); text-decoration: none; }
.vt-nav a:hover { border-color: var(--accent); }
.vt-nav .off { color: var(--muted); opacity: .55; border-style: dashed; }
.vt-nav .n { margin-left: 6px; color: var(--muted); font-size: .75rem; }
.vt-order { margin-left: auto; }
.vt-epoch { margin: 18px 0 30px; scroll-margin-top: 120px; }
.vt-epoch > h2 { font-size: 1.45rem; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--accent); }
.vt-epoch > h2 small { display: block; font: 400 .85rem var(--sans, inherit); color: var(--muted); margin-top: 2px; }
.vt-group { position: relative; margin: 0 0 16px; padding-left: 18px; border-left: 2px solid var(--line); }
.vt-group h3 { font-size: 1.05rem; margin: 6px 0 6px -26px; display: flex; align-items: center; gap: 8px; }
.vt-group h3::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); flex: none; }
.vt-group h3 .n { font: 400 .8rem var(--sans, inherit); color: var(--muted); }
.vt-row { display: grid; grid-template-columns: 7.2rem 10px 48px minmax(0, 1fr); gap: 10px; align-items: center;
  padding: 5px 6px; border-radius: 8px; color: var(--fg); text-decoration: none; }
.vt-row:hover { background: var(--card); }
.vt-date { font-size: .8rem; color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vt-dot { width: 10px; height: 10px; border-radius: 50%; }
.vt-row img, .vt-ph { width: 48px; height: 34px; object-fit: cover; border-radius: 5px; background: var(--bg-2); }
.vt-text { min-width: 0; display: flex; flex-direction: column; }
.vt-text b { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vt-text small { color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vt-more { margin: 4px 0 0 6px; }
@media (max-width: 600px) {
  .vt-row { grid-template-columns: 4.6rem 8px 40px minmax(0, 1fr); gap: 7px; }
  .vt-row img, .vt-ph { width: 40px; height: 30px; }
  .vt-order { margin-left: 0; }
}

/* site statistics */
.stats { margin-top: 28px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 14px 0 22px; }
.stat { display: flex; flex-direction: column; padding: 14px 16px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
.stat b { font: 700 1.6rem var(--serif); color: var(--accent); }
.stat span { font-weight: 600; }
.stat small { color: var(--muted); font-size: .76rem; margin-top: 4px; line-height: 1.35; }
.stat-tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.stat-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.stat-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.stat-table td:last-child { text-align: right; white-space: nowrap; }
.map.map-off { display: grid; place-items: center; padding: 20px; text-align: center; }
.search-note { color: var(--muted); }
.year-jump { display: flex; gap: 6px; margin: 4px 0 8px; }
.year-jump input { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); }
