* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #layout { height: 100%; }
body { font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif; }

#layout { display: flex; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 320px; min-width: 320px; height: 100%;
  display: flex; flex-direction: column;
  background: #1d2129; color: #e8e6e0;
  overflow: hidden;
}
#sidebar header { padding: 14px 16px 10px; border-bottom: 1px solid #333947; }
#sidebar h1 { font-size: 18px; letter-spacing: 2px; margin-bottom: 8px; }
#scenario-select {
  width: 100%; padding: 5px 8px; border-radius: 6px;
  background: #2a3040; color: #e8e6e0; border: 1px solid #3d4456;
}
#scenario-info { padding: 12px 16px; border-bottom: 1px solid #333947; }
#scenario-title { font-size: 16px; margin-bottom: 6px; }
#scenario-summary { font-size: 12px; line-height: 1.65; color: #b8b5ad; max-height: 130px; overflow-y: auto; }

#legend { padding: 10px 16px; border-bottom: 1px solid #333947; font-size: 12px; }
.legend-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.legend-swatch { width: 14px; height: 10px; border-radius: 2px; border: 1.5px solid; }
.legend-title { margin-top: 8px; font-size: 11px; color: #8f8c85; letter-spacing: 1px; }
.src-toggle { cursor: pointer; }
.src-toggle input { accent-color: #e0533d; }
.src-period { margin-left: auto; font-size: 10px; color: #6f6c66; font-variant-numeric: tabular-nums; }
.ev-src {
  display: inline-block; padding: 0 5px; border-radius: 4px; font-size: 10px;
  background: #3d4456; color: #c9c6bf; font-weight: 400;
}

#events-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 10px 12px; }
#event-search {
  width: 100%; padding: 6px 10px; margin-bottom: 8px; border-radius: 6px;
  background: #2a3040; color: #e8e6e0; border: 1px solid #3d4456;
}
#event-list { flex: 1; overflow-y: auto; list-style: none; }
#event-list li {
  padding: 7px 9px; margin-bottom: 4px; border-radius: 6px; cursor: pointer;
  background: #262c38; border-left: 3px solid transparent; font-size: 12.5px;
}
#event-list li:hover { background: #303748; }
#event-list li.active-now { border-left-color: #e0533d; }
#event-list li.importance-1 { font-weight: 600; }
#event-list .ev-date { color: #8f8c85; font-size: 11px; margin-left: 6px; font-weight: 400; }
#event-list .ev-result { display: block; color: #9a978f; font-size: 11px; margin-top: 2px; font-weight: 400; }

#sources { padding: 8px 16px 10px; font-size: 10.5px; color: #6f6c66; border-top: 1px solid #333947; max-height: 90px; overflow-y: auto; }

/* ---------- map & timebar ---------- */
#map-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#map { flex: 1; }
#timebar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #1d2129; color: #e8e6e0;
}
#play-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
  background: #e0533d; color: #fff; font-size: 14px;
}
#speed-select { background: #2a3040; color: #e8e6e0; border: 1px solid #3d4456; border-radius: 6px; padding: 4px; }
#slider-wrap { flex: 1; position: relative; padding-top: 8px; }
#phase-band { position: absolute; top: 0; left: 0; right: 0; height: 5px; display: flex; border-radius: 3px; overflow: hidden; }
#phase-band .phase-seg { height: 100%; opacity: 0.85; }
#time-slider { width: 100%; accent-color: #e0533d; }
#time-label { min-width: 210px; text-align: right; font-size: 13px; }
#date-display { font-variant-numeric: tabular-nums; font-weight: 600; }
#phase-display { display: block; font-size: 11px; color: #9a978f; }

