:root {
  --bg-parchment: #f3eee4;
  --bg-parchment-alt: #ebe4d6;
  --water-fill: #d6e0de;
  --province-fill: #efe8da;
  --province-border: #c7bba6;
  --text-main: #2b2622;
  --text-secondary: #5d554c;
  --text-muted: #8d847a;
  --vermilion: #b5452f;
  --amber-gold: #c6952b;
  --hairline: rgba(43, 38, 34, 0.12);
  --card-shadow: 0 10px 30px rgba(43, 38, 34, 0.14), 0 1px 2px rgba(43, 38, 34, 0.08);
  --corner-radius: 14px;
  --serif-stack: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
  --sans-stack: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --calligraphy-stack: 'Ma Shan Zheng', 'STKaiti', 'KaiTi', var(--serif-stack);
  --dynasty-accent: #3a3733;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--sans-stack);
  color: var(--text-main);
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(255, 250, 240, 0.9), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(214, 224, 222, 0.6), transparent 60%),
    var(--bg-parchment);
  overflow: hidden;
}

button {
  font: inherit;
  cursor: pointer;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
}

#atlas-shell {
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

/* Navigation Header */
#nav-bar {
  position: relative;
  z-index: 30;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--hairline);
  background: rgba(243, 238, 228, 0.9);
  backdrop-filter: blur(6px);
}

.brand-group h1 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand-group .seal-mark {
  font-family: var(--calligraphy-stack);
  font-size: 27px;
  font-weight: 400;
  color: var(--vermilion);
  line-height: 1;
}

.brand-group .subtitle-mark {
  font-family: var(--serif-stack);
  font-size: 11.5px;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
}

.control-strip {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.control-strip::-webkit-scrollbar {
  display: none;
}

.toolbar-divider {
  width: 1px;
  height: 18px;
  background: rgba(43, 38, 34, 0.16);
  margin: 0 2px;
  flex-shrink: 0;
}

.layers-trigger-btn .caret-mark {
  font-size: 10px;
  opacity: 0.75;
  transition: transform 0.15s ease;
}

.layers-trigger-btn.is-active {
  background: #fff !important;
  color: var(--vermilion) !important;
  border-color: var(--vermilion) !important;
  font-weight: 600;
}

.layers-trigger-btn.is-active .caret-mark {
  transform: rotate(180deg);
}

.layers-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 180px;
  width: 288px;
  background: rgba(251, 248, 241, 0.98);
  border: 1px solid rgba(181, 69, 47, 0.32);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(43, 38, 34, 0.18);
  padding: 10px 12px;
  z-index: 50;
  backdrop-filter: blur(8px);
}

.layers-pop-section + .layers-pop-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--hairline);
}

.layers-pop-heading {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.layers-pop-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.layer-chip {
  display: inline-flex;
  align-items: center;
  gap: 4.5px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 4.5px 9.5px;
  border-radius: 8px;
  background: rgba(43, 38, 34, 0.05);
  border: 1px solid transparent;
  user-select: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.layer-chip:hover {
  background: rgba(43, 38, 34, 0.09);
  color: var(--text-main);
}

.layer-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.layer-chip:has(input:checked) {
  background: rgba(181, 69, 47, 0.11);
  border-color: rgba(181, 69, 47, 0.32);
  color: var(--vermilion);
  font-weight: 600;
}

.layer-chip:has(input:checked)::before {
  content: '✓';
  font-size: 11px;
  font-weight: 700;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5.5px 10.5px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
}

.btn-svg,
.ico-svg {
  display: inline-block;
  vertical-align: -2px;
  flex-shrink: 0;
}

.action-btn:active {
  transform: translateY(1px);
}

.action-btn.subtle {
  background: rgba(255, 255, 255, 0.65);
  color: var(--text-main);
  border-color: var(--hairline);
}

.action-btn.subtle:hover {
  background: #fff;
}

.action-btn.subtle.is-active {
  background: var(--text-main);
  color: #fff;
  border-color: var(--text-main);
}

.action-btn.locale-switch {
  font-weight: 700;
  letter-spacing: 0.04em;
  min-width: 52px;
  text-align: center;
}

.github-star-btn {
  text-decoration: none;
  font-weight: 600;
  gap: 4px;
}

.github-star-btn .star-mark {
  color: var(--amber-gold);
  font-size: 12px;
  line-height: 1;
  transition: transform 0.15s ease, color 0.15s ease;
}

.github-star-btn:hover {
  border-color: var(--vermilion);
  color: var(--vermilion);
}

.github-star-btn:hover .star-mark {
  color: #d9821b;
  transform: scale(1.18);
}

.music-pill-group {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--hairline);
  overflow: hidden;
}

.music-pill-group .music-btn {
  border: none;
  border-radius: 999px 0 0 999px;
  background: transparent;
  padding-right: 10px;
}

.music-pill-group .music-next-btn {
  border: none;
  border-left: 1px solid var(--hairline);
  border-radius: 0 999px 999px 0;
  background: transparent;
  padding: 7px 9px;
  color: var(--text-secondary);
}

.music-pill-group .music-btn:hover,
.music-pill-group .music-next-btn:hover {
  background: #fff;
  color: var(--text-main);
}

.music-pill-group .music-btn.is-active {
  background: var(--text-main);
  color: #fff;
}

.action-btn.accent {
  background: var(--vermilion);
  color: #fff;
  box-shadow: 0 4px 12px rgba(181, 69, 47, 0.3);
}

.action-btn.accent:hover {
  background: #a03b26;
}

#nav-bar #act-challenge {
  background: rgba(181, 69, 47, 0.08);
  color: var(--vermilion);
  border-color: rgba(181, 69, 47, 0.34);
  box-shadow: none;
  font-weight: 600;
}

#nav-bar #act-challenge:hover,
#nav-bar #act-challenge.is-active {
  background: var(--vermilion);
  color: #fffaf2;
  border-color: var(--vermilion);
  box-shadow: 0 3px 10px rgba(181, 69, 47, 0.24);
}

.action-btn.sm {
  padding: 5px 12px;
  font-size: 12px;
}

/* Main Workspace */
#workspace-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-width: 0;
  min-height: 0;
}

#viewport-frame {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: var(--water-fill);
  border-right: 1px solid var(--hairline);
}

#atlas-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#atlas-svg.is-panning {
  cursor: grabbing;
}

#atlas-svg.is-crosshair {
  cursor: crosshair;
}

#ocean-bg {
  fill: var(--water-fill);
}

/* Terrain Shaded Relief & Hydrology Layer */
#grp-terrain {
  pointer-events: none;
  transition: opacity 0.25s ease;
}

#grp-terrain.is-hidden {
  opacity: 0;
  pointer-events: none;
}

#terrain-relief-img {
  opacity: 0.48;
  pointer-events: none;
}

#grp-rivers {
  pointer-events: none;
}

.hydro-lake {
  fill: rgba(96, 158, 188, 0.62);
  stroke: rgba(44, 108, 138, 0.78);
  stroke-width: 0.65;
  vector-effect: non-scaling-stroke;
}

.hydro-lake.rank-major {
  fill: rgba(82, 150, 184, 0.72);
  stroke: rgba(34, 98, 130, 0.88);
  stroke-width: 0.8;
}

.hydro-river-casing {
  fill: none;
  stroke: rgba(246, 239, 225, 0.48);
  stroke-width: 2.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.hydro-river {
  fill: none;
  stroke: rgba(68, 128, 156, 0.68);
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.hydro-river.rank-trunk {
  stroke: rgba(36, 102, 136, 0.9);
  stroke-width: 1.75;
}

.hydro-river.rank-major {
  stroke: rgba(48, 114, 146, 0.82);
  stroke-width: 1.25;
}

.hydro-river.rank-med {
  stroke: rgba(66, 128, 158, 0.68);
  stroke-width: 0.9;
}

.hydro-river.rank-minor {
  stroke: rgba(94, 144, 168, 0.44);
  stroke-width: 0.58;
}

.hydro-label {
  font-family: var(--serif-stack);
  font-style: italic;
  fill: rgba(20, 76, 108, 0.92);
  text-anchor: middle;
  dominant-baseline: central;
  letter-spacing: 0.14em;
  pointer-events: none;
  paint-order: stroke fill;
  stroke: rgba(246, 240, 228, 0.9);
  stroke-width: 2px;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.hydro-label.is-trunk {
  font-size: 7.6px;
  font-weight: 600;
  fill: rgba(14, 68, 98, 0.95);
}

.hydro-label.is-river {
  font-size: 6.4px;
  font-weight: 600;
  fill: rgba(22, 78, 110, 0.88);
}

.hydro-label.is-lake {
  font-size: 6.2px;
  font-style: normal;
  font-weight: 600;
  letter-spacing: 0.06em;
  fill: rgba(18, 74, 106, 0.92);
}

/* Map SVG Layers */
.neighbor-shape {
  fill: #e7dfd0;
  stroke: #c9beaa;
  stroke-width: 0.48;
  vector-effect: non-scaling-stroke;
  transition: fill 0.2s;
}

#atlas-svg.terrain-active .neighbor-shape {
  fill: rgba(231, 223, 208, 0.08);
  stroke: rgba(164, 148, 128, 0.34);
}

.neighbor-caption {
  font-family: var(--sans-stack);
  font-size: 9px;
  font-weight: 600;
  fill: #6c6256;
  text-anchor: middle;
  dominant-baseline: central;
  letter-spacing: 0.08em;
  pointer-events: none;
  paint-order: stroke fill;
  stroke: rgba(246, 240, 228, 0.86);
  stroke-width: 2px;
  stroke-linejoin: round;
}

.province-shape {
  fill: var(--province-fill);
  stroke: var(--province-border);
  stroke-width: 0.52;
  vector-effect: non-scaling-stroke;
  transition: fill 0.2s;
}

.province-shape:hover {
  fill: #e6dcc7;
}

#atlas-svg.terrain-active .province-shape:not(.maritime-dash) {
  fill: rgba(246, 239, 225, 0.04);
  stroke: rgba(154, 139, 120, 0.26);
}

#atlas-svg.terrain-active .province-shape:not(.maritime-dash):hover {
  fill: rgba(230, 220, 199, 0.22);
}

