:root {
  --ink: #071226;
  --navy: #001d35;
  --paper: #fffaf3;
  --paper-2: #f5efe6;
  --gold: #c99548;
  --line: rgba(91, 72, 51, 0.17);
  --muted: #5f6673;
  --shadow: 0 18px 44px rgba(27, 21, 13, 0.11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 250, 243, 0.96), rgba(245, 239, 230, 0.95)),
    #f5efe6;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }

.graph-header {
  min-height: 76px;
  padding: 14px clamp(18px, 4vw, 54px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: #fff;
  background:
    radial-gradient(circle at 18% 0%, rgba(24, 104, 139, 0.42), transparent 34%),
    var(--navy);
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 8px;
  color: #f8d99a;
  font: 700 24px/1 Georgia, serif;
}

.brand strong {
  display: block;
  font: 600 24px/1 Georgia, serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand small {
  color: #f8d99a;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.graph-header nav {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.graph-header nav a {
  color: #fff;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.graph-header nav a.active {
  color: #f8d99a;
}

.graph-app {
  padding: 22px clamp(14px, 3vw, 36px) 36px;
}

.graph-hero,
.timeline-panel,
.map-panel,
.detail-panel,
.entity-grid article {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 252, 247, 0.92);
  box-shadow: var(--shadow);
}

.graph-hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 22px;
  margin-bottom: 16px;
}

.kicker {
  color: #8b5b1d;
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

h1 {
  margin: 4px 0 8px;
  font: 600 clamp(2.4rem, 5vw, 4.5rem)/0.95 Georgia, serif;
}

h2 {
  margin-bottom: 6px;
  font: 600 1.12rem/1.2 Georgia, serif;
}

p {
  color: var(--muted);
  line-height: 1.48;
}

.graph-status {
  min-width: 160px;
  border: 1px solid rgba(196, 139, 59, 0.32);
  border-radius: 999px;
  padding: 8px 12px;
  color: #724812;
  background: #fff4df;
  font-weight: 800;
  text-align: center;
}

.timeline-panel {
  padding: 16px;
  margin-bottom: 16px;
}

.timeline-top,
.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

#yearOutput {
  border: 1px solid rgba(91, 72, 51, 0.18);
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff6e8;
  color: #724812;
  font-weight: 900;
}

#timelineSlider {
  width: 100%;
  accent-color: var(--gold);
}

.periodChips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.chip,
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chip {
  border: 1px solid rgba(91, 72, 51, 0.14);
  background: #fffaf3;
  color: #5f6673;
}

.chip.active {
  border-color: rgba(196, 139, 59, 0.5);
  background: #f8e2bc;
  color: #724812;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.8fr);
  gap: 16px;
  margin-bottom: 16px;
}

.map-panel,
.detail-panel {
  padding: 16px;
}

.panel-head select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fffaf3;
  color: var(--ink);
}

.map-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(91, 72, 51, 0.16);
  border-radius: 8px;
  background: #dfeef0;
}

#leafletMap {
  width: 100%;
  min-height: 480px;
  background: #dfeef0;
}

.leaflet-container {
  font: inherit;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.history-marker {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid #fffaf3;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0, 17, 32, 0.22);
}

.history-marker.established { background: #1d734c; }
.history-marker.probable,
.history-marker.moderate { background: #1e686e; }
.history-marker.possible { background: #a56b20; }
.history-marker.disputed { background: #9b2f1b; }
.history-marker.unknown { background: #65503b; }

.history-marker.selected {
  width: 30px;
  height: 30px;
  border-width: 3px;
  box-shadow: 0 0 0 5px rgba(201, 149, 72, 0.22), 0 10px 24px rgba(0, 17, 32, 0.28);
}

.marker-label {
  color: #071226;
  font-size: 0.78rem;
  font-weight: 900;
}

.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 420;
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  max-width: calc(100% - 24px);
  border: 1px solid rgba(91, 72, 51, 0.18);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 250, 243, 0.92);
  box-shadow: 0 8px 24px rgba(0, 17, 32, 0.12);
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #263142;
  font-size: 0.72rem;
  font-weight: 800;
}

.dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
}

.dot.established { background: #1d734c; }
.dot.probable { background: #1e686e; }
.dot.possible { background: #a56b20; }
.dot.disputed { background: #9b2f1b; }

.map-stage.leaflet-ready #historyMap {
  display: none;
}

#historyMap {
  display: block;
  width: 100%;
  min-height: 410px;
}

.land {
  fill: #efe0c8;
  stroke: rgba(116, 79, 44, 0.28);
  stroke-width: 2;
}

.land.alt {
  fill: #e7d5b8;
}

.route {
  fill: none;
  stroke: rgba(11, 69, 106, 0.46);
  stroke-width: 3;
  stroke-dasharray: 7 7;
}

.map-marker {
  cursor: pointer;
}

.map-marker circle {
  stroke: #fffaf3;
  stroke-width: 2;
}

.map-marker text {
  fill: #071226;
  font-size: 12px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #fffaf3;
  stroke-width: 4px;
}

.established { background: #e4f5ec; color: #1d734c; }
.probable, .moderate { background: #e2f4f2; color: #1e686e; }
.possible { background: #fff1d5; color: #835414; }
.disputed { background: #f7dfd8; color: #9b2f1b; }
.unknown { background: #ede4d8; color: #65503b; }

.detail-body {
  color: #263142;
  line-height: 1.52;
}

.detail-body h3 {
  margin: 12px 0 6px;
  color: #071226;
  font-size: 0.9rem;
}

.detail-body ul {
  margin: 0 0 10px;
  padding-left: 18px;
}

.detail-body li {
  margin-bottom: 4px;
}

.entity-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.entity-grid article {
  padding: 16px;
}

.entity-list {
  display: grid;
  gap: 8px;
}

.entity-button {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid rgba(91, 72, 51, 0.14);
  border-radius: 8px;
  padding: 10px;
  background: #fffaf3;
  color: #071226;
  text-align: left;
  cursor: pointer;
}

.entity-button:hover,
.entity-button.active {
  border-color: rgba(196, 139, 59, 0.46);
  background: #fff4df;
}

.entity-button strong {
  display: block;
  font-size: 0.92rem;
}

.entity-button small {
  color: var(--muted);
  font-size: 0.76rem;
}

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

@media (max-width: 680px) {
  .graph-header,
  .graph-hero,
  .timeline-top,
  .panel-head {
    display: block;
  }

  .graph-header nav {
    margin-top: 12px;
  }

  .graph-status,
  #yearOutput,
  .panel-head select {
    display: block;
    width: 100%;
    margin-top: 12px;
  }

  #historyMap {
    min-height: 330px;
  }
}