/* ---------- unit symbols ---------- */
.unit-icon { background: none; border: none; }
.unit-symbol { display: flex; flex-direction: column; align-items: center; transform: translateY(-4px); }
.unit-echelon {
  font-size: 8.5px; font-weight: 700; line-height: 1;
  color: #222; text-shadow: 0 0 2px #fff, 0 0 2px #fff; margin-bottom: 1px;
}
.unit-frame {
  width: 30px; height: 19px; border: 2px solid; border-radius: 2px;
  background-color: rgba(255,255,255,0.85); position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.unit-frame.kind-infantry::before, .unit-frame.kind-infantry::after {
  content: ""; position: absolute; inset: 0; background:
    linear-gradient(to top right, transparent calc(50% - 0.75px), currentColor calc(50% - 0.75px), currentColor calc(50% + 0.75px), transparent calc(50% + 0.75px));
}
.unit-frame.kind-infantry::after {
  background: linear-gradient(to bottom right, transparent calc(50% - 0.75px), currentColor calc(50% - 0.75px), currentColor calc(50% + 0.75px), transparent calc(50% + 0.75px));
}
.unit-frame.kind-naval { display: flex; align-items: center; justify-content: center; }
.ship-code { font-size: 10px; font-weight: 800; color: currentColor; letter-spacing: 0.5px; }
.unit-frame.kind-hq::before {
  content: "⚑"; position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; font-size: 11px; color: currentColor;
}
.unit-label {
  margin-top: 1px; font-size: 10px; font-weight: 600; white-space: nowrap;
  color: #1b1b1b; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
}
.unit-symbol.status-encircled .unit-frame { border-style: dashed; }
.unit-symbol.eliminated { opacity: 0.45; filter: grayscale(0.8); }
.unit-symbol.inferred { opacity: 0.55; }
.unit-symbol.inferred .unit-frame { border-style: dotted; }
.leaflet-popup-content .pop-cmd-head { color: #7a5f9e; font-weight: 700; font-size: 11px; }
.leaflet-popup-content .pop-tenure { color: #999; font-size: 10px; }
.lens-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.lens-btn {
  padding: 2px 8px; font-size: 11px; border-radius: 10px; cursor: pointer;
  background: #2a3040; color: #c9c6bf; border: 1px solid #3d4456;
}
.lens-btn:hover { background: #3d4456; }
.leaflet-popup-content .pop-cmd {
  display: block; margin: 2px 0; padding: 3px 6px; font-size: 11.5px;
  background: #f4f1fa; border-left: 2px solid #7a5f9e; border-radius: 3px;
}
.unit-symbol.eliminated .unit-frame::after {
  content: "✕"; position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; font-size: 15px; font-weight: 700; color: #444; background: none;
}

/* ---------- event markers ---------- */
.event-icon { background: none; border: none; }
.event-active {
  width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 14px;
  background: rgba(224, 83, 61, 0.25); border: 2px solid #e0533d;
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(224, 83, 61, 0.5); }
  100% { box-shadow: 0 0 0 14px rgba(224, 83, 61, 0); }
}
.event-past {
  width: 10px; height: 10px; border-radius: 50%;
  background: #7a776f; border: 2px solid #fff; opacity: 0.8;
}
.leaflet-popup-content { font-size: 12.5px; line-height: 1.6; }
.leaflet-popup-content h3 { font-size: 14px; margin-bottom: 4px; }
.leaflet-popup-content .pop-note { color: #555; }
.leaflet-popup-content .pop-fate { color: #a33; font-weight: 600; }

@media (max-width: 760px) {
  #layout { flex-direction: column; }
  #sidebar { width: 100%; min-width: 0; height: 40%; }
  #time-label { min-width: 120px; }
}

/* ---------- chronicle page ---------- */
.page-tag { font-size: 11px; color: #e0533d; letter-spacing: 1px; vertical-align: 2px; }
.nav-link { display: inline-block; margin-top: 2px; font-size: 11.5px; color: #9a978f; text-decoration: none; }
.nav-link:hover { color: #e8e6e0; }

#dim-tabs { display: flex; gap: 4px; padding: 8px 12px 0; }
.dim-tab {
  flex: 1; padding: 5px 0; font-size: 12px; border-radius: 6px 6px 0 0; cursor: pointer;
  background: #262c38; color: #9a978f; border: 1px solid #333947; border-bottom: none;
}
.dim-tab.dim-on { background: #3a4256; color: #e8e6e0; font-weight: 600; }
.tree-caret { display: inline-block; width: 14px; color: #6f6c66; }
#unit-list .ech-head {
  padding: 5px 4px 3px 10px; font-size: 10.5px; color: #8f8c85; letter-spacing: 1px; cursor: pointer;
}
#unit-list .side-head { cursor: pointer; }
.unit-badge {
  display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 10.5px;
  background: #ece7f5; color: #7a5f9e; text-decoration: none; font-weight: 600;
}
.unit-badge:hover { background: #ddd3ee; }
#chron-view a { color: inherit; }

#unit-list { flex: 1; overflow-y: auto; list-style: none; }
#unit-list .side-head {
  padding: 8px 4px 4px; font-size: 11px; font-weight: 700; letter-spacing: 1px;
  border-bottom: 1px solid #333947; margin-bottom: 4px;
}
#unit-list .unit-row {
  padding: 6px 9px; margin-bottom: 3px; border-radius: 6px; cursor: pointer;
  background: #262c38; border-left: 3px solid transparent; font-size: 12.5px;
}
#unit-list .unit-row:hover { background: #303748; }
#unit-list .unit-row.active-now { background: #3a4256; }

#chron-wrap { flex: 1; min-width: 0; overflow-y: auto; background: #f4f2ec; color: #2a2a28; }
#chron-empty { padding: 60px 40px; color: #8a877f; font-size: 14px; line-height: 1.8; }
#chron-view { max-width: 860px; margin: 0 auto; padding: 26px 30px 80px; }
#chron-head h2 { font-size: 24px; margin-bottom: 8px; }
#chron-meta { display: flex; gap: 6px; margin-bottom: 6px; }
.chron-badge { padding: 2px 9px; border-radius: 10px; font-size: 11px; color: #fff; }
.chron-badge.dim { background: #b9b5aa; }
#chron-aliases { font-size: 12px; color: #8a877f; }

#chron-panels { display: flex; gap: 14px; margin: 16px 0 14px; flex-wrap: wrap; }
.chron-panel {
  flex: 1; min-width: 260px; background: #fff; border: 1px solid #e2ded4;
  border-radius: 8px; padding: 10px 14px;
}
.chron-panel h3 { font-size: 12px; color: #8a877f; letter-spacing: 1px; margin-bottom: 6px; }
.chron-panel table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.chron-panel td { padding: 3px 0; border-bottom: 1px dashed #eee9dd; vertical-align: top; }
.chron-panel tr:last-child td { border-bottom: none; }
.tbl-date { text-align: right; color: #8a877f; font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl-role { color: #7a5f9e; font-size: 11.5px; }
.tbl-none { color: #b0aca2; }
#site-nav {
  display: flex; margin: 8px 0 10px; background: #fff;
  border: 1px solid #d8d3c6; border-radius: 7px; overflow: hidden;
}
.site-nav-item {
  flex: 1; text-align: center; padding: 5px 0; font-size: 12px;
  color: #8a877f; text-decoration: none;
}
.site-nav-item + .site-nav-item { border-left: 1px solid #eee9dd; }
.site-nav-item:hover { color: #2a2a28; background: #faf8f3; }
.site-nav-item.nav-on { background: #2a2a28; color: #f4f2ec; font-weight: 500; }

#chron-graph { margin: 6px 0 18px; background: #fff; border: 1px solid #e2ded4; border-radius: 8px; padding: 10px; }
#chron-graph svg { width: 100%; height: auto; display: block; }
#chron-graph .gv-label {
  font-size: 10.5px; paint-order: stroke; stroke: #fff; stroke-width: 3px;
  stroke-linejoin: round;
}
#chron-graph .gv-label:hover { text-decoration: underline; }
.gtl-mid {
  list-style: none; display: flex; justify-content: center; margin: 7px 0;
  background: linear-gradient(#eee9dd, #eee9dd) center / 1px 100% no-repeat;
}
.gtl-mid .gtl-card { width: 72%; border-left: 3px solid #c9a25a; cursor: default; }
.gtl-mid.act .gtl-card { border-left-color: #5a8a5a; }
.gtl-tag { font-size: 10.5px; color: #b0aca2; border: 1px solid #e2ded4; border-radius: 3px; padding: 0 4px; margin-right: 5px; }
.gv-hint { margin-top: 6px; font-size: 11px; color: #b0aca2; }

/* graph view: two-sided order timeline */
.gtl-head { display: flex; justify-content: space-between; list-style: none; color: #b0aca2; font-size: 11px; letter-spacing: 1px; margin-bottom: 8px; }
.gtl-row {
  list-style: none; display: flex; margin: 7px 0; position: relative;
  background: linear-gradient(#eee9dd, #eee9dd) center / 1px 100% no-repeat;
}
.gtl-row.recv { justify-content: flex-start; }
.gtl-row.sent { justify-content: flex-end; }
.gtl-card {
  width: 48.5%; background: #fff; border: 1px solid #e2ded4; border-radius: 8px;
  padding: 8px 11px; font-size: 12.5px; cursor: pointer;
}
.gtl-row.recv .gtl-card { border-left: 3px solid #8a877f; }
.gtl-row.sent .gtl-card { border-right: 3px solid #7a5f9e; text-align: left; }
.gtl-card:hover { border-color: #b8b09c; }
.gtl-date { color: #8a877f; font-size: 11.5px; font-variant-numeric: tabular-nums; margin-right: 4px; }
.gtl-title { color: #7a5f9e; font-size: 12px; margin-left: 4px; }
.gtl-full { margin-top: 6px; border-top: 1px dashed #eee9dd; padding-top: 6px; }
.gtl-doc { font-weight: 600; color: #5a574f; margin-bottom: 4px; }
.gtl-text { line-height: 1.8; color: #2a2a28; white-space: pre-wrap; }
.gtl-src { margin-top: 6px; font-size: 11px; color: #b0aca2; }
.src-tag {
  color: #b0aca2; font-size: 10px; border: 1px solid #e2ded4;
  border-radius: 3px; padding: 0 4px; margin-left: 4px; vertical-align: 1px;
  white-space: nowrap;
}

#chron-filters { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 14px; }
#chron-filters .lens-btn { background: #fff; color: #5a574f; border-color: #d8d3c6; }
#chron-filters .lens-btn:hover { background: #eee9dd; }
#chron-filters .lens-on { background: #e0533d; color: #fff; border-color: #e0533d; }

#chron-timeline { list-style: none; border-left: 2px solid #d8d3c6; margin-left: 6px; }
.tl-year {
  position: sticky; top: 0; z-index: 2; margin: 14px 0 8px -8px; padding: 3px 10px 3px 14px;
  font-weight: 700; font-size: 13px; background: #f4f2ec; color: #6a675f; letter-spacing: 1px;
}
.tl-item { position: relative; display: flex; gap: 10px; padding: 5px 0 5px 18px; font-size: 13px; }
.tl-icon {
  position: absolute; left: -10px; top: 6px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 1.5px solid #c9c4b6; display: flex; align-items: center;
  justify-content: center; font-size: 9.5px;
}
.tl-major .tl-icon { border-color: #e0533d; background: #fdece8; }
.tl-major .tl-claim { color: #a33; }
.tl-date { min-width: 84px; color: #8a877f; font-size: 11.5px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.tl-body { flex: 1; min-width: 0; background: #fff; border: 1px solid #e7e2d6; border-radius: 7px; padding: 6px 10px; }
.tl-claim { line-height: 1.6; }
.tl-cmdline { font-size: 11.5px; color: #7a5f9e; font-weight: 600; margin-bottom: 2px; }
.tl-place { color: #6a675f; font-size: 11px; margin-right: 6px; }
.tl-foot { margin-top: 4px; font-size: 10.5px; color: #8a877f; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tl-conflict { margin-top: 4px; padding: 5px 8px; background: #fdf3f1; border-left: 2px solid #d98577; font-size: 11.5px; color: #6a4a44; border-radius: 3px; }
.st-badge { padding: 0 6px; border-radius: 4px; font-size: 10px; }
.st-good { background: #e2efdf; color: #4a7a42; }
.st-bad { background: #f7ddd8; color: #a33; }
.st-dim { background: #eee9dd; color: #8a877f; }

/* ---------- OOB tree ---------- */
#oob-cols { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; margin-left: -18px; }
.oob-col { flex: 1; min-width: 300px; background: #fff; border: 1px solid #e2ded4; border-radius: 8px; padding: 12px 16px; }
.oob-col h3 { font-size: 14px; margin-bottom: 8px; letter-spacing: 1px; }
.oob-tree, .oob-branch { list-style: none; }
.oob-branch { margin-left: 14px; border-left: 1px dashed #d8d3c6; padding-left: 10px; }
.oob-tree li { padding: 2.5px 0; font-size: 13px; }
.oob-caret { display: inline-block; width: 16px; cursor: pointer; color: #8a877f; user-select: none; }
.oob-caret.oob-leaf { cursor: default; color: #cfc9bb; }
.oob-tree a { text-decoration: none; }
.oob-tree a:hover { text-decoration: underline; }
.oob-ech { margin-left: 6px; padding: 0 5px; border-radius: 4px; font-size: 9.5px; background: #eee9dd; color: #8a877f; }
.oob-cmd { margin-left: 6px; font-size: 11px; color: #7a5f9e; }
.oob-count { margin-left: 6px; font-size: 10.5px; color: #b0aca2; }
#oob-date { padding: 2px 8px; border: 1px solid #d8d3c6; border-radius: 6px; background: #fff; color: #2a2a28; font-size: 12.5px; }

/* ---------- site footer links ---------- */
#site-links {
  padding: 8px 16px 12px; font-size: 11px; border-top: 1px solid #333947;
  color: #6f6c66; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
#site-links a { color: #9a978f; text-decoration: none; }
#site-links a:hover { color: #e8e6e0; }
#site-links .site-note { flex-basis: 100%; color: #6f6c66; font-size: 10px; }

/* ---------- historical place labels ---------- */
.place-label-wrap { background: none; border: none; }
.place-label {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  font-size: 12px; color: #5d5a52; letter-spacing: 1px;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 4px #fff;
  pointer-events: none;
}
.place-label.t2 { font-size: 10.5px; color: #7a776d; letter-spacing: 0.5px; }