.province-shape.maritime-dash {
  fill: #9fb2b0;
  stroke: none;
  pointer-events: none;
}

#grp-provinces.is-hidden .province-shape {
  fill: none;
  stroke: rgba(141, 132, 122, 0.26);
}

#grp-prov-names {
  pointer-events: none;
}

.province-caption {
  font-family: var(--sans-stack);
  font-size: 9.2px;
  fill: #6e655b;
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke fill;
  stroke: rgba(248, 243, 232, 0.9);
  stroke-width: 2.1px;
  stroke-linejoin: round;
}

#grp-polities {
  transition: opacity 0.25s;
}

#grp-polities.is-hidden,
#grp-prefectures.is-hidden,
#grp-settlements.is-hidden,
#grp-corridors.is-hidden,
#grp-milestones.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.polity-shape {
  fill-opacity: 0.38;
  stroke-width: 1.85;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: fill-opacity 0.2s;
}

.polity-shape:hover {
  fill-opacity: 0.48;
}

#atlas-svg.terrain-active .polity-shape {
  fill-opacity: 0.3;
  mix-blend-mode: multiply;
  stroke-width: 1.9;
}

#atlas-svg.terrain-active .polity-shape:hover {
  fill-opacity: 0.42;
}

.polity-shape.rival {
  fill-opacity: 0.35;
  stroke-width: 1.65;
}

#atlas-svg.terrain-active .polity-shape.rival {
  fill-opacity: 0.28;
  stroke-width: 1.75;
}

.polity-shape.protectorate {
  fill-opacity: 0.24;
  stroke-dasharray: 5 3;
  stroke-width: 1.4;
}

#atlas-svg.terrain-active .polity-shape.protectorate {
  fill-opacity: 0.2;
}

.polity-shape.neighbor {
  fill: rgba(138, 124, 107, 0.14);
  fill-opacity: 1;
  stroke: #6e6256;
  stroke-dasharray: 3 3;
  stroke-width: 1.05;
}

#atlas-svg.terrain-active .polity-shape.neighbor {
  mix-blend-mode: normal;
  fill: rgba(138, 124, 107, 0.08);
  fill-opacity: 1;
}

.polity-shape.neighbor:hover {
  fill: rgba(138, 124, 107, 0.26);
  fill-opacity: 1;
}

/* First-Level Macro Administrative Regions (道/州/路/行省/布政使司/省) */
.region-shape-casing {
  fill: none;
  stroke: rgba(250, 244, 232, 0.68);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.region-shape {
  fill: none;
  stroke: rgba(104, 28, 12, 0.88);
  stroke-width: 1.45;
  stroke-dasharray: 7 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.region-caption {
  font-family: var(--serif-stack);
  font-size: 9px;
  font-weight: 700;
  fill: #522212;
  fill-opacity: 0.93;
  letter-spacing: 0.08em;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  paint-order: stroke fill;
  stroke: rgba(248, 243, 232, 0.92);
  stroke-width: 2.3px;
  stroke-linejoin: round;
  stroke-linecap: round;
  transition: opacity 0.16s ease;
}

.region-caption.is-crowded-hidden {
  opacity: 0;
  pointer-events: none;
}

/* Secondary Prefectures (郡/州/府/路) */
.prefecture-shape {
  fill: rgba(255, 255, 255, 0.001);
  stroke: rgba(43, 38, 34, 0.15);
  stroke-width: 0.42;
  stroke-dasharray: 2 1.5;
  vector-effect: non-scaling-stroke;
}

.prefecture-shape:hover,
.prefecture-shape.is-hovered {
  fill: rgba(181, 69, 47, 0.18);
  stroke: var(--vermilion);
  stroke-width: 1.1;
  stroke-dasharray: none;
}

.prefecture-shape.is-traced {
  fill: rgba(181, 69, 47, 0.22);
  stroke: var(--vermilion);
  stroke-width: 1.45;
  stroke-dasharray: none;
}

.polity-caption {
  font-family: var(--serif-stack);
  font-weight: 700;
  font-size: 19px;
  fill: #1c1612;
  fill-opacity: 0.92;
  letter-spacing: 0.18em;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  paint-order: stroke fill;
  stroke: rgba(248, 243, 232, 0.92);
  stroke-width: 3.1px;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.polity-caption.rival {
  font-size: 15px;
}

.polity-caption.protectorate {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.polity-caption.neighbor {
  font-size: 11.5px;
  font-weight: 600;
  fill: #433a32;
  fill-opacity: 0.9;
  letter-spacing: 0.1em;
  stroke-width: 2.3px;
}

/* Historical Corridors (Walls / Canals / Silk Road) */
#grp-corridors {
  pointer-events: stroke;
  transition: opacity 0.25s;
}

.corridor-line {
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
  cursor: pointer;
}

.corridor-line.wall {
  stroke: #5a3826;
  stroke-width: 2.4;
  stroke-dasharray: 5 2.5;
}

.corridor-line.canal {
  stroke: #1f6f8b;
  stroke-width: 2.2;
  stroke-dasharray: 7 3;
}

.corridor-line.silk,
.corridor-line.road {
  stroke: #9c6317;
  stroke-width: 1.7;
  stroke-dasharray: 2.5 3.5;
}

.corridor-line.sea {
  stroke: #2c5d8f;
  stroke-width: 1.7;
  stroke-dasharray: 2 4;
}

.corridor-line:hover {
  stroke-width: 3.4;
}

.corridor-caption {
  font-family: var(--serif-stack);
  font-size: 8.8px;
  font-weight: 700;
  fill: #4a341c;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke fill;
  stroke: rgba(248, 243, 232, 0.92);
  stroke-width: 2.2px;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.corridor-caption.canal {
  fill: #12485c;
}

.corridor-caption.sea {
  fill: #1d4266;
}

.corridor-caption.is-crowded-hidden {
  display: none;
}

/* Milestones / Events on Map */
#grp-milestones {
  transition: opacity 0.25s;
}

.milestone-pin {
  cursor: pointer;
}

.milestone-pin .ev-ring {
  fill: var(--vermilion);
  fill-opacity: 0;
  stroke: var(--vermilion);
  stroke-opacity: 0;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.milestone-pin .ev-core {
  fill: #fff6e8;
  stroke: var(--vermilion);
  stroke-width: 1.3;
  vector-effect: non-scaling-stroke;
  transition: fill 0.2s, opacity 0.2s;
}

.milestone-pin.is-future {
  display: none;
  pointer-events: none;
}

.milestone-pin.is-past .ev-core {
  opacity: 0.75;
}

.milestone-pin.is-current .ev-core,
.milestone-pin:hover .ev-core,
.milestone-pin.is-active .ev-core {
  fill: var(--vermilion);
  stroke: #fff6e8;
  opacity: 1;
}

.milestone-pin.is-current .ev-ring {
  animation: milestonePulse 1.8s ease-out infinite;
}

@keyframes milestonePulse {
  0% {
    r: 5;
    stroke-opacity: 0.7;
    fill-opacity: 0.25;
  }
  100% {
    r: 18;
    stroke-opacity: 0;
    fill-opacity: 0;
  }
}

#milestone-balloon {
  position: absolute;
  z-index: 6;
  box-sizing: border-box;
  width: max-content;
  max-width: min(348px, calc(100vw - 24px));
  background: rgba(252, 248, 240, 0.95);
  backdrop-filter: blur(5px);
  border: 1px solid rgba(181, 69, 47, 0.42);
  border-radius: 9px;
  padding: 7px 11px 8px;
  box-shadow: var(--card-shadow);
  font-size: 12.2px;
  line-height: 1.42;
  pointer-events: auto;
  transition: opacity 0.16s ease;
}

#milestone-balloon::before {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  background: rgba(252, 248, 240, 0.96);
  border: 0 solid rgba(181, 69, 47, 0.45);
  pointer-events: none;
}

#milestone-balloon[data-caret="left"]::before {
  left: -4.5px;
  top: var(--caret-y, 24px);
  transform: translateY(-50%) rotate(45deg);
  border-left-width: 1px;
  border-bottom-width: 1px;
}

#milestone-balloon[data-caret="right"]::before {
  right: -4.5px;
  top: var(--caret-y, 24px);
  transform: translateY(-50%) rotate(45deg);
  border-right-width: 1px;
  border-top-width: 1px;
}

