* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #faf8f3;
  color: #2c2c2c;
  min-height: 100vh;
  overflow-x: hidden;
}

header {
  background: linear-gradient(135deg, #fff8ee 0%, #f0e6cc 100%);
  padding: 1.5rem 2rem;
  text-align: center;
  border-bottom: 2px solid #b8860b;
  position: relative;
}

header h1 {
  font-size: 2rem;
  color: #b8860b;
  margin-bottom: 0.25rem;
}

header p {
  font-size: 0.95rem;
  color: #888;
}

.back-link {
  position: absolute;
  left: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: #2563a8;
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link:hover {
  text-decoration: underline;
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: #fff;
  border-bottom: 1px solid #d4c9b5;
  flex-wrap: wrap;
  gap: 1rem;
}

.legend {
  display: flex;
  gap: 1.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: #888;
}

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

.dot.ming { background: #c0392b; }
.dot.qing { background: #b8860b; }
.dot.event-marker { background: #e67e22; border: 2px solid #f39c12; }

.controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: #888;
}

.controls input[type="range"] {
  width: 200px;
  accent-color: #b8860b;
}

.controls button {
  background: #e8e0d0;
  border: 1px solid #d4c9b5;
  color: #2c2c2c;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.controls button:hover {
  background: #d4c9b5;
}

#year-display {
  color: #b8860b;
  font-weight: bold;
}

/* Metro Container */
.metro-container {
  width: 100%;
  overflow: hidden;
  position: relative;
  padding: 1rem 0;
}

.metro-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  padding: 1rem;
  cursor: grab;
}

.metro-scroll:active {
  cursor: grabbing;
}

#metro-svg {
  display: block;
  min-height: 420px;
}

/* SVG styles */
.metro-line {
  stroke-width: 6;
  fill: none;
  stroke-linecap: round;
}

.metro-line.ming { stroke: #c0392b; }
.metro-line.qing { stroke: #b8860b; }

.station-group { cursor: pointer; }

.station-circle {
  stroke: #faf8f3;
  stroke-width: 3;
  transition: r 0.2s, stroke-width 0.2s;
}

.station-circle.ming { fill: #c0392b; }
.station-circle.qing { fill: #b8860b; }

.station-circle:hover {
  stroke-width: 5;
  stroke: #fff;
}

.station-circle.long-reign { r: 16; }
.station-circle.short-reign { r: 10; }
.station-circle.normal-reign { r: 13; }

.station-label {
  fill: #2c2c2c;
  font-size: 12px;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  pointer-events: none;
}

.station-years {
  fill: #888;
  font-size: 10px;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  pointer-events: none;
}

.event-marker {
  fill: #e67e22;
  stroke: #f39c12;
  stroke-width: 2;
  cursor: pointer;
  transition: r 0.2s;
}

.event-marker:hover {
  r: 8;
  stroke: #fff;
}

.event-label {
  fill: #f39c12;
  font-size: 10px;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  pointer-events: none;
}

.year-tick {
  stroke: #d4c9b5;
  stroke-width: 1;
}

.year-label {
  fill: #999;
  font-size: 10px;
  font-family: monospace;
}

.dynasty-label {
  font-size: 18px;
  font-weight: bold;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

.dynasty-label.ming { fill: #c0392b; }
.dynasty-label.qing { fill: #b8860b; }

.connector-line {
  stroke: #999;
  stroke-width: 2;
  stroke-dasharray: 4 4;
}

/* Tooltip */
.tooltip {
  position: fixed;
  background: #f0ebe0;
  border: 1px solid #b8860b;
  border-radius: 8px;
  padding: 1rem;
  max-width: 320px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.tooltip.visible { opacity: 1; }

.tooltip h4 {
  color: #b8860b;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.tooltip p {
  color: #888;
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 0.3rem;
}

.tooltip .era {
  color: #2563a8;
  font-weight: bold;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.15);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: #fff;
  border: 1px solid #d4c9b5;
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  color: #888;
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-close:hover { color: #fff; }

.modal-content h2 {
  color: #b8860b;
  margin-bottom: 1rem;
  font-size: 1.3rem;
}

.modal-content p {
  color: #888;
  line-height: 1.7;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.modal-content .achievements {
  list-style: none;
  padding: 0;
}

.modal-content .achievements li {
  color: #2c2c2c;
  padding: 0.25rem 0;
  padding-left: 1.2rem;
  position: relative;
  font-size: 0.9rem;
}

.modal-content .achievements li::before {
  content: "◆";
  color: #b8860b;
  position: absolute;
  left: 0;
}

.modal-content a.wiki-link {
  display: inline-block;
  margin-top: 1rem;
  color: #2563a8;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border: 1px solid #2563a8;
  border-radius: 6px;
}

.modal-content a.wiki-link:hover {
  background: #2563a8;
  color: #faf8f3;
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem;
  color: #999;
  font-size: 0.8rem;
  border-top: 1px solid #e8e0d0;
  margin-top: 2rem;
}

/* Responsive */
@media (max-width: 768px) {
  header h1 { font-size: 1.5rem; }
  .back-link { position: static; transform: none; display: block; margin-bottom: 0.5rem; }
  .toolbar { flex-direction: column; align-items: flex-start; }
  .controls input[type="range"] { width: 150px; }
}
