/* ═══════════════════════════════════════════════════════════════
   KINGDOM MAP VIEW — Interactive map with markers + sidebar
   Theme: dark medieval gold (#d4a545)
   ═══════════════════════════════════════════════════════════════ */

/* ─── Root Container ─── */
.kc-map-root {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   MAP CONTAINER — Background + Markers
   ═══════════════════════════════════════════════════════════════ */

#kc-map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0e0c08;
}

/* ─── Inner Wrapper (maintains image aspect ratio) ─── */
#kc-map-inner {
  position: relative;
  aspect-ratio: 3 / 2;
  width: 100%;
  max-height: 100%;
  overflow: hidden;
}

/* ─── Background Layers (Day/Night) ─── */
.kc-map-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  pointer-events: none;
}

#kc-map-bg-day {
  z-index: 1;
}

#kc-map-bg-night {
  z-index: 2;
  opacity: 0;
  transition: opacity 3s ease;
}

#kc-map-bg-night.active {
  opacity: 1;
}

/* ─── Markers Layer ─── */
#kc-map-markers {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  overflow: visible;
}

/* ═══════════════════════════════════════════════════════════════
   MAP MARKERS — NPC location icons
   ═══════════════════════════════════════════════════════════════ */

.kc-map-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: pointer;
  text-align: center;
  z-index: 11;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.kc-map-marker:hover,
.kc-map-marker.hovered {
  transform: translate(-50%, -50%) scale(1.12);
  z-index: 15;
  filter: brightness(1.15);
}

.kc-map-marker.highlighted {
  animation: kc-marker-pulse 0.6s ease-in-out 3;
}

@keyframes kc-marker-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); filter: brightness(1); }
  50%      { transform: translate(-50%, -50%) scale(1.2); filter: brightness(1.4) drop-shadow(0 0 12px #d4a545); }
}

/* ─── Golden Circle behind logo (no glow) ─── */
.kc-map-marker::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 58px;
  transform: translate(-50%, -50%);
  width: 95px;
  height: 95px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212, 165, 69, 0.25) 0%, rgba(212, 165, 69, 0.08) 50%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.kc-map-marker:hover::before {
  background: radial-gradient(circle, rgba(212, 165, 69, 0.4) 0%, rgba(212, 165, 69, 0.12) 50%, transparent 70%);
}

/* ─── Logo Image (20% larger: 96 → 115px) ─── */
.kc-marker-logo {
  display: block;
  width: 115px;
  height: 115px;
  object-fit: contain;
  margin: 0 auto;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.7));
  transition: filter 0.2s ease;
  position: relative;
  z-index: 1;
}

.kc-map-marker:hover .kc-marker-logo {
  filter: drop-shadow(0 2px 10px rgba(212, 165, 69, 0.6));
}

/* ─── Fallback Dot (when no logo image) ─── */
.kc-marker-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0 auto;
}

.kc-marker-dot {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd700, #d4a545);
  border: 2px solid rgba(255, 215, 0, 0.4);
  box-shadow: 0 0 8px rgba(212, 165, 69, 0.5);
}

/* ─── Marker Labels — hidden by default, only visible in editor mode ─── */
.kc-marker-label,
.kc-marker-npc-name {
  display: none;
}

/* ─── NPC Picker (multiple NPCs at same building) ─── */
.kc-npc-picker {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 8px;
  background: rgba(14, 12, 8, 0.96);
  border: 1px solid rgba(212, 165, 69, 0.3);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 50;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7), 0 0 12px rgba(212, 165, 69, 0.15);
  animation: kc-picker-in 0.2s ease;
}

@keyframes kc-picker-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.kc-npc-picker-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(212, 165, 69, 0.05);
  border: 1px solid rgba(212, 165, 69, 0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  color: #e8d5a8;
}

.kc-npc-picker-btn:hover {
  background: rgba(212, 165, 69, 0.12);
  border-color: rgba(212, 165, 69, 0.35);
}

.kc-npc-picker-portrait {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(212, 165, 69, 0.3);
  flex-shrink: 0;
}

.kc-npc-picker-name {
  font-family: 'Cinzel', serif;
  font-size: 13px;
  font-weight: 600;
  color: #d4a545;
}

.kc-npc-picker-role {
  font-family: 'Crimson Text', serif;
  font-size: 11px;
  color: rgba(212, 165, 69, 0.6);
  margin-left: auto;
}

/* ─── Night-Only Markers — completely hidden during day ─── */
.kc-night-only.kc-hidden-day {
  display: none;
}

/* ─── Night-Only Tooltip ─── */
.kc-night-tooltip {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 10, 25, 0.95);
  color: #b8a0d4;
  font-family: 'Crimson Text', serif;
  font-size: 12px;
  font-style: italic;
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid rgba(160, 120, 200, 0.3);
  white-space: nowrap;
  pointer-events: none;
  animation: kc-tooltip-fade 2.5s ease forwards;
  z-index: 20;
}