#milestone-balloon[data-caret="bottom"]::before {
  bottom: -4.5px;
  left: var(--caret-x, 50%);
  transform: translateX(-50%) rotate(45deg);
  border-right-width: 1px;
  border-bottom-width: 1px;
}

#milestone-balloon[data-caret="top"]::before {
  top: -4.5px;
  left: var(--caret-x, 50%);
  transform: translateX(-50%) rotate(45deg);
  border-left-width: 1px;
  border-top-width: 1px;
}

#milestone-balloon.is-offscreen {
  opacity: 0;
  pointer-events: none;
}

#milestone-balloon .ep-head {
  display: flex;
  align-items: center;
  gap: 4px 6px;
  flex-wrap: wrap;
  padding-right: 22px;
}

#milestone-balloon .ep-year {
  font-family: var(--serif-stack);
  font-weight: 700;
  color: var(--vermilion);
  font-size: 11.8px;
}

#milestone-balloon .ep-place {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--text-secondary);
  font-size: 10.8px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(181, 69, 47, 0.24);
  background: rgba(181, 69, 47, 0.06);
  font-family: var(--sans-stack);
  cursor: pointer;
  max-width: 100%;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}

#milestone-balloon .ep-place:hover {
  background: rgba(181, 69, 47, 0.16);
  color: var(--vermilion);
  border-color: rgba(181, 69, 47, 0.45);
}

#milestone-balloon .ep-close {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(181, 69, 47, 0.08);
  color: var(--text-secondary);
  font-family: var(--sans-stack);
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}

#milestone-balloon .ep-close:hover {
  background: var(--vermilion);
  color: #fffaf2;
}

#milestone-balloon .ep-text {
  color: var(--text-main);
  margin-top: 4px;
  font-weight: 500;
  overflow-wrap: break-word;
}

/* Trace Place / Genealogy Card */
#genealogy-card {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 336px;
  max-height: calc(100% - 64px);
  display: flex;
  flex-direction: column;
  background: rgba(250, 246, 237, 0.96);
  border: 1px solid var(--hairline);
  border-radius: var(--corner-radius);
  box-shadow: var(--card-shadow);
  padding: 12px 14px;
  z-index: 7;
  backdrop-filter: blur(8px);
}

.genealogy-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.genealogy-tag {
  font-size: 11px;
  color: var(--vermilion);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.genealogy-title {
  font-family: var(--serif-stack);
  font-size: 18px;
  font-weight: 700;
  margin-top: 2px;
}

.genealogy-sub {
  font-size: 11.2px;
  color: var(--text-muted);
  margin: 4px 0 8px;
  padding-bottom: 7px;
  border-bottom: 1px dashed var(--hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.gen-filter-pill {
  border: 1px solid rgba(181, 69, 47, 0.28);
  background: rgba(181, 69, 47, 0.08);
  color: var(--vermilion);
  border-radius: 999px;
  padding: 1.5px 8px;
  font-size: 10.8px;
  font-family: var(--serif-stack);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}

.gen-filter-pill:hover {
  background: rgba(181, 69, 47, 0.16);
  border-color: rgba(181, 69, 47, 0.45);
}

.gen-filter-pill.is-active {
  background: var(--vermilion);
  color: #fffdf8;
  border-color: var(--vermilion);
}

.genealogy-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.genealogy-list li {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 7px;
  font-size: 12px;
  line-height: 1.35;
  cursor: pointer;
  transition: background 0.12s;
}

.genealogy-list li:hover {
  background: rgba(181, 69, 47, 0.09);
}

.genealogy-list .t-era {
  font-family: var(--serif-stack);
  font-weight: 700;
  color: var(--text-secondary);
}

.genealogy-list .t-val {
  color: var(--text-main);
  min-width: 0;
}

.genealogy-list .t-sub {
  color: var(--text-muted);
  font-size: 11px;
  display: block;
}

.t-cap-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--vermilion);
  background: rgba(181, 69, 47, 0.11);
  border: 1px solid rgba(181, 69, 47, 0.25);
  padding: 0 5px;
  border-radius: 4px;
  margin-left: 5px;
  vertical-align: 1px;
}

/* Strategic Mountain & River Passes (名关雄隘 · 天下锁钥, controlled by 关河丝路 layer & zoom) */
.settlement-node.is-pass {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

#atlas-svg.is-zoomed-passes .settlement-node.is-pass,
.settlement-node.is-pass.is-pass-trace {
  opacity: 0.94;
  pointer-events: auto;
}

#grp-settlements.is-hidden {
  display: inline !important;
}

#grp-settlements.is-hidden .settlement-node:not(.is-pass),
#atlas-svg.is-corridors-hidden .settlement-node.is-pass,
#viewport-frame.has-active-challenge .settlement-node.is-pass {
  display: none !important;
}

.settlement-node.is-pass .pass-gate-icon {
  fill: #fdf6ea;
  stroke: #8c3b22;
  stroke-width: 0.95;
  stroke-linejoin: round;
  transition: fill 0.15s ease, stroke 0.15s ease, transform 0.15s ease;
}

.settlement-node.is-pass:hover .pass-gate-icon,
.settlement-node.is-pass.is-pass-highlighted .pass-gate-icon {
  fill: #b5452f;
  stroke: #fff9f0;
  transform: scale(1.12);
}

.settlement-node.is-pass .name.pass-name {
  font-family: var(--serif-stack);
  font-size: 7.4px;
  font-weight: 700;
  fill: #6e2b17;
  letter-spacing: 0.04em;
}

.settlement-node.is-pass.is-label-crowded .name.pass-name {
  display: none;
}

.genealogy-list li.pass-lore-banner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  margin-bottom: 4px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(181, 69, 47, 0.11), rgba(156, 99, 23, 0.08));
  border: 1px solid rgba(181, 69, 47, 0.3);
  cursor: default;
}

.genealogy-list li.pass-lore-banner:hover {
  background: linear-gradient(135deg, rgba(181, 69, 47, 0.13), rgba(156, 99, 23, 0.1));
}

.pass-lore-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pass-lore-badge {
  font-family: var(--serif-stack);
  font-size: 10.5px;
  font-weight: 700;
  color: #fffaf2;
  background: #9e3a22;
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.pass-lore-range {
  font-family: var(--serif-stack);
  font-size: 11.2px;
  font-weight: 700;
  color: #6e2b17;
}

.pass-lore-desc {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-main);
}

.t-events {
  margin-top: 5px;
  padding: 3px 0 2px 8px;
  border-left: 2px solid rgba(181, 69, 47, 0.34);
  display: flex;
  flex-direction: column;
  gap: 3.5px;
}

.t-ev-row {
  font-size: 11.2px;
  line-height: 1.36;
  color: var(--text-main);
  display: flex;
  align-items: baseline;
  gap: 5px;
  flex-wrap: wrap;
  padding: 2px 4px;
  margin-left: -4px;
  border-radius: 5px;
  transition: background 0.12s;
}

.t-ev-row:hover {
  background: rgba(181, 69, 47, 0.12);
}

.t-ev-yr {
  font-weight: 700;
  color: var(--vermilion);
  font-size: 10.8px;
  flex-shrink: 0;
}

.t-ev-txt {
  flex: 1;
  min-width: 110px;
}

.trace-pin {
  fill: none;
  stroke: var(--vermilion);
  stroke-width: 2;
}

.trace-dot {
  fill: var(--vermilion);
  stroke: #fff;
  stroke-width: 1.4;
}

.trace-pin-label {
  font-family: var(--serif-stack);
  font-size: 10.5px;
  font-weight: 700;
  fill: #72190b;
  paint-order: stroke fill;
  stroke: rgba(251, 246, 236, 0.96);
  stroke-width: 3px;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: none;
}

/* Settlements / Ancient Cities (Refined compact cartographic typography) */
.settlement-node {
  cursor: pointer;
}

.settlement-node.is-tier2 {
  display: none;
}

#atlas-svg.is-zoomed-cities .settlement-node.is-tier2 {
  display: block;
}

.settlement-node .dot {
  fill: #fffdf8;
  stroke: #2b2622;
  stroke-width: 1.1;
  transition: transform 0.15s;
}

.settlement-node.is-tier2 .dot {
  fill: #f6efe2;
  stroke: #4e453d;
  stroke-width: 0.95;
}

.settlement-node.is-capital .dot {
  fill: var(--vermilion);
  stroke: #fffdf8;
  stroke-width: 1.1;
}

.settlement-node .cap-ring {
  fill: none;
  stroke: var(--vermilion);
  stroke-width: 1.05;
}

.settlement-node .name {
  font-family: var(--serif-stack);
  font-size: 8.8px;
  font-weight: 700;
  fill: #1c1713;
  paint-order: stroke fill;
  stroke: rgba(249, 244, 234, 0.94);
  stroke-width: 2.2px;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: bounding-box;
}

.settlement-node.is-tier2 .name {
  font-size: 8px;
  font-weight: 600;
  fill: #2c251f;
  stroke-width: 2px;
}

.settlement-node.is-capital .name {
  font-size: 9.8px;
  font-weight: 700;
  fill: #72190b;
  stroke: rgba(251, 246, 236, 0.96);
  stroke-width: 2.5px;
}

.settlement-node:hover .name {
  fill: var(--vermilion);
}

.settlement-node.is-label-crowded text {
  display: none;
}

.settlement-node.is-label-crowded:hover text {
  display: block;
}

