:root {
  color-scheme: light;
  --ink: #1d2527;
  --muted: #66747a;
  --line: #d9ded9;
  --panel: #fbfbf8;
  --paper: #ffffff;
  --accent: #8a3f2d;
  --accent-strong: #662d22;
  --forest: #24564c;
  --gold: #c49139;
  --shadow: 0 18px 45px rgba(31, 42, 38, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--panel);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100vh;
  min-height: 0;
  padding: 18px;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-width: 0;
  z-index: 500;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--forest);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.05;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--paper);
  background: var(--forest);
  cursor: pointer;
}

.search-panel,
.filters {
  display: grid;
  gap: 12px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--paper);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--forest);
  box-shadow: 0 0 0 3px rgba(36, 86, 76, 0.16);
}

.filter-row {
  display: grid;
  gap: 6px;
}

.status-strip {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.status-strip strong {
  color: var(--accent);
  font-size: 28px;
}

.project-note {
  border: 1px solid rgba(36, 86, 76, 0.18);
  border-radius: 8px;
  padding: 8px 11px;
  color: var(--muted);
  background: rgba(36, 86, 76, 0.05);
  font-size: 12px;
}

.project-note summary {
  color: var(--forest);
  font-weight: 800;
  cursor: pointer;
}

.project-note p {
  margin: 8px 0 0;
  line-height: 1.55;
}

.event-list {
  display: grid;
  flex: 1 1 auto;
  align-content: start;
  gap: 7px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 1px 5px 8px 1px;
}

.event-card {
  display: grid;
  gap: 0;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
}

.event-card:hover {
  border-color: rgba(138, 63, 45, 0.55);
  box-shadow: 0 5px 14px rgba(31, 42, 38, 0.07);
}

.event-card.active {
  border-color: rgba(138, 63, 45, 0.78);
  box-shadow: inset 3px 0 0 var(--accent);
}

.event-card:focus-visible {
  outline: 3px solid rgba(36, 86, 76, 0.18);
  outline-offset: -1px;
}

.event-card-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.event-card-summary h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-card-year {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.event-card-chevron {
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
  transition: transform 160ms ease;
}

.event-card.expanded .event-card-chevron {
  transform: rotate(180deg);
}

.event-card-details {
  display: grid;
  gap: 7px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition:
    max-height 220ms ease,
    margin-top 220ms ease,
    opacity 160ms ease;
}

.event-card.expanded .event-card-details {
  max-height: 320px;
  margin-top: 9px;
  opacity: 1;
}

.event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--accent-strong);
  background: rgba(196, 145, 57, 0.18);
  font-weight: 700;
}

.dynasty-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--forest);
  background: rgba(36, 86, 76, 0.12);
  font-weight: 800;
}

.event-card h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
}

.event-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.map-stage {
  position: relative;
  min-width: 0;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100vh;
}

.map-overlay {
  position: fixed;
  right: 22px;
  bottom: 22px;
  display: grid;
  gap: 12px;
  width: min(390px, calc(100vw - 44px));
  z-index: 900;
  pointer-events: none;
}

.overlay-legend {
  position: fixed;
  right: 22px;
  top: 22px;
  z-index: 880;
  width: min(360px, calc(100vw - 44px));
  border: 1px solid rgba(29, 37, 39, 0.12);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.overlay-legend strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}

.overlay-legend p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.legend-items span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.legend-items i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

#resetButton,
.selected-event {
  pointer-events: auto;
}

#resetButton {
  justify-self: end;
  min-height: 38px;
  border: 1px solid rgba(29, 37, 39, 0.18);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--paper);
  background: rgba(29, 37, 39, 0.82);
  cursor: pointer;
}

.selected-event {
  border: 1px solid rgba(29, 37, 39, 0.12);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.selected-event h2 {
  margin: 0 0 10px;
  font-size: 21px;
}

.selected-event p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.selected-event .event-meta {
  margin-bottom: 10px;
}

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

.history-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  color: var(--paper);
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(29, 37, 39, 0.22);
  font-size: 16px;
  font-weight: 900;
}

.marker-count {
  position: absolute;
  top: -8px;
  right: -10px;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  border: 2px solid var(--paper);
  border-radius: 999px;
  padding: 0 5px;
  color: var(--paper);
  background: var(--forest);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
}

.place-cluster {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  color: var(--paper);
  background: var(--forest);
  box-shadow:
    0 10px 24px rgba(29, 37, 39, 0.24),
    0 0 0 8px rgba(36, 86, 76, 0.16);
  line-height: 1;
}

.place-cluster strong {
  margin-top: 4px;
  font-size: 18px;
}

.place-cluster span {
  font-size: 10px;
  font-weight: 800;
}

.overlay-label {
  min-width: 54px;
  border: 1px solid rgba(29, 37, 39, 0.14);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 7px 18px rgba(29, 37, 39, 0.14);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  white-space: nowrap;
  backdrop-filter: blur(6px);
}

.user-marker {
  position: relative;
  width: 18px;
  height: 18px;
  border: 4px solid var(--paper);
  border-radius: 50%;
  background: #2d74c4;
  box-shadow: 0 0 0 12px rgba(45, 116, 196, 0.18);
}

.user-marker::after {
  position: absolute;
  inset: -11px;
  border: 2px solid rgba(45, 116, 196, 0.42);
  border-radius: 50%;
  content: "";
}

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

@media (min-width: 821px) and (max-height: 760px) {
  .sidebar {
    gap: 8px;
    padding: 12px;
  }

  .eyebrow {
    margin-bottom: 2px;
  }

  h1 {
    font-size: 24px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .search-panel,
  .filters {
    gap: 7px;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-row {
    gap: 3px;
  }

  input,
  select {
    min-height: 34px;
  }

  .status-strip {
    padding: 7px 10px;
  }

  .status-strip strong {
    font-size: 22px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: 48vh;
    max-height: 48vh;
    padding: 12px;
    gap: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-stage,
  #map {
    min-height: 52vh;
    height: 52vh;
  }

  .map-overlay {
    right: 12px;
    bottom: 12px;
    width: calc(100% - 24px);
  }
}
