html, body, #app {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

#app, .map-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  background-color: #000; /* For Dark Matter tile */
}

/* UI Overlays Default Style */
.map-title, .legend, .chapter-panel, .info-panel, .chat-panel, .loading-bar, .chat-toggle-btn, .novel-selector {
  position: absolute;
  background: rgba(20, 20, 40, 0.9);
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  padding: 15px;
}

/* Novel Selector */
.novel-selector {
  top: 20px;
  left: 20px;
  display: flex;
  gap: 10px;
  padding: 10px;
}

.novel-btn {
  background: transparent;
  color: #aaa;
  border: 1px solid #444;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: bold;
}

.novel-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.novel-btn.active {
  background: #c9a96e;
  border-color: #c9a96e;
  color: #222;
}

/* Map Title */
.map-title {
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
  font-weight: bold;
  color: #c9a96e;
  padding: 15px 30px;
  letter-spacing: 2px;
}

/* Legend */
.legend {
  top: 80px;
  left: 20px;
  max-width: 250px;
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}

.legend h3 {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: #c9a96e;
  border-bottom: 1px solid #444;
  padding-bottom: 5px;
}

.legend-section {
  margin-top: 15px;
}

.legend-item {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  cursor: pointer;
}
.legend-item:hover {
  color: #fff;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
  border: 1px solid #fff;
}

.legend-line {
  width: 20px;
  height: 3px;
  margin-right: 8px;
  flex-shrink: 0;
  box-shadow: 0 0 3px rgba(0,0,0,0.8);
}

/* Chapter Progress Panel */
.chapter-panel {
  bottom: 20px;
  right: 20px;
  width: 500px;
  padding: 20px;
}

.vol-slider-wrap {
  position: relative;
  margin: 20px 0 30px 0;
}

.chapter-slider {
  width: 100%;
  margin: 0;
  cursor: pointer;
  accent-color: #c9a96e;
}

.vol-ticks {
  position: absolute;
  top: 25px;
  left: 0;
  right: 0;
  height: 20px;
  pointer-events: none;
}

.tick-label {
  position: absolute;
  transform: translateX(-50%);
  font-size: 12px;
  color: #aaa;
}

.vol-info {
  text-align: center;
  font-size: 14px;
  color: #c9a96e;
  font-weight: bold;
}

.events-section {
  margin-top: 15px;
  max-height: 120px;
  overflow-y: auto;
  border-top: 1px solid #444;
  padding-top: 10px;
}

.events-title {
  font-weight: bold;
  margin-bottom: 8px;
  color: #c9a96e;
}

.event-item {
  display: flex;
  margin-bottom: 5px;
  font-size: 13px;
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  transition: background 0.2s;
}

.event-item:hover {
  background: rgba(201, 169, 110, 0.2);
}

.event-ch {
  color: #c9a96e;
  min-width: 60px;
  margin-right: 10px;
  flex-shrink: 0;
}

/* Info Panel for Factions/Events */
.info-panel {
  top: 80px;
  right: 20px;
  width: 300px;
  max-height: 400px;
  overflow-y: auto;
}

.info-panel h3 {
  margin-top: 0;
  border-bottom: 1px solid #444;
  padding-bottom: 5px;
}

.info-panel p {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  cursor: pointer;
  font-size: 20px;
  color: #aaa;
}
.close-btn:hover {
  color: #fff;
}

/* Loading Bar */
.loading-bar {
  top: 0;
  left: 0;
  width: 100vw;
  height: 4px;
  background: #222;
  border-radius: 0;
  border: none;
  padding: 0;
  z-index: 2000;
}

.loading-inner {
  height: 100%;
  background: #c9a96e;
  transition: width 0.3s ease;
}

.loading-text {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  color: #c9a96e;
  background: rgba(0,0,0,0.8);
  padding: 5px 15px;
  border-radius: 4px;
}

/* Tooltips */
.city-label-dark, .faction-label-dark {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #e0e0e0;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000, -1px -1px 2px #000, 1px -1px 2px #000, -1px 1px 2px #000;
  white-space: nowrap;
}

.faction-label-dark {
  font-size: 16px;
  letter-spacing: 2px;
}

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: rgba(30, 30, 40, 0.95);
  color: #e0e0e0;
  border: 1px solid #c9a96e;
}
.leaflet-popup-content h4 {
  margin: 0 0 5px 0;
  color: #c9a96e;
}

/* Chat AI UI */
.chat-toggle-btn {
  bottom: 300px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 30px;
  background: linear-gradient(135deg, #1a2a6c, #11998e, #38ef7d);
  color: white;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
  transition: transform 0.2s;
  z-index: 1001;
}

.chat-toggle-btn:hover {
  transform: scale(1.05);
}

.chat-panel {
  bottom: 20px;
  right: 20px;
  width: 350px;
  height: 500px;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.chat-header {
  padding: 15px;
  background: rgba(30, 40, 80, 0.8);
  border-bottom: 1px solid #444;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header h3 {
  margin: 0;
  font-size: 16px;
  color: #00ffcc;
}

.chat-messages {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-bubble.user {
  background: #2b5278;
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.chat-bubble.assistant {
  background: #2a2a35;
  color: #e0e0e0;
  border: 1px solid #444;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}

.chat-bubble.loading {
  font-style: italic;
  opacity: 0.7;
}

.chat-input-area {
  padding: 15px;
  background: rgba(20, 20, 30, 0.95);
  border-top: 1px solid #444;
  display: flex;
  gap: 10px;
}

.chat-input-area input {
  flex: 1;
  padding: 10px 12px;
  background: #111;
  border: 1px solid #555;
  border-radius: 6px;
  color: white;
  outline: none;
}

.chat-input-area input:focus {
  border-color: #00ffcc;
}

.chat-input-area button {
  padding: 0 15px;
  background: #1a2a6c;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}

.chat-input-area button:disabled {
  background: #444;
  color: #888;
  cursor: not-allowed;
}

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #666;
  border-radius: 3px;
}