/* Map Legend */
#map-key {
  position: absolute;
  left: 14px;
  bottom: 14px;
  background: rgba(243, 238, 228, 0.92);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(6px);
  max-width: 338px;
}

.key-phase-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--hairline);
}

.key-phase-badge {
  font-family: var(--serif-stack);
  font-size: 11px;
  font-weight: 700;
  color: var(--vermilion);
  white-space: nowrap;
}

.key-phase-dots {
  display: inline-flex;
  align-items: center;
  gap: 3.5px;
  flex-wrap: nowrap;
}

.phase-dot {
  width: 5.5px;
  height: 5.5px;
  flex-shrink: 0;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: rgba(43, 38, 34, 0.24);
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
}

.phase-dot:hover {
  background: rgba(181, 69, 47, 0.65);
  transform: scale(1.25);
}

.phase-dot.is-active {
  background: var(--vermilion);
  transform: scale(1.3);
}

.key-heading {
  font-family: var(--serif-stack);
  font-weight: 700;
  font-size: 12px;
  color: var(--text-main);
  padding-bottom: 3px;
  border-bottom: 1px dashed var(--hairline);
}

.key-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 12px;
}

.key-entry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.key-note {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1.5px solid currentColor;
  display: inline-block;
}

/* Floating Quick Search Box */
#map-search-box {
  position: absolute;
  left: 14px;
  top: 12px;
  width: 248px;
  z-index: 9;
  transition: width 0.18s ease;
}

#map-search-box:focus-within {
  width: min(320px, calc(100% - 28px));
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(247, 242, 232, 0.9);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 4px 11px;
  box-shadow: 0 3px 10px rgba(43, 38, 34, 0.08);
  backdrop-filter: blur(6px);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

#map-search-box:focus-within .search-input-wrap {
  background: rgba(252, 249, 242, 0.98);
  border-color: var(--vermilion);
  box-shadow: 0 6px 18px rgba(43, 38, 34, 0.14);
}

.search-ico {
  color: var(--text-muted);
  flex-shrink: 0;
}

#inp-map-search {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-family: var(--sans-stack);
  font-size: 12px;
  color: var(--text-main);
  padding: 1px 0;
}

#inp-map-search::placeholder {
  color: var(--text-muted);
}

.search-results-list {
  list-style: none;
  margin: 5px 0 0;
  padding: 5px;
  background: rgba(250, 246, 237, 0.97);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(8px);
  max-height: 290px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-results-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.35;
  transition: background 0.1s;
}

.search-results-list li:hover,
.search-results-list li.is-active {
  background: rgba(181, 69, 47, 0.11);
}

.sr-main {
  font-family: var(--serif-stack);
  font-weight: 700;
  color: var(--text-main);
}

.sr-sub {
  font-family: var(--sans-stack);
  font-weight: 400;
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 5px;
}

.sr-tag {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(181, 69, 47, 0.11);
  color: var(--vermilion);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Gesture Hint & Hover Tooltip */
#gesture-guide {
  position: absolute;
  right: 14px;
  top: 12px;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(243, 238, 228, 0.78);
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  pointer-events: none;
  transition: opacity 0.65s ease, transform 0.65s ease;
}

#gesture-guide.is-dismissed,
#viewport-frame.has-active-genealogy #gesture-guide,
#viewport-frame.has-active-journey #gesture-guide,
#viewport-frame.has-active-challenge #gesture-guide {
  opacity: 0;
  transform: translateY(-4px);
}

#hover-tip {
  position: absolute;
  pointer-events: none;
  background: rgba(32, 28, 24, 0.92);
  color: #f7f2e8;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  max-width: 240px;
  line-height: 1.45;
  z-index: 10;
}

#hover-tip.is-interactive {
  pointer-events: auto;
}

#hover-tip .tt-sub {
  color: #cfc6b8;
  font-size: 11px;
}

#hover-tip .tt-trace-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  padding: 3.5px 9px;
  border-radius: 999px;
  border: 1px solid rgba(217, 123, 102, 0.55);
  background: rgba(181, 69, 47, 0.32);
  color: #fff6e8;
  font-family: var(--sans-stack);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

#hover-tip .tt-trace-btn:active {
  background: rgba(181, 69, 47, 0.52);
}

/* Quiz / Challenge Overlay */
#viewport-frame.has-active-challenge:not(.is-challenge-answered) .region-caption,
#viewport-frame.has-active-challenge:not(.is-challenge-answered) #grp-prov-names {
  opacity: 0 !important;
  pointer-events: none !important;
}

#challenge-card {
  position: absolute;
  top: 14px;
  left: 14px;
  width: min(440px, calc(100% - 28px));
  background: rgba(250, 246, 237, 0.96);
  border: 1px solid rgba(181, 69, 47, 0.35);
  border-radius: var(--corner-radius);
  padding: 12px 14px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(8px);
  z-index: 8;
}

.challenge-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.mode-pill {
  border: none;
  background: transparent;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.mode-pill.is-active {
  background: var(--vermilion);
  color: #fff;
  font-weight: 600;
}

.pill-badge {
  background: rgba(181, 69, 47, 0.12);
  color: var(--vermilion);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.score-readout {
  margin-left: auto;
  font-weight: 600;
  color: var(--text-main);
}

.icon-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 6px;
}

.icon-close:hover {
  background: var(--hairline);
  color: var(--text-main);
}

.challenge-prompt {
  font-family: var(--serif-stack);
  font-size: 15px;
  line-height: 1.5;
}

.challenge-prompt b {
  color: var(--vermilion);
}

.challenge-clue-box {
  margin-top: 7px;
  padding: 6px 10px;
  border-radius: 7px;
  background: rgba(181, 69, 47, 0.06);
  border-left: 2.5px solid var(--vermilion);
  font-family: var(--serif-stack);
  font-size: 12.6px;
  line-height: 1.48;
  color: var(--text-secondary);
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.clue-tag {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--vermilion);
  background: rgba(181, 69, 47, 0.12);
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.challenge-feedback {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.guess-pin {
  fill: #2b6cb0;
  stroke: #fff;
  stroke-width: 1.5;
}

.guess-preview-ring {
  fill: rgba(43, 108, 176, 0.16);
  stroke: #2b6cb0;
  stroke-width: 1.3;
  stroke-dasharray: 3 2;
}

.answer-pin {
  fill: #2f855a;
  stroke: #fff;
  stroke-width: 1.5;
}

.error-line {
  stroke: #b5452f;
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  fill: none;
}

.target-ring {
  fill: rgba(47, 133, 90, 0.12);
  stroke: #2f855a;
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

/* Right Chronicle Sidebar */
#chronicle-pane {
  padding: 18px 20px;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(255, 252, 245, 0.7), rgba(235, 228, 214, 0.5));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dynasty-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 2px solid var(--dynasty-accent);
  padding-bottom: 8px;
}

#dynasty-title {
  font-family: var(--calligraphy-stack);
  font-size: 38px;
  font-weight: 400;
  color: var(--dynasty-accent);
  line-height: 1.05;
}

.span-label {
  font-family: var(--serif-stack);
  font-size: 13px;
  color: var(--text-secondary);
}

.seat-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.seat-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(181, 69, 47, 0.12);
  color: var(--vermilion);
  font-weight: 600;
}

.dynasty-desc {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-main);
  font-family: var(--serif-stack);
}

.milestone-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--text-secondary);
  font-weight: 600;
}

#milestone-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#milestone-list li {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 8px;
  font-size: 12.5px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--hairline);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#milestone-list li:hover,
#milestone-list li.is-current {
  background: #fff;
  border-color: var(--vermilion);
}

#milestone-list .ev-yr {
  font-family: var(--serif-stack);
  font-weight: 600;
  color: var(--vermilion);
}

#milestone-list .ev-map-tag {
  display: inline-block;
  margin-left: 5px;
  font-size: 11px;
  opacity: 0.82;
  vertical-align: baseline;
}

.disclaimer-box {
  margin-top: auto;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-muted);
  padding-top: 10px;
  border-top: 1px dashed var(--hairline);
}

/* Bottom Scrubber Timeline */
#scrubber-dock {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--hairline);
  background: rgba(235, 228, 214, 0.9);
  backdrop-filter: blur(6px);
  transition: opacity 0.2s ease;
}

#scrubber-dock.is-challenge-locked {
  opacity: 0.52;
}

#scrubber-dock.is-challenge-locked #scrubber-track,
#scrubber-dock.is-challenge-locked .round-btn,
#scrubber-dock.is-challenge-locked .step-nav-btn,
#scrubber-dock.is-challenge-locked #inp-year {
  cursor: not-allowed;
}

.round-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: #fff;
  color: var(--text-main);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(43, 38, 34, 0.1);
}

.round-btn:hover {
  border-color: var(--vermilion);
  color: var(--vermilion);
}

#scrubber-rail-wrap {
  position: relative;
  padding-top: 22px;
  min-width: 0;
}

#scrubber-Bubble {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  background: var(--text-main);
  color: #f8f3e8;
  font-family: var(--serif-stack);
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

#scrubber-Bubble::after {
  content: '';
  position: absolute;
  left: var(--arrow-left, 50%);
  bottom: -4px;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--text-main);
  border-bottom: 0;
}