@keyframes kc-tooltip-fade {
  0%   { opacity: 0; transform: translateX(-50%) translateY(4px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR — Location list (enlarged)
   ═══════════════════════════════════════════════════════════════ */

#kc-sidebar {
  width: 320px;
  min-width: 320px;
  background: linear-gradient(180deg, rgba(14, 12, 8, 0.95), rgba(20, 16, 10, 0.98));
  border-left: 1px solid rgba(212, 165, 69, 0.15);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}

#kc-sidebar.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  border-left: none;
}

/* ─── Sidebar Open Button (visible when collapsed) ─── */
#kc-sidebar-open {
  display: none;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 25;
  background: rgba(14, 12, 8, 0.9);
  border: 1px solid rgba(212, 165, 69, 0.4);
  color: #d4a545;
  font-size: 16px;
  cursor: pointer;
  padding: 12px 8px;
  border-radius: 6px 0 0 6px;
  transition: background 0.2s;
}
#kc-sidebar-open.visible {
  display: block;
}
#kc-sidebar-open:hover {
  background: rgba(212, 165, 69, 0.2);
}

/* ─── Sidebar Header ─── */
#kc-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(212, 165, 69, 0.12);
}

.kc-sidebar-title {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  font-weight: 600;
  color: #d4a545;
  letter-spacing: 0.5px;
}

#kc-sidebar-toggle {
  background: none;
  border: 1px solid rgba(212, 165, 69, 0.2);
  color: #d4a545;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 3px;
  transition: background 0.2s;
}

#kc-sidebar-toggle:hover {
  background: rgba(212, 165, 69, 0.1);
}

/* ─── Sidebar List ─── */
#kc-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 165, 69, 0.2) transparent;
}

/* ─── Sidebar Items ─── */
.kc-sidebar-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  cursor: pointer;
  transition: background 0.15s ease;
  border-left: 3px solid transparent;
}

.kc-sidebar-item:hover {
  background: rgba(212, 165, 69, 0.08);
  border-left-color: rgba(212, 165, 69, 0.4);
}

.kc-sidebar-item.locked {
  opacity: 0.4;
  cursor: default;
}

.kc-sidebar-item.locked:hover {
  background: none;
  border-left-color: transparent;
}

.kc-sidebar-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

.kc-sidebar-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.kc-sidebar-name {
  font-family: 'Cinzel', serif;
  font-size: 15px;
  font-weight: 600;
  color: #e8d5a8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kc-sidebar-npc {
  font-family: 'Crimson Text', serif;
  font-size: 14px;
  color: rgba(212, 165, 69, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kc-sidebar-npc.empty {
  color: rgba(150, 140, 120, 0.4);
  font-style: italic;
}

.kc-sidebar-level {
  font-family: 'Cinzel', serif;
  font-size: 13px;
  color: rgba(212, 165, 69, 0.5);
  flex-shrink: 0;
}

.kc-sidebar-night {
  font-size: 14px;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   PHASE INDICATOR — Day/Night timer
   ═══════════════════════════════════════════════════════════════ */

#kc-phase-indicator {
  padding: 12px 16px;
  border-top: 1px solid rgba(212, 165, 69, 0.12);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Cinzel', serif;
  font-size: 14px;
}

#kc-phase-indicator.kc-phase-day {
  color: #f0c050;
}

#kc-phase-indicator.kc-phase-night {
  color: #b8a0d4;
}

.kc-phase-icon {
  font-size: 18px;
}

