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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: #faf8f3;
  color: #555;
  min-height: 100vh;
  font-size: 16px;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

header {
  text-align: center;
  margin-bottom: 20px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.back-btn {
  display: inline-block;
  color: #888;
  text-decoration: none;
  font-size: 16px;
  padding: 6px 14px;
  border: 1px solid #bbb;
  border-radius: 6px;
  transition: color 0.2s, border-color 0.2s;
}

.back-btn:hover {
  color: #b8860b;
  border-color: #b8860b;
}

header h1 {
  font-size: 28px;
  color: #b8860b;
  margin-bottom: 4px;
}

header .subtitle {
  font-size: 15px;
  color: #888;
}

main {
  display: flex;
  gap: 20px;
  height: calc(100vh - 180px);
  min-height: 500px;
}

#map-container {
  flex: 2;
  background: #fff8ee;
  border-radius: 12px;
  border: 1px solid #555;
  overflow: hidden;
  position: relative;
}

#palace-map {
  width: 100%;
  height: 100%;
}

#sidebar {
  flex: 1;
  background: #f0e6cc;
  border-radius: 12px;
  border: 1px solid #555;
  overflow-y: auto;
  min-width: 350px;
  max-width: 450px;
}

#sidebar-content {
  padding: 20px;
}

.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #666;
}

.placeholder .icon { font-size: 64px; margin-bottom: 16px; }
.placeholder h2 { font-size: 20px; margin-bottom: 8px; color: #888; }
.placeholder p { font-size: 16px; }

/* Palace rectangles in SVG */
.palace-rect {
  cursor: pointer;
  transition: filter 0.2s, stroke-width 0.2s;
  stroke-width: 2;
  stroke: transparent;
}

.palace-rect:hover {
  filter: brightness(1.4);
  stroke: #fff;
  stroke-width: 3;
}

.palace-rect.selected {
  stroke: #fff;
  stroke-width: 4;
  filter: brightness(1.5);
}

.palace-rect.dimmed {
  opacity: 0.3;
}

.palace-label {
  font-size: 15px;
  font-weight: bold;
  fill: #fff;
  text-anchor: middle;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.palace-alias {
  font-size: 12px;
  fill: #555;
  text-anchor: middle;
  pointer-events: none;
}

/* Sidebar palace detail */
.palace-detail h2 {
  font-size: 24px;
  color: #b8860b;
  margin-bottom: 6px;
}

.palace-detail .aliases {
  font-size: 15px;
  color: #888;
  margin-bottom: 12px;
}

.palace-detail .description {
  font-size: 16px;
  line-height: 1.8;
  margin-bottom: 16px;
  color: #555;
}

.palace-detail .info-grid {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 6px 12px;
  font-size: 15px;
  margin-bottom: 16px;
}

.palace-detail .info-label { color: #888; }
.palace-detail .info-value { color: #555; }

.section-title {
  font-size: 17px;
  color: #b8860b;
  border-bottom: 1px solid #555;
  padding-bottom: 6px;
  margin: 16px 0 10px;
}

.relation-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid #e0d5c0;
  font-size: 15px;
}

.relation-item .type-badge {
  background: #b8860b22;
  color: #b8860b;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 13px;
  white-space: nowrap;
  margin-top: 2px;
}

.relation-item .details { flex: 1; }
.relation-item .details .name { color: #555; font-weight: bold; }
.relation-item .details .note { color: #888; font-size: 14px; margin-top: 2px; }

.event-item {
  padding: 12px;
  background: #fff8ee;
  border-radius: 6px;
  margin-bottom: 10px;
  font-size: 15px;
}

.event-item .event-name {
  color: #e74c3c;
  font-weight: bold;
  margin-bottom: 4px;
  font-size: 16px;
}

.event-item .event-desc { color: #666; line-height: 1.6; font-size: 15px; }
.event-item .event-year { color: #888; font-size: 13px; margin-top: 4px; }

/* Timeline bar */
#timeline-bar {
  margin-top: 16px;
  padding: 14px 20px;
  background: #f0e6cc;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
}

#timeline-bar label { color: #888; }

#year-slider {
  flex: 1;
  accent-color: #b8860b;
  height: 6px;
}

#year-display {
  color: #b8860b;
  font-weight: bold;
  min-width: 70px;
}

#dynasty-display {
  color: #888;
  min-width: 100px;
}

/* Responsive */
@media (max-width: 900px) {
  #app { padding: 12px; }

  header { margin-bottom: 12px; }
  header h1 { font-size: 24px; }
  header .subtitle { font-size: 14px; }
  .back-btn { font-size: 14px; padding: 4px 10px; }

  main {
    flex-direction: column;
    height: auto;
    gap: 12px;
  }

  #map-container {
    min-height: 50vh;
    width: 100%;
  }

  #sidebar {
    min-width: unset;
    max-width: unset;
    max-height: none;
    width: 100%;
  }

  #sidebar-content { padding: 16px; }

  .palace-detail h2 { font-size: 22px; }
  .palace-detail .description { font-size: 16px; }
  .palace-detail .info-grid { font-size: 15px; }
  .section-title { font-size: 17px; }
  .relation-item { font-size: 15px; }
  .event-item { font-size: 15px; }

  #timeline-bar {
    flex-wrap: wrap;
    font-size: 14px;
    padding: 12px;
    gap: 8px;
  }

  #year-slider { order: 3; width: 100%; flex: unset; }
}

@media (max-width: 480px) {
  header h1 { font-size: 20px; }
  .back-btn { font-size: 13px; padding: 3px 8px; }
  .palace-detail h2 { font-size: 20px; }
  .palace-detail .description { font-size: 15px; }
  .relation-item { font-size: 14px; }
  .event-item { font-size: 14px; padding: 10px; }
  .event-item .event-name { font-size: 15px; }
  #timeline-bar { font-size: 13px; }
}