#scrubber-track {
  position: relative;
  height: 34px;
  border-radius: 8px;
  background: #e3dac8;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  user-select: none;
  touch-action: none;
  outline: none;
  min-width: 0;
}

#scrubber-track:focus-visible {
  box-shadow: 0 0 0 3px rgba(181, 69, 47, 0.25);
}

#dynasty-bands {
  display: flex;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}

.band-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif-stack);
  font-size: 12px;
  color: #fffaf0;
  letter-spacing: 0.05em;
  border-right: 1px solid rgba(255, 255, 255, 0.35);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  opacity: 0.72;
  transition: opacity 0.2s, filter 0.2s;
  overflow: hidden;
  white-space: nowrap;
  min-width: 0;
}

.band-cell:last-child {
  border-right: none;
}

.band-cell:hover {
  opacity: 0.9;
}

.band-cell.is-active {
  opacity: 1;
  filter: saturate(1.1);
}

.band-cell.is-narrow {
  color: transparent;
  text-shadow: none;
}

#scrubber-handle {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 4px;
  margin-left: -2px;
  background: var(--text-main);
  border-radius: 2px;
  box-shadow: 0 0 0 2px rgba(243, 238, 228, 0.9);
  pointer-events: none;
}

#scrubber-ticks {
  position: relative;
  height: 14px;
  margin-top: 2px;
  font-size: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

#scrubber-ticks span {
  position: absolute;
  top: 2px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#scrubber-ticks span.is-hidden-tick {
  visibility: hidden;
}

.year-stepper {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 3px 5px;
  font-size: 12px;
}

.step-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  background: rgba(90, 74, 58, 0.07);
  color: var(--text-main);
  font-family: var(--sans-stack);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}

.step-nav-btn:hover {
  background: rgba(181, 69, 47, 0.12);
  border-color: rgba(181, 69, 47, 0.35);
  color: var(--vermilion);
}

.step-nav-btn:active {
  transform: scale(0.95);
}

.year-stepper input {
  width: 60px;
  border: none;
  outline: none;
  font: inherit;
  font-family: var(--serif-stack);
  font-weight: 600;
  text-align: right;
  background: transparent;
}

.year-stepper .unit-label {
  color: var(--text-muted);
  margin-right: 2px;
}

.is-hidden {
  display: none !important;
}

.fade-enter {
  animation: fadeEnter 0.25s ease-out;
}

@keyframes fadeEnter {
  from {
    opacity: 0.25;
  }
  to {
    opacity: 1;
  }
}

/* English Locale Typography Adjustments */
html[lang="en"] .brand-group .subtitle-mark {
  letter-spacing: 0.04em;
}

html[lang="en"] #dynasty-title {
  font-family: var(--serif-stack);
  font-size: 23px;
  font-weight: 700;
  line-height: 1.2;
}

html[lang="en"] .polity-caption {
  font-size: 13px;
  letter-spacing: 0.04em;
}

html[lang="en"] .polity-caption.rival {
  font-size: 11px;
}

html[lang="en"] .polity-caption.protectorate,
html[lang="en"] .polity-caption.neighbor {
  font-size: 9.5px;
  letter-spacing: 0.02em;
}

html[lang="en"] .region-caption {
  font-size: 7.5px;
  letter-spacing: 0.01em;
}

html[lang="en"] .prefecture-caption {
  font-size: 6.4px;
  letter-spacing: 0;
}

html[lang="en"] .band-cell {
  font-family: var(--sans-stack);
  font-size: 10px;
  letter-spacing: -0.01em;
}

html[lang="en"] #milestone-list li {
  grid-template-columns: 78px 1fr;
}

html[lang="en"] .genealogy-list li {
  grid-template-columns: 88px 1fr;
}

@media (max-width: 900px) {
  #nav-bar {
    gap: 8px;
    padding: 8px 10px;
  }
  .brand-group .seal-mark {
    font-size: 22px;
  }
  .brand-group .subtitle-mark {
    display: none;
  }
  .control-strip {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 5px;
    padding-bottom: 1px;
  }
  .control-strip::-webkit-scrollbar {
    display: none;
  }
  .action-btn {
    flex-shrink: 0;
    padding: 5px 9px;
    font-size: 11.5px;
  }
  .music-pill-group {
    flex-shrink: 0;
  }
  #workspace-body {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 40px;
    transition: grid-template-rows 0.22s ease;
  }
  #workspace-body.is-mobile-chronicle-open {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr min(50vh, 310px);
  }
  #workspace-body.is-pane-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 0px;
  }
  #viewport-frame {
    border-right: none;
    border-bottom: 1px solid var(--hairline);
  }
  #gesture-guide {
    display: none;
  }
  #map-search-box {
    left: 8px;
    top: 8px;
    width: 210px;
  }
  #map-search-box:focus-within,
  #map-search-box.is-expanded {
    width: calc(100% - 16px);
  }
  /* Single Floating Overlay Mutex on Mobile (<= 900px) */
  #viewport-frame.has-active-journey #map-search-box,
  #viewport-frame.has-active-challenge #map-search-box,
  #viewport-frame.has-active-genealogy #map-search-box,
  #viewport-frame.has-active-journey #map-key,
  #viewport-frame.has-active-challenge #map-key,
  #viewport-frame.has-active-genealogy #map-key,
  #viewport-frame.has-active-journey #scale-bar-box,
  #viewport-frame.has-active-challenge #scale-bar-box,
  #viewport-frame.has-active-genealogy #scale-bar-box {
    opacity: 0;
    pointer-events: none;
  }
  #map-key {
    left: 8px;
    bottom: 8px;
    max-width: calc(100% - 16px);
    padding: 5px 8px;
    font-size: 11px;
    gap: 3px;
  }
  .key-heading {
    font-size: 11px;
  }
  #canvas-br-dock {
    right: 8px;
    bottom: 8px;
    gap: 6px;
  }
  .canvas-reset-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
  #scale-bar-box {
    padding: 3px 7px 5px;
    transition: opacity 0.18s ease;
  }
  #act-toggle-pane {
    display: none;
  }
  #challenge-card {
    top: 8px;
    left: 8px;
    right: 8px;
    width: auto;
    max-height: calc(100% - 16px);
    padding: 10px 12px;
    z-index: 14;
  }
  #genealogy-card {
    top: auto;
    bottom: 8px;
    left: 8px;
    right: 8px;
    width: auto;
    max-height: min(50%, 340px);
    padding: 10px 12px;
    z-index: 14;
  }
  #milestone-balloon .ep-place {
    padding: 3.5px 9px;
    font-size: 11.5px;
  }
  #chronicle-pane {
    padding: 10px 14px;
    gap: 8px;
  }
  .dynasty-title-row {
    padding-bottom: 4px;
  }
  #dynasty-title {
    font-size: 26px;
  }
  .seat-row {
    margin-top: 4px;
    font-size: 12px;
  }
  .dynasty-desc {
    font-size: 12.5px;
    line-height: 1.55;
  }
  #milestone-list li {
    padding: 5px 7px;
    font-size: 12px;
  }
  #scrubber-dock {
    gap: 8px;
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  }
  #scrubber-track {
    height: 30px;
  }
}

@media (max-width: 640px) {
  #nav-bar {
    padding: 6px 7px;
    gap: 4px;
  }
  .brand-group .seal-mark {
    font-size: 18.5px;
  }
  .control-strip {
    gap: 3.5px;
  }
  .toolbar-divider,
  .layers-trigger-btn .layers-count-pill,
  #act-locale .btn-svg,
  #lbl-music,
  #act-github-star {
    display: none !important;
  }
  .action-btn {
    padding: 4px 6.5px;
    font-size: 11px;
    gap: 2.5px;
  }
  .action-btn .btn-svg {
    width: 11.5px;
    height: 11.5px;
  }
  .action-btn.locale-switch {
    min-width: 0;
    padding: 4px 6px;
  }
  .music-pill-group .music-btn {
    padding: 4px 6.5px;
  }
  .layers-popover {
    left: 8px;
    right: 8px;
    width: auto;
  }
  /* Collapsible 34x34px Search Button on Mobile (<= 640px) */
  #map-search-box:not(:focus-within):not(.is-expanded) {
    width: 34px;
    height: 34px;
  }
  #map-search-box:not(:focus-within):not(.is-expanded) .search-input-wrap {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    cursor: pointer;
  }
  #map-search-box:not(:focus-within):not(.is-expanded) #inp-map-search {
    width: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
  }
  #map-key {
    max-width: calc(100% - 134px);
  }
  #canvas-br-dock {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    right: 6px;
    bottom: 6px;
  }
  .canvas-reset-btn {
    padding: 3.5px 7px;
    font-size: 10.5px;
  }
  #scale-bar-box {
    padding: 2.5px 6px 4px;
  }
  .scale-label {
    font-size: 9.5px;
  }
  /* Keep thumb-friendly ‹ / › step buttons on mobile while hiding numeric input */
  .year-stepper {
    padding: 2px;
    gap: 2px;
    border-radius: 7px;
  }
  .year-stepper input,
  .year-stepper .unit-label {
    display: none;
  }
  .step-nav-btn {
    width: 28px;
    height: 30px;
    font-size: 16px;
  }
  #scrubber-Bubble {
    font-size: 11px;
    padding: 2px 7px;
    max-width: 100%;
  }
  #tick-present {
    left: auto !important;
    right: 0 !important;
    transform: none !important;
  }
  #scrubber-ticks span:first-child {
    transform: none;
  }
  .dynasty-title-row {
    flex-wrap: wrap;
    gap: 4px 8px;
  }
}