.kc-phase-time {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

.kc-phase-toggle {
  background: rgba(212, 165, 69, 0.15);
  border: 1px solid rgba(212, 165, 69, 0.3);
  color: #d4a545;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: auto;
  transition: background 0.2s;
}
.kc-phase-toggle:hover {
  background: rgba(212, 165, 69, 0.3);
}

/* ═══════════════════════════════════════════════════════════════
   QUEST BADGES — NPC quest state indicators
   ═══════════════════════════════════════════════════════════════ */

.kc-quest-badge {
  position: absolute;
  top: -4px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel', serif;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  z-index: 12;
  pointer-events: none;
  border: 2px solid rgba(0, 0, 0, 0.6);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* New quest available — gold "!" with bounce */
.kc-quest-available {
  background: radial-gradient(circle at 35% 35%, #ffd700, #b8860b);
  color: #1a0f00;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.6), 0 0 16px rgba(255, 215, 0, 0.3);
  animation: kc-quest-bounce 2s ease-in-out infinite;
}

/* Quest active — slate "..." */
.kc-quest-active {
  background: radial-gradient(circle at 35% 35%, #7a8896, #4a5568);
  color: #e2e8f0;
  font-size: 16px;
  box-shadow: 0 0 6px rgba(100, 120, 140, 0.4);
}

/* Quest completable — bright gold "?" with pulse */
.kc-quest-completable {
  background: radial-gradient(circle at 35% 35%, #ffd700, #daa520);
  color: #1a0f00;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.7), 0 0 20px rgba(255, 215, 0, 0.4);
  animation: kc-quest-pulse 1.5s ease-in-out infinite;
}

/* All quests done — green check */
.kc-quest-done {
  background: radial-gradient(circle at 35% 35%, #48bb78, #276749);
  color: #f0fff4;
  font-size: 12px;
  box-shadow: 0 0 6px rgba(72, 187, 120, 0.4);
}

@keyframes kc-quest-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

@keyframes kc-quest-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 10px rgba(255, 215, 0, 0.7); }
  50%      { transform: scale(1.15); box-shadow: 0 0 16px rgba(255, 215, 0, 0.9); }
}

/* Sidebar quest badge — inline, no absolute positioning */
.kc-sidebar-item .kc-quest-badge {
  position: static;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  font-size: 12px;
}

.kc-sidebar-item .kc-quest-completable,
.kc-sidebar-item .kc-quest-available {
  animation: none;
}

/* ═══════════════════════════════════════════════════════════════
   ANIMATED FLAGS
   ═══════════════════════════════════════════════════════════════ */

.kc-map-flag {
  width: 32px;
  height: 24px;
  object-fit: contain;
  animation: kc-flag-wave 2.5s ease-in-out infinite;
  transform-origin: left center;
  position: absolute;
  pointer-events: none;
  z-index: 8;
}

@keyframes kc-flag-wave {
  0%   { transform: skewY(0deg) scaleX(1); }
  20%  { transform: skewY(-1.5deg) scaleX(0.97); }
  40%  { transform: skewY(1deg) scaleX(1.01); }
  60%  { transform: skewY(-0.5deg) scaleX(0.99); }
  80%  { transform: skewY(1.5deg) scaleX(0.98); }
  100% { transform: skewY(0deg) scaleX(1); }
}

/* Stagger flag animations for natural feel */
.kc-map-flag:nth-child(2n) {
  animation-delay: -0.8s;
  animation-duration: 2.8s;
}
.kc-map-flag:nth-child(3n) {
  animation-delay: -1.4s;
  animation-duration: 2.2s;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  #kc-sidebar {
    width: 240px;
    min-width: 240px;
  }

  .kc-marker-logo {
    width: 86px;
    height: 86px;
  }

  .kc-map-marker::before {
    width: 72px;
    height: 72px;
    top: 43px;
  }

  .kc-sidebar-logo {
    width: 34px;
    height: 34px;
  }

  .kc-quest-badge {
    width: 20px;
    height: 20px;
    font-size: 11px;
    top: -2px;
    right: 4px;
  }
}

@media (max-width: 600px) {
  /* Sidebar overlays on mobile */
  #kc-sidebar {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 240px;
    min-width: 240px;
    z-index: 30;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.6);
  }

  #kc-sidebar.collapsed {
    width: 0;
    min-width: 0;
    box-shadow: none;
  }

  .kc-marker-logo {
    width: 68px;
    height: 68px;
  }

  .kc-map-marker::before {
    width: 56px;
    height: 56px;
    top: 34px;
  }

  .kc-quest-badge {
    width: 18px;
    height: 18px;
    font-size: 10px;
    border-width: 1px;
  }

  /* Reduce animations on mobile for performance */
  .kc-quest-available,
  .kc-quest-completable {
    animation: none;
  }
}

@media (max-width: 480px) {
  .kc-marker-logo {
    width: 44px;
    height: 44px;
  }

  .kc-map-marker::before {
    width: 36px;
    height: 36px;
    top: 22px;
  }

  .kc-quest-badge {
    width: 16px;
    height: 16px;
    font-size: 9px;
    top: -1px;
    right: 0;
  }
}

/* ═══════════════════════════════════════════════════════════════
   DEV: EDITOR MODE (drag & drop markers)
   Toggle via console: window._toggleMapEditor()
   ═══════════════════════════════════════════════════════════════ */

#kc-map-markers.kc-editor-mode {
  outline: 2px dashed rgba(255, 215, 0, 0.4);
  outline-offset: -2px;
}

#kc-map-markers.kc-editor-mode .kc-map-marker {
  cursor: grab;
}

#kc-map-markers.kc-editor-mode .kc-map-marker:active {
  cursor: grabbing;
}

/* Show labels during editing for identification */
.kc-map-marker.kc-editor-visible .kc-marker-label,
.kc-map-marker.kc-editor-visible .kc-marker-npc-name {
  display: block;
  opacity: 1;
  font-family: 'Cinzel', serif;
  font-size: 11px;
  font-weight: 600;
  color: #d4a545;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 6px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
  margin-top: 2px;
}

/* Disable click-through during editing */
.kc-map-marker.kc-editor-visible {
  outline: 1px solid rgba(255, 215, 0, 0.2);
  border-radius: 4px;
}