/* =========================================================================
   First-Principles UI/UX Enhancements (#1 – #6)
   ========================================================================= */

/* #1 Bidirectional Legend <-> Polity Highlight & Click-to-Focus */
.key-entry.is-interactive {
  cursor: pointer;
  padding: 2px 5px;
  margin: -2px -5px;
  border-radius: 5px;
  transition: background 0.14s, color 0.14s, transform 0.12s;
}

.key-entry.is-interactive:hover {
  background: rgba(181, 69, 47, 0.12);
  color: var(--text-main);
}

#grp-polities.has-polity-focus .polity-shape:not(.is-focused) {
  fill-opacity: 0.08 !important;
  stroke-opacity: 0.22 !important;
}

#grp-polities.has-polity-focus .polity-caption:not(.is-focused) {
  fill-opacity: 0.18 !important;
}

#grp-polities.has-polity-focus .polity-shape.is-focused {
  fill-opacity: 0.56 !important;
  stroke-width: 2.6 !important;
}

#grp-polities.has-polity-focus .polity-caption.is-focused {
  fill-opacity: 1 !important;
}

/* #2 Scrubber Intra-Dynasty Phase Ticks & Event Micro-Dots */
.band-label {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

.band-cell.is-narrow .band-label {
  opacity: 0;
}

.band-phase-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 250, 240, 0.34);
  pointer-events: none;
}

.band-ev-dot {
  position: absolute;
  bottom: 3px;
  width: 3.5px;
  height: 3.5px;
  margin-left: -1.75px;
  border-radius: 50%;
  background: rgba(255, 248, 231, 0.85);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

/* #3 Stage Transition Ghost Diff Outline */
#grp-ghost-diff {
  pointer-events: none;
}

.polity-ghost-path {
  fill: none;
  stroke-width: 2.4;
  stroke-dasharray: 7 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 3px rgba(181, 69, 47, 0.28));
}

.polity-ghost-path.is-protectorate {
  stroke-dasharray: 4 3;
}

.polity-ghost-path.is-fade {
  animation: ghostFadeOut 2.8s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.polity-ghost-path.is-preview {
  stroke-opacity: 0.85;
  fill: rgba(181, 69, 47, 0.09);
}

@keyframes ghostFadeOut {
  0%,
  22% {
    stroke-opacity: 0.88;
    fill: rgba(181, 69, 47, 0.12);
  }
  100% {
    stroke-opacity: 0;
    fill: rgba(181, 69, 47, 0);
  }
}

/* #4 Genealogy Card Active Dynasty Row Sync */
.genealogy-list li.is-current {
  background: rgba(181, 69, 47, 0.13);
  box-shadow: inset 3px 0 0 var(--vermilion);
}

.genealogy-list li.is-current .t-era {
  color: var(--vermilion);
}

/* #5 Dynamic Dual-Unit Historical Scale Bar & Canvas Reset Button */
#canvas-br-dock {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.canvas-reset-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 4.5px;
  padding: 5.5px 10px;
  background: rgba(243, 238, 228, 0.88);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  backdrop-filter: blur(5px);
  color: var(--text-main);
  font-family: var(--sans-stack);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(43, 38, 34, 0.08);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.canvas-reset-btn:hover {
  background: #fff;
  border-color: var(--vermilion);
  color: var(--vermilion);
}

.canvas-reset-btn:active {
  transform: translateY(1px);
}

#scale-bar-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  padding: 5px 9px 6px;
  background: rgba(243, 238, 228, 0.84);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  backdrop-filter: blur(5px);
  pointer-events: none;
  user-select: none;
}

.scale-label {
  font-family: var(--serif-stack);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.1;
  white-space: nowrap;
}

.scale-ruler {
  width: 84px;
  height: 5px;
  border-bottom: 1.8px solid var(--text-secondary);
  border-left: 1.8px solid var(--text-secondary);
  border-right: 1.8px solid var(--text-secondary);
  transition: width 0.12s ease-out;
}

/* #6 Collapsible Chronicle Sidebar / Full-Map Mode */
#workspace-body {
  transition: grid-template-columns 0.22s ease;
}

#workspace-body.is-pane-collapsed {
  grid-template-columns: minmax(0, 1fr) 0px;
}

#workspace-body.is-pane-collapsed #chronicle-pane {
  min-width: 0;
  width: 0;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

#workspace-body.is-pane-collapsed #viewport-frame {
  border-right: none;
}

#act-toggle-pane {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  width: 22px;
  min-height: 64px;
  padding: 7px 0;
  border: 1px solid rgba(181, 69, 47, 0.28);
  border-right: none;
  border-radius: 8px 0 0 8px;
  background: rgba(250, 245, 235, 0.95);
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  box-shadow: -2px 0 10px rgba(43, 38, 34, 0.1);
  transition: background 0.15s, color 0.15s, border-color 0.15s, width 0.15s, box-shadow 0.15s;
}

#act-toggle-pane .tp-arrow {
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: var(--vermilion);
}

#act-toggle-pane .tp-label {
  font-family: var(--serif-stack);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.15;
  writing-mode: vertical-rl;
  letter-spacing: 0.06em;
}

html[lang="en"] #act-toggle-pane .tp-label {
  font-family: var(--sans-stack);
  font-size: 9.5px;
  letter-spacing: 0.02em;
}

#act-toggle-pane:hover {
  width: 26px;
  background: #fffdf8;
  color: var(--vermilion);
  border-color: rgba(181, 69, 47, 0.55);
  box-shadow: -3px 0 12px rgba(181, 69, 47, 0.16);
}

/* #7 Historical Journeys (青史行迹 · 人物时空巡礼) */
.journey-pop-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.journey-chip-btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(181, 69, 47, 0.32);
  background: rgba(181, 69, 47, 0.06);
  color: var(--vermilion);
  font-family: var(--serif-stack);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.journey-chip-btn:hover,
.journey-chip-btn.is-active {
  background: var(--vermilion);
  border-color: var(--vermilion);
  color: #fffaf2;
}

.ev-journey-btn {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(181, 69, 47, 0.42);
  background: rgba(181, 69, 47, 0.09);
  color: var(--vermilion);
  font-family: var(--serif-stack);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.35;
  vertical-align: baseline;
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}

.ev-journey-btn:hover {
  background: var(--vermilion);
  color: #fffaf2;
}

.sr-section-head {
  padding: 5px 12px 3px !important;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: rgba(235, 228, 214, 0.55);
  border-bottom: 1px solid rgba(90, 74, 58, 0.1) !important;
  cursor: default !important;
  pointer-events: none;
}

#viewport-frame.has-active-journey #grp-settlements {
  opacity: 0.22;
  transition: opacity 0.25s ease;
}

#viewport-frame.has-active-journey #map-key {
  opacity: 0;
  pointer-events: none;
}

#viewport-frame.has-active-journey #grp-corridors {
  opacity: 0.22;
  transition: opacity 0.25s ease;
}

.journey-track-bg {
  fill: none;
  stroke: rgba(248, 243, 232, 0.88);
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.journey-track-upcoming {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 5 4.5;
  opacity: 0.68;
  pointer-events: none;
}

.journey-track-passed {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.92;
  pointer-events: none;
}

.journey-track-flow {
  fill: none;
  stroke: #fffaf0;
  stroke-linecap: round;
  stroke-dasharray: 2.5 11;
  opacity: 0.88;
  animation: journeyDashFlow 1.6s linear infinite;
  pointer-events: none;
}

@keyframes journeyDashFlow {
  to {
    stroke-dashoffset: -27;
  }
}

.journey-node {
  cursor: pointer;
}

.jn-pulse {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8px;
  opacity: 0.78;
  animation: journeyPulse 1.8s ease-out infinite;
}

@keyframes journeyPulse {
  0% {
    r: 7px;
    opacity: 0.85;
  }
  100% {
    r: 16px;
    opacity: 0;
  }
}

.jn-disc {
  fill: #fffaf2;
  stroke: currentColor;
  stroke-width: 2.2px;
  transition: transform 0.16s ease, fill 0.16s ease;
}

.journey-node.is-passed .jn-disc {
  fill: #f9efe6;
}

.journey-node.is-current .jn-disc {
  fill: currentColor;
  stroke: #fffaf2;
  stroke-width: 2.2px;
}

.jn-num {
  font-family: var(--sans-stack);
  font-size: 8.4px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  fill: currentColor;
  pointer-events: none;
}

.journey-node.is-current .jn-num {
  fill: #fffaf2;
  font-size: 9px;
}

.jn-label {
  font-family: var(--serif-stack);
  font-size: 10.4px;
  font-weight: 700;
  text-anchor: middle;
  fill: #1b1611;
  paint-order: stroke fill;
  stroke: rgba(249, 244, 234, 0.95);
  stroke-width: 2.5px;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: none;
}

.journey-node.is-current .jn-label {
  font-size: 11.8px;
  fill: currentColor;
}

.journey-node.is-upcoming {
  opacity: 0.88;
}

#journey-card {
  position: absolute;
  left: 14px;
  bottom: 26px;
  z-index: 8;
  width: min(492px, calc(100% - 28px));
  padding: 11px 14px 11px;
  border-radius: 10px;
  border: 1px solid rgba(181, 69, 47, 0.36);
  background: rgba(248, 243, 233, 0.96);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(36, 28, 20, 0.18);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.jc-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  border-bottom: 1px solid rgba(90, 74, 58, 0.15);
  padding-bottom: 6px;
}

.jc-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
}

.jc-mobile-person {
  display: none;
  font-family: var(--serif-stack);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--vermilion);
  margin-right: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jc-tab-btn {
  padding: 3px 7.5px;
  border-radius: 5px;
  border: 1px solid rgba(90, 74, 58, 0.18);
  background: rgba(90, 74, 58, 0.06);
  color: var(--text-secondary);
  font-family: var(--serif-stack);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s;
}

.jc-tab-btn:hover {
  color: var(--text-main);
  background: rgba(90, 74, 58, 0.14);
}

.jc-tab-btn.is-active {
  background: var(--vermilion);
  border-color: var(--vermilion);
  color: #fffaf2;
}

.jc-close-btn {
  padding: 2.5px 7px;
  border-radius: 5px;
  border: 1px solid var(--hairline);
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-secondary);
  font-family: var(--sans-stack);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.14s, color 0.14s;
}

.jc-close-btn:hover {
  border-color: var(--vermilion);
  color: var(--vermilion);
}

.jc-stop-head {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.jc-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--vermilion);
  color: #fffaf2;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.jc-stop-title {
  font-family: var(--serif-stack);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-main);
}

.jc-stop-year {
  margin-left: auto;
  font-family: var(--serif-stack);
  font-size: 11.5px;
  color: var(--vermilion);
  font-weight: 600;
}

.jc-stop-place {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.jc-stop-place .ico-svg {
  color: var(--vermilion);
}

.jc-stop-desc {
  margin: 0;
  font-family: var(--serif-stack);
  font-size: 12.4px;
  line-height: 1.54;
  color: var(--text-main);
}

.jc-stop-quote {
  margin: 0;
  padding: 4px 8px;
  border-left: 2.5px solid var(--vermilion);
  background: rgba(181, 69, 47, 0.06);
  border-radius: 0 4px 4px 0;
  font-family: var(--serif-stack);
  font-size: 11.6px;
  color: #5b3b2c;
  line-height: 1.46;
}

.jc-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 3px;
  flex-wrap: wrap;
}

.jc-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.jc-dot {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(90, 74, 58, 0.26);
  background: rgba(255, 252, 246, 0.9);
  color: var(--text-secondary);
  font-family: var(--sans-stack);
  font-size: 10.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.14s;
}

.jc-dot:hover {
  border-color: var(--vermilion);
  color: var(--vermilion);
}

.jc-dot.is-passed {
  background: rgba(181, 69, 47, 0.12);
  border-color: rgba(181, 69, 47, 0.36);
  color: var(--vermilion);
}

.jc-dot.is-current {
  background: var(--vermilion);
  border-color: var(--vermilion);
  color: #fffaf2;
  transform: scale(1.08);
}

.jc-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
}

.jc-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3.5px 9px;
  border-radius: 5px;
  border: 1px solid var(--hairline);
  background: #fff;
  color: var(--text-main);
  font-family: var(--serif-stack);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.14s, color 0.14s, background 0.14s;
}

.jc-nav-btn:hover {
  border-color: var(--vermilion);
  color: var(--vermilion);
}

.jc-nav-btn.is-primary {
  background: rgba(181, 69, 47, 0.1);
  border-color: rgba(181, 69, 47, 0.38);
  color: var(--vermilion);
}

.jc-nav-btn.is-primary:hover {
  background: var(--vermilion);
  border-color: var(--vermilion);
  color: #fffaf2;
}

/* Custom Multi-Stop Route Control Bar (#journey-card.is-custom-route) */
#journey-card.is-custom-route {
  width: min(540px, calc(100% - 28px));
  padding: 9px 12px 9px;
  gap: 6px;
}

.cr-dist-label {
  font-family: var(--serif-stack);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.cr-top-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
}

.cr-stops-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.cr-stops-list {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.cr-stop-arrow {
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
}

.cr-stop-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2.5px 7px;
  border-radius: 999px;
  border: 1px solid rgba(158, 42, 43, 0.28);
  background: rgba(255, 252, 246, 0.92);
  color: var(--text-main);
  font-family: var(--serif-stack);
  font-size: 11.2px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.14s;
}

.cr-stop-pill:hover {
  border-color: #9e2a2b;
  color: #9e2a2b;
}

.cr-stop-pill.is-current {
  background: #9e2a2b;
  border-color: #9e2a2b;
  color: #fffaf2;
}

.cr-stop-num {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: rgba(158, 42, 43, 0.14);
  color: #9e2a2b;
  font-family: var(--sans-stack);
  font-size: 9.8px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cr-stop-pill.is-current .cr-stop-num {
  background: rgba(255, 250, 242, 0.24);
  color: #fffaf2;
}

@media (max-width: 900px) {
  #viewport-frame.has-active-genealogy #journey-card.is-custom-route {
    top: 8px;
    bottom: auto;
  }
}

@media (max-width: 640px) {
  #journey-card,
  #journey-card.is-custom-route {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    padding: 9px 10px 8px;
    gap: 5px;
  }
  .jc-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    min-width: 0;
    padding-bottom: 1px;
  }
  .jc-tabs::-webkit-scrollbar {
    display: none;
  }
  .jc-tab-btn {
    flex-shrink: 0;
    padding: 2.5px 7px;
    font-size: 10.5px;
  }
  .jc-mobile-person {
    display: none;
  }
  .cr-stops-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .cr-stops-list::-webkit-scrollbar {
    display: none;
  }
  .jc-stop-desc {
    font-size: 11.8px;
    line-height: 1.45;
  }
  .jc-stop-quote {
    font-size: 11px;
  }
  .jc-dot {
    width: 18px;
    height: 18px;
    font-size: 9.5px;
  }
}

/* #8 Mobile Compact Chronicle Bar (Scheme A) & Collapsible Legend */
.mobile-chronicle-btn,
.key-mobile-toggle,
.key-phase-bar.is-single-phase {
  display: none;
}

@media (max-width: 900px) {
  .mobile-chronicle-btn {
    display: inline-flex;
    align-items: center;
    margin-left: auto;
    flex-shrink: 0;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid rgba(181, 69, 47, 0.36);
    background: rgba(181, 69, 47, 0.09);
    color: var(--vermilion);
    font-family: var(--serif-stack);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane {
    padding: 0 12px;
    overflow: hidden;
    display: flex;
    flex-direction: row;
    align-items: center;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .dynasty-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 0;
    padding: 0;
    border-bottom: none;
    cursor: pointer;
    min-width: 0;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .dynasty-title-row {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    padding-bottom: 0;
    border-bottom: none;
    flex-wrap: nowrap;
    flex-shrink: 0;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-title {
    font-size: 17.5px;
    line-height: 1;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-span {
    font-size: 11px;
    white-space: nowrap;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .seat-row {
    margin-top: 0;
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane #dynasty-summary,
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .milestone-section,
  #workspace-body:not(.is-mobile-chronicle-open) #chronicle-pane .disclaimer-box {
    display: none;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .dynasty-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    cursor: pointer;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .dynasty-title-row {
    padding-bottom: 0;
    border-bottom: none;
    gap: 6px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane #dynasty-title {
    font-size: 21px;
  }

  #workspace-body.is-mobile-chronicle-open #chronicle-pane .seat-row {
    margin-top: 0;
    font-size: 12px;
  }

  /* Mobile Compact Map Legend (#map-key) */
  .key-phase-bar.is-single-phase {
    display: flex;
  }

  .key-phase-dots {
    display: none;
  }

  .key-phase-bar {
    gap: 5px;
    padding-bottom: 3px;
  }

  .key-phase-badge {
    font-size: 10.5px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .key-phase-btns {
    margin-left: auto;
    flex-shrink: 0;
  }

  .key-mobile-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(90, 74, 58, 0.25);
    background: rgba(255, 255, 255, 0.78);
    color: var(--text-secondary);
    font-family: var(--sans-stack);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
  }

  #map-key:not(.is-mobile-expanded) {
    max-height: none;
    overflow: visible;
    padding: 5px 8px;
    gap: 3px;
  }

  #map-key:not(.is-mobile-expanded) .key-heading,
  #map-key:not(.is-mobile-expanded) .key-note,
  #map-key:not(.is-mobile-expanded) .key-corridors-grid,
  #map-key:not(.is-mobile-expanded) .key-neighbor-entry {
    display: none;
  }

  #map-key:not(.is-mobile-expanded) .key-polities-grid {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 4px 8px;
    font-size: 10.5px;
  }

  #map-key:not(.is-mobile-expanded) .key-polities-grid::-webkit-scrollbar {
    display: none;
  }

  #map-key:not(.is-mobile-expanded) .key-polities-grid .key-entry {
    white-space: nowrap;
    flex-shrink: 0;
  }

  #map-key.is-mobile-expanded {
    max-width: calc(100% - 16px);
    max-height: 190px;
    overflow-y: auto;
    padding: 7px 10px;
    gap: 4px;
    z-index: 7;
    background: rgba(248, 243, 233, 0.96);
  }

  #map-key.is-mobile-expanded .key-mobile-toggle {
    border-color: var(--vermilion);
    color: var(--vermilion);
    background: #fff;
  }
}

/* =========================================================================
   First-Time Visitor Subtle Onboarding Cues (Capital Ink Halo & Journey Menu)
   ========================================================================= */
.settlement-node .cap-breath-ring {
  fill: rgba(181, 69, 47, 0.16);
  stroke: var(--vermilion);
  stroke-width: 1.15;
  pointer-events: none;
  animation: capInkBreath 2.8s cubic-bezier(0.22, 0.61, 0.36, 1) infinite;
}

.settlement-node .cap-breath-ring.is-delayed {
  animation-delay: 1.4s;
}

@keyframes capInkBreath {
  0% {
    r: 4.8px;
    stroke-opacity: 0.85;
    fill-opacity: 0.24;
  }
  75% {
    r: 17.5px;
    stroke-opacity: 0;
    fill-opacity: 0;
  }
  100% {
    r: 17.5px;
    stroke-opacity: 0;
    fill-opacity: 0;
  }
}

.settlement-node .cap-hint-tag {
  cursor: pointer;
  pointer-events: all;
}

.settlement-node .cap-hint-inner {
  animation: capWhisperFloat 3.2s ease-in-out infinite;
}

@keyframes capWhisperFloat {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.94;
  }
  50% {
    transform: translateY(1.2px);
    opacity: 1;
  }
}

.settlement-node .cap-hint-stem {
  stroke: rgba(181, 69, 47, 0.55);
  stroke-width: 0.9;
  stroke-dasharray: 1.5 1.5;
  pointer-events: none;
}

.settlement-node .cap-hint-bg {
  fill: rgba(251, 246, 235, 0.95);
  stroke: rgba(181, 69, 47, 0.52);
  stroke-width: 0.9;
  filter: drop-shadow(0 2px 4px rgba(43, 38, 34, 0.15));
  transition: fill 0.15s ease, stroke 0.15s ease;
}

.settlement-node .cap-hint-dot {
  fill: var(--vermilion);
  transition: fill 0.15s ease;
}

.settlement-node .cap-hint-text {
  font-family: var(--serif-stack);
  font-size: 7.6px;
  font-weight: 700;
  fill: #7a2617;
  letter-spacing: 0.02em;
  dominant-baseline: central;
  text-anchor: middle;
  transition: fill 0.15s ease;
}

.settlement-node:hover .cap-hint-bg,
.settlement-node .cap-hint-tag:hover .cap-hint-bg {
  fill: var(--vermilion);
  stroke: var(--vermilion);
}

.settlement-node:hover .cap-hint-text,
.settlement-node .cap-hint-tag:hover .cap-hint-text,
.settlement-node:hover .cap-hint-dot,
.settlement-node .cap-hint-tag:hover .cap-hint-dot {
  fill: #fffaf2;
}

.onboarding-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--vermilion);
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 0 0 rgba(181, 69, 47, 0.58);
  animation: toolbarDotPulse 2.4s ease-out infinite;
}

.onboarding-dot.is-hidden {
  display: none;
}

@keyframes toolbarDotPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(181, 69, 47, 0.55);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(181, 69, 47, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(181, 69, 47, 0);
  }
}

.journey-popover {
  width: 318px;
}

@media (max-width: 640px) {
  .journey-popover {
    width: auto;
  }
}

.journey-pop-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin: -2px 0 8px;
  line-height: 1.4;
}

.journey-menu-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.journey-menu-item.journey-chip-btn {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid rgba(181, 69, 47, 0.24);
  background: rgba(255, 252, 246, 0.88);
  color: var(--text-main);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.journey-menu-item.journey-chip-btn:hover,
.journey-menu-item.journey-chip-btn.is-active {
  background: rgba(181, 69, 47, 0.11);
  border-color: var(--vermilion);
  color: var(--text-main);
}

.journey-menu-item.journey-chip-btn.is-active .jm-title {
  color: var(--vermilion);
}

.jm-badge {
  font-family: var(--serif-stack);
  font-size: 10.5px;
  font-weight: 700;
  color: #fffaf2;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 1px;
  line-height: 1.3;
}

.jm-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.jm-title {
  font-family: var(--serif-stack);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
}

.jm-meta {
  font-family: var(--sans-stack);
  font-size: 10.8px;
  color: var(--text-secondary);
  line-height: 1.3;
}

@media (max-width: 900px) {
  #milestone-balloon {
    max-width: min(268px, calc(100vw - 20px));
    padding: 6px 9px 7px;
    font-size: 11.5px;
    line-height: 1.38;
  }

  #milestone-balloon .ep-head {
    padding-right: 26px;
  }

  #milestone-balloon .ep-year {
    font-size: 11.2px;
  }

  #milestone-balloon .ep-close {
    top: 5px;
    right: 6px;
    width: 22px;
    height: 22px;
    font-size: 14px;
  }

  #viewport-frame.has-active-journey #milestone-balloon,
  #viewport-frame.has-active-challenge #milestone-balloon,
  #viewport-frame.has-active-genealogy #milestone-balloon,
  #workspace-body.is-mobile-chronicle-open #milestone-balloon {
    display: none !important;
  }
}
/* =========================================================================
   Mobile Cartographic Legibility & Stroke Hierarchy (<= 900px & <= 640px)
   ========================================================================= */
@media (max-width: 900px) {
  :root {
    --text-main: #1e1915;
    --text-secondary: #433b33;
    --text-muted: #665d53;
  }

  .settlement-node .name {
    font-size: 9.4px;
    fill: #16120e;
    stroke-width: 2.3px;
  }

  .settlement-node.is-capital .name {
    font-size: 10.6px;
    fill: #6e1508;
    stroke-width: 2.6px;
  }

  .settlement-node.is-tier2 .name {
    font-size: 8.5px;
    fill: #241e18;
    stroke-width: 2.1px;
  }

  .region-caption {
    font-size: 9.4px;
    fill: #4e2010;
    fill-opacity: 0.95;
  }

  .hydro-label.is-trunk {
    font-size: 8px;
  }

  .hydro-label.is-river,
  .hydro-label.is-lake {
    font-size: 6.8px;
  }

  /* Progressive disclosure for 300+ secondary prefecture mesh on mobile */
  #atlas-svg:not(.is-mobile-zoomed-detail) .prefecture-shape:not(:hover):not(.is-hovered) {
    stroke: rgba(43, 38, 34, 0.08);
    stroke-width: 0.3;
  }

  #atlas-svg.is-mobile-zoomed-detail .prefecture-shape:not(:hover):not(.is-hovered) {
    stroke: rgba(43, 38, 34, 0.2);
    stroke-width: 0.42;
  }
}

@media (max-width: 640px) {
  #terrain-relief-img {
    opacity: 0.48;
  }

  /* Slim down non-scaling border & corridor strokes by ~38% so lines don't overpower text */
  .polity-shape,
  #atlas-svg.terrain-active .polity-shape {
    stroke-width: 1.18;
    stroke-opacity: 0.86;
  }

  .polity-shape.rival,
  #atlas-svg.terrain-active .polity-shape.rival {
    stroke-width: 0.95;
    stroke-opacity: 0.84;
  }

  .polity-shape.protectorate,
  #atlas-svg.terrain-active .polity-shape.protectorate {
    stroke-width: 0.85;
    stroke-dasharray: 4 2.5;
  }

  .polity-shape.neighbor,
  #atlas-svg.terrain-active .polity-shape.neighbor {
    stroke-width: 0.68;
    stroke-dasharray: 2.5 2.5;
    fill: rgba(138, 124, 107, 0.1);
    fill-opacity: 1;
  }

  .region-shape-casing {
    stroke: rgba(250, 244, 232, 0.64);
    stroke-width: 2.5;
  }

  .region-shape {
    stroke: rgba(104, 28, 12, 0.86);
    stroke-width: 1.2;
    stroke-dasharray: 6 2.6;
  }

  .province-shape,
  #atlas-svg.terrain-active .province-shape:not(.maritime-dash) {
    stroke: rgba(154, 139, 120, 0.22);
    stroke-width: 0.42;
  }

  .neighbor-shape,
  #atlas-svg.terrain-active .neighbor-shape {
    stroke: rgba(164, 148, 128, 0.26);
    stroke-width: 0.38;
  }

  .corridor-line.wall {
    stroke-width: 1.45;
    stroke-dasharray: 4 2;
  }

  .corridor-line.canal {
    stroke-width: 1.35;
    stroke-dasharray: 5 2.5;
  }

  .corridor-line.silk,
  .corridor-line.road,
  .corridor-line.sea {
    stroke-width: 1.1;
  }

  .hydro-river-casing {
    stroke-width: 1.85;
  }

  .hydro-river.rank-trunk {
    stroke-width: 1.22;
  }

  .hydro-river.rank-major {
    stroke-width: 0.88;
  }

  .hydro-river.rank-med {
    stroke-width: 0.62;
  }

  /* Boost UI surface contrast on mobile chrome */
  #nav-bar,
  #scrubber-dock,
  #chronicle-pane {
    background: rgba(243, 238, 228, 0.96);
  }
}

/* Visually hidden semantic SEO index for search engine crawlers & screen readers */
.sr-only-seo {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
